pdf-icon

BALA 上手指南

为了使用M5Bala,需要M5Stack FIRE或M5GO(白色)。

准备

开发环境

UIFlow编辑

  1. 烧录 UIFlow 固件
  2. 配置 Wi-Fi 连接
  3. 将 POGO Pin 弹簧针堆叠放置在 M5Bala 底座上.
  1. 单击M5Core侧边的红色按键开机(快速双击为关机).
  1. 单击M5Bala底座的按键启动电源(连续点击两次时关闭电源).
  1. 访问 UIFlow , 将编程模式Blockly 切换至 Python.
  1. 复制粘贴以下代码,并执行程序.
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)

Arduino IDE编辑

  1. 在Arduino IDE的库管理安装m5stack
  1. 在Arduino IDE的库管理安装NeoPixelBus
  1. 在Arduino IDE的库管理安装MPU6050_tockn
  1. 将M5Core连接至电脑.点击Tools->Port中选择设备使用的串行端口.

  2. 开发板Board选项选择M5Stack-Core-ESP32M5Stack-Fire.

  1. 使用Shell命令下载 M5Bala案例程序 . 如果你还未安装Git, 请点击此处 进行下载.
git clone --recursive https://github.com/m5stack/M5Bala.git
  1. 点击 Sketch -> Include Library -> Add .ZIP Library... . 选择下载好的 M5Bala 的文件
  1. 打开 BALA 程序案例: 点击 File -> Examples -> M5Bala -> Basic.
  1. 编译并上传程序.
On This Page