Skip to content

Instantly share code, notes, and snippets.

@tkeyo
Last active June 5, 2021 12:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tkeyo/240540f796590adc005ab75b946d4952 to your computer and use it in GitHub Desktop.
Save tkeyo/240540f796590adc005ab75b946d4952 to your computer and use it in GitHub Desktop.
import utime
from machine import Timer, Pin, I2C
from drivers.mpu6500 import MPU6500, SF_DEG_S, SF_M_S2
# MPU6500 module was adjusted from:
# https://github.com/tuupola/micropython-mpu9250
# set up I2C serial communication protcol
i2c = I2C(scl=Pin(22), sda=Pin(21))
# create MPU6500 instance
mpu6500 = MPU6500(i2c, accel_sf=SF_M_S2, gyro_sf=SF_DEG_S)
# read sensor function
def read_sensor(timer):
print(utime.ticks_ms(), mpu6500.acceleration, mpu6500.gyro)
# hardware timer setup
timer = Timer(0)
timer.init(period=10, mode=Timer.PERIODIC, callback=read_sensor)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment