Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Melexis906400 with the Adafruit library on RPI4: Too Many Re
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Melexis906400 with the Adafruit library on RPI4: Too Many Re

by mbobinger on Mon May 11, 2020 9:07 am

20200511_mlx90640_adafruit.PNG
20200511_mlx90640_adafruit.PNG (192.31 KiB) Viewed 325 times
Dear Adafruit-fellows,

I've followed the MLX90640 tutorial and all code examples work fine for me. However, as soon as I try to set:
mlx.refresh_rate = adafruit_mlx90640.RefreshRate.REFRESH_16_HZ
the refresh rate to higher than 4Hz, tried for 8, 16, 32 and 64Hz, I receive the following error msg (please also see attached IMG):

Code: Select all | TOGGLE FULL SIZE
  raise RuntimeError("Too many retries")
RuntimeError: Too many retries
>>> %Run mlx90640.py
MLX addr detected on I2C ['0x1627', '0x8e69', '0x187']
Traceback (most recent call last):
  File "/home/pi/FTP/code/mlx90640/mlx90640.py", line 16, in <module>
    mlx.getFrame(frame)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_mlx90640.py", line 143, in getFrame
    status = self._GetFrameData(mlx90640Frame)
  File "/usr/local/lib/python3.7/dist-packages/adafruit_mlx90640.py", line 172, in _GetFrameData
    raise RuntimeError("Too many retries")
RuntimeError: Too many retries


This error has been discussed previously:
https://github.com/melexis/mlx90640-library/issues/57
and was already somehow addressed by Melexis in an update.

And on the adafruit forum:
viewtopic.php?f=19&p=808699

The problem seems to be clearly that the sensor status can not be requested:
Code: Select all | TOGGLE FULL SIZE
    def _GetFrameData(self, frameData):
        dataReady = 0
        cnt = 0
        statusRegister = [0]
        controlRegister = [0]

        while dataReady == 0:
            self._I2CReadWords(0x8000, statusRegister)
            dataReady = statusRegister[0] & 0x0008
            # print("ready status: 0x%x" % dataReady)

        while (dataReady != 0) and (cnt < 5):
            self._I2CWriteWord(0x8000, 0x0030)
            # print("Read frame", cnt)
            self._I2CReadWords(0x0400, frameData, end=832)

            self._I2CReadWords(0x8000, statusRegister)
            dataReady = statusRegister[0] & 0x0008
            # print("frame ready: 0x%x" % dataReady)
            cnt += 1

        if cnt > 4:
            raise RuntimeError("Too many retries")


Changing the bus speeds of I2C from 0.8MHz to 1.5Mhz didn't help either (nor lowering of course):
i2c = busio.I2C(board.SCL, board.SDA, frequency=15000000)

Please have a look at my setup, I've used long and then short SDA, SCL wires to avoid crosstalk - didn't help. Always 8Hz was the limit.

Thank you!
Attachments
20200510_mlx_90640_rpi_setup2.jpg
20200510_mlx_90640_rpi_setup2.jpg (155.69 KiB) Viewed 325 times
20200510_mlx_90640_rpi_setup1pg.jpg
20200510_mlx_90640_rpi_setup1pg.jpg (171.5 KiB) Viewed 325 times

mbobinger
 
Posts: 20
Joined: Mon Jul 15, 2019 8:10 am

Re: Melexis906400 with the Adafruit library on RPI4: Too Man

by mikeysklar on Mon May 11, 2020 2:54 pm

Hi mbobinger,

Thanks for doing your research and testing on this and posting your findings of the higher than 4Hz refresh rate.

Had you come across the extreme timing sensitivity thread in the github archive for the library (another related one to the link you had posted).

https://github.com/melexis/mlx90640-library/issues/7

Increase the i2c frequency in order to decrease the read-out time - note that the device supports
FM+ (1MHz), but the EEPROM should be read at maximum 400KHz so one would have to switch the
i2c clock
Decrease the MLX90640 refresh rate in order to have more time for the data readout.
I think that the best approach to sort this out is:
Use continuous mode (the device is still alternating the sub pages automatically)
Set the refresh rate of the MLX90640 to 0.5Hz - this would allow a readout time of 2seconds.
Check the i2c clock signal frequency - at 1MHz, a full frame read out would take a bit less than 15us, so if the clock is not really slow you should not have problems with invalid data.
If the above routine works, you could start optimizing the refresh rate and the i2c speed so that you
get the desired performance.

mikeysklar
 
Posts: 1995
Joined: Mon Aug 01, 2016 8:10 pm

Please be positive and constructive with your questions and comments.