RED HAT
RED HAT
DIIDevHeads IoT Integration Server
Created by Enthernet Code on 7/30/2024 in #middleware-and-os
How to Fix "Failed to Read Sensor: OSError" on Arduino Nano 33 BLE Sense with MicroPython?
@Enthernet Code Sometimes, sensors might not be initialized correctly if their addresses are not detected. You can use an I2C scanner script to check if the sensors are detected on the I2C bus. Try this I2C scanner script:
import machine

i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21))
devices = i2c.scan()

if len(devices) == 0:
print("No I2C devices found")
else:
print("I2C devices found:", [hex(device) for device in devices])
import machine

i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21))
devices = i2c.scan()

if len(devices) == 0:
print("No I2C devices found")
else:
print("I2C devices found:", [hex(device) for device in devices])
Also, ensure that the I2C bus speed is compatible with your sensors. You might need to set the I2C frequency when initializing the I2C bus. Try setting the frequency to 100kHz:
i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21), freq=100000)
i2c = machine.I2C(scl=machine.Pin(22), sda=machine.Pin(21), freq=100000)
5 replies