Skip to content
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

I2C I/O Error on Teensy 4.1 #8448

Open
jksjaz opened this issue Sep 30, 2023 · 1 comment
Open

I2C I/O Error on Teensy 4.1 #8448

jksjaz opened this issue Sep 30, 2023 · 1 comment
Labels
bug busio mimxrt10xx iMX RT based boards such as Teensy 4.x
Milestone

Comments

@jksjaz
Copy link

jksjaz commented Sep 30, 2023

CircuitPython version

Adafruit CircuitPython 8.2.3 on 2023-08-11; Teensy 4.1 with IMXRT1062DVJ6A

Code/REPL

import adafruit_bno055
import busio

# Initialize the IMU imu_sensor
imu_i2c = busio.I2C(board.SCL, board.SDA)
imu_sensor = adafruit_bno055.BNO055_I2C(imu_i2c)

last_val = 0xFFFF


def temperature():
    global last_val  # pylint: disable=global-statement
    result = imu_sensor.temperature
    if abs(result - last_val) == 128:
        result = imu_sensor.temperature
        if abs(result - last_val) == 128:
            return 0b00111111 & result
    last_val = result
    return result


while True:
    print("Temperature: {} degrees C".format(imu_sensor.temperature))
    """
    print(
        "Temperature: {} degrees C".format(temperature())
    )  # Uncomment if using a Raspberry Pi
    """
    print("Accelerometer (m/s^2): {}".format(imu_sensor.acceleration))
    print("Magnetometer (microteslas): {}".format(imu_sensor.magnetic))
    print("Gyroscope (rad/sec): {}".format(imu_sensor.gyro))
    print("Euler angle: {}".format(imu_sensor.euler))
    print("Quaternion: {}".format(imu_sensor.quaternion))
    print("Linear acceleration (m/s^2): {}".format(imu_sensor.linear_acceleration))
    print("Gravity (m/s^2): {}".format(imu_sensor.gravity))
    print()

    time.sleep(1)

Behavior

code.py output:
Temperature: 0 degrees C
Accelerometer (m/s^2): (0.0, 0.0, 0.0)
Magnetometer (microteslas): (10.0625, 13.75, -39.375)
Gyroscope (rad/sec): (-0.00109083, 0.00218166, -0.00218166)
Euler angle: (0.0, 0.0, 0.0)
Quaternion: (0.0, 0.0, 0.0, 0.0)
Linear acceleration (m/s^2): (0.0, 0.0, 0.0)
Gravity (m/s^2): (0.0, 0.0, 0.0)

Temperature: 28 degrees C
Traceback (most recent call last):
  File "code.py", line 291, in <module>
  File "adafruit_bno055.py", line 416, in acceleration
  File "adafruit_bno055.py", line 155, in __get__
  File "adafruit_register/i2c_struct.py", line 49, in __get__
OSError: [Errno 5] Input/output error

Description

While testing the Adafruit BNO055 sensor connected using STEMMA QT, I encountered the following error which seems to be an issue with the I2C protocol.

I've submitted the same issue in the specific library as well but no response there so posting here as well. adafruit/Adafruit_CircuitPython_BNO055#118

Additional information

No response

@jksjaz jksjaz added the bug label Sep 30, 2023
@tannewt tannewt added mimxrt10xx iMX RT based boards such as Teensy 4.x busio labels Oct 2, 2023
@tannewt tannewt added this to the Long term milestone Oct 2, 2023
@jksjaz
Copy link
Author

jksjaz commented Oct 10, 2023

After some debugging, it would seem the I2C frequency is not compatible with Teensy is why it's failing. After changing it, I was able to make the sensor work:

import time
import board
import adafruit_bno055
import busio


i2c = busio.I2C(board.SCL, board.SDA, frequency=400000)
sensor = adafruit_bno055.BNO055_I2C(i2c)

last_val = 0xFFFF


def temperature():
    global last_val  # pylint: disable=global-statement
    result = sensor.temperature
    if abs(result - last_val) == 128:
        result = sensor.temperature
        if abs(result - last_val) == 128:
            return 0b00111111 & result
    last_val = result
    return result


while True:
    try:
        print("Temperature: {} degrees C".format(sensor.temperature))
        """
        print(
            "Temperature: {} degrees C".format(temperature())
        )  # Uncomment if using a Raspberry Pi
        """
        print("Accelerometer (m/s^2): {}".format(sensor.acceleration))
        print("Magnetometer (microteslas): {}".format(sensor.magnetic))
        print("Gyroscope (rad/sec): {}".format(sensor.gyro))
        print("Euler angle: {}".format(sensor.euler))
        print("Quaternion: {}".format(sensor.quaternion))
        print("Linear acceleration (m/s^2): {}".format(sensor.linear_acceleration))
        print("Gravity (m/s^2): {}".format(sensor.gravity))
        print()
    except:
        print("Error")

    time.sleep(1)

It still does error out randomly sometimes however it's working fine for about 95% of the time which is enough for most applications.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug busio mimxrt10xx iMX RT based boards such as Teensy 4.x
Projects
None yet
Development

No branches or pull requests

2 participants