adafruit / adafruit/Adafruit_CircuitPython_MLX90640

i2c.write_then_readinto slows down frame rate after running the library for a couple seconds at 64Hz

Open
#29 2 comments 0 reactions 0 assignees View on GitHub
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.
![before 5 seconds](https://user-images.githubusercontent.com/100394102/195725319-0d73af05-1099-482c-86a1-861a282a10f0.PNG)

Line Profiler Data after around 5 seconds has passed.
![After 5 seconds](https://user-images.githubusercontent.com/100394102/195725329-12d6c183-78a2-439a-a9e1-48919b6153ea.PNG)

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.