Using The Second UART Port – Serial1

Serial1 Demo
In this post, we’re going to quickly tell you how to use the second hardware serial port that’s present on the Pico/Nano boards. The board support package (BSP) already contains the required libraries so all you need to do is call the appropriate functions in your sketch.

Wiring:

The default hardware serial port uses the D0 (Tx) & D1 (Rx) pins for communication. This is very common across almost all the Arduino boards. These two pins are connected to the USB-serial converter on the Pico/Nano and are used to upload sketches from the Arduino IDE.

The second hardware serial port uses the D11 (Tx) & D12 (Rx) pins for communication. These are also marked as TX1 and RX1 on the pinout cards. If you are using the Pico then you can locate these on the finer 1.27mm pitch header pins.

Since the Pico and Nano are both 5V boards, you will need a 5V USB-serial converter to test this demo. Please connect the following pins to the board:

  • Connect D11 to the Rx pin of a USB-serial converter
  • Connect D12 to the Tx pin of a USB-serial converter
  • Power up the Pico or Nano using USB or an external 5V power supply

Serial1/UART1 Wiring Serial1/UART1 Wiring

The Sketch:

Using the new serial port is very simple. You simply need to use Serial1 instead of Serial. Here’s what the setup function looks like:

  Serial1.begin(57600);     //opens serial port, sets data rate to 57600 bps
  Serial1.println("Boot Success: Hello World!");
  Serial1.println("Communicating through serial1.");
}

As can be seen, we simply setup the serial port for 57600 baud and then send two messages to make sure everything is OK.

We now need to make sure that we can successfully receive data using the serial port. To do this, we can use a simple sketch like the one below:

  if (Serial1.available() > 0) 
  {
    incomingByte = Serial1.read();        //read the incoming byte
    Serial1.print("Received: ");          
    Serial1.println(incomingByte, DEC);   //send the byte to the terminal in decimal format
  }

We wait for serial data to be available at the port and then read this into a variable called “incomingByte”. We then print this byte back to the terminal using the decimal format as that will print out the ASCII values of the bytes.

After uploading the code, you need to select the COM port corresponding to your USB to serial converter and then open up the Serial Monitor (Tools -> Serial Monitor). Make sure the correct baud rate is selected. Simply type in some test characters like ABC123 and press enter. You will then be able to view the ASCII values for the bytes like so:

Serial Output Serial Output

The last byte with value 10 is the ASCII value for the line feed (Enter)

Download the UART1 demo sketch here.

That’s all you need to do to use the new serial port. If you are using existing 3rd party libraries, then you will have to manually update the libraries to use Serial1 instead of Serial. Unfortunately, not all the libraries currently support using an alternate serial port.