Thanks in advance for your attention.
I am trying to read my IMU sensor data, I have already tried this sensor with an Arduino and it works fine. However when I use this sensor with my pico I get strange values as you see in the photos , .
In the first photo the IMU is placed flat to the surface and I get 1g of acceleration in Z axis, which is normal, but in the X,Y axis I get strange values. In the second photo the IMU is placed perpendicular to the surface and I get 1g of acceleration in Y axis, which is normal, but in the X,Z axis I get strange values. Someone could tell me of this strange behaviour?
Here is my code:
And here the pin conections:
Code: Select all
import os import utime from machine import Pin, I2C from micropython import const # SETUP IMU ISM330DHCXAddress = const(0x6B) # Device address ACC_CONFIG_CTRL1_G = const(0x10) # Accel configuration register address GYR_CONFIG_CTRL2_G = const(0x11) # Gyro configuration register address ISM330DHCX_STATUS_REG = const(0x1E) # New data available register ISM330DHCX_OUTX_L_G = const(0x22) # X gyro data register address ISM330DHCX_OUTY_L_G = const(0x24) # Y gyro data register address ISM330DHCX_OUTZ_L_G = const(0x26) # Z gyro data register address ISM330DHCX_OUTX_L_A = const(0x28) # X accel data register address ISM330DHCX_OUTY_L_A = const(0x2A) # Y accel data register address ISM330DHCX_OUTZ_L_A = const(0x2C) # Z accel data register address i2c=I2C(0,scl=Pin(1),sda=Pin(0),freq=100000) i2c.writeto_mem(ISM330DHCXAddress,ACC_CONFIG_CTRL1_G, b'\x44') i2c.writeto_mem(ISM330DHCXAddress,GYR_CONFIG_CTRL2_G, b'\x4C') while True: dataAvailable=i2c.readfrom_mem(ISM330DHCXAddress,ISM330DHCX_STATUS_REG , 1) if dataAvailable==7: data=i2c.readfrom_mem(ISM330DHCXAddress,ISM330DHCX_OUTX_L_G , 12) rawGyrX = data | data << 8 rawGyrY = data | data << 8 rawGyrZ = data | data << 8 rawAccX = data | data << 8 rawAccY = data | data << 8 rawAccZ = data | data << 8 print('AccX: ' + str(rawAccX*0.000488) + ' AccY: ' + str(rawAccY*0.000488)+' AccZ: ' + str(rawAccZ*0.000488)) print('AccX: ' + str(rawGyrX*0.07) + ' GyrY: ' + str(rawGyrY*0.07) + ' GyrZ: ' + str(rawGyrZ*0.07)+'\n')