Skip to content

Instantly share code, notes, and snippets.

@thushan
Last active January 18, 2024 23:26
Show Gist options
  • Save thushan/72f4c7e126d6a72db107c259cccf76fe to your computer and use it in GitHub Desktop.
Save thushan/72f4c7e126d6a72db107c259cccf76fe to your computer and use it in GitHub Desktop.
WaveShare PICO 10DOF IMU for RaspberryPi Pico CircuitPython Example

This gist contains a simple example of the WaveShare Pico 10DOF IMU sensor module for RaspberyPi Pico using the Adafruit CircuitPython libraries instead of the chaotic WaveShare example code.

Setup for RaspberryPi Pico

You need to setup your RaspberryPi Pico to run CircuitPython by:

This example uses the following Adafruit libaries within CircuitPython:

After downloading the libraries, we need to grab the following libraries and copy them to your Pico (now named & mounted as 'CIRCUITPY') /lib folder:

  • /adafruit_bus_device
  • /adafruit_register
  • adafruit_icm20x.mpy
  • adafruit_lps2x.mpy

Once you've copied them over, you can utilise the code.py below and run the example which prints a steady stream of data from the sensors as shown below:

Acceleration: X:0.14, Y: -0.14, Z: 10.07 m/s^2
Gyro X:-0.02, Y: 0.02, Z: -0.01 rads/s
Magnetometer X:-7.50, Y: 14.85, Z: -96.60 uT
Pressure: 1001.28 hPa
Temperature: 21.59 C

Acceleration: X:0.11, Y: -0.12, Z: 10.18 m/s^2
Gyro X:-0.03, Y: 0.02, Z: -0.01 rads/s
Magnetometer X:-7.50, Y: 14.40, Z: -95.85 uT
Pressure: 1001.25 hPa
Temperature: 21.59 C

Acceleration: X:0.15, Y: -0.11, Z: 10.11 m/s^2
Gyro X:-0.02, Y: 0.02, Z: -0.00 rads/s
Magnetometer X:-8.25, Y: 15.15, Z: -94.80 uT
Pressure: 1001.28 hPa
Temperature: 21.59 C

Enjoy!

import time
import board
import busio
import adafruit_icm20x
import adafruit_lps2x
DEVICE_ADDRESS_ICM = 0x68
DEVICE_ADDRESS_LPS = 0x5C
DEVICE_I2C_SCL = board.GP7
DEVICE_I2C_SDA = board.GP6
i2c = busio.I2C(scl=DEVICE_I2C_SCL, sda=DEVICE_I2C_SDA)
icm = adafruit_icm20x.ICM20948(i2c, DEVICE_ADDRESS_ICM)
lps = adafruit_lps2x.LPS22(i2c, DEVICE_ADDRESS_LPS)
while True:
print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2" % (icm.acceleration))
print("Gyro X:%.2f, Y: %.2f, Z: %.2f rads/s" % (icm.gyro))
print("Magnetometer X:%.2f, Y: %.2f, Z: %.2f uT" % (icm.magnetic))
print("Pressure: %.2f hPa" % lps.pressure)
print("Temperature: %.2f C" % lps.temperature)
print("")
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment