Welcome to IMU Sensor Module repository
For Raspberry Pi Pico
Pico-IIC Data Reading
This example uses the Pico2 development board, a Windows computer, several DuPont wires, and an IMU attitude sensor.
1. Connecting the Device

| IMU Attitude Sensor | Pico2 |
|---|---|
| SDA | GP4 |
| SCL | GP5 |
| GND | GND |
| 5V | 3V3(OUT) |

2. Key Code Analysis
Please refer to the source code in the documentation for specific code.
x
# Get accelerometer triaxial data, return accel=[a_x, a_y, a_z] def get_accelerometer_data(self): values = self._read_data(self.FUNC_RAW_ACCEL, 6) # 转化单位为g accel_ratio = 16 / 32767.0 a_x = struct.unpack('h', bytearray(values[0:2]))[0]*accel_ratio a_y = struct.unpack('h', bytearray(values[2:4]))[0]*accel_ratio a_z = struct.unpack('h', bytearray(values[4:6]))[0]*accel_ratio accel = [a_x, a_y, a_z] if self._delay_time > 0: time.sleep(self._delay_time) return accel # Get the gyro triaxial data, return gyro=[g_x, g_y, g_z] def get_gyroscope_data(self): values = self._read_data(self.FUNC_RAW_GYRO, 6) # 转化单位为rad/s AtoR = math.pi / 180.0 gyro_ratio = (2000 / 32767.0) * AtoR g_x = struct.unpack('h', bytearray(values[0:2]))[0]*gyro_ratio g_y = struct.unpack('h', bytearray(values[2:4]))[0]*gyro_ratio g_z = struct.unpack('h', bytearray(values[4:6]))[0]*gyro_ratio gyro = [g_x, g_y, g_z] if self._delay_time > 0: time.sleep(self._delay_time) return gyro # Get the quaternion of the IMU, return quat=[w, x, y, z] def get_imu_quaternion_data(self): values = self._read_data(self.FUNC_QUAT, 16) q0 = struct.unpack('f', bytearray(values[0:4]))[0] q1 = struct.unpack('f', bytearray(values[4:8]))[0] q2 = struct.unpack('f', bytearray(values[8:12]))[0] q3 = struct.unpack('f', bytearray(values[12:16]))[0] quat = [q0, q1, q2, q3] if self._delay_time > 0: time.sleep(self._delay_time) return quat # Get the board's attitude angle, returning euler=[roll, pitch, yaw]# ToAngle=True returns the angle, ToAngle=False returns the radians。 def get_imu_attitude_data(self, ToAngle=True): values = self._read_data(self.FUNC_EULER, 12) roll = struct.unpack('f', bytearray(values[0:4]))[0] pitch = struct.unpack('f', bytearray(values[4:8]))[0] yaw = struct.unpack('f', bytearray(values[8:12]))[0] if ToAngle: RtoA = 180.0 / math.pi roll = roll * RtoA pitch = pitch * RtoA yaw = yaw * RtoA euler = [roll, pitch, yaw] if self._delay_time > 0: time.sleep(self._delay_time) return eulerget_accelerometer_data(): Gets the accelerometer's three-axis data, returning accel=[a_x, a_y, a_z]
get_gyroscope_data(): Gets the gyroscope's three-axis data, returning gyro=[g_x, g_y, g_z]
get_imu_quaternion_data(): Gets the IMU's quaternion, returning quat=[w, x, y, z]
get_imu_attitude_data(): Gets the board's attitude angle, returning euler=[roll, pitch, yaw]
3. Reading IMU Data
After the program runs, the IMU data can be displayed in the terminal below.

Note: The above is for reading data from a 10-axis IMU; 6-axis data is without a magnetometer and barometer; 9-axis data is without a barometer.