gridstop wrote:1) All setups show an odd response to I2C.scan() both on micropython and circuitpython. The BNO08x takes a really long time to respond to the first hit on address 0x4A. In fact, micropython's scan() shows a device on 0x4B instead of 4A, it's so slow. Attached is the result of a scan() on circuitpython. This scan resulted in a "TimeoutError: Clock Stretch Too Long" message, instead of like micropython showing the wrong address.
i2c_capture.png
That capture was helpful, I was able to at least get I2C initialized and the device showing up on i2c.scan(). I had to use the bitbangio library and increase the timeout to >700us to get it working reliably. I seem to get clock stretch errors most often with a timeout of around 400-500us, which if I'm reading your graph right is close to what you were seeing. This is what I ended up running to narrow down the timing:
Code: Select all
import board
import bitbangio
I2C_DATA = board.GP16
I2C_CLOCK = board.GP17
def scan_bus():
while not i2c.try_lock():
pass
try:
print("I2C addresses found:", [hex(device_address)
for device_address in i2c.scan()])
finally:
i2c.unlock()
test = 1000
while test > 10:
print("Trying", test)
for x in range(1,10):
i2c = bitbangio.I2C(scl=I2C_CLOCK,sda=I2C_DATA,timeout=test)
scan_bus()
i2c.deinit()
i2c = None
test = test - 10
print("")
This eventually results in failures:
Code: Select all
Trying 540
I2C addresses found: ['0x4a']
I2C addresses found: ['0x4a']
I2C addresses found: ['0x4a']
I2C addresses found: ['0x4a']
I2C addresses found: ['0x4a']
I2C addresses found: ['0x4a']
Traceback (most recent call last):
File "<stdin>", line 20, in <module>
File "<stdin>", line 10, in scan_bus
TimeoutError: Clock stretch too long
Specifically, I got failures with the following values for
bitbangio.I2C(...,timeout=X):
470,480,700,650,550,410,410,410,620,540
I'm still not able to talk to the BNO085 properly however, there is an error in the adafruit library when processing the packet:
Code: Select all
import time
import board
from adafruit_bno08x import (
BNO_REPORT_ACCELEROMETER,
BNO_REPORT_GYROSCOPE,
BNO_REPORT_MAGNETOMETER,
BNO_REPORT_ROTATION_VECTOR,
BNO_REPORT_GYRO_INTEGRATED_ROTATION_VECTOR
)
from adafruit_bno08x.i2c import BNO08X_I2C
I2C_DATA = board.GP16
I2C_CLOCK = board.GP17
import bitbangio
i2c = bitbangio.I2C(scl=I2C_CLOCK,sda=I2C_DATA,frequency=400000,timeout=1000)
bno = BNO08X_I2C(i2c)
bno.enable_feature(BNO_REPORT_ACCELEROMETER)
bno.enable_feature(BNO_REPORT_GYROSCOPE)
bno.enable_feature(BNO_REPORT_MAGNETOMETER)
bno.enable_feature(BNO_REPORT_ROTATION_VECTOR)
bno.enable_feature(BNO_REPORT_GYRO_INTEGRATED_ROTATION_VECTOR)
while True:
time.sleep(2)
quat_i, quat_j, quat_k, quat_real = bno.quaternion
print("I: %0.6f J: %0.6f K: %0.6f Real: %0.6f" % (quat_i, quat_j, quat_k, quat_real))
Code: Select all
********** Packet *************
DBG:: HEADER:
DBG:: Data Len: 14
DBG:: Channel: GYRO_ROTATION_VECTOR (5)
DBG:: Sequence number: 2
DBG:: Data:
DBG:: [0x04] 0x1B 0x00 0x2C 0x01
DBG:: [0x08] 0x05 0x00 0xFD 0x3F
DBG:: [0x0C] 0x00 0x00 0x00 0x00
DBG:: [0x10] 0x00 0x00
*******************************
Traceback (most recent call last):
File "<stdin>", line 25, in <module>
File "adafruit_bno08x/__init__.py", line 547, in quaternion
File "adafruit_bno08x/__init__.py", line 797, in _process_available_packets
File "adafruit_bno08x/__init__.py", line 855, in _handle_packet
File "adafruit_bno08x/__init__.py", line 850, in _handle_packet
File "adafruit_bno08x/__init__.py", line 361, in _separate_batch
File "adafruit_bno08x/__init__.py", line 350, in _report_length
KeyError: 27
(above is captured via the console in Thonny)