Serial2 on Raspberry Pi Pico

I found the solution after reading Raspberry pi pico unable to use 2 hardware serial ports (Serial1&2) · Issue #210 · arduino/ArduinoCore-mbed · GitHub.

Although the proposed code did not compile as it was shown there.

UART Serial2(8, 9); // did not compile

What worked for me was:

UART Serial2(8, 9, 0, 0);

Full code:

    #include <Arduino.h>
    
    UART Serial2(8, 9, 0, 0);
    
    void setup() {
      Serial2.begin(9600);
      // ...
      Serial2.write("hello world");
    }
    
    void loop {}
3 Likes