adafruit / adafruit/Adafruit_CircuitPython_MLX90640
i2c.write_then_readinto slows down frame rate after running the library for a couple seconds at 64Hz
- Dominant language
- Python
- Stars
- 72
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
I have been trying to get the sensor to run as close to 60hz as possible however I have recently run into a problem. After modifying the library a little bit using the code from chimajero in (https://github.com/adafruit/Adafruit_CircuitPython_MLX90640/issues/22), I have managed a frame rate of roughly 57 FPS, however, after a few seconds, this frame rate drops slowly down to the '30s. I narrowed the code down to the _I2CReadWrods function and the line, i2c.write_then_readinto(), taking the most time and slowing down the rest of the program. This can be seen in the Line Profiler data shown below.
I know next to nothing about the i2c bus or how to interact with it so if anyone has any idea what may be happening, or how to speed up this process, it would be greatly appreciated. If you need any more clarification or need the code for the slightly modified library I would be glad to provide it.
Thank you!
Edit: Another thing to note is that when the end value is changed in i2c.write_then_readinto(addrbuf, inbuf, in_end=read_words * 2) to a smaller value under 300 (I used 256 as its just 768/3, end=256) the frame rate stayed the same and did not lower leading me to believe the problem is the amount of data taken from the i2c bus. This is just my guess.
Line Profiler Data within the first 5 seconds.

Line Profiler Data after around 5 seconds has passed.

Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the _I2CReadWrods function and profile i2c.write_then_readinto() while reproducing the frame-rate drop at 64Hz. Compare the full read_words * 2 transfer with the smaller in_end value of 256, using the reported profiler data as a reference. Done means identifying the cause of the slowdown and documenting or implementing a verified fix.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- embedded-iot
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100