M5Stick 系および M5Stack Core2 デバイスで IMU(加速度・ジャイロ)を記録し、PC にバイナリ/CSVとして吸い出すためのファームウェア+PCツールのセットです。
- ファームウェアは64バイトのヘッダ+生データのシンプルなログ形式で
/ACCLOG.BINに記録します。 - PCツール(GUI/CLI)はシリアル経由で
ACCLOG.BINをダウンロードし、必要に応じてCSVへ変換します。 - 新ファーム(v2/0x0200)は加速度+ジャイロを同時記録。旧ログ(加速度のみ v1/0x0100)も自動判別して対応します。
- 拡張ヘッダ(0x0201)では IMU 種別/機種 ID/スケール情報を含み、Core2 など M5Unified 利用ボードでもスケーリングをメタ経由で正しく行います。
- M5Stick本体のボタン操作で記録開始/停止
- 取得レートやレンジは
config.hで設定 - シリアルDUMPはプリアンブル混入やタイミング差にロバスト
- デコーダはログ形式(v1/v2)を自動判別しCSV出力
- SH200Q 搭載デバイス(StickC系のSH200Qモデルなど)は既知の挙動差・スケールばらつき回避のため、
imu_sh200q.hでレジスタ直叩きし、生の int16 を記録する。 - それ以外のIMU(例: MPU6886 搭載の Core2 や Stick 系バリエーション)は不具合なしとみなし、M5Unified(公式ライブラリ)経由の設定・取得を採用する。ヘッダ 0x0201 に
imu_type/device_model/lsb_per_g/lsb_per_dpsを記録し、PC側で正しくスケーリングする。 - いずれもデバイス内後処理を最小化し、PC側で統一解析する方針。将来的にライブラリ側で生値取得が安定した場合は再評価する。
- SH200Q 搭載モデル(例: M5StickC/Plus/Plus2 のSH200Q版) — レジスタ直叩き
- それ以外のIMU搭載モデル(例: M5Stack Core2 の MPU6886、将来の非SH200Q Stick系など) — M5Unified 経由
firmware_m5_multi_acc_logger/— M5Stick 向け Arduino ファームウェアpc_tools/— PC側ツール(GUI/CLI/decoder)docs/— 追加ドキュメント(任意)
- Arduino IDE で
firmware_m5_multi_acc_logger/firmware_m5_multi_acc_logger.inoを開く - ボード(M5StickC / M5StickC Plus / M5StickC Plus2 など)を選択
- ビルドして書き込み
- 記録操作:
- 本体ボタンAで開始/停止
- デバイス内に
/ACCLOG.BINが生成されます
パーティション設定(重要)
- Arduino IDE メニューの「ツール」→「Partition Scheme」で、次を推奨します。
- Core2(16MB想定): 同梱
tools/partitions_core2_16mb.csvの No OTA (APP 2MB / LittleFS 13MB 目安) - StickC 系ほか容量不明:
No OTA (1MB APP/3MB SPIFFS)をフォールバック選択
- Core2(16MB想定): 同梱
- この設定によりフラッシュをファイルシステム(LittleFS領域)に広く割り当てます。表示名は「SPIFFS」ですが、実装は LittleFS を使用します(同一FS領域を共有)。
設定(config.h)
ODR_HZサンプリングレート(例: 128 Hz、SH200Qの対応値に自動丸め)RANGE_G加速度レンジ(2/4/8/16 g)GYRO_RANGE_DPSジャイロレンジ(250/500/1000/2000 dps、既定2000)SERIAL_BAUDシリアル速度(既定 115200)
シリアルプロトコル(抜粋)
PING→PONG\nINFO→ 1行JSON(ODR/レンジ/ファイルサイズ/FS使用率など)HEAD→ 先頭64バイトのヘッダを16進で表示DUMP→OK <filesize> <millis>の後に生データ、本体は最後に\nDONE\nERASE→/ACCLOG.BIN削除START/STOP→ 記録開始/停止
ヘッダ(64バイト, little-endian)
- magic[8]:
"ACCLOG\0\0"(古いv1では"ACCLOG\0") - format_ver: uint16(v1: 0x0100 加速度のみ, v2: 0x0200 加速度+ジャイロ, 拡張: 0x0201 メタ追加)
- device_uid: uint64
- start_unix_ms: uint64(任意)
- odr_hz: uint16
- range_g: uint16
- v2+: gyro_range_dps: uint16(v1のreserved領域を再利用)
- v2.1+: imu_type, device_model, lsb_per_g, lsb_per_dps(旧reserved内に追加)
- total_samples: uint32(記録中は 0xFFFFFFFF)
- dropped_samples: uint32
- reserved: 64バイトにゼロ詰め(上記以外)
ペイロード(MSB first の int16 配列)
- v1:
[ax][ay][az]の繰り返し - v2+:
[ax][ay][az][gx][gy][gz]の繰り返し
CSV列
- v1:
n, t_sec, ax_g, ay_g, az_g - v2+:
n, t_sec, ax_g, ay_g, az_g, gx_dps, gy_dps, gz_dps
要件(Python 3.10+ 推奨):
python -m pip install -r pc_tools/requirements.txt
GUI(Tkinter)
python pc_tools/AccDumpGUI.py
- シリアルポートを選択して DUMP をクリック
- 「CSVへ変換」にチェックで、
ACCLOG.BINと同じ場所にCSVを自動生成
CLI
特定ポートからDUMPしてCSVへ変換:
python pc_tools/accdump_cli.py --port /dev/ttyUSB0 --out logs/ --csv
利用可能な全ポートからDUMP:
python pc_tools/accdump_cli.py --all --out logs/
既存のログをCSVへ変換:
python pc_tools/decoder.py logs/ACCLOG.BIN --csv
- デバイスが使用中(
Device or resource busy)- 他のシリアルモニタ(Arduino Serial Monitor / screen / minicom / VS Code拡張など)を終了
- Linuxでは ModemManager がポートを触る場合があります:
sudo systemctl stop ModemManager dialoutグループ所属を確認し、追加後は再ログイン
- ヘッダ待ちタイムアウト/途中で止まる
- PC側は
ACCLOGを探索し、見つからない場合はロウコピーにフォールバック - 先頭にプリアンブルがある場合でも decoder が自動でヘッダ位置へ同期
- 解決しない場合はデバイスの電源再投入、再試行
- PC側は
- CSV変換エラー(invalid magic など)
- 最新のファーム/ツールで再DUMP
.binサイズと先頭64バイトのhexを共有いただければ解析可能
- 通信が不安定/遅い
- ツールは10秒のシリアルタイムアウトと4KBチャンクで受信。再試行推奨
PyInstaller で配布用バイナリを作成:
python -m pip install -r pc_tools/requirements.txt pyinstaller
pyinstaller --onefile --windowed pc_tools/AccDumpGUI.py
pyinstaller --onefile pc_tools/accdump_cli.py
dist/ に成果物が生成されます。
- 新ファーム(format 0x0200)はジャイロを追加。decoder は v1 と後方互換
- ファームは MSB first で int16 を書き込み、decoder は big-endian として解釈します
Firmware + PC tools to log IMU (accelerometer/gyroscope) on M5Stick devices and dump as binary/CSV to your computer.
- Firmware stores
/ACCLOG.BINwith a 64‑byte header followed by raw samples. - PC tools (GUI/CLI) download
ACCLOG.BINover serial and optionally convert to CSV. - Latest firmware (v2) logs accel+gyro; older accel‑only logs (v1) are supported.
- Button‑controlled recording on device
- Configurable ODR/ranges in
config.h - Robust serial dump (handles preambles/timing)
- Decoder auto‑detects format (v1 accel‑only, v2 accel+gyro)
- Devices with SH200Q (e.g., StickC/Plus/Plus2 SH200Q models) — register-level driver
- Devices with other IMUs (e.g., Core2 with MPU6886, future non-SH200Q Stick variants) — M5Unified
- SH200Q devices use
imu_sh200q.hto configure registers directly and keep raw int16 samples for reproducibility and to avoid known quirks. - Non-SH200Q devices use M5Unified APIs; format 0x0201 stores
imu_type/device_model/lsb_per_g/lsb_per_dpsto ensure correct scaling on PC. - Direct register control preserves repeatability for offline analysis; once the M5 library officially exposes raw access with configurable ODR/range we can revisit the decision.
firmware_m5_multi_acc_logger/— Arduino firmwarepc_tools/— PC tools (GUI/CLI/decoder)docs/— extra docs
- Open
firmware_m5_multi_acc_logger/firmware_m5_multi_acc_logger.inoin Arduino IDE. - Select your M5Stick board, set the partition scheme, build and upload.
- Recording: Button A toggles logging;
/ACCLOG.BINis created.
Configuration (config.h):
ODR_HZsampling rate (e.g., 128 Hz; rounded to nearest supported by SH200Q)RANGE_Gaccelerometer full scale (2/4/8/16 g)GYRO_RANGE_DPSgyroscope full scale (250/500/1000/2000 dps, default 2000)SERIAL_BAUDserial speed (115200 default)
Serial Protocol
PING→PONG\nINFO→ JSON line (ODR/ranges/file size/FS usage, etc.)HEAD→ dump first 64-byte header as hexDUMP→OK <filesize> <millis>then raw bytes, then\nDONE\nERASE→ remove/ACCLOG.BINSTART/STOP→ control logging
Header (64 bytes, little‑endian): magic ACCLOG\0\0 (v1 may be ACCLOG\0), version, UID, start time, ODR, ranges, totals, reserved.
Payload (int16, MSB first):
- v1:
[ax][ay][az] - v2+:
[ax][ay][az][gx][gy][gz]
CSV Columns:
- v1:
n, t_sec, ax_g, ay_g, az_g - v2+:
n, t_sec, ax_g, ay_g, az_g, gx_dps, gy_dps, gz_dps
Requirements:
python -m pip install -r pc_tools/requirements.txt
GUI:
python pc_tools/AccDumpGUI.py
CLI:
python pc_tools/accdump_cli.py --port /dev/ttyUSB0 --out logs/ --csv
python pc_tools/accdump_cli.py --all --out logs/
python pc_tools/decoder.py logs/ACCLOG.BIN --csv
- Busy port: close other monitors; stop ModemManager on Linux; ensure
dialoutgroup. - Header timeouts/partials: dumper searches for
ACCLOGand decoder scans/aligns; retry after power‑cycle if needed. - CSV errors: re‑dump with latest firmware/tools; share
.binsize and first 64 bytes (hex) for help. - Unstable link: tools use 10‑second timeout and 4 KB chunks; retry.
python -m pip install -r pc_tools/requirements.txt pyinstaller
pyinstaller --onefile --windowed pc_tools/AccDumpGUI.py
pyinstaller --onefile pc_tools/accdump_cli.py
- v2 firmware (0x0200) adds gyro channels; decoder remains backward‑compatible.
- Firmware writes int16 MSB‑first; decoder reads big‑endian. Partition Scheme (Important)
- In Arduino IDE, go to Tools → Partition Scheme and select:
No OTA (1MB APP/3MB SPIFFS)
- This grants ~3MB to the filesystem (used by LittleFS) for longer recordings. The default schemes provide a smaller FS and will reduce recording time.
- The menu label mentions SPIFFS, but this project uses LittleFS on the same partition region.