Raspberry Pi With Arduino: UART Communication (Pi 5 + UNO, Python, C++)

In this tutorial, we’ll connect a Raspberry Pi with Arduino boards over UART: the Raspberry Pi 5’s GPIO14 (TX) and GPIO15 (RX) pins wired to an Arduino UNO’s serial pins, with no USB cable between the two boards. You’ll learn how to wire a 3.3v Raspberry Pi to a 5v Arduino safely, which serial port to open on the Raspberry Pi 5, why the UNO’s D0/D1 pins fight with its own USB chip, which baud rates work between the two chips, and how to send commands and read values reliably. The Raspberry Pi side is written twice, in Python (pyserial) and C++ (LibSerial).

We’ll answer the question most readers bring here: how do I wire the Pi’s TX and RX to a 5v Arduino UNO without damaging the Pi, and send data both ways without garbage or lost bytes? You’ll see five complete examples (sending a line, reading the reply, a command protocol with checksums and timeouts, reading the UNO’s A0 to dim its LED, and a data stream with no lost lines), plus oscilloscope captures, error counts at seven baud rates, and the round-trip time compared with USB serial. Without further ado, let’s get right into it!

Raspberry Pi With Arduino Series: Part 2 of 4
1 USB Serial2 UART3 I2C4 SPI

Note: All examples in this tutorial are tested with: Raspberry Pi 5 (8GB) with Raspberry Pi OS (64-bit) Trixie, an Arduino UNO R3 (Arduino IDE 2), and a BSS138 level shifter.

This tutorial assumes your Raspberry Pi is set up with Raspberry Pi OS and reachable over SSH. If it isn’t, follow the Raspberry Pi Setup Guide first. Enabling the UART and the Raspberry Pi 5’s serial ports are covered in detail in my Raspberry Pi UART tutorial; this tutorial uses UART0 on GPIO14/15.

Raspberry Pi Arduino UART Communication in 3 Steps

To connect a Raspberry Pi to an Arduino over UART, cross the TX and RX lines through a 3.3v to 5v level shifter and share ground, enable UART0, then open /dev/ttyAMA0 at the same baud rate the sketch uses:

  1. Wire it: Pi GPIO14 TX (pin 8) → shifter → UNO RX; UNO TX → shifter → Pi GPIO15 RX (pin 10); GND to GND. Never connect the UNO’s 5v TX straight to the Pi.
  2. Enable UART0: add dtparam=uart0=on to /boot/firmware/config.txt and reboot. On a Raspberry Pi 5 the GPIO UART is /dev/ttyAMA0; /dev/serial0 is the debug connector.
  3. Talk: Serial.begin(115200) on the UNO and serial.Serial('/dev/ttyAMA0', 115200) on the Pi ( sudo apt install python3-serial).

Arduino Code example (the UNO answers every line it receives)

Python Code example (the Raspberry Pi sends three lines and prints the UNO’s replies)

Raspberry Pi with Arduino UART: the Pi sends three lines to the UNO over GPIO14/15 and prints each reply, Python and C++
Raspberry Pi with Arduino UART: the Pi sends three lines to the UNO over GPIO14/15 and prints each reply, Python and C++

The rest of this tutorial explains each step and the two traps the short version hides: the UNO’s D0/D1 are shared with its USB chip, and some baud rates the UNO can’t produce.


UART, USB, I2C or SPI Between a Raspberry Pi and an Arduino

A Raspberry Pi and an Arduino can talk over four links. This tutorial is about the GPIO UART; pick the link by what your project needs:

Raspberry Pi with Arduino: 4 ways to connect them, USB, UART, I2C and SPI compared

USB SerialUART (GPIO)I2CSPI
Wires1 USB cableTX, RX, GNDSDA, SCL, GNDSCLK, MOSI, MISO, CS, GND
Level shifter for a 5v UNONoYesYesYes
Who starts a transferEither sideEither sidePi (master)Pi (master)
One-byte round trip (measured)~4 ms0.49 ms at 115200, 0.09 ms at 1Msee Part 3see Part 4
Best forProgramming + data on one cableText commands, streams, either side talks firstSeveral devices on two wiresFast, fixed-size frames

