m5stack/m5stickc

repository·master·Indexed 19 days ago

https://github.com/m5stack/m5stickc

Hardware 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.

Tokens
6.3K
Snippets
28
Records
43
Agent score
65%

What's inside m5stickc

  1. M5StickC Hardware Overview and Operation

    master

    The 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.
  2. Hardware Overview of M5StickC

    master

    The 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.
  3. Display Chinese characters using HZK16 font

    master

    The HZK16 font uses the GB2312 Chinese encoding format. Because of this encoding, the character data in src.h (specifically within GbkStr) may appear as garbled text (mojibake) when viewed in standard UTF-8 editors like the Arduino IDE.

    To correctly manage and display Chinese characters:

    1. 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.
    2. Modify characters: To change the displayed text, modify the content within the GbkStr variable in src.h using the GB2312 encoding.
    3. 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.
  4. Use the BeetleC Web Control Interface

    master

    The BeetleC example sets up an HTTP server that allows remote control via a web browser.

    Workflow:

    1. The device initializes WiFi and an HTTP server.
    2. The device enters a loop waiting for control messages.
    3. When a user accesses the control page at http://192.168.4.1/ctl, the test_handler serves a control interface.
    4. Pushing buttons on the web interface sends decoded messages that trigger the control callback, which ultimately drives the BeetleC base motors.
  5. Migrate from M5StickC to M5GFX and M5Unified

    master

    The m5stickc library 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.

  6. Initialize M5Display

    master

    To use the display, instantiate M5Display and call the begin() method. M5Display inherits from TFT_eSPI, providing standard TFT drawing capabilities alongside specialized M5StickC features.

    M5Display display;
    
    void setup() {
        display.begin();
    }
  7. Initialize the M5StickC device

    master

    To use the M5StickC, you must first call M5.begin() in your setup() function. This initializes the core components of the device.

    Parameters:

    • LCDEnable (bool, default true): Whether to enable the LCD.
    • PowerEnable (bool, default true): Whether to enable the power management chip (AXP192).
    • SerialEnable (bool, default true): 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
    }
  8. BeetleC HTTP Server API Reference

    master

    The 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 /ctl endpoint. 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.