-
Notifications
You must be signed in to change notification settings - Fork 11
add retries and delays to work around ESP32-S3 problems #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
After downloading the latest version of the adafruit_lc709203f.mpy library and running your sample code on my feather_s3_tft I got the following errors:
|
@BeatArnet The proposed fix is not yet available as .mpy. Please try: |
Unfortunately, after some impressive results…
```
Battery Percent: 100.00 %
Battery Voltage: 4.19 V
Battery Percent: 100.00 %
Battery Voltage: 4.19 V
Battery Percent: 100.00 %
Battery Voltage: 4.19 V
Battery Percent: 100.00 %
Battery Voltage: 4.19 V
Battery Percent: 100.00 %
Battery Voltage: 4.19 V
Battery Percent: 100.00 %
Battery Voltage: 4.19 V
Battery Percent: 100.00 %
Battery Voltage: 4.19 V
Battery Percent: 100.00 %
Battery Voltage: 4.19 V
retrying reads
retrying reads
retrying reads
retrying reads
retrying reads
retrying reads
retrying reads
retrying reads
retrying reads
retrying reads
retrying reads
retrying reads
retrying reads
retrying reads
retrying reads
retrying reads
retrying reads
retrying reads
retrying reads
retrying reads
```
|
@BeatArnet hmm, I saw a few missing reads, but not continuous as you did 🙁 . Are you using exactly the same test program, and which board are you testing on? |
I used your sample-code and the latest library *.py. I have an Adafruit S3 TFT board.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All makes sense to me! Question of of curiosity, why is ValueError
what's being raised by the failed instancing of I2CDevice
and not something like OSError
itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I missed the ongoing conversation. Requesting changes so it doesn't show as "approved" until that's sorted out, my bad!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes look good to me. I think it's worthwhile to go ahead and merge this improvement even if there is still some situations that can still be problematic for other reasons.
I tested the code posted in this PR on a Feather S3 TFT with 8.0.0.beta.5. It has run successfully for several minutes for me with the branch from this PR.
@dhalbert or @tekktrik Do we have any specific reason to hold off merging this? It seems like there may still be underlying issues from upstream that can cause trouble, but the improvements here seem to stand on their own as well for this library.
I'll defer to @dhalbert but I agree with you. Also, I didn't fully realize until now that CircuitPython implemented the |
@FoamyGuy @tekktrik I did not merge it because @BeatArnet still had trouble. But it may be particular samples. So ok, let's merge it, and it will fix the problem at least some of the time. |
I could solve the problems, using the following code: # The following code for scanning the I2C addresses is necessary so that the voltage can be measured
BATTERY_MON_ADDRESS = 0x0B # Address for ESP32-s3 tft Feather
def hack_for_i2c_issue():
i2c = board.I2C()
while not i2c.try_lock():
pass
running = True
try:
while running:
print("I2C addresses found:",
[hex(device_address) for device_address in i2c.scan()]
)
# time.sleep(2)
running = False
return i2c
finally: # unlock the i2c bus when ctrl-c'ing out of the loop
i2c.unlock()
try:
print("Searching for battery monitor...")
i2c = hack_for_i2c_issue()
battery_monitor = LC709203F(i2c) For me, the problem is solved with the above hack. |
@BeatArnet The code I added is similar to your hack, but only tries three times to wake up the LC709203F. However, if it doesn't succeed, it will throw an exception. So I don't know why your eventually gets read failures. Perhaps the sensor is going back to sleep in a scenario I hadn't envisioned. We could retry reads a few times as well. |
Updating https://github.com/adafruit/Adafruit_CircuitPython_LC709203F to 2.2.10 from 2.2.9: > Merge pull request adafruit/Adafruit_CircuitPython_LC709203F#21 from dhalbert/esp32-s3-retries > Add .venv to .gitignore Updating https://github.com/adafruit/Adafruit_CircuitPython_TLC59711 to 2.0.9 from 2.0.8: > Merge pull request adafruit/Adafruit_CircuitPython_TLC59711#22 from tcfranks/main > Add .venv to .gitignore > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_Wiznet5k to 1.12.17 from 1.12.16: > Merge pull request adafruit/Adafruit_CircuitPython_Wiznet5k#76 from BiffoBear/Rename_example_to_prevent_clash_with_pytest Updating https://github.com/adafruit/Adafruit_CircuitPython_framebuf to 1.5.0 from 1.4.14: > Merge pull request adafruit/Adafruit_CircuitPython_framebuf#48 from philsuth/rgb565 > Add .venv to .gitignore > Update .pylintrc for v2.15.5 > Fix release CI files > Update pylint to 2.15.5 > Updated pylint version to 2.13.0 > Switching to composite actions Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA: > Updated download stats for the libraries
ESP32-S3 has some issues with the clock-stretching and sleeping done by the LC709203F. See adafruit/circuitpython#6311.
ValueError
for bad args, notAttributeError
.OSError
instead ofRuntimeError
on CRC failure. This makes it easier to catch all read/write failures so you can retry.Tested with this program. Note the
try
-except
which catchesOSError
. There can still be occasional failures, so it's good to catch and retry.@Gingertrout @BeatArnet @mopore @ThomasAtBBTF Could you try this changed version and see if it works for you? Thank you. You just need to copy the
adafruit_lc709203f.py
file in this pull request to your CIRCUITPY drive, which will override what is in yourlib/
. You should be able to remove thei2c.scan()
code from your existing programs, since this does approximately the same thing.New code is available at https://github.com/adafruit/Adafruit_CircuitPython_LC709203F/blob/1007e4c96bc465204de0cb5a3684022e9e0fb71b/adafruit_lc709203f.py