UART is the link to pick when either board may start talking, when you want plain text commands you can read on a scope or in a terminal, and when USB’s 4ms delay is too slow. Every link in this series runs on the same Raspberry Pi 5 and Arduino UNO; for why a project uses both boards at all, see Raspberry Pi vs Arduino.


Raspberry Pi Arduino UART Wiring: Level Shifter or Divider

Note: Never wire the UNO’s TX straight to the Raspberry Pi. The UNO’s TX swings to 5v, and the Raspberry Pi’s GPIO pins are 3.3v only and aren’t 5v tolerant (Raspberry Pi documentation).

Measured through a BSS138 level shifter on my bench: the Pi’s TX idles at 3.34v on the 3.3v side and at 5.12v on the UNO’s RX; the Pi’s RX idles at 3.31v. At 1Mbaud the UNO-side edge rises in 261ns (10–90%) and falls in 44ns, so a 1µs bit still settles, and 60-byte bursts at 1M and 2M arrived with zero errors. Both directions need attention for different reasons:

  • UNO TX → Pi RX must be shifted down: 5v into a 3.3v pin is the one connection that can damage the Pi.
  • Pi TX → UNO RX works without a shifter on paper, but with little margin: the ATmega328P reads a HIGH from 0.6 × VCC = 3.0v at 5v (ATmega328P datasheet, Table 30-1), and the Pi drives 3.3v. The shifter brings it to a full 5v.

I use a common 4-channel BSS138 level shifter: each channel is a BSS138 MOSFET with a 10kΩ pull-up on each side, the circuit from NXP’s AN10441. It’s bidirectional, so you don’t have to care which channel carries TX and which carries RX.

The Resistor Divider Alternative

If you have no level shifter, a divider on the UNO’s TX line works: 1kΩ from the UNO’s TX to the Pi’s RX, and 2kΩ from the Pi’s RX to GND gives 5v × 2k / 3k = 3.33v at the Pi. Leave the Pi’s TX wired straight to the UNO’s RX (3.3v against the 3.0v threshold). The divider has two costs: it loads the UNO’s TX with 1.67mA at idle, and it adds an RC delay with the Pi’s pin capacitance, which is harmless at 115200 and is the reason to prefer a shifter at 1Mbaud. Everything measured in this tutorial ran through the BSS138.

Wiring Diagram and Parts

QTY.Component NameAmazon.comAliExpress
1Raspberry Pi 5 (4GB or 8GB)AmazonAliExpress
1Raspberry Pi 27W USB-C Power SupplyAmazonAliExpress
1Arduino UNO R3 (or a UNO kit)AmazonAliExpress
1BSS138 4-Channel Logic Level Shifter––
110kΩ PotentiometerAmazon–
1LED (5mm) + 220Ω ResistorAmazon–
1BreadboardAmazonAliExpress
1Jumper Wires (Female-Male + Male-Male)AmazonAliExpress
Raspberry Pi with Arduino UART wiring diagram: Raspberry Pi 5 GPIO14 TX and GPIO15 RX to the Arduino UNO D0 and D1 through a BSS138 level shifter, LED on D6, potentiometer on A0

Raspberry Pi 5 Level Shifter GPIO14 TX (pin 8) Shifter LV1 GPIO15 RX (pin 10) Shifter LV2 3.3v (pin 17) Shifter LV GND (pin 20) Shifter GND
Arduino UNO Connects To D0 RX Shifter HV1 D1 TX Shifter HV2 5V Shifter HV + pot GND Shifter GND + pot D6 220Ω → LED → GND A0 Potentiometer wiper

The Pi’s GPIO14 (TX) goes through channel 1 to the UNO’s D0 (RX), and the UNO’s D1 (TX) comes back through channel 2 to the Pi’s GPIO15 (RX): TX always goes to RX. The shifter’s LV side takes 3.3v from the Pi, its HV side takes 5V from the UNO, and GND ties the grounds together. On the UNO, D6 drives an LED through a 220Ω resistor, and A0 reads a 10kΩ potentiometer.

Power and Ground

Power each board from its own supply: the Pi from its USB-C supply, and the UNO from your PC’s USB port (that’s also how you upload sketches). Don’t connect the Pi’s 5v pin to the UNO’s 5V pin; the only links between the boards are TX, RX and ground. Without the common ground, the Pi receives nothing or garbage.


Which Serial Port: /dev/ttyAMA0, Not /dev/serial0, on the Raspberry Pi 5

Most guides (and Google’s AI Overview) tell you to open /dev/serial0. On a Raspberry Pi 3 or 4 that pointed at the GPIO UART; on a Raspberry Pi 5 it points at /dev/ttyAMA10, the 3-pin debug connector between the HDMI ports. The UNO on GPIO14/15 is on /dev/ttyAMA0, which exists only after you enable UART0:

DeviceRaspberry Pi 5 hardwareUse it for
/dev/ttyAMA0UART0 on GPIO14 (TX, pin 8) / GPIO15 (RX, pin 10)The Arduino in this tutorial
/dev/serial0 → ttyAMA10Debug UART connector (3-pin JST), Linux consoleSerial console, not the GPIO header
/dev/ttyACM0Arduino plugged in by USBPart 1: USB serial
On a Raspberry Pi 5 /dev/serial0 is ttyAMA10, the debug connector: a PING sent there gets no reply from the Arduino on GPIO14/15
On a Raspberry Pi 5 /dev/serial0 is ttyAMA10, the debug connector: a PING sent there gets no reply from the Arduino on GPIO14/15

Leave the Linux serial console where Raspberry Pi OS puts it on the Pi 5: on the debug connector. A console on GPIO14/15 (for example after enable_uart=1 with no debug cable) answers your Arduino with login: prompts; my Raspberry Pi UART tutorial shows every UART on the Pi 5 and how to move the console.

For Python, install pyserial from the Raspberry Pi OS packages: sudo apt install python3-serial (it’s already on the Full image). pip install pyserial stops with externally-managed-environment on current Raspberry Pi OS (PEP 668). For C++, install LibSerial: sudo apt install libserial-dev.


Arduino D0/D1 vs SoftwareSerial vs AltSoftSerial

The UNO has one hardware UART, on D0 (RX) and D1 (TX), and its USB chip already uses it: the ATmega16U2’s TX and RX reach D0 and D1 through two 1kΩ resistors (RN4 on the UNO R3 schematic). When the Raspberry Pi is wired to the same pins, two transmitters share D0:

Arduino UNO D0 and D1 are shared with the ATmega16U2 USB chip through 1k resistors, so the Raspberry Pi's TX blocks uploads and Serial Monitor input

What I Measured With the Pi on D0/D1

  • Uploads fail while the Pi’s UART is enabled, even with no program running on the Pi: avrdude prints not in sync: resp=0x00 ten times. With GPIO14 released ( pinctrl set 14 ip pn) the same upload works.
  • The scope shows why: the Pi holds its TX high, and through the BSS138’s body diode it holds D0 up; the USB chip’s 1kΩ can pull D0 down only to about 2.6v, far above the 1.5v the ATmega needs for a 0. Nothing from the PC reaches the UNO.
  • Serial Monitor: you see everything the UNO sends (D1 feeds both the PC and the Pi), but what you type never arrives. Opening the Serial Monitor also resets the UNO, exactly as in Part 1.
  • Data between the Pi and the UNO is perfect: 0 errors in both directions at 9,600, 57,600, 115,200, 250,000 and 500,000 baud (5s runs; 230,400 is a baud rate problem, covered below).
Arduino upload fails while the Raspberry Pi is wired to D0/D1: avrdude not in sync resp=0x00
Arduino upload fails while the Raspberry Pi is wired to D0/D1: avrdude not in sync resp=0x00

Oscilloscope: during an upload, the UNO's D0 only falls to about 2.6v because the Raspberry Pi's TX holds the BSS138, so the ATmega never sees a 0
Oscilloscope: during an upload, the UNO’s D0 only falls to about 2.6v because the Raspberry Pi’s TX holds the BSS138, so the ATmega never sees a 0

The PC's serial port shows everything the Arduino sends to the Raspberry Pi on D1, but the PC can't send to the UNO while the Pi drives D0
The PC’s serial port shows everything the Arduino sends to the Raspberry Pi on D1, but the PC can’t send to the UNO while the Pi drives D0

SoftwareSerial and AltSoftSerial Measured

Moving the Pi to other pins frees D0/D1 for USB. I ran the same bench sketch with the Pi on SoftwareSerial (D2/D3, built into the Arduino IDE) and on AltSoftSerial (D8/D9, PJRC library, install it from the Library Manager):

UNO sideClean in both directionsFails atReceive while sendingLoop speed while receiving 57,600 baudUSB uploads with the Pi wired
Serial on D0/D19,600–500,000230,400 (UNO’s baud error)Yes (full duplex)189k loops/sNo (release GPIO14 first)
AltSoftSerial on D8/D99,600–57,600115,200 (both ways)Yes: 0 errors at 9,600; at 57,600, 7 bad bytes on the UNO and 185 on the Pi150k loops/sYes
SoftwareSerial on D2/D39,600–57,600115,200 (Pi → UNO)No: 793 of 926 bytes bad at 9,60027k loops/sYes

The loop speed is how many times the bench sketch’s loop() ran per second while a continuous stream arrived, a direct measure of the CPU time each receiver leaves for your code. SoftwareSerial receives in a pin-change interrupt that busy-waits through every byte and sends with interrupts off ( cli() in its write()), so at any baud it takes over 80% of the UNO and can’t listen while it talks. AltSoftSerial uses Timer1’s input capture instead, costs much less, and works in both directions at once; the price is D10’s PWM.

Tip: My recommendation: use AltSoftSerial on D8/D9 at 57,600 baud while you develop, so uploads and the Serial Monitor keep working with the Pi connected. Move to Serial on D0/D1 at 115,200 baud or faster when the UNO runs on its own or you need the speed, and release GPIO14 ( pinctrl set 14 ip pn, then pinctrl set 14 a4 pn) or unplug the TX wire whenever you upload. Skip SoftwareSerial for a link to a Raspberry Pi.

Raspberry Pi to Arduino UART wiring with AltSoftSerial: GPIO14 and GPIO15 through the BSS138 to the UNO's D8 (RX) and D9 (TX)

Arduino UNO Connects To D8 RX Shifter HV1 D9 TX Shifter HV2

Only the two signal wires move; the Pi side, power, the LED on D6 and the pot on A0 stay as they are.


Example 1: Send a Line From the Raspberry Pi to the Arduino

Upload Arduino_UART_Echo from the code example to the UNO (with the Pi on D0/D1, release GPIO14 for the upload). The sketch collects characters until '\n' and answers each complete line. On the Pi, writing is one call; flush() returns once the bytes have left the UART.

Python Code example (Raspberry Pi sends three text lines to the Arduino)

C++ Code example (Raspberry Pi sends three text lines to the Arduino)

Build and run the C++ version on the Pi:

Raspberry Pi sends text lines to the Arduino UNO over GPIO UART, Python and C++
Raspberry Pi sends text lines to the Arduino UNO over GPIO UART, Python and C++

No time.sleep(2) after opening the port: unlike USB, the GPIO UART has no DTR line, so opening /dev/ttyAMA0 doesn’t reset the UNO. The sketch is already running and the first byte gets through.


