M5Atomを開発ツールPlatformIOで使う(Windows10版)
2020/10/9+
PlatformIO M5ATOM on Windows10
PlatformIO M5ATOM on Windows10
概要
以下のM5Atomを開発ツールPlatformIOで使う(Windows10版)。
ホストPCとしてはwindows10を想定している。
Peripherals Pin Map
Lite:
Func | GPIO |
---|---|
RGB Led(Neo) | G27 |
Btn | G39 |
IR | G12 |
Matrix:
Func | GPIO |
---|---|
Neo | G27 |
Btn | G39 |
IR | G12 |
CLK(MPU6886) | G21 |
SDA(MPU6886) | GP25 |
Grove Interface
GND | 5V | G26 | G32 |
---|---|---|---|
GND | 5V | SDA | SCL |
platformioをインストールする
以下の手順でインストールする:
PowerShell:
# scoopをインストール
Set-ExecutionPolicy RemoteSigned -scope CurrentUser
iwr -useb get.scoop.sh | iex
# pythonをインストールする
scoop install python
pip3 install platformio
# windows用VScodeをインストールする
scoop bucket add extras
scoop install vscode
scoopの簡単な説明:
# xxxxをインストール
scoop install
# Scoop自身とローカル内にあるアプリの更新情報を更新
scoop update
# 最新バージョンでないアプリがあるかをチェック
scoop status
# xxxxを更新
scoop update xxxx
# すべてのアプリを更新
scoop update *
# xxxxをアンインストール
scoop uninstall xxxx
テスト用プロジェクト sample を作成/実行する
# プロジェクト sample のディレクトリを作成する
mkdir sample
cd sample
# 以下を実行して必要なファイルを作成する
pio init --board m5stick-c
# platformをupdateする
pio platform update
code platformio.ini
以下にように編集する:
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:esp32dev]
platform = espressif32
board = m5stick-c
framework = arduino
monitor_speed = 115200
lib_deps =
# use M5Atom lib
3113
# use "FastLED"
126
lib_ldf_mode = deep+
# テスト用のbutton.inoを作成する
code src/button.ino
以下のように編集する:
/****************************************************************
*
* This Example is used to test button
*
* Arduino tools Setting
* -board : M5StickC
* -Upload Speed: 115200 / 750000 / 1500000
*
****************************************************************/
#include "M5Atom.h"
uint8_t DisBuff[2 + 5 * 5 * 3];
void setBuff(uint8_t Rdata, uint8_t Gdata, uint8_t Bdata)
{
DisBuff[0] = 0x05;
DisBuff[1] = 0x05;
for (int i = 0; i < 25; i++)
{
DisBuff[2 + i * 3 + 0] = Rdata;
DisBuff[2 + i * 3 + 1] = Gdata;
DisBuff[2 + i * 3 + 2] = Bdata;
}
}
void setup()
{
M5.begin(true, false, true);
delay(10);
setBuff(0xff, 0x00, 0x00);
M5.dis.displaybuff(DisBuff);
}
uint8_t FSM = 0;
void loop()
{
if (M5.Btn.wasPressed())
{
switch (FSM)
{
case 0:
setBuff(0x40, 0x00, 0x00);
break;
case 1:
setBuff(0x00, 0x40, 0x00);
break;
case 2:
setBuff(0x00, 0x00, 0x40);
break;
case 3:
setBuff(0x20, 0x20, 0x20);
break;
default:
break;
}
M5.dis.displaybuff(DisBuff);
FSM++;
if (FSM >= 4)
{
FSM = 0;
}
}
delay(50);
M5.update();
}
続き:
# build
pio run
# ボードをホストPCに接続する
# build&upload(flash)
pio run -t upload
# buildしないで書き込む場合は以下を実行する:
pio run -t nobuild -t upload -v
# -v は、詳細を表示するオプション
# 以上で、基本的な操作としては完了となる
書き込み後、ボタンを押す度に、LEDの色が変化する。 (本スケッチは、Matrix/Lite兼用になっていて、Matrixの場合、5x5のLEDが同じ色で光る。Liteの場合、一つのLEDが光る)
これ以降、別のプログラムを動かすときは sampleのディレクトリをまるごと コピーして別のプロジェクトのディレクトリを作り そこにプログラム(.ino)を置く。
例:
cp sample m5a_proj01
cd m5a_proj01
...
MPU6886を利用するスケッチ#1(Matrix限定)
src/mpu6886_2.ino
#include "M5Atom.h"
#define SIG_MAX (4096)
uint8_t DisBuff[2 + 5 * 5 * 3];
int16_t adX,adY,adZ;
void setBuffP(uint8_t posData, uint8_t Rdata, uint8_t Gdata, uint8_t Bdata)
{
DisBuff[2 + posData * 3 + 0] = Rdata;
DisBuff[2 + posData * 3 + 1] = Gdata;
DisBuff[2 + posData * 3 + 2] = Bdata;
}
void setBuff(uint8_t Rdata, uint8_t Gdata, uint8_t Bdata)
{
for (uint8_t i = 0; i < 25; i++)
setBuffP(i, Rdata, Gdata, Bdata);
}
void shftBuff()
{
for (uint8_t i = 24; i > 0; i--)
{
for (uint8_t j = 0; j < 3; j++)
DisBuff[2 + i * 3 + j] = DisBuff[2 + (i-1) * 3 + j];
}
}
void setup()
{
DisBuff[0] = 0x05;
DisBuff[1] = 0x05;
M5.begin(false, true, true);
delay(10);
M5.IMU.Init();
setBuff(0x20, 0x20, 0x20);
M5.dis.displaybuff(DisBuff);
//
Serial.begin(115200);
}
void loop()
{
M5.update();
if (M5.Btn.read()==0)
{
M5.IMU.getAccelAdc(&adX, &adY, &adZ);
int r = min(max((int)map(adX,-SIG_MAX,SIG_MAX,0,255),0),255);
int g = min(max((int)map(adY,-SIG_MAX,SIG_MAX,0,255),0),255);
int b = min(max((int)map(adZ,-SIG_MAX,SIG_MAX,0,255),0),255);
shftBuff();
setBuffP(0,r,g,b);
M5.dis.displaybuff(DisBuff);
//
Serial.printf("x,y,z: %d,%d,%d\r\n", adX, adY, adZ);
}
delay(20);
}
書き込み実行し、M5Atomを傾けるとそれに応じて5x5のLEDの色が変化する。
MPU6886を利用するスケッチ#2(Matrix限定)
src/mpu6886_3.ino
#include "M5Atom.h"
float accX = 0, accY = 0, accZ = 0;
float gyroX = 0, gyroY = 0, gyroZ = 0;
float temp = 0;
bool IMU6886Flag = false;
void setup()
{
M5.begin(true, false, true);
if (M5.IMU.Init() != 0)
IMU6886Flag = false;
else
IMU6886Flag = true;
}
void loop()
{
if (IMU6886Flag == true)
{
M5.IMU.getGyroData(&gyroX, &gyroY, &gyroZ);
M5.IMU.getAccelData(&accX, &accY, &accZ);
M5.IMU.getTempData(&temp);
Serial.printf("%.2f,%.2f,%.2f o/s \r\n", gyroX, gyroY, gyroZ);
Serial.printf("%.2f,%.2f,%.2f mg\r\n", accX * 1000, accY * 1000, accZ * 1000);
Serial.printf("Temperature : %.2f C \r\n", temp);
}
delay(500);
M5.update();
}
WiFi対応スケッチ
ESP32のWiFi対応スケッチと互換性があるので、以下をソースの先頭に入れると動作するようだ。
#ifdef M5ATOM
#include "M5Atom.h"
#define ESP32
#endif
したがって、以下のスケッチの先頭に上のコードを入れるとM5Atomでも動作するようになる:
・Wio-Terminal/ESP8622/ESP32ボードを共通のスケッチでWorld Time APIを使う(WorldTimeAPI編)
・Wio-Terminal/ESP8622/ESP32ボードを共通のスケッチで動かす(HTTP-ACCESS編)
・Wio-Terminal/ESP8622/ESP32ボードを共通のスケッチで動かす(NTP-CLIENT編)
・Wio-Terminal/ESP8622/ESP32ボードを共通のスケッチで動かす(REST-API2編)
・Wio-Terminal/ESP8622/ESP32ボードを共通のスケッチで動かす(OSC編)
・Wio-Terminal/ESP8622/ESP32ボードを共通のスケッチで動かす(MQTT編)
補足
「Serial.printf("Temperature : %.2f C \r\n", temp);」などが動作していないようだ。 (USBシリアルが動作していないようだ)
参考情報
WindowsコマンドラインツールScoopのすすめ(基礎編)
Windowsでパッケージ管理したいなら、先ずScoopより始めよ
Atom pixel tool
wget https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/software/AtomPixTool.exe
windowsのプログラムだがlinuxのwineでも動作するようだ。
マトリックスのデザインを作成でき、それを保存すると、そのデータのC言語ソースができあがる
Display API Document:
https://github.com/m5stack/M5Atom
サンプル・スケッチ:
git clone https://github.com/m5stack/M5Atom.git
git clone https://github.com/hajimef/m5atom-matrix-samples.git
M5AtomをPlatformIOで動かす-ライブラリインストールから加速度取得まで
以上
| 固定リンク
「PlatformIO」カテゴリの記事
- NuEVI/NuRADのビルド(2022.08.18)
- Wio_ExtFlashLoad(WriteSampleMenu.ino)スケッチをplatformioでビルドする(2022.02.03)
- uncannyeyesスケッチをplatformioでビルドする(2022.01.31)
- LovyanGFX-Display ライブラリを使用したスケッチをplatformioでビルドする(2022.01.30)
- Wio-Terminal/M5Core2のWiFiAnallyzer(2022.01.24)
「ESP32」カテゴリの記事
- Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(STARWARS編)(2020.12.28)
- Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(MQTT編)(2020.12.27)
- Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(REST-API編)(2020.12.27)
- Wio-Terminal/M5Atom/ESP8622/ESP32ボードを共通のスケッチで動かす(v2)(OSC編)(2020.12.26)
- M5Atomを開発ツールPlatformIOで使う(Windows10版)(2020.10.09)
「windows10」カテゴリの記事
- platfomioを使ってnaitive(linux/windows)のプログラムをビルドする方法(2021.03.10)
- windows10にplatformioをインストールする(scoop版)(2021.03.01)
- M5Atomを開発ツールPlatformIOで使う(Windows10版)(2020.10.09)
- XIAOボードでTinyGOを動かす(Windows10版)(2020.10.09)
この記事へのコメントは終了しました。
コメント