This is the firmware repo for the Core Electronics PiicoDev® Motion Sensor MPU-6050
This module depends on the PiicoDev Unified Library. Place PiicoDev_Unified.py in the same directory.
See the Quickstart Guides:
main.py is a simple example to get started.
# Example code for PiicoDev Motion Sensor MPU6050
from PiicoDev_MPU6050 import PiicoDev_MPU6050
from time import sleep
motion = PiicoDev_MPU6050()
while True:
# Accelerometer data
accel = motion.read_accel_data() # read the accelerometer [ms^-2]
aX = accel["x"]
aY = accel["y"]
aZ = accel["z"]
print("x:" + str(aX) + " y:" + str(aY) + " z:" + str(aZ))
# Gyroscope Data
gyro = motion.read_gyro_data() # read the gyro [deg/s]
gX = gyro["x"]
gY = gyro["y"]
gZ = gyro["z"]
print("x:" + str(gX) + " y:" + str(gY) + " z:" + str(gZ))
# Rough temperature
temp = motion.read_temperature() # read the device temperature [degC]
print("Temperature: " + str(temp) + "°C")
# G-Force
gforce = motion.read_accel_abs(g=True) # read the absolute acceleration magnitude
print("G-Force: " + str(gforce))
sleep(0.1)
| Parameter | Type | Range | Default | Description |
|---|---|---|---|---|
| bus | int | 0,1 | Raspberry Pi Pico: 0, Raspberry Pi: 1 | I2C Bus. Ignored on Micro:bit |
| freq | int | 100-1000000 | Device dependent | I2C Bus frequency (Hz). Ignored on Raspberry Pi |
| sda | Pin | Device Dependent | Device Dependent | I2C SDA Pin. Implemented on Raspberry Pi Pico only |
| scl | Pin | Device Dependent | Device Dependent | I2C SCL Pin. Implemented on Raspberry Pi Pico only |
| address | int | 0x68, 0x69 | 0x68 | This address needs to match the PiicoDev Motion Sensor MPU6050 hardware address configured by the jumper or ADR pin |
Returns a dictionary x y z
| Parameter | Type | Default | Description | Unit |
|---|---|---|---|---|
| g | bool | False | If False, retuned units are m/s. If True, returned units are g | |
| returned x | float | x acceleration | g or m/s | |
| returned y | float | y acceleration | g or m/s | |
| returned z | float | z acceleration | g or m/s |
| Parameter | Type | Default | Description | Unit |
|---|---|---|---|---|
| g | bool | False | If False, retuned units are m/s. If True, returned units are g | |
| returned | float | Acceleration magnitude | g or m/s |
Returns a dictionary x y z
| Parameter | Type | Description | Unit |
|---|---|---|---|
| returned x | float | x value from gyroscope | deg/s |
| returned y | float | y value from gyroscope | deg/s |
| returned z | float | z value from gyroscope | deg/s |
| Parameter | Type | Description | Unit |
|---|---|---|---|
| returned | float | Temperature | degC |
| Parameter | Type | Default | Description | Unit |
|---|---|---|---|---|
| raw | bool | False | If False, returned ranger is integer: -1, 2, 4, 8 or 16. If True, returned range is the raw value from the ACCEL_CONFIG register | |
| returned | int | Accelerometer range | # |
| Parameter | Type | Description |
|---|---|---|
| accel_range | int | the range to set the accelerometer to. Using a pre-defined range from the MPU-6050 datasheet is advised. |
| Parameter | Type | Default | Description | Unit |
|---|---|---|---|---|
| raw | bool | False | If False, returned range is deg/s. If True, returned range is the raw value from GYRO_CONFIG register | |
| returned | int | Gyro range | # |
| Parameter | Type | Description |
|---|---|---|
| gyro_range | int | The range to set the gyro to. Using a pre-defined range from the MPU-6050 datasheet is advised. |
Returns a dictionary x y
| Parameter | Type | Description |
|---|---|---|
| returned x | float | Radians: The tilt angle about the x-axis. Refer to silkscreen axes |
| returned y | float | Radians: The tilt angle about the y-axis. Refer to silkscreen axes |
This project is open source - please review the LICENSE.md file for further licensing information.
If you have any technical questions, or concerns about licensing, please contact technical support on the Core Electronics forums.
"PiicoDev" and the PiicoDev logo are trademarks of Core Electronics Pty Ltd.