Example 2: Read the Arduino’s Reply on the Raspberry Pi

Reading needs one rule: never wait forever. Give the port a timeout, read a line, and check that it ends in '\n'; a missing reply then becomes an error you can handle instead of a frozen program.

Python Code example (the Pi sends a line and reads the reply with a 0.5s timeout)

C++ Code example (the Pi sends a line and reads the reply with a 500ms timeout)

Raspberry Pi reads the Arduino UNO's replies over GPIO UART, Python and C++
Raspberry Pi reads the Arduino UNO’s replies over GPIO UART, Python and C++

reset_input_buffer() ( FlushInputBuffer() in LibSerial) drops anything that arrived before your program started, such as half a line the UNO sent while the port was closed.


Example 3: A Command Protocol With Checksums and Timeouts

Plain lines are fine for a demo. A project needs to know that a command arrived intact and was carried out, so the protocol in this example gives every message the same shape, a checksum, and a reply:

Raspberry Pi to Arduino UART protocol frame: $BODY*HH with an XOR checksum, a reply to every command, error replies and retries

  • $ starts a frame, so bytes left over from noise or a half line are thrown away.
  • *HH is the XOR of the body in hex, the checksum NMEA GPS sentences use. Easy to compute on both sides, and readable in a terminal.
  • Every command gets a reply: $OK,..., a value, or $ERR,CHK / CMD / ARG / LEN.
  • The Pi waits 200ms for a reply, retries twice, then raises an error. No sleep() anywhere: the reply itself tells the Pi when the UNO is done.

Arduino Code example (Arduino UNO command protocol: LED, PWM, A0, status)

Set LINK_PORT to 1 and LINK_BAUD to 57600 for AltSoftSerial on D8/D9 (the setup I recommend while developing); the rest of the sketch doesn’t change.

Python Code example (protocol helper class)

Python Code example (run every command and show the error replies)

C++ Code example (protocol helper class)

C++ Code example (run every command and show the error replies)

Raspberry Pi to Arduino UART command protocol at 115200 baud: PING, LED, PWM, A0, status and error replies, Python and C++
Raspberry Pi to Arduino UART command protocol at 115200 baud: PING, LED, PWM, A0, status and error replies, Python and C++

One PING and its PONG took 2.2ms at 115,200 baud on D0/D1, in Python and in C++, and 4.1ms at 57,600 baud on AltSoftSerial. Here is the same exchange on the oscilloscope, decoded:

Oscilloscope UART decode: the Raspberry Pi's $PING*10 command on the UNO's D0 and the $PONG*16 reply on D1, 88µs apart
Oscilloscope UART decode: the Raspberry Pi’s $PING*10 command on the UNO’s D0 and the $PONG*16 reply on D1, 88µs apart

The same protocol with the UNO on AltSoftSerial (D8/D9) at 57600 baud, USB still free
The same protocol with the UNO on AltSoftSerial (D8/D9) at 57600 baud, USB still free


Example 4: Read A0 and Set the LED From the Raspberry Pi

The Raspberry Pi has no analog inputs, and the UNO has a 10-bit ADC (one of the reasons to use both boards). In this example the Pi asks for A0 twenty times per second, scales it from 0–1023 to a 0–255 PWM duty, and sends it back to the LED on D6. The protocol sketch from Example 3 runs on the UNO unchanged.

Python Code example (read the potentiometer on the UNO’s A0 and set the LED brightness)

C++ Code example (read the potentiometer on the UNO’s A0 and set the LED brightness)

Raspberry Pi reads the Arduino's A0 over UART and sets the LED duty, Python and C++
Raspberry Pi reads the Arduino’s A0 over UART and sets the LED duty, Python and C++

Raspberry Pi with Arduino UART demo: turning the potentiometer on the UNO’s A0 changes the LED brightness set by the Raspberry Pi


Example 5: Stream Data From the Arduino Without Losing Lines

