def __init__(self, txt_rf_ms, verbose): self.txt_rf_ms = txt_rf_ms self.verbose = verbose self.tmax = 30 # Initial temperature range self.tmin = 15 self.mode = _NORM # Enable initial update self.rf_disp = True self.rf_txt = True # Instantiate color mapper self.mapper = Mapper(self.tmin, self.tmax) # Instantiate switches self.timer = Delay_ms(duration=2000) # Long press delay # Release arg rarg enables calling switch to be identified. for item in (('X4', self.chmax, 5, self.ar, 0), ('Y1', self.chmax, -5, self.ar, 1), ('X5', self.chmin, 5, eliza, 2), ('X6', self.chmin, -5, eliza, 3)): sw, func, arg, long_func, rarg = item cs = Switch(Pin(sw, Pin.IN, Pin.PULL_UP)) cs.close_func(self.press, (func, arg)) cs.open_func(self.release, (long_func, rarg)) # Instantiate display pdc = Pin('X1', Pin.OUT_PP, value=0) pcs = Pin('X2', Pin.OUT_PP, value=1) prst = Pin('X3', Pin.OUT_PP, value=1) # In practice baudrate made no difference to update rate which is # dominated by interpolation time spi = SPI(2, baudrate=13_500_000) verbose and print('SPI:', spi) ssd = SSD(spi, pcs, pdc, prst) # Create a display instance ssd.fill(0) ssd.show() self.avg = 0.0 # Instantiate PIR temperature sensor i2c = I2C(2) pir = AMG88XX(i2c) pir.ma_mode(True) # Moving average mode # Run the camera asyncio.create_task(self.run(pir, ssd))
def read_temperature(): '''Read temperatures from sensor on I2C bus and set the highest detected temperature to variable highest_pixel_value.''' i2c = machine.I2C(1) sensor = AMG88XX(i2c) try: while True: highest_pixel_temp = 0 utime.sleep(0.2) sensor.refresh() #refresh values from all pixels in sensor. for row in range(8): for col in range(8): if sensor[ row, col] > highest_pixel_temp: #select the highest of the pixel 64 detected temperatures highest_pixel_value = sensor[row, col] return highest_pixel_temp except Exception as e: print("Temperature read error: " + str(e))
from time import ticks_us, ticks_diff, sleep_ms from amg88xx import AMG88XX from helper import busio, dio # Die 5V-Spannungsversorgung muss aktiviert werden, falls die Wärmebildkamera # an ein Robotling-Board angeschlossen ist dio.DigitalOut(16, value=True) try: # I2C-Objekt erstellen, 400 kHz Busfrequenz, SCL an Pin 22, SDA and Pin 23 i2c = busio.I2CBus(400000, 22, 23) # Wärmebildkamera-Treiber starten und etwas warten amg = AMG88XX(i2c) sleep_ms(500) # Beispielbild einlesen, es entspricht einer 1D Liste von 64 (8x8 pixel) # Temperaturwerten (in °Celsius) img = list(amg.pixels_64x1) print("Image:", img) print() def find_some_blobs(n): # Liest `n` Bilder ein und versucht Blobs zu finden. Dazu wird die # Funktion `find_blobs` aus dem Modul `blob` benutzt; `find_blobs` läuft # auf dem Mikrokontroller. Die gefundenen Blobs und die mittlere Lauf- # zeit von `find_blobs` werden ausgegeben. delta = 0 for i in range(n): # Bild einlesen img = list(amg.pixels_64x1)
# Instantiate color mapper mapper = Mapper(TMIN, TMAX) # Instantiate display pdc = machine.Pin('X1', machine.Pin.OUT_PP, value=0) pcs = machine.Pin('X2', machine.Pin.OUT_PP, value=1) prst = machine.Pin('X3', machine.Pin.OUT_PP, value=1) spi = machine.SPI(1) ssd = SSD1331(spi, pcs, pdc, prst) ssd.fill(0) ssd.show() # Instantiate temperature sensor i2c = machine.I2C(1) sensor = AMG88XX(i2c) sensor.ma_mode(True) # Moving average mode # Demo use in timer callback. No point in running faster than 10Hz as this is # the update rate of the chip. # tim = pyb.Timer(1) # tim.init(freq=10) # tim.callback(sensor.refresh) # Draw color scale at right of display col = 80 val = TMIN dt = (TMAX - TMIN) / 32 for row in range(63, -1, -2): ssd.fill_rect(col, row, 15, 2, ssd.rgb(*mapper(int(val)))) val += dt