Skip to main content

MicroPython I2C driver for MPU6886 6-axis motion tracking device

Project description

[WIP] MicroPython MPU-6886 I2C driver

The MPU-6886 is a 6-axis motion tracking device that combines a 3-axis gyroscope and a 3-axis accelerometer.

Usage

Simple test with never ending loop.

import utime
from machine import I2C, Pin
from mpu6886 import MPU6886

i2c = I2C(scl=Pin(22), sda=Pin(21))
sensor = MPU6886(i2c)

print("MPU6886 id: " + hex(sensor.whoami))

while True:
    print(sensor.acceleration)
    print(sensor.gyro)
    print(sensor.temperature)

    utime.sleep_ms(1000)

By default the library returns 3-tuple of X, Y, Z axis values for acceleration and gyroscope. Default units are m/s^2, rad/s and °C. It is possible to also get acceleration values in g and gyro values deg/s. See the example below.

import utime
from machine import I2C, Pin
from mpu6886 import MPU6886, SF_G, SF_DEG_S

i2c = I2C(scl=Pin(22), sda=Pin(21))
sensor2 = MPU6886(i2c, accel_sf=SF_G, gyro_sf=SF_DEG_S)

print("MPU6886 id: " + hex(sensor.whoami))

while True:
    print(sensor.acceleration)
    print(sensor.gyro)
    print(sensor.temperature)

    utime.sleep_ms(1000)

More realistic example usage with timer. If you get OSError: 26 or i2c driver install error after soft reboot do a hard reboot.

import micropython
from machine import I2C, Pin, Timer
from mpu6886 import MPU6886

micropython.alloc_emergency_exception_buf(100)

i2c = I2C(scl=Pin(22), sda=Pin(21))
sensor = MPU6886(i2c)

def read_sensor(timer):
    print(sensor.acceleration)
    print(sensor.gyro)
    print(sensor.temperature)

print("MPU6886 id: " + hex(sensor.whoami))

timer_0 = Timer(0)
timer_0.init(period=1000, mode=Timer.PERIODIC, callback=read_sensor)

Gyro Calibration

TODO

License

The MIT License (MIT). Please see License File for more information.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

micropython-mpu6886-0.1.0.tar.gz (4.3 kB view details)

Uploaded Source

File details

Details for the file micropython-mpu6886-0.1.0.tar.gz.

File metadata

  • Download URL: micropython-mpu6886-0.1.0.tar.gz
  • Upload date:
  • Size: 4.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.4

File hashes

Hashes for micropython-mpu6886-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b391276ffcb25571157b83af50652980e1490beddf0628becf196903498777c5
MD5 4baa7e830aa9e1f373fd33e117b3d287
BLAKE2b-256 ef688f5b887b17623fa05684fd6c796646cc4ca32c98acafdce66413e6c48360

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page