Micropython Libraries for the RP2040 Connect IMU

Does anyone know where I can find MicroPython libraries that work with the IMU on the
RP2040 Connect?

I did find one library but it uses I2C and asks for the two I2C pins. Does the RP2040 Connect built in IMU use I2C? What would I put for the pins in this library.

Or if anyone has a working library that would be great.

Hi @studiogamma.

That is correct.

I don't have any experience with any LSM6DSOXTR MicroPython libraries, so I can't provide any assistance with their specific usage regardless, but other forum helpers might have familiarity with whatever mysterious library you happen to be using. They would only be able to provide assistance if they know which library it is, so you should add a reply here to tell them which specific library you are using.

. I can tell you that the I2C bus, which is used for communication with the LSM6DSOXTR IMU, is on Arduino pins A4 and A5 on the board.

This is the library I'm looking at. In the Simple Test example, this is the code to start it:

i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
lsm = LSM6DSOX(i2c)

This is my question, since the IMU is built in on the RP2040 connect and not hooked up by pins, what would I put for those values? Would this library work with the RP2040 Connect?

If I'm looking at the Connect schematic correctly, SDA is GPIO12 and SCL is GPIO13 so

i2c = I2C(0, sda=Pin(12), scl=Pin(13))  # Correct I2C pins for RP2040

would be the correct code.

I tried this in the sample file (with SDA as 12 and SCL as 13)

I got this error:
Traceback (most recent call last):
File "", line 9, in
ValueError: bad SCL pin

I tried it on two different RP2040's and got the same error so I believe its not a defective chip.
Any ideas?

Post the exact code that produced that error.

This is the code, its from the examples file from the library listed above

import time
from machine import Pin, I2C
from micropython_lsm6dsox import LSM6DSOX

i2c = I2C(1, sda=Pin(12), scl=Pin(13)) # Correct I2C pins for RP2040
lsm = LSM6DSOX(i2c)

while True:
accx, accy, accz = lsm.acceleration
print(f"x:{accx:.2f}m/s2, y:{accy:.2f}m/s2, z{accz:.2f}m/s2")
gyrox, gyroy, gyroz = lsm.gyro
print(f"x:{gyrox:.2f}°/s, y:{gyroy:.2f}°/s, z{gyroz:.2f}°/s")
print("")
time.sleep(0.5)

Pin(12) and Pin(13) belong to I2C0
Your code should be

i2c = I2C(0, sda=Pin(12), scl=Pin(13)) # Correct I2C pins for RP2040

like I showed you in Post #4

It worked, thanks!

You're welcome.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.