0

I want to use Serial1 and Serial2 in a sketch in Arduino IDE for a Raspberry pi pico. My goal is to communicate from the pico with two other Arduino boards.

I use Arduino 1.8.9 and the official board for Raspberry Pi Pico: "Arduino Mbed OS RP2040 Boards by Arduino version 2.1.0"

Serial2 does not seem to be configured. When I compile

    #include <Arduino.h>
    void setup() {
        Serial2.begin(9600);
    }

    void loop(){}

I get: "undefined reference to '_UART2_'".

I found some documents (not rpi pico specific) that state you can define a second UART like this:

    #include "wiring_private.h"
    Uart mySerial (&sercom3, 1, 0, SERCOM_RX_PAD_1, UART_TX_PAD_0); // Create the new UART instance assigning it to pin 1 and 0

But that throws " 'Uart' does not name a type; did you mean 'sqrt'?"

Does anyone have an example of how to use Serial1 and Serial2 (2 serial communications to two other boards) on a Raspberry Pi Pico using Arduino-IDE?

Thanks a lot!

1

I found the solution after reading https://github.com/arduino/ArduinoCore-mbed/issues/210#issuecomment-849502556.

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 {}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.