adafruit / circuitpython

CircuitPython - a Python implementation for teaching coding with microcontrollers
https://circuitpython.org
Other
4.08k stars 1.2k forks source link

busio.I2C issues on ESP32-S3: LC709203F #6311

Closed kattni closed 11 months ago

kattni commented 2 years ago

CircuitPython version

Adafruit CircuitPython 7.3.0-beta.1 on 2022-04-07; Adafruit Feather ESP32S2 with ESP32S2

Code/REPL

import time
import board
import bitbangio
from adafruit_lc709203f import LC709203F, PackSize

i2c = bitbangio.I2C(board.SCL, board.SDA, frequency=250000, timeout=1000000)
battery_monitor = LC709203F(i2c)

battery_monitor.pack_size = PackSize.MAH400

while True:
    print("Battery Percent: {:.2f} %".format(battery_monitor.cell_percent))
    print("Battery Voltage: {:.2f} V".format(battery_monitor.cell_voltage))
    time.sleep(2)

Behavior

Fails on line 9 with the following:

code.py output:
Traceback (most recent call last):
  File "code.py", line 9, in <module>
  File "adafruit_lc709203f.py", line 119, in __init__
  File "adafruit_lc709203f.py", line 164, in power_mode
  File "adafruit_lc709203f.py", line 247, in _write_word
OSError: [Errno 5] Input/output error

Description

frequency and timeout have no effect on the behavior. It was already crashing consistently after a short period of time with busio and board.I2C(), or straight up not seeing the chip (even though I2C scan sees it). So we wanted to try bitbang I2C. bitbangio crashed more quickly than busio did.

After chatting with @dhalbert about it, as per request, I am filing a bug here.

Additional information

No response

dhalbert commented 11 months ago

I retested with CircuitPython 9.0.0-alpha.2, which is upgraded to ESP-IDF v5.1. lc709203f_simpletest.py now works much better. I am closing this as fixed in 9.0.0, but we can reopen or make a new issue as needed.