For logging, let the UNO talk on its own: the Arduino_UART_Stream sketch sends one numbered line every 5ms ( seq,millis,A0), and the Pi checks that every sequence number arrives.

Arduino Code example (numbered data lines every 5ms)

The only real loss I could produce is at the start. When the Pi opens the port in the middle of the stream, the first line can begin with junk bytes, received while nobody was reading:

Opening /dev/ttyAMA0 in the middle of an Arduino stream: the first line can start with junk bytes, the next ones are clean
Opening /dev/ttyAMA0 in the middle of an Arduino stream: the first line can start with junk bytes, the next ones are clean

So the readers below throw away the first line, then parse each line and count gaps in the sequence numbers:

Python Code example (receive the stream for 30s and count lost lines)

C++ Code example (receive the stream for 30s and count lost lines)

Raspberry Pi receives 5,974 numbered lines from the Arduino in 30s over UART with 0 lost, Python and C++
Raspberry Pi receives 5,974 numbered lines from the Arduino in 30s over UART with 0 lost, Python and C++

5,974 lines in 30s and none lost, in both languages. The Linux serial driver buffers incoming data while your program is busy (more than 1MB in my UART tests), so a slow reader falls behind rather than losing lines. Losses come from the Arduino side: a sketch that sends faster than the baud rate blocks in Serial.print(), and a UNO that receives faster than its loop() reads overflows its 64-byte buffer.


Raspberry Pi Arduino Baud Rate: Which Speeds Work and Why

A UART link works when both ends send and sample at nearly the same rate. The two chips get there differently:

  • The Raspberry Pi 5’s PL011 UART divides a 50MHz clock with a 1/64 fraction and lands within 0.006% of any common baud rate (measured in my Raspberry Pi UART tutorial).
  • The UNO’s ATmega328P divides 16MHz by 8 × (UBRR + 1) with a whole-number UBRR (HardwareSerial.cpp). Rates that divide 2MHz evenly come out exact: 250,000, 500,000, 1,000,000. The classic rates don’t: 115,200 becomes 117,647 (+2.1%) and 230,400 becomes 222,222 (−3.5%).

I measured the UNO’s real rate with the scope (a stream of 0x55 is a square wave at half the baud rate) and ran 5s of data at each rate in both directions:

Serial.begin()UNO sendsErrorPi → UNOUNO → Pi
9,6009,620+0.21%0 errors0 errors
57,60058,824 (formula)+2.12%0 errors0 errors
115,200117,600+2.08%0 errors0 errors
230,400222,120−3.59%97% bad0 errors
250,000249,880−0.05%0 errors0 errors
500,000500,000 (formula)0%0 errors0 errors
1,000,0001,000,000 (formula)0%0 errors in bursts¹0 errors

¹ The line is clean at 1M and even 2M (60-byte bursts arrived without an error), but a continuous stream overruns the UNO: at 10µs per byte, the bench sketch’s loop() couldn’t empty the 64-byte receive buffer in time and lost or misread 20% of 500,000 bytes.

Raspberry Pi 5 to Arduino UNO UART baud rate error per rate: 230400 is 3.6% slow and fails from the Pi to the UNO; 250000, 500000 and 1M are exact

Oscilloscope: the Arduino UNO at Serial.begin(230400) sends 4.50µs bits, 222,222 baud, 3.6% slower than the Raspberry Pi's 230400
Oscilloscope: the Arduino UNO at Serial.begin(230400) sends 4.50µs bits, 222,222 baud, 3.6% slower than the Raspberry Pi’s 230400

Why does 230,400 fail in only one direction? The ATmega328P samples each bit 8 times (the core uses double-speed mode) and the datasheet recommends at most ±1.5% total error (Table 20-3); −3.6% is past it, so the UNO misreads the Pi’s bytes. The Pi’s PL011 samples 16 times per bit and tolerated the UNO’s slow bytes. At +2.1%, 115,200 is outside the recommendation too, but well inside the hard limits, and it ran clean in every test.

