Created
August 28, 2023 02:38
-
-
Save algas/c19acca7bbe7983e7b92953c8cf67173 to your computer and use it in GitHub Desktop.
M5Stack Fire 6DoF IMU
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from m5stack import * | |
from m5ui import * | |
from uiflow import * | |
import i2c_bus | |
setScreenColor(0x222222) | |
PWR_MGMT_1 = None | |
PWR_MGMT_2 = None | |
i = None | |
def buttonA_wasPressed(): | |
global PWR_MGMT_1, PWR_MGMT_2, i, i2c0 | |
lcd.clear() | |
lcd.print(((str('acc_x: ') + str((i2c0.read_u16(0x2D, byteorder="big"))))), 0, 20, 0xffffff, rotate=0) | |
lcd.print(((str('acc_y: ') + str((i2c0.read_u16(0x2F, byteorder="big"))))), 0, 40, 0xffffff, rotate=0) | |
lcd.print(((str('acc_z: ') + str((i2c0.read_u16(0x31, byteorder="big"))))), 0, 60, 0xffffff, rotate=0) | |
lcd.print(((str('gyro_x: ') + str((i2c0.read_u16(0x33, byteorder="big"))))), 0, 80, 0xffffff, rotate=0) | |
lcd.print(((str('gyro_y: ') + str((i2c0.read_u16(0x35, byteorder="big"))))), 0, 100, 0xffffff, rotate=0) | |
lcd.print(((str('gyro_z: ') + str((i2c0.read_u16(0x37, byteorder="big"))))), 0, 120, 0xffffff, rotate=0) | |
pass | |
btnA.wasPressed(buttonA_wasPressed) | |
i2c0 = i2c_bus.easyI2C(i2c_bus.PORTA, 0x00, freq=100000) | |
i2c0.addr=(0x69) | |
if i2c0.available(): | |
PWR_MGMT_1 = i2c0.read_u8(0x06) | |
i2c0.write_u8(0x06, ((PWR_MGMT_1 & (~ (0x01 << 6))))) | |
PWR_MGMT_2 = i2c0.read_u8(0x07) | |
for i in range(6): | |
PWR_MGMT_2 = (PWR_MGMT_2 & (~ (0x01 << i))) | |
i2c0.write_u8(0x07, PWR_MGMT_2) | |
lcd.print('success', 0, 0, 0xffffff, rotate=0) | |
else: | |
lcd.print('failure', 0, 0, 0xffffff, rotate=0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment