M5Unified Hardware Abstraction Library

repository·master·Indexed 19 days ago

https://github.com/m5stack/m5unified

A hardware abstraction library for the M5Stack ecosystem providing a unified API for displays, touch, audio, sensors, and power management across ESP32-based devices. It supports multiple frameworks including Arduino IDE and ESP-IDF, and is compatible with a wide range of hardware from the M5Stack Core, M5Stick, M5ATOM, and M5Paper series. The library requires M5GFX for display functionality and provides unified access to built-in hardware via the m5 namespace.

Tokens
18.7K
Snippets
19
Records
28
Agent score
71%

What's inside M5Unified

  1. Get started with M5Unified

    master

    M5Unified is an Arduino/ESP-IDF library designed to provide a unified interface for accessing the built-in hardware of the M5Stack series of controllers. All library functionality is accessed through the m5 namespace.

    Core Capabilities

    • Display: LCD access, fonts, and graphical primitives (requires M5GFX).
    • Input: Touchscreen and hardware button access.
    • Audio: Speaker and microphone access.
    • Power: Power and battery charging control.
    • Sensors: Accelerometer, gyroscope, and magnetometer access.
    • Time: Real-time clock (RTC) and wakeup timer access.

    Prerequisites

    • M5GFX: This library requires M5GFX to be installed to handle display functionality.
    #include "M5Unified.h"
  2. Explore M5Unified examples

    master

    If you are using the Arduino IDE and have installed M5Unified via the Library Manager, you can find built-in examples under File > Examples > M5Unified > Basic.

    Available Basic Examples

    • HowToUse: A combined demonstration of several functions.
    • Displays: Demonstrates printing text on supported M5Stack displays.
    • Button: Detects and responds to button presses.
    • Touch: Detects and reacts to touch events.
    • Speaker: Plays wave audio through built-in speakers or compatible accessories.
    • RTC: Connects to an Internet time server via WiFi to set the built-in clock.
    • Microphone: Records a short audio clip and plays it back through the speaker.
    • IMU: Demonstrates accelerometer, gyroscope, and magnetometer usage.

    Advanced Examples

    Advanced functionality, such as playing audio over Bluetooth or streaming/decoding MP3 audio, can be found in the examples/Advanced folder of the repository.

  3. Manage power and battery with Power_Class

    master

    The m5::Power_Class provides a unified interface for managing power, battery status, and sleep modes across different M5Stack hardware. It abstracts the underlying PMIC (Power Management IC) such as AXP192, AXP2101, or IP5306.

    Key Capabilities

    • Battery Monitoring: Check battery level (0-100), voltage (mV), and current (mA).
    • Charging Control: Enable/disable charging and set charge current/voltage (on supported models).
    • Sleep Modes: Use deepSleep, lightSleep, or timerSleep (with duration, time, or date/time) to manage power consumption.
    • External Port Control: Enable/disable and configure output for external ports (specific to models like M5Station or M5PowerHub).
    • USB Power: Control the main USB port power output (specific to CoreS3).
    // Example usage of Power_Class methods
    m5::Power_Class power;
    power.begin();
    
    // Check battery status
    int32_t level = power.getBatteryLevel();
    int16_t voltage = power.getBatteryVoltage();
    
    // Enter deep sleep for 10 seconds
    power.deepSleep(10000000); // 10,000,000 microseconds
  4. Configure the Microphone with mic_config_t

    master

    The mic_config_t structure allows you to configure the hardware parameters for audio input. You can use it to specify I2S pins, sampling rates, channel modes, and background task settings.

    Key configuration fields:

    • pin_data_in: The data input pin (required). If using an analog mic, set use_adc = true.
    • pin_bck, pin_mck, pin_ws: I2S clock pins. Use I2S_PIN_NO_CHANGE (-1) if not used.
    • sample_rate: Input sampling rate in Hz (default is 16000).
    • input_channel: Set via input_channel_t to input_only_right, input_only_left, or input_stereo.
    • use_adc: Set to true to use an analog input microphone.
    • dma_buf_len and dma_buf_count: I2S DMA buffer settings.
    • task_priority and task_pinned_core: Settings for the background recording task.
    m5::mic_config_t cfg;
    cfg.pin_data_in = 13;
    cfg.sample_rate = 44100;
    cfg.input_channel = m5::input_stereo;
    cfg.use_adc = false;
    
    mics.config(cfg);
  5. Configure the Speaker via speaker_config_t

    master

    The speaker_config_t struct allows you to customize the audio output hardware settings. You can pass this configuration to Speaker_Class::config() before calling begin().

    Key configuration options:

    • pin_data_out: I2S data output pin.
    • pin_bck: I2S bit clock pin.
    • pin_mck: I2S master clock pin.
    • pin_ws: I2S word select (LRCK) pin.
    • sample_rate: Output sampling rate in Hz (default: 48000).
    • stereo: Set to true for stereo output.
    • buzzer: Set to true to use a single GPIO buzzer (requires only pin_data_out).
    • use_dac: Set to true to use the ESP32 internal DAC (requires pin_data_out to be GPIO_NUM_25 or GPIO_NUM_26 and i2s_port to be I2S_NUM_0).
    • dac_zero_level: Zero level reference value when using DAC.
    • magnification: Multiplier for output value.
    • dma_buf_len: I2S DMA buffer length (max 1024).
    • dma_buf_count: I2S DMA buffer count.
    • task_priority: Background task priority.
    • task_pinned_core: Background task pinned core.
    • i2s_port: The I2S port to use (e.g., i2s_port_t::I2S_NUM_0).
    m5::speaker_config_t cfg;
    cfg.pin_data_out = 13;
    cfg.sample_rate = 44100;
    cfg.stereo = true;
    
    // Apply configuration
    speaker.config(cfg);
  6. Supported external displays and audio accessories

    master

    M5Unified provides support for various external modules and adapters.

    External Displays and Video Adapters

    • Unit LCD, Unit OLED, Unit Mini OLED
    • Unit RCA (Note: Not supported on ESP32-S3 series)
    • Unit GLASS / Unit GLASS2
    • ATOM Display adapter (HDMI output for M5ATOM series)
    • Module Display adapter (HDMI output for M5Stack Core/Core2/Tough/CoreS3 series)
    • Module RCA adapter (Composite NTSC/PAL output for M5Stack Core/Core2/Tough, excluding ESP32-S3 series)

    External Speakers and Audio Adapters

    • SPK HAT / SPK HAT2
    • ATOMIC SPK
    • ATOMIC ECHO BASE
    • Module Display adapter (Audio over HDMI for M5Stack Core/Core2/Tough/CoreS3 series)
    • Module RCA adapter (M5Stack Core/Core2/Tough)

    Other External Accessories

    • Unit RTC
    • Unit IMU
  7. AXP2101 Power Management IC usage

    master

    The AXP2101 PMIC is used in newer M5Stack models like Core2v1.1 and CoreS3. The following table maps its outputs to device functions.

    OutputM5Stack Core2v1.1M5Stack CoreS3 / CoreS3SE
    ALDO1---VDD 1v8
    ALDO2LCD RSTVDDA 3v3
    ALDO3SPK ENCAM 3v3
    ALDO4Periph PW (TF, TP, LCD)TF 3v3
    BLDO1LCD BLAVDD
    BLDO2PORT 5V ENDVDD
    DLDO1/DC1VIB MOTORLCD BL
    DLDO2/DC2------
    BACKUPRTC BATRTC BAT
  8. GPIO Pin Mapping for M5Stamp C3 and M5Stamp C3U

    master

    This reference provides the GPIO pin assignments for the ESP32-C3 based M5Stack devices: M5Stamp C3 and M5Stamp C3U. Use this to identify available pins for I2C, buttons, RGB LEDs, and serial communication.

    M5Stamp C3 Pinout

    • I2C0 (PORT.A): SCL on GPIO 0, SDA on GPIO 1
    • RGB LED: GPIO 2
    • BTN_A: GPIO 3
    • USB/Serial: GPIO 18 (D-), GPIO 19 (D+), GPIO 20 (Serial), GPIO 21 (Serial)
    • Bus/General Purpose: GPIO 4-8, GPIO 10

    M5Stamp C3U Pinout

    • I2C (PORT.A): SCL on GPIO 0, SDA on GPIO 1
    • RGB LED: GPIO 2
    • Bus: GPIO 3, GPIO 4, GPIO 5, GPIO 6, GPIO 7, GPIO 8, GPIO 10, GPIO 20, GPIO 21
    • BTN_A: GPIO 9
    • USB/PORT.U: GPIO 18 (D-), GPIO 19 (D+)
    • Serial: GPIO 20, GPIO 21 (Note: GPIO 20/21 are listed as Bus in the table, but GPIO 18/19 are explicitly USB)
    |               |M5Stamp<BR>C3            |M5Stamp<BR>C3U                  |
    |:-------------:|:-----------------------:|:------------------------------:|
    |GPIO 0         |`PORT.A`<BR>**I2C0_SCL** |`PORT.A`<BR>**I2C_SCL**         |
    |GPIO 1         |`PORT.A`<BR>**I2C0_SDA** |`PORT.A`<BR>**I2C_SDA**         |
    |GPIO 2         |**RGB LED**             |**RGB LED**                     |
    |GPIO 3         |**BTN_A**               |`Bus`                           |
    |GPIO 4         |`Bus`                   |`Bus`                           |
    |GPIO 5         |`Bus`                   |`Bus`                           |
    |GPIO 6         |`Bus`                   |`Bus`                           |
    |GPIO 7         |`Bus`                   |`Bus`                           |
    |GPIO 8         |`Bus`                   |`Bus`                           |
    |GPIO 9         | ---                   |**BTN_A**                       |
    |GPIO10         |`Bus`                   |`Bus`                           |
    |GPIO18<BR>`USB`|`PORT.U`<BR>**D-**         |`USB`<BR>`PORT.U`<BR>**D-**         |
    |GPIO19<BR>`USB`|`PORT.U`<BR>**D+**         |`USB`<BR>`PORT.U`<BR>**D+**         |
    |GPIO20         |`USB`<BR>**Serial**      |`Bus`<BR>                       |
    |GPIO21         |`USB`<BR>**Serial**      |`Bus`<BR>                       |
  9. GPIO Pinout for ESP32-S3 M5Stack Devices

    master

    This reference provides the GPIO mapping for various M5Stack devices based on the ESP32-S3 chip. Use this to identify which physical pins correspond to specific functions like I2C (SDA/SCL), LCD interfaces (CS, SCK, MOSI), Buttons (BTN_A), or specialized peripherals (InfraRed, Key Matrix, TF/SD Card) across different hardware models.

    Supported Devices in this list:

    • M5Stack CoreS3 / CoreS3SE
    • M5ATOMS3R / S3RCam
    • M5ATOMS3 / S3Lite
    • M5ATOMS3U
    • M5STAMPS3
    • M5Dial
    • M5Capsule
    • M5Cardputer
    |               |M5Stack<BR>CoreS3<BR>CoreS3SE    |M5ATOMS3R <BR>/ S3RCam   |M5ATOMS3 <BR>/ S3Lite    |M5ATOMS3U                | M5STAMPS3                         | M5Dial                   | M5Capsule                | M5Cardputer                |               |
    |:-------------:|:-------------------------------:|:-----------------------:|:-----------------------:|:-----------------------:|:---------------------------------:|:------------------------:|:------------------------:|:------------------------:|:-------------|
    |GPIO 0         |`M-Bus`<BR>**SPK_LRCK**          |**I2Cx_SCL**<br>forIMU   | ---                     | ---                     | `Bus`<BR>**BTN_A**                | ---                      | ---                      | **BTN_A**                |GPIO 0         |
    |GPIO 1         |`PORT.A`<BR>**I2C0_SCL**        |`PORT.A`<BR>**I2C0_SCL** |`PORT.A`<BR>**I2C0_SCL** |`PORT.A`<BR>**I2C0_SCL** | `Bus`                             | `PORT.B`                 | ---                      | `PORT.A`<BR>**I2C0_SCL** |GPIO 1         |
    |GPIO 2         |`PORT.A`<BR>**I2C0_SDA**        |`PORT.A`<BR>**I2C0_SDA** |`PORT.A`<BR>**I2C0_SDA** |`PORT.A`<BR>**I2C0_SDA** | `Bus`                             | `PORT.B`                 | **Beep**                 | `PORT.A`<BR>**I2C0_SDA** |GPIO 2         |
    |GPIO 3         |**LCD_CS**                     |**CAM_Y2**               |vdd3v3                   |vdd3v3                   | `Bus`                             | **Beep**                 | ---                      | **KEY_MATRIX**           |GPIO 3         |
    |GPIO 4         |**TF_CS**                      |**CAM_Y6**               |**InfraRed**             | ---                     | `Bus`                             | **LCD_RS**               | **InfraRed**             | **KEY_MATRIX**           |GPIO 4         |
    |GPIO 5         |`M-Bus`                        |`Bus`                    |`Bus`                    | ---                     | `Bus`                             | **LCD_MOSI**             | ---                      | **KEY_MATRIX**           |GPIO 5         |
    |GPIO 6         |`M-Bus`                        |`Bus`                    |`Bus`                    | ---                     | `Bus`                             | **LCD_SCK**               | **BAT_ADC**              | **KEY_MATRIX**           |GPIO 6         |
    |GPIO 7         |`M-Bus`                        |`Bus`                    |`Bus`                    | ---                     | `Bus`                             | **LCD_CS**               | ---                      | **KEY_MATRIX**           |GPIO 7         |
    |GPIO 8         |`M-Bus`<BR>`PORT.B`            |`Bus`                    |`Bus`                    | ---                     | `Bus`                             | **LCD_RST**              | **I2C1_SDA**             | **KEY_MATRIX**           |GPIO 8         |
    |GPIO 9         |`M-Bus`<BR>`PORT.B`            |**I2Cy_SCL**<br>forCam   | ---                     | ---                     | `Bus`                             | **LCD_BL**               | ---                      | **KEY_MATRIX**           |GPIO 9         |
    |GPIO10         |`M-Bus`                        |**CAM_VSYNC**            | ---                     | ---                     | `Bus`                             | **RFID_INT**             | **I2C1_SCL**             | **BAT_ADC**              |GPIO10         |
    |GPIO11         |**I2C1_SCL**                   |**CAM_Y8**               | ---                     | ---                     | `Bus`                             | **I2C1_SDA**             | **TF_CS**                | **KEY_MATRIX**           |GPIO11         |
    |GPIO12         |**I2C1_SDA**                   |**I2Cy_SDA**<br>forCam   | ---                     |**InfraRed**             | `Bus`                             | **I2C1_SCL**             | **TF_MOSI**              | **TF_CS**                |GPIO12         |
    |GPIO13         |`M-Bus`<BR>**SPK_D**            |**CAM_Y9**               | ---                     | ---                     | `Bus`<BR>`PORT.A`<BR>**I2C0_SDA** | `PORT.A`<BR>**I2C0_SDA** | `PORT.A`<BR>**I2C0_SDA** | **KEY_MATRIX**           |GPIO13         |
    |GPIO14         |`M-Bus`<BR>**MIC_IN**            |**LCD_CS<BR>CAM_HREF**   | ---                     |`Bus`                             | `Bus`                             | **TP_INT**               | **TF_CLK**               | **TF_MOSI**              |GPIO14         |
    |GPIO15         |**CAM_D6**                     |**LCD_SCLK**             |**LCD_CS**               | ---                     | `Bus`<BR>`PORT.A`<BR>**I2C0_SCL** | `PORT.A`<BR>**I2C0_SCL** | `PORT.A`<BR>**I2C0_SCL** | **KEY_MATRIX**           |GPIO15         |
    |GPIO16         |**CAM_D7**                     |**IMU_INT**              |**LCD_BL**               | ---                     | `FPC`                             | ---                      | ---                      | ---                      |GPIO16         |
    |GPIO17         |`M-Bus`<BR>`PORT.C`             |**CAM_Y7**               |**LCD_SCLK**             |`Bus`                             | `FPC`                             | ---                      | ---                      | ---                      |GPIO17         |
    |GPIO18         |`M-Bus`<BR>`PORT.C`             |**POWER_N**              | ---                     | ---                     | `FPC`                             | ---                      | ---                      | ---                      |GPIO18         |
    |GPIO19<BR>`USB`|`USB`<BR>**D--**                 |`USB`<BR>**D--**         |`USB`<BR>**D--**         |`USB`<BR>**D--**         | `USB`<BR>**D--**                  | `USB`<BR>**D--**         | `USB`<BR>**D--**         | `USB`<BR>**D--**         |GPIO19<BR>`USB`|
    |GPIO20<BR>`USB`|`USB`<BR>**D++**                 |`USB`<BR>**D++**         |`USB`<BR>**D++**         |`USB`<BR>**D++**         | `USB`<BR>**D++**                  | `USB`<BR>**D++**         | `USB`<BR>**D++**         | `USB`<BR>**D++**         |GPIO20<BR>`USB`|
    |GPIO21         |**I2C_INT**                    |**LCD_MOSI<BR>CAM_XCLK** |**LCD_MOSI**             | ---                     | **RGB LED**                       | **RGB LED**              | **RGB LED**              | **RGB_LED**              |GPIO21         |
    |GPIO33         |**SPK_WCK**                     |OPI PSRAM                |**LCD_DC**               | ---                     | `FPC`                             | ---                      | ---                      | **LCD_RST**               |GPIO33         |
    |GPIO34         |**SPK_BCK**                     |OPI PSRAM                |**LCD_RST**               | ---                     | `FPC`                             | ---                      | ---                      | **LCD_RS**                |GPIO34         |
    |GPIO35         |`M-Bus`<BR>**SPI_MISO<BR>LCD DC** |OPI PSRAM                |**RGB LED**              |**RGB LED**              | `FPC`                             | ---                      | ---                      | **LCD_DAT**               |GPIO35         |
    |GPIO36         |`M-Bus`<BR>**SPI_SCLK**          |OPI PSRAM                | ---                     | ---                     | `FPC`                             | ---                      | ---                      | **LCD_SCK**               |GPIO36         |
    |GPIO37         |`M-Bus`<BR>**SPI_MOSI**          |OPI PSRAM                | ---                     | ---                     | `FPC`                             | ---                      | ---                      | **LCD_CS**               |GPIO37         |
    |GPIO38         |**CAM_HREF**                   |`Bus`                    |`Bus`<BR>**I2C1_SDA**    |**PDM_DAT**              | `Bus`                             | ---                      | **TF_MISO**               | **TF_MISO**              |GPIO38         |
    |GPIO39         |**CAM_D2**                     |`Bus`                    |`Bus`<BR>**I2C1_SCL**       |**PDM_CLK**              | `Bus`                             | ---                      | **MIC_CLK**              | **TF_CLK**               |GPIO39         |
    |GPIO40         |**CAM_D3**                     |**CAM_PCLK**             | ---                     |`Bus`                    | `Bus`                             | **ENCODER_B**            | **MIC_DAT**              | **SPK_BCLK**             |GPIO40         |
    |GPIO41         |**CAM_D4**                     |**BTN_A**                |**BTN_A**                |**BTN_A**                | `Bus`                             | **ENCODER_A**            | **BTN_A**                | **SPK_SDATA**            |GPIO41         |
    |GPIO42         |**CAM_D5**                     |**LCD_D/D<BR>CAM_Y3**   | ---                     |`Bus`                    | `Bus`                             | **BTN_A**                | **BTN_A**                | **I2S_LRCLK**            |GPIO42         |
    |GPIO43         |`M-Bus`<BR>**SerialTX**          | ---                     | ---                     | ---                     | `Bus`                             | ---                      | ---                      | **InfraRed**             |GPIO43         |
    |GPIO44         |`M-Bus`<BR>**SerialRX**          | ---                     | ---                     | ---                     | `Bus`                             | ---                      | ---                      | **MIC_DAT**              |GPIO44         |
    |GPIO45         |**CAM_PCLK**                   |**I2Cx_SDA**<br>forIMU   | ---                     | ---                     | ---                               | ---                      | ---                      | **KEY_MATRIX**           |GPIO45         |
    |GPIO46         |**CAM_VSYNC**                  |**CAM_Y4**               | ---                     | ---                     | `Bus`                             | **HOLD**                 | **HOLD**                 | **MIC_DAT**              |GPIO46         |
    |GPIO47         |**CAM_D9**                     |**InfraRed**             | ---                     | ---                     | ---                               | ---                      | ---                      | ---                      |GPIO47         |
    |GPIO48         |**CAM_D8**                     |**LCD_RST<BR>CAM_Y5**   | ---                     | ---                     | ---                               | ---                      | ---                      | ---                      |GPIO48         |
  10. ESP32 GPIO mapping for M5Stack devices

    master

    The M5Unified library supports a wide range of M5Stack hardware. Because different devices use different GPIO pins for the same functions (like LCD, SPI, or I2C), refer to the hardware mapping table to understand how pins are allocated across various models.

    Key device families include:

    • M5Stack BASIC/GRAY/GO/FIRE
    • M5Stack Core2 (AWS/Tough)
    • M5Stick C/CPlus/CPlus2
    • M5Paper / CoreInk
    • M5Station
    • M5ATOM (Lite/Matrix/ECHO/U/PSRAM)
    • M5STAMP PICO

    Commonly shared pin functions across devices include LCD_CS, LCD_D/C, SPI_MOSI, I2C_SDA, and BTN_A/B/C.

    |                    |M5Stack<BR>BASIC<BR>GRAY           |M5Stack<BR>GO/FIRE                 |M5Stack<BR>Core2(AWS)<BR>Tough         |M5Stick<BR>C/CPlus            |M5Stick<BR>CPlus2            |M5Stack<BR>CoreInk          |M5Paper            |M5Station              |M5ATOM<BR>Lite/Matrix<BR>ECHO/U<BR>PSRAM |M5STAMP<BR>PICO     |
    |:------------------:|:---------------------------------:|:---------------------------------:|:-------------------------------------:|:----------------------------:|:-------------------------:|:----------------------:|:---------------------:|:---------------------:|:---------------------------------------:|:------------------:|
    |GPIO 0<BR>`ADC2_CH1`|`M-Bus`<BR>IIS_MK                  |`M-Bus`<BR>IIS_MK                  |`M-Bus`<BR>**SPK_LRCK<BR>PDM_C**(Core2)|`HAT`<BR>`PAD`<BR>**PDM_C**   |`HAT`<BR>**PDM_C**         |**EPD_RST**             | ---                   | ---                   | ---                                     |                    |GPIO 0<BR>`ADC2_CH1`|
    |GPIO 1<BR>`USB_TX`  |`M-Bus`<BR>**Serial**              |`M-Bus`<BR>**Serial**              |`M-Bus`<BR>**Serial**                  |**Serial**                    |**Serial**                 |**Serial**              |**Serial**             |**Serial**                               |**Serial**          |GPIO 1<BR>`USB_TX`  |
    |GPIO 2<BR>`ADC2_CH2`|`M-Bus`<BR>                        |`M-Bus`<BR>                        |`M-Bus`<BR>**SPK_D**                   |`PAD`<BR>**Beep**(CPlus)   |**Beep**                   |**Beep**                |**PW_Hold**            |**ReadEn**             | ---                                     | ---                |GPIO 2<BR>`ADC2_CH2`|
    |GPIO 3<BR>`USB_RX`  |`M-Bus`<BR>**Serial**              |`M-Bus`<BR>**Serial**              |`M-Bus`<BR>**Serial**                  |**Serial**                    |**Serial**                 |**Serial**              |**Serial**             |**Serial**                               |**Serial**          |GPIO 3<BR>`USB_RX`  |
    |GPIO 4<BR>`ADC2_CH0`|**TF_CS**                          |**TF_CS**                              |**TF_CS**                              | ---                          |**PW_Hold**                |**EPD_BUSY**            |**TF_CS**              |**RGB LED**            | ---                                     | ---                |GPIO 4<BR>`ADC2_CH0`|
    |GPIO 5              |`M-Bus`                            |`M-Bus`                            |**LCD_CS**                             |**LCD_CS**                    |**LCD_CS**                 |**BTN_HAT**             |**EXT_5V**             |**LCD_CS**             |`Bus`(P)<BR>**PDM_C**(U)                 | ---                |GPIO 5              |
    |GPIO 9              | ---                               | ---                               | ---                                   |**InfraRed**                  | ---                       |**EPD_CS**              | ---                   | ---                   | ---                                     | ---                |GPIO 9              |
    |GPIO10              | ---                               | ---                               | ---                                   |**LED**                        | ---                       |**LED**                 | ---                   | ---                   | ---                                     | ---                |GPIO10              |
    |GPIO12<BR>`ADC2_CH5`|`M-Bus`<BR>IIS_SK                  |`M-Bus`<BR>IIS_SK                  |**SPK_BCLK**                           | ---                          |**LCD_RST**                 |**PW_Hold**             |**SPI_MOSI**           |**USB_PW**             |**InfraRed**                             | ---                |GPIO12<BR>`ADC2_CH5`|
    |GPIO13<BR>`ADC2_CH4`|`M-Bus`<BR>IIS_WS                  |`M-Bus`<BR>IIS_WS                  |**RXD2**                               |**SPI_SCLK**                |**SPI_SCLK**               |`MI-Bus`<BR>RXD2        |**SPI_MISO**           |**PORT.C1**             | ---                                     | ---                |GPIO13<BR>`ADC2_CH4`|
    |GPIO14<BR>`ADC2_CH6`|**LCD_CS**                         |**LCD_CS**                             |`M-Bus`<BR>TXD2                        | ---                          |**LCD_D/C**                 |`MI-Bus`<BR>TXD2        |**SPI_SCLK**           |**PORT.C1**             | ---                                     | ---                |GPIO14<BR>`ADC2_CH6`|
    |GPIO15<BR>`ADC2_CH3`|`M-Bus`<BR>IIS_OUT                 |`M-Bus`<BR>**RGB LED**                   |**LCD_D/C**                            |**SPI_MOSI**                 |**SPI_MOSI**               |**EPD_D/C**             |**EPD_CS**             |**LCD_RST**            | ---                                     | ---                |GPIO15<BR>`ADC2_CH3`|
    |GPIO16<BR>`PSRAM`   |`M-Bus`<BR>RXD2                    |`M-Bus`<BR>`PORT.C`<BR>RXD2        | ---                                   | ---                          |---                        | ---                   | ---                   |`PORT.C2`<BR>RXD2      | ---                                     | ---                |GPIO16<BR>`PSRAM`   |
    |GPIO17<BR>`PSRAM`   |`M-Bus`<BR>TXD2                    |`M-Bus`<BR>`PORT.C`<BR>TXD2      | ---                                   | ---                          |---                        | ---                   | ---                   |`PORT.C2`<BR>TXD2      | ---                                     | ---                |GPIO17<BR>`PSRAM`   |
    |GPIO18              |`M-Bus`<BR>**SPI_SCLK**            |`M-Bus`<BR>**SPI_SCLK**            |**SPI_SCLK**                           |**LCD_RST**                   |---                        |`MI-Bus`<BR>**SPI_SCLK**|`PORT.C`               |**SPI_SCLK**           | ---                                     |                    |GPIO18              |
    |GPIO19              |`M-Bus`<BR>**SPI_MISO**            |`M-Bus`<BR>**SPI_MISO**            |`M-Bus`                                | ---                          |**LED**<BR>**InfraRed**   |**RTC_INT**             |`PORT.C`               |LCD_D/C                |`Bus`<BR>**SPK_C**(ECHO)<BR>***PDM_D**(U)|                    |GPIO19              |
    |GPIO21              |`M-Bus`<BR>`PORT.A`<BR>**I2C0_SDA**|`M-Bus`<BR>`PORT.A`<BR>**I2C0_SDA**|**I2C1_SDA**                           |**I2C1_SDA**                  |**I2C1_SDA**               |`MI-Bus`<BR>**I2C1_SDA**|**I2C1_SDA**           |**I2C1_SDA**           |`Bus`<BR>**I2C1_SCL**                    |                    |GPIO21              |
    |GPIO22              |`M-Bus`<BR>`PORT.A`<BR>**I2C0_SCL**|`M-Bus`<BR>`PORT.A`<BR>**I2C0_SCL**|**I2C1_SCL**                           |**I2C1_SCL**                  |**I2C1_SCL**               |`MI-Bus`<BR>**I2C1_SCL**|**I2C1_SCL**           |**I2C1_SCL**           |`Bus`<BR>**SPK_D**(ECHO)                 |                    |GPIO22              |
    |GPIO23              |`M-Bus`<BR>**SPI_MOSI**            |`M-Bus`<BR>**SPI_MOSI**            |**SPI_MOSI**                           |**LCD_D/C**                   | ---                        |`MI-Bus`<BR>**SPI_MOSI**|**EPD_RST**            |**SPI_MOSI**           |`Bus`<BR>**PDM_D**(ECHO)                 | ---                |GPIO23              |
    |GPIO25<BR>`DAC1`    |`M-Bus`<BR>**SPK_DAC**                |`M-Bus`<BR>**SPK_DAC**                |`M-Bus`<BR>**RGB LED**(AWS)    |`HAT`(CPlus)<BR>`PAD`         |`HAT`                      |`MI-Bus`<BR>`HAT`       |`PORT.A`<BR>I2C0_SDA   |`PORT.B1`              |`Bus`<BR>**I2C1_SDA**                    |                    |GPIO25<BR>`DAC1`    |
    |GPIO26<BR>`DAC2`    |`M-Bus`                            |`M-Bus`<BR>`PORT.B`                |`M-Bus`                                |`HAT`<BR>`PAD`                |`HAT`                      |`MI-Bus`<BR>`HAT`       |`PORT.B`               |`PORT.B2`              |`PORT.A`<BR>**I2C0_SDA**                 |                    |GPIO26<BR>`DAC2`    |
    |GPIO27<BR>`ADC2_CH7`|**LCD_D/C**                         |**LCD_D/C**                             |`M-Bus`                                |**AXP192 VBUSEN**             |**LCD_BL**                 |**BTN_PWR**             |**EPD_BUSY**           |**IMU_INT**            |**RGB LED**                              |**RGB LED**         |GPIO27<BR>`ADC2_CH7`|
    |GPIO32<BR>`ADC1_CH4`|**LCD_BL**                         |**LCD_BL**                         |`M-Bus`<BR>`PORT.A`<BR>I2C0_SDA        |`PORT.A`<BR>I2C0_SDA          |`PORT.A`<BR>I2C0_SDA       |`PORT.A`<BR>I2C0_SDA    |`PORT.A`<BR>I2C0_SCL   |`PORT.A`<BR>I2C0_SDA   |`PORT.A`<BR>**I2C0_SCL**                 |`PORT.A`<BR>I2C0_SDA|GPIO32<BR>`ADC1_CH4`|
    |GPIO33<BR>`ADC1_CH5`|**LCD_RST**                         |**LCD_RST**                         |`M-Bus`<BR>`PORT.A`<BR>I2C0_SCL        |`PORT.A`<BR>I2C0_SCL          |`PORT.A`<BR>I2C0_SCL       |`PORT.A`<BR>I2C0_SCL    |`PORT.B`               |`PORT.A`<BR>I2C0_SCL   |`Bus`<BR>**PDM_C**(ECHO)                 |`PORT.A`<BR>I2C0_SCL|GPIO33<BR>`ADC1_CH5`|
    |GPIO34<BR>`ADC1_CH6`|`M-Bus`<BR>IIS_IN                  |`M-Bus`<BR>**MIC_ADC**<BR>IIS_IN   |`M-Bus`<BR>**PDM_D**(Core2)    |**PDM_D**                     |**PDM_D**                  |`MI-Bus`<BR>**SPI_MISO**| ---                   | USB Current?          |                                         | ---                |GPIO34<BR>`ADC1_CH6`|
    |GPIO35<BR>`ADC1_CH7`|`M-Bus`                            |`M-Bus`                            |`M-Bus`                                |**RTC_INT**                    |**BTN_PWR**                |**BAT_V**              |**BAT_V**              |`PORT.B1`              | ---                                     | ---                |GPIO35<BR>`ADC1_CH7`|
    |GPIO36<BR>`ADC1_CH0`|`M-Bus`                            |`M-Bus`<BR>`PORT.B`                |`M-Bus`                                |`HAT`<BR>`PAD`                |`HAT`                      |`MI-Bus`<BR>`HAT`       |**TP_INT**             |`PORT.B2`              | ---                                     | ---                |GPIO36<BR>`ADC1_CH0`|
    |GPIO37<BR>`ADC1_CH1`|**BTN_C**                          |**BTN_C**                          | ---                                   |**BTN_A**                     |**BTN_A**                  |**SW_Up**              |**SW_Up**              |**BTN_A**              | ---                                     | ---                |GPIO37<BR>`ADC1_CH1`|
    |GPIO38<BR>`ADC1_CH2`|**BTN_B**                          |**BTN_B**                          |`M-Bus`<BR>**SPI_MISO**                  |`PAD`                         |**BAT_V**                  |**SW_Press**            |**SW_Press**           |**BTN_B**              | ---                                     | ---                |GPIO38<BR>`ADC1_CH2`|
    |GPIO39<BR>`ADC1_CH3`|**BTN_A**                          |**BTN_A**                          |**TP_INT**                             |**BTN_B**                     |**BTN_B**                  |**SW_Down**             |**SW_Down**             |**BTN_C**              |**BTN**                                  |**BTN**             |GPIO39<BR>`ADC1_CH3`|
  11. SPI device specifications by model

    master

    The following table lists the SPI-connected display and TF card chipsets and their Chip Select (CS) pins for various M5Stack models.

    DeviceM5Stack BASIC/GRAY/GO/FIREM5Stack Core2/ToughM5Stick CM5Stick CPlusM5Stack CoreInkM5Paper
    DisplayILI9342C (320x240) CS:G14ILI9342C (320x240) CS:G5ST7735S (80x160) CS:G5ST7789V2 (135x240) CS:G5GDEW0154M09 (200x200) CS:G9IT8951 (960x540) CS:G15
    TF CardCS:4CS:4---------CS:4
  12. Supported frameworks and devices for M5Unified

    master

    M5Unified supports multiple frameworks and a wide range of M5Stack hardware across different ESP32 chip architectures.

    Supported Frameworks

    • ESP-IDF
    • Arduino IDE

    Supported Hardware by Chip Architecture

    ESP32

    • M5Stack Core (BASIC / GRAY / GO / FIRE)
    • M5Stack Core2 / Core2 v1.1 / Tough
    • M5Stick C / CPlus / CPlus2
    • M5Stack CoreInk
    • M5Station
    • M5Paper
    • M5ATOM Lite / Matrix / ECHO / PSRAM / U
    • M5STAMP PICO

    ESP32-S3

    • M5Stack CoreS3 / CoreS3SE
    • M5StickS3
    • M5ATOMS3 / S3Lite / S3U
    • M5ATOMS3R / S3RExt / S3RCam / ECHO S3R
    • M5STAMPS3 (S3 / S3A) / S3Bat / S3Mini
    • M5STAMPPLC
    • M5Dial
    • M5DinMeter
    • M5Capsule
    • M5Cardputer / M5CardputerADV
    • M5VAMeter
    • M5AirQ
    • M5PaperS3
    • M5PaperColor
    • M5PaperMono
    • M5PaperDIY
    • M5PowerHub
    • M5StopWatch
    • M5StackChan
    • M5ChainCaptain
    • M5DualKey

    ESP32-C3

    • M5STAMPC3 / C3U

    ESP32-C5

    • M5STAMPC5
    • M5ToughC5

    ESP32-C6

    • M5NanoC6
    • M5UnitC6L
    • M5STAMPC6
    • ArduinoNessoN1

    ESP32-H2

    • M5NanoH2

    ESP32-P4

    • M5Tab5
    • M5STAMPP4
    • M5UnitPoEP4