jposada202020 / micropython_lsm6dsox Goto Github PK
View Code? Open in Web Editor NEWMicroPython Library for the ST LSM6DSOX accelerometer/gyro Sensor
License: MIT License
MicroPython Library for the ST LSM6DSOX accelerometer/gyro Sensor
License: MIT License
I am trying to get the IMU unit to work on my Nano RP2040.
I get these same results on multiple Arduino Nano RP2040s
I installed the python library into the rp2040 using the command ./mpremote.exe mip install github:jposada202020/MicroPython_LSM6DSOX and ran the following code:
import time
from machine import Pin, I2C
from lib.micropython_lsm6dsox.lsm6dsox import LSM6DSOX
# from lsm6dsox import LSM6DSOX
i2c = I2C(1, sda=Pin(2), scl=Pin(3)) # Correct I2C pins for RP2040
print(str(i2c))
devices = i2c.scan()
print(str(devices))
if devices:
for d in devices:
print(hex(d))
time.sleep(1)
time.sleep(1)
lsm = LSM6DSOX(i2c)
while (True):
print('Accelerometer: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*lsm.accel()))
print('Gyroscope: x:{:>8.3f} y:{:>8.3f} z:{:>8.3f}'.format(*lsm.gyro()))
print("")
time.sleep_ms(100)
and got:
MPY: soft reboot
I2C(1, freq=399361, scl=3, sda=2, timeout=50000)
[]
106 15 1 #this is coming from a debug line I wrote to print 'obj._address, self.register, self.lenght' in the 'RegisterStruct' class of i2c_helpers.py
Traceback (most recent call last):
File "<stdin>", line 14, in <module>
File "lib/micropython_lsm6dsox/lsm6dsox.py", line 159, in __init__
File "/lib/micropython_lsm6dsox/i2c_helpers.py", line 120, in __get__
OSError: [Errno 116] ETIMEDOUT
When I try the same thing using the following I2C config, I get:
i2c=I2C(0, scl=Pin(13), sda=Pin(12))
MPY: soft reboot
I2C(0, freq=399361, scl=13, sda=12, timeout=50000)
[106]
0x6a
106 15 1
Traceback (most recent call last):
File "<stdin>", line 16, in <module>
AttributeError: 'LSM6DSOX' object has no attribute 'accel'
Platform: MicroPython v1.22.1 on 2024-01-05; Arduino Nano RP2040 Connect with RP2040
Code:
import time
from micropython_lsm6dsox import LSM6DSOX
from machine import Pin, I2C
lsm = LSM6DSOX(I2C(0, scl=Pin(13), sda=Pin(12)))
while (True):
accx, accy, accz = lsm.acceleration
gyrox, gyroy, gyroz = lsm.gyro
print(f"Accelerometer: x:{accx:8.3f} y:{accy:8.3f} z:{accz:8.3f}")
print(f"Gyroscope: x:{gyrox:8.3f} y:{gyroy:8.3f} z:{gyroz:8.3f}")
print(f"Temperature: :{lsm.temperature}")
print("")
time.sleep_ms(1000)
When executed (using ampy) , generates the expected output lines for Accelerometer and Gyroscope, but then the error:
File "/lib/micropython_lsm6dsox/lsm6dsox.py", line 402, in temperature\r\nTypeError: 'int' object isn't subscriptable
It seems that in the line 402 there is an implicit conversion from int to float, which generates the error.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.