Skip to content

11 KB

Machine-translated by Robotheca from the original in Japanese (opens in a new tab). License: MIT (opens in a new tab).

Examples

This folder contains Arduino sketches for controlling the M5Stack Q-Spider quadruped robot.


Folder Structure

FolderDescription
M5_Spider_WebserverControl the robot from a web browser via WiFi.
M5_Spider_esp-nowControl the robot with a game controller using ESP-NOW communication.
ESP32_ChipInfoUtility sketch to check the ESP32 chip info and MAC address.

Common Requirements

  • M5Stack Basic (ESP32 based)
  • SG-90 or compatible 9g servos × 9
  • PCA9685 servo driver module (I2C address: 0x72)
  • Arduino IDE with the following libraries:
    • M5Stack / M5Unified
    • Adafruit PWM Servo Driver Library (for PCA9685)
    • M5StackUpdater

An Arduino IDE with the following libraries installed is required.

  • M5Stack / M5Unified
  • Adafruit PWM Servo Driver Library (for PCA9685)
  • M5StackUpdater

The servo channel assignment is common across all sketches.

The servo channel assignment is common across all sketches.

ChannelFunctionFunction
0FR0Front Right knee / Front right leg knee joint
1FR1Front Right leg swing / Front right leg swing
2FL0Front Left knee / Front left leg knee joint
3FL1Front Left leg swing / Front left leg swing
4TILTHead tilt / Head tilt
6RR0Rear Right knee / Rear right leg knee joint
7RR1Rear Right leg swing / Rear right leg swing
8RL0Rear Left knee / Rear left leg knee joint
9RL1Rear Left leg swing / Rear left leg swing

M5_Spider_Webserver

By default, this sketch starts the M5Stack as a standalone WiFi access point and serves a simple web controller on port 80.

By default, this sketch starts the M5Stack as a standalone WiFi access point and serves a simple web controller on port 80.

Features / 機能

  • Standalone WiFi access point mode by default

  • Optional WiFi setup via WiFiManager (captive portal)

  • OTA (Over The Air) firmware updates in WiFiManager mode

  • Web UI with buttons for forward, backward, left/right shift, spin, and stop

  • Face animation (eye blink, mouth open) on the M5Stack LCD

  • Calibration mode (adjMode) triggered when powered on while charging

  • Operates as a standalone WiFi access point by default

  • WiFi configuration is also available via WiFiManager (captive portal)

  • Supports firmware updates via OTA in WiFiManager mode

  • Web UI for forward, backward, left/right shift, spin, and stop operations

  • Displays face animations (eye blinks, mouth movements) on the M5Stack LCD

  • Entering calibration mode (adjMode) by turning on the power while charging

WiFi Mode / WiFi Mode

usesoftAP is defined by default near the top of M5_Spider_Webserver.ino. In this mode, the M5Stack creates an access point named ESP32-xxxx with the password esp32. Connect directly to it and open http://192.168.4.1/.

In M5_Spider_Webserver.ino, usesoftAP is defined by default near the top. In this mode, the M5Stack creates an access point named ESP32-xxxx with the password esp32. Connect directly to it and open http://192.168.4.1/.

To connect the M5Stack to an existing WiFi access point instead, comment out #define usesoftAP. The sketch then uses the WiFiManager portal for network configuration and enables OTA updates.

To connect the M5Stack to an existing WiFi access point instead, comment out #define usesoftAP. In that case the WiFiManager configuration portal is used, and OTA updates are also enabled.

How to Use / How to Use

  1. Open M5_Spider_Webserver.ino in Arduino IDE.

  2. Select the M5Stack-Core-ESP32 board.

  3. Keep #define usesoftAP enabled for standalone AP mode, or comment it out for WiFiManager mode.

  4. Upload the sketch to M5Stack.

  5. Connect to the AP name displayed on the LCD.

  6. Open the IP address shown on the LCD with a browser.

  7. Open M5_Spider_Webserver.ino in Arduino IDE.

  8. Select the M5Stack-Core-ESP32 board.

  9. In standalone AP mode, keep #define usesoftAP enabled; in WiFiManager mode, comment it out.

  10. Upload the sketch to M5Stack.

  11. Connect to the access point name shown on the LCD.

  12. Open the IP address shown on the LCD in a browser.

Main Files / 主なファイル

  • M5_Spider_Webserver.ino: Main sketch

  • WebPage.h: HTML for the web controller

  • wifi_setup.cpp/h: WiFi connection helper and OTA setup

  • avatar.cpp/h: Face animation class

  • M5_Spider_Webserver.ino: Main sketch

  • WebPage.h: HTML for the web controller

  • wifi_setup.cpp/h: WiFi connection helper and OTA setup

  • avatar.cpp/h: Face animation class


M5_Spider_esp-now

This sketch receives control commands wirelessly from a custom ESP-NOW controller (such as M5AtomPad) and drives the robot.

This sketch receives control commands wirelessly from a custom ESP-NOW controller (such as M5AtomPad) and drives the robot.

