m5stack/m5stickc
repository·master·Indexed 19 days ago
https://github.com/m5stack/m5stickcHardware abstraction library for the M5StickC ESP32 development board, providing control for its 0.96 inch TFT display, 6-axis IMU (SH200Q/MPU6886), AXP192 power management IC, and peripherals. Includes support for HZK16 Chinese fonts, QR code generation, and BeetleC base control via HTTP. Note: This library is deprecated; users are encouraged to migrate to M5Unified and M5GFX.
What's inside m5stickc
- ⚠️ DEPRECATED: The M5StickC library is deprecated. For future development, it is recommended to use M5GFX and M5Unified instead.
M5StickC Hardware Overview and Operation
masterThe M5StickC is an ESP32-based development board featuring:
- Display: 0.96 inch TFT color screen (80 * 160 resolution).
- Sensors/Peripherals: 6-axis IMU (SH200Q), Microphone, IR transmitter, and a Red LED.
- Power: 80 mAH battery and ESP32-Pico module with 4MB built-in flash.
- Input: Physical buttons.
Power Management
- Turn On: Press the button for two seconds.
- Turn Off: Press and hold the button for six seconds.
Hardware Overview of M5StickC
masterThe M5StickC is a compact ESP32-based development board featuring an ESP32-Pico module with 4MB of flash. Key hardware components include:
- Display: 0.96 inch TFT color screen (80 x 160 resolution).
- Sensors: Six-axis motion sensor (SH200Q).
- Audio/Input: Microphone and buttons.
- Connectivity/Output: Infrared (IR) transmitter.
- Indicators: Red LED.
- Power: 80mAh battery.
Power Operations:
- Power On: Short press for 2 seconds.
- Power Off: Long press for 6 seconds.
Display Chinese characters using HZK16 font
masterThe HZK16 font uses the GB2312 Chinese encoding format. Because of this encoding, the character data in
src.h(specifically withinGbkStr) may appear as garbled text (mojibake) when viewed in standard UTF-8 editors like the Arduino IDE.To correctly manage and display Chinese characters:
- Open the file with correct encoding: Use an editor like Notepad++ and set the encoding to GB2312 to view the characters correctly in
src.h. - Modify characters: To change the displayed text, modify the content within the
GbkStrvariable insrc.husing the GB2312 encoding. - IDE Note: The Arduino IDE uses UTF-8, so expect the source code to look garbled within the IDE itself; this is normal behavior for this specific font implementation.
- Open the file with correct encoding: Use an editor like Notepad++ and set the encoding to GB2312 to view the characters correctly in
Use the BeetleC Web Control Interface
masterThe BeetleC example sets up an HTTP server that allows remote control via a web browser.
Workflow:
- The device initializes WiFi and an HTTP server.
- The device enters a loop waiting for control messages.
- When a user accesses the control page at
http://192.168.4.1/ctl, thetest_handlerserves a control interface. - Pushing buttons on the web interface sends decoded messages that trigger the
controlcallback, which ultimately drives the BeetleC base motors.
Migrate from M5StickC to M5GFX and M5Unified
masterThe
m5stickclibrary is deprecated. For all new development, you should use the following modern libraries instead:- M5GFX: A high-performance, lightweight graphics and display driver library for M5 devices.
- M5Unified: A unified base library for M5 devices that handles IO/peripherals, power management, audio, and more.
- M5UnitUnified: A library for unified handling of various M5 unit products.
Using these newer libraries ensures better compatibility and access to updated features across the M5Stack ecosystem.
Deprecated: M5StickC Library
masterWarning: This library is deprecated.
Users should transition to using M5GFX and M5Unified for better performance, compatibility, and unified hardware abstraction across the M5Stack ecosystem.
Initialize M5Display
masterTo use the display, instantiate
M5Displayand call thebegin()method.M5Displayinherits fromTFT_eSPI, providing standard TFT drawing capabilities alongside specialized M5StickC features.M5Display display; void setup() { display.begin(); }Initialize the M5StickC device
masterTo use the M5StickC, you must first call
M5.begin()in yoursetup()function. This initializes the core components of the device.Parameters:
LCDEnable(bool, defaulttrue): Whether to enable the LCD.PowerEnable(bool, defaulttrue): Whether to enable the power management chip (AXP192).SerialEnable(bool, defaulttrue): Whether to enable Serial communication.
You should also call
M5.update()in your main loop to handle button state updates and other periodic tasks.#include <M5StickC.h> void setup() { M5.begin(); // Initializes LCD, Power, and Serial by default } void loop() { M5.update(); // Required for button state updates }Blink the onboard LED
masterThe
blink()function can be used to trigger a visual indicator by turning the LED on and off sequentially three times.void blink();Control the BeetleC base via carLRcontrol()
masterThe
carLRcontrol(int8_t left, int8_t right)function is used to send directional control values to the BeetleC base. It accepts two parameters representing the power/direction for the left and right motors respectively.carLRcontrol(int8_t left, int8_t right);BeetleC HTTP Server API Reference
masterThe following functions manage the web-based control interface for the BeetleC base:
static esp_err_t http_server_init(): Initializes the HTTP server and sets up the necessary callback functions.static void initWifi(): Performs WiFi initialization to allow network connectivity.esp_err_t test_handler(httpd_req_t *req): The handler for the/ctlendpoint. It serves the HTML control page to the client.esp_err_t control(httpd_req_t *req): The callback function for the HTTP server that processes incoming HTTP requests to command the BeetleC base.