Skip to content

Serial Connection

You can connect an Arduino to a Raspberry Pi in two ways: USB or via the GPIO pins. USB is the simplest and most reliable method, but if the Pi's USB ports are occupied or inaccessible, you can fall back on the GPIO pins with a bit of extra hardware and setup.

Serial Over USB (The Easy Way)

The easiest method is to connect the Arduino directly to the Raspberry Pi using a standard USB cable.

USB-to-USB
USB-to-USB Between Arduino and RPi

Serial Over RPi GPIO Pins

On the side opposite the display ports, the Raspberry Pi features a 40-pin header. Of these, 27 pins serve as general-purpose input/output (GPIO) pins, which can be configured for various functions, including serial communication.

Raspberry Pi GPIO Pins

Voltage Differences

The Arduino and Raspberry Pi use different logic voltages: the Arduino runs at 5V, while the Raspberry Pi runs at 3.3V. Connecting them directly through the GPIO pins can permanently damage the Pi. To safely bridge the two, you’ll need voltage regulation. While there are several ways to achieve this, this guide focuses on using a logic level converter, the safest and simplest method.

Arduino and RPi Bridged Through a Logic Level Converter

What is a Logic Level Converter?

A logic level converter merely steps voltage signals up or down between two independent circuits.

In addition to the information provided in this guide, you may also find SparkFun's detailed Hookup Guide helpful.

Components

You'll need the following or similar:

Enable Serial Over GPIO Pins

By default, the Raspberry Pi GPIO pins are not enabled and must be activated using the Raspberry Pi Configuration Tool.

sudo raspi-config

Using raspi-config

When the tool opens select Interface Options.

RPi Config Screen 1

Select Serial Port.

RPi Config Screen 2

Select No to login over serial.

RPi Config Screen 3

Select Yes to enable serial GPIO hardware.

RPi Config Screen 4

Click OK and then Finish.

RPi Config Screen 5

Now, restart the Raspberry Pi.

After restarting, you should be able to see the GPIO port ttyS0 using the ls and grep commands.

ls /dev | grep tty
Listing RPi Ports

If ttyS0 is listed, the GPIO pins are configured and ready to be wired to the Arduino.


Wiring the Logic Level Converter

Identifying TX/RX Pins

Do not connect pins TX to TX and RX to RX. Instead, cross them between the two devices. Connect the transmit pin of the Arduino to the receive pin of the RPi and the transmit pin of the RPi to the receive pin of the Arduino.

Transmit and Receive Pins for Arduino and RPi

Build the Circuit

Logic Level Converter between Arduino and RPi GPIO Pins
Reset Line

In the diagram above, notice the purple connection between the Arduino RESET and RPi GPIO 4 pins.cThis circuit is not part of the serial data connection but is instead used to reset the Arduino, and covered in the Electrically Resetting the Arduino from the RPi section later.

LLC Pins

Ensure the Arduino is connected to the high voltage (HV) side and the RPi is connected to the low voltage (LV) side.

There's nothing special about any of the four channels of the logic level converter. Any channel can be used for any signal.

Channel Signal
HV4 to LV4 (any signal)
HV3 to LV3 (any signal)
HV2 to LV2 (any signal)
HV1 to LV1 (any signal)

Testing Serial Connectivity

Once connected by USB or GPIO, run the board list command to determine if the RPi can detect your Arduino.

arduino-cli board list
Arduino Found via /dev/ttyACM0 (USB)

An Arduino connected via USB should show under port /dev/ttyACM0.

Arduino Found via /dev/ttys0 (GPIO)

An Arduino connected via GPIO pins should show under port /dev/ttyS0.

The Arduino is listed as Unknown in this example

The board showing as unknown doesn't necessarily mean there is a problem with the connection. Currently boards connected over GPIO may not be correctly indentified.