为了使用M5Bala,需要M5Stack FIRE或M5GO(白色)。
Blockly
切换至 Python
.from m5stack import *
from m5ui import *
from m5bala import M5Bala
import i2c_bus
clear_bg(0x111111)
m5bala = M5Bala(i2c_bus.get(i2c_bus.M_BUS))
btnA = M5Button(name="ButtonA", text="ButtonA", visibility=False)
btnB = M5Button(name="ButtonB", text="ButtonB", visibility=False)
btnC = M5Button(name="ButtonC", text="ButtonC", visibility=False)
title0 = M5Title(title="Title", fgcolor=0xFFFFFF, bgcolor=0x0000FF)
title0.setTitle('calirate start')
wait(2)
sampleCount = 2000
gyroXSum = 0
gyroYSum = 0
gyroZSum = 0
for _ in range(sampleCount):
gyroXYZ = m5bala.imu.gyro
gyroXSum += gyroXYZ[0] # X
gyroYSum += gyroXYZ[1] # Y
gyroZSum += gyroXYZ[2] # Z
gyroXMean = gyroXSum / sampleCount
gyroYMean = gyroYSum / sampleCount
gyroZMean = gyroZSum / sampleCount
m5bala.imu.setGyroOffsets(gyroXMean, gyroYMean, gyroZMean)
title0.setTitle('balance start')
while True:
m5bala.balance()
wait(0.001)
m5stack
库NeoPixelBus
库MPU6050_tockn
库将M5Core连接至电脑.点击Tools
->Port
中选择设备使用的串行端口.
开发板Board
选项选择M5Stack-Core-ESP32
或M5Stack-Fire
.
git clone --recursive https://github.com/m5stack/M5Bala.git
Sketch
-> Include Library
-> Add .ZIP Library...
. 选择下载好的 M5Bala
的文件File
-> Examples
-> M5Bala
-> Basic
.