Pimoroni Melexis MLX90640 Thermal Camera Breakout

Hmm… thanks for the reply. I am really at a loss with these sensors on my hand. Having individual RPi for single sensor doesn’t make sense. Please let me know if you find any method to change the I2C address.

In your case that is a bit of a bummer. You can change the address on other Pimoroni sensors so you can use two, just not on that thermal camera. My BME680 for example has an address change jumper on the back. Its marked ADDR+1 and it says i2c 0x76 or 0x77


And many of the other breakouts have that same function. Unfortunately, you just happen to have one of the very few that don’t support address change.
I have several Pi’s with multiple i2c devices hooked up. So far I haven’t had to change any addresses, none of them have the same address and I’m only using 1 of each different sensor.
I don’t own a thermal camera so I have no idea if you can fudge it to change the address? Wish I could be more help.

I wish if I had that option to change the address :(
Thanks again for your response

You can change the address on the MLX90640. You just need a small piece of code to change the address in EEPROM. I’ve done it several times on these sensors and will post the code if there’s still interest. If you want to figure it out for yourself, page 19 in the datasheet. First you need to overwrite that register with 0x0000, write new address, POR (power on/off reset) and then it should be changed.

1 Like

Hello ion_four,

Thanks a ton. If you have the code to change this, please pass to me. If you can put in any common link, I can download it from there too. Which development board did yo use to overwrite the register?

Regards,
Arun

Nice, that type of thing is above my current skill level. Might be something I’d try down the road though, if the need arises.
@anarayanan I would run i2cdetect on that Pi with no MLX90640’s connected. That will tell you if anything else you may have connected is using an i2c address. That way you don’t accidentally use one already in use.
If you don’t have anything else connected to i2c there is no real need to do it though.

The working code I have is for Arduino. (Would that help you at all?) I had something for the RPi that was ALMOST working, but I seem to have broken something as far as libraries/drivers.

So…If you want something for the RPi, I need some help, first! ha

I had things working (including all of the pimoroni examples), but then I broke something after installing libi2c-dev and adding some additional i2c busses using dtoverlay. I couldn’t get any actual data from the sensors after this.

I’ve gone so far as to wipe the SD card and start fresh, newest kernel, tried to follow the instructions (without and with libi2c-dev installed), yet nothing works. So, can anyone help me out? If you have it working, telling me which kernel and drivers you have and which libraries/modules you had to install would be great.

I would think that I damaged the sensors, but find it unlikely since I have three and all of them still read/write using the Arduino.

1 Like

I can’t help much help unfortunately. I own several Arduino’s but don’t own a MLX90640 camera.
If you have some python code for the MLX90640 post it and I may be able to spot something?

I do have an Arduino with me. So if you have the code for Arduino, I can try it out. Please let me know the steps you took to make it work as well. Do you mean that, if I change the address using the Arduino, I may not be able to interface the sensor with the RPi afterwards?

For working with the single sensor using RPi and read the thermal image, I used the github files from here: https://github.com/pimoroni/mlx90640-library

The I2C address is hardcoded in the pimoroni programs and doesn’t have provisions to do anything with more than one sensor at a time. So, you can change the address of the sensor and the address in the code, but you’re still only going to be using one sensor with each program instance.

I was just trying to make the Arduino program more user friendly (accept address change information from the serial monitor instead of having it hardcoded) and I seem to have written one of my sensors out of range. So, I guess I get to add that to the list of problems to solve before moving forward! Stay tuned, if I get this sorted out. Otherwise, I don’t want to send you something that will give you more headache than help!

The problem is that it’s not just my code that isn’t working. The pimoroni examples have also stopped working. So, it’s deeper than just my poor coding ability ha!

It seems that these sensors MAY be easy to screw up by writing invalid values to their registers, ie. no internal checks against it.

I2C address range should be 0x03-0x77 and (after playing around with my address changing code), I suddenly couldn’t find the sensor in that range. Scanning beyond the valid range shows something at 0x00 and 0x80, but I have the suspicion those aren’t real.

You can change what address the Pimoroni code looks for, for some sensors anyway.
For example if I was wanting to use two BME680’s I change
sensor = bme680.BME680()
too
sensor1 = bme680.BME680(76)
sensor2 = bme680.BME680(77)

And with the one sensor using the alternate address its
sensor = bme680.BME680(77)

You’d also have to edit some of the other code
if sensor.get_sensor_data(77):
etc.
Thats my understanding anyway, I haven’t attempted to do it as of yet. I was at one time wanting to track indoor versus outdoor temps and humidity etc. Just can’t find my round 2it. ;)