Tip: Pick 115,200 for a link that also suits LibSerial and any terminal program, or 250,000 / 500,000 when you want an exact match (pyserial accepts them; LibSerial’s BaudRate list doesn’t include 250,000, so C++ needs termios2 there). Avoid 230,400 with a 16MHz Arduino.


GPIO UART vs USB Serial: Latency and Throughput

In Part 1, the same UNO talked to the same Pi over its USB cable. Here are both links measured with the same method (1,000 tagged one-byte echoes, Python):

GPIO UART (this tutorial)USB serial (Part 1)
One-byte round trip, 115,200 baud0.49ms (median)~4.0ms
One-byte round trip, 1,000,000 baud0.093ms~4.0ms
UNO → Pi without lossLine rate up to 500,000 baud (49.9kB/s)Up to 250,000 baud
Opening the port resets the UNONo (no DTR on GPIO)Yes, 1.57s until the sketch runs
Old data on openCan be junk bytes (drop the first line)Old lines buffered in the 16U2

The USB link is slow for one reply because the UNO’s ATmega16U2 firmware sends serial data to the PC on a 4ms timer. The GPIO UART has no such buffer: the round trip is the two frames on the wire plus the Pi’s receive timeout, which is why it shrinks with the baud rate.


Raspberry Pi Arduino UART Troubleshooting

Nothing Received

Check three things in this order: TX goes to RX in both directions (TX to TX is the most common mistake), the grounds are connected, and you opened /dev/ttyAMA0, not /dev/serial0 (see the capture above: a PING to serial0 returns b''). On the UNO, make sure the sketch’s port matches the wiring: Serial for D0/D1, AltSoftSerial for D8/D9.

Garbage Characters

Garbage means the two ends disagree on the bit timing: a different baud rate in the sketch and on the Pi, or a rate the UNO can’t make (230,400, see the baud rate table). A 5v signal straight into the Pi also corrupts data before it damages anything; on my scope that is the only place I look at a 5v TX line, never on the Pi’s pin.

Permission denied

pyserial SerialException: [Errno 13] could not open port /dev/ttyAMA0: Permission denied
pyserial SerialException: [Errno 13] could not open port /dev/ttyAMA0: Permission denied

Your user must be in the dialout group ( sudo usermod -aG dialout $USER, then log out and in). If a getty (the serial console) owns the port, ttyAMA0 becomes root-only: turn the login shell off in raspi-config as shown in my Raspberry Pi UART tutorial.

The Upload Fails While the Pi Is on D0/D1

avrdude reports not in sync: resp=0x00 because the Pi’s TX holds D0 high (see the D0/D1 section). Release the pin with pinctrl set 14 ip pn, upload, then give it back with pinctrl set 14 a4 pn; or unplug the TX wire; or use AltSoftSerial on D8/D9, where uploads work with the Pi connected.

The Linux Console Talks to the Arduino

If cmdline.txt sends the console to GPIO14/15, the UNO receives boot messages and a login: prompt, and the Pi answers your sketch’s output as a failed login. Keep the console on the debug connector (the default on the Pi 5) and the serial hardware enabled.

pip install pyserial Fails

pip install pyserial on Raspberry Pi OS: error externally-managed-environment
pip install pyserial on Raspberry Pi OS: error externally-managed-environment

Use sudo apt install python3-serial, or a virtual environment if you need a newer pyserial.

Lost Bytes at High Baud Rates

From the Pi to the UNO, a continuous stream above about 500,000 baud overruns the UNO’s 64-byte buffer; keep the UNO’s loop() short, send in bursts and wait for a reply (the protocol in Example 3 does that), or lower the rate. SoftwareSerial and AltSoftSerial top out at 57,600.


Raspberry Pi Arduino UART FAQ

Can I connect the Arduino’s TX to the Raspberry Pi’s RX directly?

