Serial2 on M5StickC

  • Has anyone been able to get Serial2 working on the M5StickC?
    I've tried all that I can think of but I'm stuck.

    I'm trying to use the hat pins at the top of the board, and from what I've read the ESP32 has the ability to assign almost any function to a particular pin. In my case I wanted to use pins 26 and 36 for TX and RX.

    I've tried a few different things including:

    • Using pins 36, 26 in setup
    • Using pins 5 and 15 in setup (based on this diagram I thought the pins might have been wrong)
    • Switched to just trying digitalWrite on the pins and looking for a result.

    My setup is:

    • M5StickC connected via USB to laptop - COM6
    • USB to serial device (jumper set to 3.3v) - COM7
    #include <M5StickC.h>
    void setup() {
      // Setup the TFT display
      // Setup the serial port for debugging
      //Serial2.begin(115200, SERIAL_8N1, 26, 36);
      //Serial2.println("Testing Serial2");
      pinMode(5, OUTPUT);
      pinMode(15, OUTPUT);
    void loop() {
      //Serial2.print("Testing Serial2: ");
      digitalWrite(5, HIGH);
      digitalWrite(15, HIGH);
      digitalWrite(5, LOW);
      digitalWrite(15, LOW);

    Any thoughts?

  • Pin 36 can only be set as input, so 36 has to be rx

  • @chriswr thanks for the suggestion, but still no luck.

    I've gone back to basics and tried to do a loopback test but can't even get that working! Will look further in to the manuals and see if there is any restriction on pins used for UART.

    Out of interest, can anyone tell me if the pin numbers quoted on the GitHub page for the M5StickC are the actual pin numbers we are supposed to use in the Arduino environment? Or do the GPIO numbers need to be converted to pin numbers?


  • I think I may have found my answer in the RS485 hat lib:

  • @klimbot Sorry, not a user of arduino, I use micropython but yes, the rshat gives the clue.

    Pin 26, 0 is the communication port, 36 is the input.