Hi ion_four,

you mentioned you have a working code for Arduino for changing the i2c address. Do you mind sharing that?

Regards,
Arun

Hi Arun,

I just had some commands with hardcoded addresses, but decided to it make slightly more user friendly by allowing input from the Serial Monitor. When compiled, it gives some warnings about type conversions, but it seems to work despite this. I tested it by changing a sensor address back and forth, several times and no issues. There are instructions and warnings at the top of the code, but to reiterate…

Be warned, there is no error checking. You enter just the least significant byte of the address in hex. So, default address is 33 and you might want to change it to 34, for example. If you put in an invalid or unintended address (ex. 8438523, cat, dog, 0x33, !@#*&$#), who knows what you will get and it may cause you some big troubles.

https://www.codepile.net/pile/vZ4dwxZ4

1 Like

Arun,

If you remember any details of how you got the sensors working on the RPi, such as what libraries you installed (using pip3 or apt-get?) and any issues, that would be great. Like I said, I had them working, but installed some other libraries and seem to have broken it, even after a fresh install. :(

I’m also curious what your plans are with the multiple sensors, as I also bought four…suspicious coincidence!

1 Like

Hi ion_four,

On a newly installed Debian OS and after running the “sudo apt-get update” command, I followed the exact steps in the Pimoroni github: https://github.com/pimoroni/mlx90640-library.

Ran the command to install the I2C device library:

sudo apt-get install libi2c-dev

Then:

dtparam=i2c1_baudrate=400000

To build the MLX90640 library and examples in LINUX I2C mode:

make clean
make I2C_MODE=LINUX

To use the bcm2835 library:

wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.55.tar.gz
tar xvfz bcm2835-1.55.tar.gz
cd bcm2835-1.55
./configure
make
sudo make install

For dependencies on some example codes:

libav for video example:

sudo apt-get install libavutil-dev libavcodec-dev libavformat-dev

SDL2 for sdlscale example:

sudo apt install libsdl2-dev

Once everything installed, use cd command to the mlx… folder and when under the folder, make the example code:

make examples/hotspot
sudo examples/hotspot

It was working right away for me.

Hi ion-four,
I have added the reply with the steps I took to make it work using the pimoroni github page. The post is under review by the page admin it seems, should be released after the review.

I am using it to monitor the temperature change of a large industrial equipment. To build some sort of condition monitoring prototype :)

btw, thanks much for the code. I will try it out and let you know the result. So as I understand I just need to input “33” for the old address when prompted and “34” (assuming I want it as “34”) for the new address. I do not need to supply it as “0x33” and “0x34”, am I correct?

Yes, supply the addresses as merely “33” and “34” , etc. No leading 0x, no MSB as that’s hardcoded. I had more instructions in the serial monitor output, but my little old Arduino was running out of dynamic memory, so I removed them.

Current address, (enter), New address, (enter), Power On/Off Reset, (enter) and the new address should be written and displayed.

If you’re a more accomplished programmer, please help with the type mismatch warnings and adding error checking would be great. When I first changed it to take serial input I was writing an int (two bytes) to the address byte and seem to have lost one of my sensors doing this. Not terribly amusing, considering the cost of them!

1 Like

Sure, thanks for the information.

Not sure why the admin is taking so long to release my reply on the steps I took, probably due to multiple links in the post.

Let me try this method and see if I can improve on the code, not a pro coder myself though…