No. The UNO’s TX swings to 5v and the Raspberry Pi’s GPIO pins are 3.3v only, per the Raspberry Pi documentation. Use a level shifter or a 1kΩ/2kΩ divider on that line.

Does a 3.3v Arduino need a level shifter?

No. Boards that run at 3.3v (Arduino Pro Mini 3.3v, Nano 33, Due) connect pin to pin with a common ground.

Which Arduino has a spare hardware UART for the Raspberry Pi?

The Arduino Mega 2560 has three more UARTs (Serial1–Serial3 on pins 18/19, 16/17 and 14/15, Arduino docs), so the Pi gets its own port and USB stays free; it still needs a level shifter.

Which baud rate should I use between a Raspberry Pi and an Arduino?

115,200 works reliably with a UNO and suits every tool; 250,000 and 500,000 are exact on a 16MHz AVR. Avoid 230,400, which the UNO sends 3.6% slow.

Can the Raspberry Pi program the Arduino over the GPIO UART?

Not without the reset line: the bootloader runs only right after a reset, which USB triggers through DTR. Program the UNO over USB, from the Pi as in Part 1 or from your PC.


Raspberry Pi With Arduino Tutorial Series

This tutorial is the second part of our Raspberry Pi With Arduino tutorial series:

PartTutorialWhat You’ll Build
1Raspberry Pi With Arduino: USB Serial and ProgrammingProgram the UNO from the Pi (arduino-cli, Arduino IDE), USB serial in Python and C++
2Raspberry Pi With Arduino: UART Communication (this tutorial)Serial over the GPIO pins with a level shifter, Python and C++
3Raspberry Pi With Arduino: I2C CommunicationThe UNO as an I2C target, register protocol, clock stretching
4Raspberry Pi With Arduino: SPI CommunicationThe UNO as an SPI slave, the one-byte lag, a framed protocol

Download Raspberry Pi With Arduino UART Examples

The download contains the three Arduino sketches, every Raspberry Pi example in Python and C++, and the bench sketch and script behind the measurements, with a README that lists each command.

Download Raspberry Pi With Arduino UART Examples (Arduino, Python, C++)

Download all attachment files for this Article/Tutorial (project files, schematics, code, etc.) using the link below. Everything is tested and verified to work on real hardware, as you’ve seen in the demo videos & screenshots. Please consider supporting my work if it helped you.


Wrap Up

To conclude this tutorial, we’ve connected a Raspberry Pi 5 to an Arduino UNO over UART through a BSS138 level shifter, found the right port ( /dev/ttyAMA0), measured why the UNO’s D0/D1 block uploads while the Pi is attached, compared SoftwareSerial and AltSoftSerial, and built a checksummed command protocol in Python and C++. The baud rate table shows which speeds the two chips agree on, and the GPIO link answers about eight times faster than USB serial at 115,200 baud.

This was Part 2 of the Raspberry Pi With Arduino series: Part 1 covers USB serial and uploading sketches from the Pi, Part 3 I2C, and Part 4 SPI. For the Raspberry Pi’s UARTs in general, see my Raspberry Pi UART tutorial; for the Arduino side, the Arduino UART tutorial, Arduino serial communication and serial communication between two Arduino boards; and for more Raspberry Pi projects, the Raspberry Pi tutorials page.

Share This Page With Your Network!
Join Our +25,000 Newsletter Subscribers!

Stay Updated With All New Content Releases. You Also Get Occasional FREE Coupon Codes For Courses & Other Stuff!

Photo of author
Author
Embedded systems engineer with several years of experience in embedded software and hardware design. I work as an embedded SW engineer in the Automotive & e-Mobility industry. However, I still do Hardware design and SW development for DSP, Control Systems, Robotics, AI/ML, and other fields I'm passionate about.
I love reading, writing, creating projects, and teaching. A reader by day and a writer by night, it's my lifestyle. I believe that the combination of brilliant minds, bold ideas, and a complete disregard for what is possible, can and will change the world! I will be there when it happens, will you?

Leave a Comment