diff --git a/scripts/examples/OpenMV/12-Thermopile-Shield/AMG8833_camera.py b/scripts/examples/Arduino/Nano 33 BLE Sense/04-Thermal/thermal_camera.py similarity index 68% rename from scripts/examples/OpenMV/12-Thermopile-Shield/AMG8833_camera.py rename to scripts/examples/Arduino/Nano 33 BLE Sense/04-Thermal/thermal_camera.py index 7445630f1..008a96d44 100644 --- a/scripts/examples/OpenMV/12-Thermopile-Shield/AMG8833_camera.py +++ b/scripts/examples/Arduino/Nano 33 BLE Sense/04-Thermal/thermal_camera.py @@ -1,4 +1,4 @@ -# AMG8833 Camera Demo +# Thermal Camera Demo # # This example shows off how to overlay a heatmap onto your OpenMV Cam's # live video output from the main camera. @@ -8,9 +8,19 @@ import image, time, fir drawing_hint = image.BICUBIC # or image.BILINEAR or 0 (nearest neighbor) # Initialize the thermal sensor -fir.init(type=fir.FIR_AMG8833) -w = fir.width() * 20 -h = fir.height() * 20 +fir.init() +w = fir.width() +h = fir.height() + +if (fir.type() == fir.FIR_MLX90621): + w = w * 5 + h = h * 5 +elif (fir.type() == fir.FIR_MLX90640): + w = w * 5 + h = h * 5 +elif (fir.type() == fir.FIR_AMG8833): + w = w * 10 + h = h * 10 # FPS clock clock = time.clock() diff --git a/scripts/examples/OpenMV/12-Thermopile-Shield/MLX90621_camera.py b/scripts/examples/OpenMV/12-Thermopile-Shield/MLX90621_camera.py deleted file mode 100644 index 8ff134991..000000000 --- a/scripts/examples/OpenMV/12-Thermopile-Shield/MLX90621_camera.py +++ /dev/null @@ -1,29 +0,0 @@ -# MLX90621 Camera Demo -# -# This example shows off how to overlay a heatmap onto your OpenMV Cam's -# live video output from the main camera. - -import image, time, fir - -drawing_hint = image.BICUBIC # or image.BILINEAR or 0 (nearest neighbor) - -# Initialize the thermal sensor -fir.init(type=fir.FIR_MLX90621) -w = fir.width() * 20 -h = fir.height() * 20 - -# FPS clock -clock = time.clock() - -while (True): - clock.tick() - - try: - img = fir.snapshot(x_size=w, y_size=h, - color_palette=fir.PALETTE_IRONBOW, hint=drawing_hint, - copy_to_fb=True) - except OSError: - continue - - # Print FPS. - print(clock.fps()) diff --git a/scripts/examples/OpenMV/12-Thermopile-Shield/MLX90621_overlay.py b/scripts/examples/OpenMV/12-Thermopile-Shield/MLX90621_overlay.py deleted file mode 100644 index b049ec383..000000000 --- a/scripts/examples/OpenMV/12-Thermopile-Shield/MLX90621_overlay.py +++ /dev/null @@ -1,60 +0,0 @@ -# MLX90621 Overlay Demo -# -# This example shows off how to overlay a heatmap onto your OpenMV Cam's -# live video output from the main camera. - -import sensor, image, time, fir - -drawing_hint = image.BICUBIC # or image.BILINEAR or 0 (nearest neighbor) - -ALT_OVERLAY = False # Set to True to allocate a second ir image. - -sensor.reset() -sensor.set_pixformat(sensor.RGB565) -sensor.set_framesize(sensor.QQVGA) -sensor.skip_frames(time = 2000) - -# Initialize the thermal sensor -fir.init(type=fir.FIR_MLX90621) - -# Allocate another frame buffer for smoother video. -extra_fb = sensor.alloc_extra_fb(sensor.width(), sensor.height(), sensor.RGB565) - -# FPS clock -clock = time.clock() - -while (True): - clock.tick() - - # Capture an image - img = sensor.snapshot() - - # Capture FIR data - # ta: Ambient temperature - # ir: Object temperatures (IR array) - # to_min: Minimum object temperature - # to_max: Maximum object temperature - try: - ta, ir, to_min, to_max = fir.read_ir() - except OSError: - continue - - if not ALT_OVERLAY: - # Scale the image and belnd it with the framebuffer - fir.draw_ir(img, ir, hint=drawing_hint) - else: - # Create a secondary image and then blend into the frame buffer. - extra_fb.clear() - fir.draw_ir(extra_fb, ir, alpha=256, hint=drawing_hint) - img.blend(extra_fb, alpha=128) - - # Draw ambient, min and max temperatures. - img.draw_string(8, 0, "Ta: %0.2f C" % ta, color = (255, 0, 0), mono_space = False) - img.draw_string(8, 8, "To min: %0.2f C" % to_min, color = (255, 0, 0), mono_space = False) - img.draw_string(8, 16, "To max: %0.2f C"% to_max, color = (255, 0, 0), mono_space = False) - - # Force high quality streaming... - img.compress(quality=90) - - # Print FPS. - print(clock.fps()) diff --git a/scripts/examples/OpenMV/12-Thermopile-Shield/MLX90621_overlay_lcd.py b/scripts/examples/OpenMV/12-Thermopile-Shield/MLX90621_overlay_lcd.py deleted file mode 100644 index bacb37ed7..000000000 --- a/scripts/examples/OpenMV/12-Thermopile-Shield/MLX90621_overlay_lcd.py +++ /dev/null @@ -1,64 +0,0 @@ -# MLX90621 Overlay Demo -# -# This example shows off how to overlay a heatmap onto your OpenMV Cam's -# live video output from the main camera. - -import sensor, image, time, fir, lcd - -drawing_hint = image.BICUBIC # or image.BILINEAR or 0 (nearest neighbor) - -ALT_OVERLAY = False # Set to True to allocate a second ir image. - -sensor.reset() -sensor.set_pixformat(sensor.RGB565) -sensor.set_framesize(sensor.QQVGA2) -sensor.skip_frames(time = 2000) - -# Initialize the thermal sensor -fir.init(type=fir.FIR_MLX90621) - -# Init the lcd. -lcd.init() - -# Allocate another frame buffer for smoother video. -extra_fb = sensor.alloc_extra_fb(sensor.width(), sensor.height(), sensor.RGB565) - -# FPS clock -clock = time.clock() - -while (True): - clock.tick() - - # Capture an image - img = sensor.snapshot() - - # Capture FIR data - # ta: Ambient temperature - # ir: Object temperatures (IR array) - # to_min: Minimum object temperature - # to_max: Maximum object temperature - try: - ta, ir, to_min, to_max = fir.read_ir() - except OSError: - continue - - if not ALT_OVERLAY: - # Scale the image and belnd it with the framebuffer - fir.draw_ir(img, ir, hint=drawing_hint) - else: - # Create a secondary image and then blend into the frame buffer. - extra_fb.clear() - fir.draw_ir(extra_fb, ir, alpha=256, hint=drawing_hint) - img.blend(extra_fb, alpha=128) - - # Draw ambient, min and max temperatures. - img.draw_string(8, 0, "Ta: %0.2f C" % ta, color = (255, 0, 0), mono_space = False) - img.draw_string(8, 8, "To min: %0.2f C" % to_min, color = (255, 0, 0), mono_space = False) - img.draw_string(8, 16, "To max: %0.2f C"% to_max, color = (255, 0, 0), mono_space = False) - - lcd.display(img) - # Force high quality streaming... - img.compress(quality=90) - - # Print FPS. - print(clock.fps()) diff --git a/scripts/examples/OpenMV/12-Thermopile-Shield/MLX90640_overlay.py b/scripts/examples/OpenMV/12-Thermopile-Shield/MLX90640_overlay.py deleted file mode 100644 index da684df17..000000000 --- a/scripts/examples/OpenMV/12-Thermopile-Shield/MLX90640_overlay.py +++ /dev/null @@ -1,60 +0,0 @@ -# MLX90640 Overlay Demo -# -# This example shows off how to overlay a heatmap onto your OpenMV Cam's -# live video output from the main camera. - -import sensor, image, time, fir - -drawing_hint = image.BICUBIC # or image.BILINEAR or 0 (nearest neighbor) - -ALT_OVERLAY = False # Set to True to allocate a second ir image. - -sensor.reset() -sensor.set_pixformat(sensor.RGB565) -sensor.set_framesize(sensor.QQVGA) -sensor.skip_frames(time = 2000) - -# Initialize the thermal sensor -fir.init(type=fir.FIR_MLX90640, refresh=32) # 16Hz, 32Hz or 64Hz. - -# Allocate another frame buffer for smoother video. -extra_fb = sensor.alloc_extra_fb(sensor.width(), sensor.height(), sensor.RGB565) - -# FPS clock -clock = time.clock() - -while (True): - clock.tick() - - # Capture an image - img = sensor.snapshot() - - # Capture FIR data - # ta: Ambient temperature - # ir: Object temperatures (IR array) - # to_min: Minimum object temperature - # to_max: Maximum object temperature - try: - ta, ir, to_min, to_max = fir.read_ir() - except OSError: - continue - - if not ALT_OVERLAY: - # Scale the image and belnd it with the framebuffer - fir.draw_ir(img, ir, hint=drawing_hint) - else: - # Create a secondary image and then blend into the frame buffer. - extra_fb.clear() - fir.draw_ir(extra_fb, ir, alpha=256, hint=drawing_hint) - img.blend(extra_fb, alpha=128) - - # Draw ambient, min and max temperatures. - img.draw_string(8, 0, "Ta: %0.2f C" % ta, color = (255, 0, 0), mono_space = False) - img.draw_string(8, 8, "To min: %0.2f C" % to_min, color = (255, 0, 0), mono_space = False) - img.draw_string(8, 16, "To max: %0.2f C"% to_max, color = (255, 0, 0), mono_space = False) - - # Force high quality streaming... - img.compress(quality=90) - - # Print FPS. - print(clock.fps()) diff --git a/scripts/examples/OpenMV/12-Thermopile-Shield/MLX90640_overlay_lcd.py b/scripts/examples/OpenMV/12-Thermopile-Shield/MLX90640_overlay_lcd.py deleted file mode 100644 index da96c2546..000000000 --- a/scripts/examples/OpenMV/12-Thermopile-Shield/MLX90640_overlay_lcd.py +++ /dev/null @@ -1,64 +0,0 @@ -# MLX90640 Overlay Demo -# -# This example shows off how to overlay a heatmap onto your OpenMV Cam's -# live video output from the main camera. - -import sensor, image, time, fir, lcd - -drawing_hint = image.BICUBIC # or image.BILINEAR or 0 (nearest neighbor) - -ALT_OVERLAY = False # Set to True to allocate a second ir image. - -sensor.reset() -sensor.set_pixformat(sensor.RGB565) -sensor.set_framesize(sensor.QQVGA2) -sensor.skip_frames(time = 2000) - -# Initialize the thermal sensor -fir.init(type=fir.FIR_MLX90640, refresh=32) # 16Hz, 32Hz or 64Hz. - -# Init the lcd. -lcd.init() - -# Allocate another frame buffer for smoother video. -extra_fb = sensor.alloc_extra_fb(sensor.width(), sensor.height(), sensor.RGB565) - -# FPS clock -clock = time.clock() - -while (True): - clock.tick() - - # Capture an image - img = sensor.snapshot() - - # Capture FIR data - # ta: Ambient temperature - # ir: Object temperatures (IR array) - # to_min: Minimum object temperature - # to_max: Maximum object temperature - try: - ta, ir, to_min, to_max = fir.read_ir() - except OSError: - continue - - if not ALT_OVERLAY: - # Scale the image and belnd it with the framebuffer - fir.draw_ir(img, ir, hint=drawing_hint) - else: - # Create a secondary image and then blend into the frame buffer. - extra_fb.clear() - fir.draw_ir(extra_fb, ir, alpha=256, hint=drawing_hint) - img.blend(extra_fb, alpha=128) - - # Draw ambient, min and max temperatures. - img.draw_string(8, 0, "Ta: %0.2f C" % ta, color = (255, 0, 0), mono_space = False) - img.draw_string(8, 8, "To min: %0.2f C" % to_min, color = (255, 0, 0), mono_space = False) - img.draw_string(8, 16, "To max: %0.2f C"% to_max, color = (255, 0, 0), mono_space = False) - - lcd.display(img) - # Force high quality streaming... - img.compress(quality=90) - - # Print FPS. - print(clock.fps()) diff --git a/scripts/examples/OpenMV/12-Thermopile-Shield/MLX90640_camera.py b/scripts/examples/OpenMV/12-Thermopile-Shield/thermal_camera.py similarity index 67% rename from scripts/examples/OpenMV/12-Thermopile-Shield/MLX90640_camera.py rename to scripts/examples/OpenMV/12-Thermopile-Shield/thermal_camera.py index a218ea335..59249a416 100644 --- a/scripts/examples/OpenMV/12-Thermopile-Shield/MLX90640_camera.py +++ b/scripts/examples/OpenMV/12-Thermopile-Shield/thermal_camera.py @@ -1,4 +1,4 @@ -# MLX90640 Camera Demo +# Thermal Camera Demo # # This example shows off how to overlay a heatmap onto your OpenMV Cam's # live video output from the main camera. @@ -8,9 +8,19 @@ import image, time, fir drawing_hint = image.BICUBIC # or image.BILINEAR or 0 (nearest neighbor) # Initialize the thermal sensor -fir.init(type=fir.FIR_MLX90640) -w = fir.width() * 10 -h = fir.height() * 10 +fir.init() +w = fir.width() +h = fir.height() + +if (fir.type() == fir.FIR_MLX90621): + w = w * 10 + h = h * 10 +elif (fir.type() == fir.FIR_MLX90640): + w = w * 10 + h = h * 10 +elif (fir.type() == fir.FIR_AMG8833): + w = w * 20 + h = h * 20 # FPS clock clock = time.clock() diff --git a/scripts/examples/OpenMV/12-Thermopile-Shield/AMG8833_overlay.py b/scripts/examples/OpenMV/12-Thermopile-Shield/thermal_overlay.py similarity index 97% rename from scripts/examples/OpenMV/12-Thermopile-Shield/AMG8833_overlay.py rename to scripts/examples/OpenMV/12-Thermopile-Shield/thermal_overlay.py index 85b7c44ef..cba9fe8f6 100644 --- a/scripts/examples/OpenMV/12-Thermopile-Shield/AMG8833_overlay.py +++ b/scripts/examples/OpenMV/12-Thermopile-Shield/thermal_overlay.py @@ -1,4 +1,4 @@ -# AMG8833 Overlay Demo +# Thermal Overlay Demo # # This example shows off how to overlay a heatmap onto your OpenMV Cam's # live video output from the main camera. @@ -15,7 +15,7 @@ sensor.set_framesize(sensor.QQVGA) sensor.skip_frames(time = 2000) # Initialize the thermal sensor -fir.init(type=fir.FIR_AMG8833) +fir.init() # Allocate another frame buffer for smoother video. extra_fb = sensor.alloc_extra_fb(sensor.width(), sensor.height(), sensor.RGB565) diff --git a/scripts/examples/OpenMV/12-Thermopile-Shield/AMG8833_overlay_lcd.py b/scripts/examples/OpenMV/12-Thermopile-Shield/thermal_overlay_lcd.py similarity index 97% rename from scripts/examples/OpenMV/12-Thermopile-Shield/AMG8833_overlay_lcd.py rename to scripts/examples/OpenMV/12-Thermopile-Shield/thermal_overlay_lcd.py index a1619b9d7..4ed8e92d9 100644 --- a/scripts/examples/OpenMV/12-Thermopile-Shield/AMG8833_overlay_lcd.py +++ b/scripts/examples/OpenMV/12-Thermopile-Shield/thermal_overlay_lcd.py @@ -1,4 +1,4 @@ -# AMG8833 Overlay Demo +# Thermal Overlay Demo # # This example shows off how to overlay a heatmap onto your OpenMV Cam's # live video output from the main camera. @@ -15,7 +15,7 @@ sensor.set_framesize(sensor.QQVGA2) sensor.skip_frames(time = 2000) # Initialize the thermal sensor -fir.init(type=fir.FIR_AMG8833) +fir.init() # Init the lcd. lcd.init() diff --git a/src/omv/modules/py_fir.c b/src/omv/modules/py_fir.c index be4deb3b4..18dc7eb52 100644 --- a/src/omv/modules/py_fir.c +++ b/src/omv/modules/py_fir.c @@ -31,7 +31,7 @@ #include "py_fir_lepton.h" #endif -#define MLX90621_ADDR 0xC0 +#define MLX90621_ADDR 0x50 #define MLX90621_WIDTH 16 #define MLX90621_HEIGHT 4 #define MLX90621_EEPROM_DATA_SIZE 256 @@ -51,6 +51,8 @@ #define AMG8833_TEMPERATURE_REGISTER 0x80 #define AMG8833_INITIAL_RESET_VALUE 0x3F +#define LEPTON_ADDR 0x54 + #define AMG8833_12_TO_16(value) \ ({ \ __typeof__ (value) __value = (value); \ @@ -284,7 +286,41 @@ mp_obj_t py_fir_init(uint n_args, const mp_obj_t *args, mp_map_t *kw_args) { py_fir_deinit(); bool first_init = true; - switch (py_helper_keyword_int(n_args, args, 0, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_type), FIR_MLX90621)) { + int type = py_helper_keyword_int(n_args, args, 0, kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_type), -1); + if (type == -1) { + cambus_init(&fir_bus, FIR_I2C_ID, CAMBUS_SPEED_STANDARD); + switch (cambus_scan(&fir_bus)) { + #if (OMV_ENABLE_FIR_MLX90621 == 1) + case (MLX90621_ADDR << 1): { + type = FIR_MLX90621; + break; + } + #endif + #if (OMV_ENABLE_FIR_MLX90640 == 1) + case (MLX90640_ADDR << 1): { + type = FIR_MLX90640; + break; + } + #endif + #if (OMV_ENABLE_FIR_AMG8833 == 1) + case AMG8833_ADDR: { + type = FIR_AMG8833; + break; + } + #endif + #if (OMV_ENABLE_FIR_LEPTON == 1) + case LEPTON_ADDR: { + type = FIR_LEPTON; + break; + } + #endif + default: { + nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "No device type found!")); + } + } + cambus_deinit(&fir_bus); + } + switch (type) { case FIR_NONE: { return mp_const_none; }