adafruit/Adafruit_CircuitPython_MLX90640

OSError: [Errno 5] Input/output error in raspberry pi 4

Opened this issue · 12 comments

Hi. I try the sample code and modify it for measure process time
When it run 2833 sec after start ,I got the error 'OSError: [Errno 5] Input/output error '
And the second try to got the same error with 594 sec
Do you know how can I fix it?

here is my code:

import time
import board
import busio
import adafruit_mlx90640
t0=time.time()
i2c = busio.I2C(board.SCL, board.SDA, frequency=800000)

mlx = adafruit_mlx90640.MLX90640(i2c)
print("MLX addr detected on I2C", [hex(i) for i in mlx.serial_number])

# if using higher refresh rates yields a 'too many retries' exception,
# try decreasing this value to work with certain pi/camera combinations
mlx.refresh_rate = adafruit_mlx90640.RefreshRate.REFRESH_2_HZ

frame = [0] * 768
while True:
    try:
        mlx.getFrame(frame)
    except ValueError:
        # these happen, no biggie - retry
        continue

    for h in range(24):
        for w in range(32):
            t = frame[h*32 + w]
    processtime = time.time()-t0
    print(round(frame[0],1))
    print('processtime: %d sec'%processtime)

and here is the error report:

Traceback (most recent call last):
File "", line 18, in
File "/usr/local/lib/python3.9/dist-packages/adafruit_mlx90640.py", line 126, in getFrame
status = self._GetFrameData(mlx90640Frame)
File "/usr/local/lib/python3.9/dist-packages/adafruit_mlx90640.py", line 140, in _GetFrameData
self._I2CReadWords(0x8000, statusRegister)
File "/usr/local/lib/python3.9/dist-packages/adafruit_mlx90640.py", line 828, in _I2CReadWords
i2c.write_then_readinto(
File "/usr/local/lib/python3.9/dist-packages/adafruit_bus_device/i2c_device.py", line 141, in write_then_readinto
self.i2c.writeto_then_readfrom(
File "/usr/local/lib/python3.9/dist-packages/busio.py", line 192, in writeto_then_readfrom
return self._i2c.writeto_then_readfrom(
File "/usr/local/lib/python3.9/dist-packages/adafruit_blinka/microcontroller/generic_linux/i2c.py", line 90, in writeto_then_readfrom
readin = self._i2c_bus.read_i2c_block_data(
File "/usr/local/lib/python3.9/dist-packages/Adafruit_PureIO/smbus.py", line 275, in read_i2c_block_data
ioctl(self._device.fileno(), I2C_RDWR, request)
OSError: [Errno 5] Input/output error

How is the camera attached to the Pi?

How is the camera attached to the Pi?

hi, @caternuson
the camera attached to the Pi as below Pic
image

Is it possible to make the Vin attached with the other power supply instand of GPIO 3.3V on Pi ,and attached the GND of camera/power supply/Pi all toghther?
Is it helpful for this case?

Wiring is nominally correct:
https://learn.adafruit.com/adafruit-mlx90640-ir-thermal-camera/python-circuitpython#python-computer-wiring-3053145

But need to see photos of your actual setup and connections.

Hi, @caternuson
Thanks for reply.

This is the connection on MLX90640
SDA>GREEN
SCL>YELLOW
GND>ORANGE
3Vo>RED
VIN>BROWN
PXL_20221125_023918239 PORTRAIT

I connect the dupont line again with same color (pin to pin) to make it longer
PXL_20221125_024205964 PORTRAIT

And here is the original connection on Pi GPIO
I find a mistake here.
I connect the RED(3Vo) to GPIO PIN1(3.3V)

RED> PIN1(3.3V)
GREEN > PIN3(GPIO2 SDA)
YELLOW > PIN 5(GPIO3 SCL)
ORANGE > PIN 6(GND)
BROWN > NO CONNECTED
PXL_20221125_024057160 PORTRAIT

Then I fix the mistake to let Brown(VIN) connected to GPIO PIN1(3.3V)
The error report "input/output error" is still exist.

Then I fix the mistake to let Brown(VIN) connected to GPIO PIN1(3.3V)

Correct - the 3Vo pin should not be connected to anything. It's an output from the camera module.

Are these timing repeatable? Or is the amount of time random?

When it run 2833 sec after start ,I got the error 'OSError: [Errno 5] Input/output error '
And the second try to got the same error with 594 sec

@caternuson
The timing is random.
I connected MLX90640 Vin to other power supply (not the rpi GPIO) 3.3V and got the same error after 2460sec and 640 sec.

@caternuson
I try to modify Rpi i2c speed from 1MHz to 400K Hz and change the mlx90640.RefreshRate from 16Hz to 4Hz.
The program is working for 75260 sec and still working.
Maybe Rpi I2C speed is the key of this error?

It could be related. Were you changing the I2C speed by modifying /boot/config.txt on the Pi? That's required - the frequency parameter here has no effect on a Pi:

i2c = busio.I2C(board.SCL, board.SDA, frequency=800000)

@caternuson
Yes,I modified the I2C speed in /boot/config.txt from 1M Hz to 400K Hz.
I keep the frequency =800000 in my code.

@yuehshienlin i have exactly the same problem you encountered. And also it occured on my Rasperry pi and mlx90640 interface.
have you solved this problem?

@Electricutionerr
It would be the I2C speed problem.
I solved the problem with 2 actions as below:
1.
Modified the I2C speed in /boot/config.txt from 1M Hz to 400K Hz. I think the default I2C speed 100k Hz would be better. But ,if you set I2C speed to 100k Hz ,the reflash rate of action 2 would be 2Hz or 1Hz
2.
Slow down the reflash rate in the sample code from 16HZ to 4Hz( Much slow ,much stable)

Without any modifications to /boot/config.txt, a Raspberry Pi's default I2C clock speed is 100kHz.

The mlx90640_simpletest.py example tries to set a 800kHz I2C clock speed and then use a 2Hz refresh rate for the MLX90640. However, the code line setting 800kHz will have no affect on a Raspberry Pi (requires config.txt mod)

The need to increase the I2C clock speed to achieve higher MLX90640 refresh rates is generally expected - if there is an attempt to actually also read the sensor data back at this same rate.

It sounds like this issue is generally being resolved by setting the Raspberry Pi I2C clock speed in combination with adjusting the MLX90640's refresh rate as needed?