Skip to content

Instantly share code, notes, and snippets.

@0x7d7b
Last active November 28, 2021 09:47
Show Gist options
  • Save 0x7d7b/4d4d74c5503e6063c22d85bac09f85f7 to your computer and use it in GitHub Desktop.
Save 0x7d7b/4d4d74c5503e6063c22d85bac09f85f7 to your computer and use it in GitHub Desktop.
Raspberry Pi Serial Connection Setup

Sometimes it is necessary to access a Raspberry Pi via a serial connection. Especially on a Raspberry Pi Zero which has no ethernet port. This short article explains how to enable a serial connection and how to use it.

Prerequisites

First you need a connection cable. I use a USB to serial cable with a PL-2303 chip (Amazon link).

PL-2303 cable

Driver

If you plan to connect to your Pi from a Mac you probably need to install a driver, first. The guys at mac-usb-serial.com offer a very good PL-2303 driver for a small price. Download and install it. They also offer a Serial Detect tool which you can use to first test whether your USB serial adapter has been found by the system.

Configuration

After burning the Raspbian image to an SD card as usual you need to do some modifications. So mount the boot partition.

Then edit the config.txt and enable UART:

enable_uart=1

In addition open the cmdline.txt and check whether the console has been properly setup with 115200 baud:

console=serial0,115200

Save the files and unmount the boot partition.

Wiring

Connect the GND (black), RXD (GPIO 16 - green) and TXD (GPIO 15 - white) pins. DO NOT CONNECT THE 5V PIN! I assume that your Pi is already powered by its own USB connection.

PL-2303 cable connection

Usage

Boot up your Pi.

After plugging in the USB to serial adapter cable on a Mac, a new device shows up: /dev/cu.Repleo-PL2303-00001014. The number suffix will be different on your system.

Now open a serial connection using screen:

screen /dev/cu.Repleo-PL2303-00001014 115200

Now you will get a terminal login screen to your Pi.

To quit the screen session first log out and then press CTRL-a+d.

Bonus: through a serial connection you can also watch the boot messages which would not be possible via SSH.

ZMODEM

In order to send/receive files via a serial connection different tools are required. One option is to use the ZMODEM protocol. Therefore you need to install the lrzsz package on both systems (sender and receiver). Then you only need a terminal emulator that supports ZMODEM like minicom.

To send a file from the local computer to the remote one open a serial connection via minicom like:

$ minicom -D /dev/cu.Repleo-PL2303-00001014 -b 115200 -o

Then type the rz command on the receivers commandline. It will get into a waiting state. Then send a file to it using minicom by typing META+Z and then S. From the dropdown choose zmodem. A file chooser will appear where you can select a file.

To receive a local file from a remote computer type the sz <filename> command on the senders commandline. Minicom will automatically receive the file and store it to the local directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment