CircuitPython is based upon MicroPython, so CircuitPython probably inherits its I2C bugs. I vaguely recall seeing similar bug reports in MicroPython forums. I don't know how to fix CircuitPython/MicroPython. I'm no Python developer. I'm maybe one step above a Python newbie. I normally use C.
The I2C bus clearing step is described in the I2C specification. See section 3.1.16:
https://www.nxp.com/docs/en/user-guide/UM10204.pdf
I can read the SHD31D by using busio but not bitbangio.
I can read the BNO055 by using bitbangio but not busio.
I haven't found one way to read both sensors.
Here's my test code:
Code: Select all
import board
import digitalio
import time
print("\n\n***** Hello world *****")
if True: # optionally wiggle SCL to clear I2C slave devices
print("***** Clear I2C bus *****")
scl = digitalio.DigitalInOut(board.SCL)
scl.direction = digitalio.Direction.OUTPUT # want open drain scl.drive_mode = digitalio.DriveMode.OPEN_DRAIN
for n in range(1,20):
scl.value = 0
time.sleep(0.0001)
scl.value = 1
time.sleep(0.0001)
scl.direction = digitalio.Direction.INPUT
scl.deinit()
for k in range (2):
print("***** Hello SHT31D *****")
import busio
import adafruit_sht31d
i2c = busio.I2C(board.SCL, board.SDA, frequency=100000, timeout=10000)
sht31d = adafruit_sht31d.SHT31D(i2c)
for n in range (10):
time.sleep(0.1)
print("Temperature: {:+7.2f}".format(sht31d.temperature))
i2c.deinit()
print("***** Goodbye SHT31D *****")
print("***** Hello BNO055 *****")
import bitbangio
import adafruit_bno055
i2c = bitbangio.I2C(board.SCL, board.SDA, frequency=100000, timeout=10000)
bno055 = adafruit_bno055.BNO055_I2C(i2c)
for n in range (10):
time.sleep(0.1)
print("Quaternion: {:+8.5f} {:+8.5f} {:+8.5f} {:+8.5f}".format(*bno055.quaternion))
i2c.deinit()
print("***** Goodbye BNO055 *****")
print("***** Goodbye cruel world *****\n")