Linking a Raspberry Pi 4 and a PICO over a serial connection

I want the Pure Data patches in my Chocolate Synthbox to be able to display lights that flash in time with the music. The lights in question are a bunch of neopixels connected to a Raspberry Pi PICO which is handing all the inputs and outputs for the device. I’ve done this to keep the design simpler and to remove any chance of issues with the sound code on the Pi interfering with the pixel animations.

However, to make it work I have to connect the Pi and the PICO together. Both devices have plenty of serial ports, so the best way is just to use one of those.

On the Raspberry Pi 4 (note that this only works for the 4) there are four serial ports which are surfaced on the “hat” connector. You have to enable them and they surface as devices you can use.

You enable them by editing the /boot/config.txt file:

sudo nano /boot/config.txt

Then, if you want to enable serial port 2 (which I do) add the following line at the end of the file:

dtoverlay=uart2

Save the file and then restart the Pi. You can now ask it which pins it uses with the command

dtoverlay -h uart2

The important part of this information is the “uart 2 on GPIOS 0-3. This means that the pins will be assigned as follows:

Pin 27 GPIO0 UART2 TX
Pin 28 GPIO1 UART2 RX

The other two pins (GPIO2 and GPIO2) can be used for hardware handshaking, but I’ve not enabled that. The device will appear as /dev/ttyAMA1, I’m going to use it in Pure Data (but that’s a different blog post. For this one, let’s discover how to connect the port to a PICO. I’ve decided to use uart1 in the PICO. This can be used on pins GP8 (TX) and GP9 (RX). So the wiring I need is:

Raspberry PI         PICO
Pin 38 GND           Pin 13 GND
Pin 27 GP0 UART TX   Pin 12 GP9 UART1 RX
Pin 28 GP1 UART RX   Pin 11 GP8 UART1 TX

Note that the TX and RX are crossed over. The PIC is running Circuit Python, this is how to connect a program to this port:

serial_port = busio.UART(board.GP8, board.GP9, baudrate=19200,receiver_buffer_size=500)

Now if the Circuit Python program in the PICO sends data to this port it can be picked up in the PI.