Features

  • ESP-NOW peer-to-peer communication

  • NES (Famicom) style gamepad input support

  • Continuous walking/spinning controlled by flags

  • FreeRTOS face animation task on Core 0

  • Two machine presets (modeNES = 1 for SpiderW, modeNES = 2 for SpiderB) for per-unit calibration

  • Calibration mode triggered by charging detection (define chgDET to enable)

  • ESP-NOW peer-to-peer communication

  • NES (Famicom) style gamepad input support

  • Continuous walking/spinning controlled by flags

  • FreeRTOS face animation task on Core 0

  • Two machine presets (modeNES = 1 for SpiderW, modeNES = 2 for SpiderB) for per-unit calibration

  • Calibration mode triggered by charging detection (enabled by defining chgDET)

Controller Button Mapping / コントローラのボタン割り当て

NES ButtonCommandAction / 動作
UPrNES_UPWalk forward / 前進
DOWNrNES_DOWNWalk backward / 後退
LEFTrNES_LEFTShift left / 左移動
RIGHTrNES_RIGHTShift right / 右移動
ArNES_ASpin right / 右旋回
BrNES_BSpin left / 左旋回
START/SELECT-Reserved / 予約
(no input)rNES_STOPStop / 停止

How to Use / How to Use

  1. Open M5_Spider_esp-now.ino in Arduino IDE.

  2. Set modeNES to match your robot unit (1 or 2).

  3. Make sure the controller MAC address is registered in the OnDataRecv filter.

  4. Upload the sketch to M5Stack.

  5. Power on the ESP-NOW controller and gamepad.

  6. Open M5_Spider_esp-now.ino in Arduino IDE.

  7. Set modeNES to 1 or 2 to match your robot unit.

  8. Make sure the controller MAC address is registered in the OnDataRecv filter.

  9. Upload the sketch to M5Stack.

  10. Power on the ESP-NOW controller and gamepad.

Main Files

  • M5_Spider_esp-now.ino: Main sketch

  • avatar.cpp/h: Face animation class

  • M5_Spider_esp-now.ino: Main sketch

  • avatar.cpp/h: Face animation class

For the transmitter side, see the M5AtomPad repository.

For the transmitter side, see the M5AtomPad repository.

https://github.com/tomorrow56/M5AtomPad (opens in a new tab)

When registering a controller in the OnDataRecv MAC filter, you can use ESP32_ChipInfo on each M5Stack to check its MAC address.

When registering a controller in the OnDataRecv MAC address filter, you can run ESP32_ChipInfo on each M5Stack to check its MAC address.


ESP32_ChipInfo

A simple utility sketch that prints ESP32 chip information (model, features, core count, revision, flash size, and most importantly the MAC address) to the Serial Monitor.

A simple utility sketch that prints ESP32 chip information (model, features, core count, revision, flash size, and most importantly the MAC address) to the Serial Monitor.

Use Case / 用途

Useful for checking the MAC address of an M5Stack unit before registering it as an ESP-NOW peer (see M5_Spider_esp-now) or before hardcoding a peer's MAC address in a controller sketch.

Useful for checking the MAC address of an M5Stack unit before registering it as an ESP-NOW peer (see M5_Spider_esp-now) or before hardcoding a peer's MAC address in a controller sketch.

How to Use / 使い方

  1. Open ESP32_ChipInfo.ino in Arduino IDE.

  2. Upload the sketch to the M5Stack.

  3. Open the Serial Monitor at 115200 baud.

  4. The chip model, features, core count, revision, MAC address, flash size, and chip ID are printed once at startup.

  5. Open ESP32_ChipInfo.ino in Arduino IDE.

  6. Upload the sketch to the M5Stack.

  7. Open the Serial Monitor at 115200 baud.

  8. The chip model, features, core count, revision, MAC address, flash size, and chip ID are printed once at startup.

Main Files / 主なファイル

  • ESP32_ChipInfo.ino: Main sketch

  • ESP32_ChipInfo.ino: Main sketch


Calibration

All sketches provide a calibration mode that moves every servo to its center position. This is useful during mechanical assembly.

いずれのスケッチでも、すべてのサーボをセンター位置に移動するキャリブレーションモードがあります。機械的な組み立て時に便利です。

  • Web versions: Enter calibration mode automatically when powered on while M5Stack is charging.

  • ESP-NOW version: Define chgDET at the top of the sketch to enable the same behavior.

  • Web版:M5Stackの充電中に電源を入れると、自動的にキャリブレーションモードへ移行します。

  • ESP-NOW版:スケッチ先頭でchgDETを定義すると、同じ動作が有効になります。

SketchCalibration Trigger / トリガ
M5_Spider_WebserverPower on while charging / 充電中に電源ON
M5_Spider_Webserver_taskPower on while charging / 充電中に電源ON
M5_Spider_esp-nowEnable chgDET then power on while charging / chgDETを有効にして充電中に電源ON

Press the B button to exit calibration mode.

Bボタンでキャリブレーションモードを終了します。

Files by @tomorrow56, at commit 07778c2, read from GitHub in your browser. Hardware license: MIT; software license: MIT. Robotheca doesn't review code: read it before running it.