Unlocking the MLX90640 IR Sensor for MicroPython

Introduction

In order to use an IR / thermal camera for detecting brood nest and winter cluster, @clemens already got his hands dirty collecting some bits of software support from the community, essentially making the MLX90640 IR Sensor work on ESP32 MCUs, see also Getting the MLX90640 IR Sensor Running with an ESP32.

Thoughts

In the spirit of native 1-Wire support for Pycom/ESP32 and I2S support for MicroPython on ESP32, it would be cool to see this device supported through MicroPython for ESP32 by creating an appropriate binding to a respective extension to the ESP-IDF/FreeRTOS.

Quick research

While there are obviously some implementations for Python running on a RaspberryPi around like

this is not exactly what we are looking at but well could serve as an interface-blueprint for the real thing.

According to fir — thermal sensor driver (fir == far infrared) — MicroPython 1.20 documentation and OSError: Failed to init the MLX90640! - OpenMV Products - OpenMV Forums, the OpenMV project might also have support for the Pimoroni MLX90640 sensor already.

OpenMV Cam H7

While I’ve not been able to find this back, I well believe we found this project on kickstarter the other day which is based on OpenMV and MicroPython. The campaign is already finished, it might have some outcome into a product which can be obtained from some reseller.

I believe @Basti already bought an early version of this piece as a testbed for evaluating his BambiCam idea.

The OpenMV project was successfully funded via Kickstarter back in 2015 and has come a long way since then. For more information, please visit https://openmv.io

https://www.kickstarter.com/projects/1798207217/openmv-cam-h7-machine-vision-w-micropython/posts/2291796

More research

It looks like OpenMV is completely based on MicroPython altogether.


The MicroPython libraries specific to the OpenMV Cam are listed within the documentation at MicroPython libraries — MicroPython 1.20 documentation. There are respective examples to be found at https://github.com/openmv/openmv/tree/master/scripts/examples/12-Thermopile-Shield.

References to the flir module can be found within Renamed MLX module and redid strings for it by kwagyeman · Pull Request #13 · openmv/micropython · GitHub. Hm, the FLIR is obviously a different kind of piece by Lepton – don’t know what to figure from that now.

Here we go

C-level driver for the MLX

MicroPython binding

Conclusion

This looks good so far.

However, please note the C-level things referenced here have been conceived for running on a STM32 MCU. So, we would still have to port this over to FreeRTOS/ESP-IDF/ESP32.

So, don’t panic. All of this was just a quick research into the topic on how far the community might have come in the meanwhile.

FYI.

Hier hat sich jemand schon die Mühe gemacht das auf MicroPython zu portieren, dort läuft es nun auf einem WiPy:

https://mobile.twitter.com/avs_g8/status/1250426318568583170

Avishek @avs_g8 · 15. Apr.
A little bit of tweaking in the @adafruit @CircuitPython libraries for MLX90640 and it is ready to be used with @pycomIOT wipy micropython. Now spitting out all the 768 pixel values to my @NodeRED server on @Raspberry_Pi.

Danke für den Hinweis @Andreas

@Andreas hat mich drauf gestubst; ich hab dem werten Menschen mal den Code in die Öffentlichkeit entlocken können, Dank an Avishek/avs_g8/avsg8!:

“This is a quick and dirty implementation, and hence may not be robust against all kinds of errors. If it gets stuck somewhere, I have found using the wipy watchdog timer module helps.”

1 Like