Skip to content

Instantly share code, notes, and snippets.

@stonehippo
Created January 9, 2026 18:26
Show Gist options
  • Select an option

  • Save stonehippo/09197b82557d7ac6d7c1bc0b0e062c96 to your computer and use it in GitHub Desktop.

Select an option

Save stonehippo/09197b82557d7ac6d7c1bc0b0e062c96 to your computer and use it in GitHub Desktop.
Raspberry Pi Pico serial tap

RP2040 Serial Tap

I wanted a very basic serial tap, a device I can insert between two other devices that are communicating via UART serial, so that I can inspect the messages going over the wire in real time.

The following are two implementations of this basic tap using an RP2040-based board, like a Raspberry Pi Pico. It takes advantage of the fact that the RP2040 has two UARTs, in addition to the USB serial used for programming and the REPL. There is one implementation in CircuitPython and another in MicroPython.

'''
A basic serial tap, where this device sits between two others
and transparently echoes serial comms. This is useful for
debugging and for "logic level" shifting between to devices
with serial interfaces running at different speeds.
'''
import board
import busio
import digitalio
DEFAULT_BPS = 115200
# Set up the default UARTs
u0 = busio.UART(board.GP0, board.GP1, baudrate=DEFAULT_BPS)
u1 = busio.UART(board.GP4, board.GP5, baudrate=DEFAULT_BPS)
def config(u0_baudrate=DEFAULT_BPS, u1_baudrate=DEFAULT_BPS):
global u0
global u1
u0.reset_input_buffer()
u1.reset_input_buffer()
u0.deinit()
u1.deinit()
u0 = busio.UART(board.GP0, board.GP1, baudrate=u0_baudrate)
u1 = busio.UART(board.GP4, board.GP5, baudrate=u1_baudrate)
def exchange_bytes():
if u0.in_waiting:
b0 = u0.read(1)
u1.write(b0)
print(f"u0 -> {b0} -> u1")
if u1.in_waiting:
b1 = u1.read(1)
u0.write(b1)
print(f"u0 <- {b1} <- u1")
'''
A basic serial tap, where this device sits between two others
and transparently echoes serial comms. This is useful for
debugging and for "logic level" shifting between to devices
with serial interfaces running at different speeds.
'''
from machine import UART, Pin
# Set up the default UARTs
u0 = UART(0)
u1 = UART(1)
DEFAULT_BPS = 115200
def config(u0_bps=DEFAULT_BPS, u1_bps=DEFAULT_BPS):
global u0
global u1
u0.deinit()
u1.deinit()
u0 = UART(0, baudrate=u0_bps)
u1 = UART(1, baudrate=u1_bps)
def exchange_bytes():
if u0.any():
b0 = u0.read(1)
u1.write(b0)
print(f"u0 -> {b0} -> u1")
if u1.any():
b1 = u1.read(1)
u0.write(b1)
print(f"u0 <- {b1} <- u1")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment