MLX90640 Thermal Camera with Trackball Breakout (PIM447)

The trackball (PIM447) doesn’t seem to be able to cope with the required I2C bus speed for the thermal camera:
setting in config.txt:

I get errors:
> ioctl(self.fd, I2C_RDWR, ioctl_data)
OSError: [Errno 121] Remote I/O error


raise RuntimeError(“Invalid chip ID: 0x{:04X}, expected 0x{:04X}”.format(chip_id, CHIP_ID))
RuntimeError: Invalid chip ID: 0x0000, expected 0xBA11

I am testing it on a Pi 4 Model B / 2GB

Is there a way I can both use the thermal camera and the trackball?

You could try lowering the baud rate and see if the camera still works? It may be a compromise but may get them working until a better solution comes by.

Thanks for your help! 👍

If I reduce the baud rate, even to 400000, the MLX90640 starts giving errors (“cnt > 4 error” after the x.get_frame() command).

And the trackball does not work on that rate. I have to further slow the rate down to 100000 and then the MLX90640 doesn’t work at all.

I would like to use the trackball for creating a user interface with the 1.3" SPI Colour Square LCD (240x240) Breakout. If have done that with other projects and I really like the little trackball, it’s perfect for such jobs!

OK, that didn’t work. I guess enable i2c0 and move the camera to it?
I2C Bus/Interface in Raspberry Pi (

Thanks for the hint, but that path is beyond my level of experience with the Pi. Also, I am afraid to break the camera, Pi or the little trackball.

However, I had an old Pi-Zero (not a W, the basic model, costing € 5,-) lying, collecting dust, so I used that to handle the trackball and use a serial connection to the Pi-4 for getting the trackball data (almost none) to the program. I tested it with a complicated user interface I wrote earlier for another project and it seems to work fine so far.

I may need to use some IO’s for the shutdown of the Pi-Zero, reboot, etc., but so far the serial seems to behave without much problems. I will be sending data to and from the Pi-4, as the trackball has an advanced rgb LED, which I would like to address, according to the state and functions of the program.

This (using a Pi-Z) may be a strange way to proceed, but at least this way I know more or less what I am doing 🙃. And I get what I want: the superb trackball, which offers me the most flexibility for a user interface.

Sometimes you have to think out side of the box. I’ve done my fair share of “but it works” ;). I have one of those trackballs. I haven’t put it to good use just yet, its on my list of side projects.

If you have ever used one to build a GUI (with several settings, modes, etc.) you will never want something else, it’s awesome!

Facing the I2C problems now, I considered using some buttons to build a GUI, but I know this project will grow and become more complicated, have more settings, modes, etc. and then the trackball offers the most flexibility.

I have a SmartiPi V2 with a Pi 4B 8gig and the official 7 inch touch screen. The issue I have is touch support in PIOS is sorely lacking. The screen supports 10 finger touch but PiOS only supports 1 finger touch. No right click etc? My plan is to mount the trackball breakout where the camera a would normally go in the case. And set its click function up as a right click. Just have to find my round 2it. ;)

Well… my story has not ended yet 😮

If found this:

Made a clean install for it at a fresh SD card. Worked nice, slightly different I2C settings in config.txt and circuitpython used for the camera. Same problems with trackball though. But I noticed that just reading the ball’s status caused no problems, setting it’s colour made it crash.

So I put the “old” SD back, same there: reading was OK, setting LED not.
But… at some point everything was OK. And I changed nothing at all! Didn’t touch it! 🙃

Now camera + trackball seem to work as I expected it to work in the first place.
I have absolutely no idea wat was wrong 😑.

Are you doing this all from one python file?

Yes, but for the testing of the trackball at the high (1MHz) I2C baudrate, I simply used the Pimoroni examples. Setting the LED made it crash at first, now all examples work fine.

OK, that’s what I thought, just wanted to make sure. Two separate files both using i2c at the same time would I think cause issues. I was pretty sure you already knew that but making assumptions can get you in trouble sometimes.
I don’t think I was using my Trackball with other i2c devices. Other than maybe an RV3028 RTC, but I wasn’t running any python on it.

Using the “new” SD card (so: slightly different I2C settings in config.txt and Adafruits circuitpython used for the camera) I was able to reproduce the problem.

I am happy with that, because there is one thing I even hate more then errors on itself: errors I do not understand and I cannot reproduce, which will show up in the future at the most inconvenient time. I want to get to the bottom of this 🤔.