fir — thermal sensor driver (fir == far infrared)

The fir module is used for controlling the thermal sensors.

Example usage:

import csi, fir

# Setup camera.
csi0 = csi.CSI()
csi0.reset()
csi0.pixformat(csi.RGB565)
csi0.framesize(csi.QVGA)
csi0.snapshot(time=2000)
fir.init()

# Show image.
while(True):
    img = csi0.snapshot()
    ta, ir, to_min, to_max = fir.read_ir()
    fir.draw_ir(img, ir)
    print("====================")
    print("Ambient temperature: %0.2f" % ta)
    print("Min temperature seen: %0.2f" % to_min)
    print("Max temperature seen: %0.2f" % to_max)

Functions

fir.init(type: int = -1, refresh: int | None = None, resolution: int | None = None) None

Initializes an attached thermal sensor.

type indicates the type of thermal sensor:

By default type is -1 which causes fir.init() to automatically scan and initialize an attached thermal sensor based on its I2C address. Note that fir.FIR_MLX90640 and fir.FIR_MLX90641 share the same I2C address so you must pass fir.FIR_MLX90641 to type to initialize it specifically.

refresh is the thermal sensor refresh rate in Hz:

A higher refresh rate lowers the accuracy and vice-versa.

resolution is the thermal sensor measurement resolution in bits:

A higher resolution lowers the maximum temperature range and vice-versa.

fir.deinit() None

Deinitializes the thermal sensor and frees up resources.

fir.width() int

Returns the horizontal resolution (in pixels) of the thermal sensor in-use.

fir.height() int

Returns the vertical resolution (in pixels) of the thermal sensor in-use.

fir.type() int

Returns the type of the thermal sensor in-use. One of fir.FIR_MLX90621, fir.FIR_MLX90640, fir.FIR_MLX90641, or fir.FIR_AMG8833.

fir.refresh() int

Returns the current refresh rate (Hz) set during the fir.init() call.

fir.resolution() int

Returns the current resolution (bits) set during the fir.init() call.

fir.read_ta() float

Returns the ambient temperature (i.e. sensor temperature) in celsius as a float.

fir.read_ir(hmirror: bool = False, vflip: bool = False, transpose: bool = False, timeout: int = -1) Tuple[float, List[float], float, float]

Returns a 4-tuple (ta, ir, to_min, to_max) containing the ambient temperature, a flat width * height list of float temperatures, the minimum temperature seen, and the maximum temperature seen. All values are in celsius.

hmirror if True horizontally mirrors the ir array.

vflip if True vertically flips the ir array.

transpose if True transposes the ir array (swaps width and height).

timeout if not -1, the number of milliseconds to wait for a new frame.

fir.draw_ir(image: image.Image, ir: List[float], x: int = 0, y: int = 0, x_scale: float | None = None, y_scale: float | None = None, roi: Tuple[int, int, int, int] | None = None, rgb_channel: int = -1, alpha: int = 255, color_palette: int | None = image.PALETTE_RAINBOW, alpha_palette: int | None = None, hint: int = 0, scale: Tuple[float, float] | None = None) None

Draws the ir array onto image with its top-left corner at (x, y).

ir is the flat width * height temperature list returned by fir.read_ir().

x_scale controls how much the rendered image is scaled in the x direction. A negative value flips horizontally. If unspecified, matches y_scale to maintain aspect ratio.

y_scale controls how much the rendered image is scaled in the y direction. A negative value flips vertically. If unspecified, matches x_scale to maintain aspect ratio.

roi is the region-of-interest rectangle (x, y, w, h) of the source IR data to draw.

rgb_channel is the RGB channel (0=R, 1=G, 2=B) to render onto the destination image when the destination is RGB565. -1 (default) renders all channels.

alpha controls how much of the source image to blend into the destination (0-255). 255 is fully opaque; 0 results in no modification.

color_palette is a color palette enum (e.g. image.PALETTE_RAINBOW, image.PALETTE_IRONBOW) or a 256-pixel RGB565 image used as a lookup table on the grayscale source value.

alpha_palette is a 256-pixel GRAYSCALE image used as an alpha lookup table that modulates alpha per source pixel value.

hint is a logical OR of:

scale is a 2-tuple (min, max) controlling the min/max temperature (in celsius) used to scale the ir array. Defaults to the actual ir min and max.

fir.snapshot(hmirror: bool = False, vflip: bool = False, transpose: bool = False, x_scale: float | None = None, y_scale: float | None = None, roi: Tuple[int, int, int, int] | None = None, rgb_channel: int = -1, alpha: int = 255, color_palette: int | None = image.PALETTE_RAINBOW, alpha_palette: int | None = None, hint: int = 0, scale: Tuple[float, float] | None = None, pixformat: int = image.RGB565, copy_to_fb: bool = False, timeout: int = -1) image.Image

Captures a frame from the thermal sensor and returns it as an image.Image. Works similarly to sensor.snapshot(). If copy_to_fb is False the new image is allocated on the MicroPython heap (which is limited); set copy_to_fb to True to write the result into the frame buffer instead.

hmirror if True horizontally mirrors the new image.

vflip if True vertically flips the new image.

transpose if True transposes the new image.

x_scale controls how much the new image is scaled in the x direction. A negative value flips horizontally. If unspecified, matches y_scale to maintain aspect ratio.

y_scale controls how much the new image is scaled in the y direction. A negative value flips vertically. If unspecified, matches x_scale to maintain aspect ratio.

roi is the region-of-interest rectangle (x, y, w, h) of the source IR data to draw.

rgb_channel is the RGB channel (0=R, 1=G, 2=B) to render. -1 (default) renders all channels.

alpha controls how much of the source image is blended (0-255). 255 is fully opaque.

color_palette is a color palette enum or a 256-pixel RGB565 image used as a lookup table on the grayscale source value.

alpha_palette is a 256-pixel GRAYSCALE image used as an alpha lookup table.

hint is a logical OR of the same flags accepted by fir.draw_ir().

scale is a 2-tuple (min, max) controlling the min/max temperature (in celsius) used to scale the IR array. Defaults to the actual IR min and max.

pixformat controls the output pixel format. Must be image.GRAYSCALE or image.RGB565.

copy_to_fb if True writes the result into the frame buffer instead of allocating on the heap.

timeout if not -1, the number of milliseconds to wait for a new frame.

Constants

fir.FIR_SHIELD: int

The OpenMV Cam Thermopile Shield (MLX90621). Alias for fir.FIR_MLX90621.

fir.FIR_MLX90621: int

MLX90621 thermal sensor (16x4).

fir.FIR_MLX90640: int

MLX90640 thermal sensor (32x24).

fir.FIR_MLX90641: int

MLX90641 thermal sensor (16x12).

fir.FIR_AMG8833: int

AMG8833 thermal sensor (8x8).