Projects / Pi plus Pico co-processor

Pi plus Pico co-processor

Intermediate3 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. Pi 5PICO

    Load MicroPython on the Pico

    With Thonny.

  2. Pi 5PICO

    Copy main.py to the Pico

    The first file.

  3. Pi 5

    Enable the Pi serial port

    raspi-config.

  4. Pi 5

    Wire TX to RX, RX to TX and ground

    Cross the data wires.

  5. Pi 5

    Run bridge.py on the Pi

    In a virtual environment.

  6. Pi 5

    Open the page

    http://pi-address:8000.

  7. Pi 5

    Switch the LED

    With curl -X POST .../led/on.

In short

How do you build a pi plus Pico co-processor?

A Pico handles real-time sensing and a Pi 5 handles the web page and database, linked by UART. You need Raspberry Pi 5, Raspberry Pi Pico H, SanDisk microSD card 32 GB (A1, Class 10), Raspberry Pi 27 W USB-C power supply and Jumper wires male to female (40 pcs). It takes 7 steps and about 180 minutes.

Level
Intermediate
Time
About 180 min
Parts
5

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Pico GP0 (UART0 TX)Pi 5 GPIO15 (RXD, pin 10)Readings to the Pi
Pico GP1 (UART0 RX)Pi 5 GPIO14 (TXD, pin 8)Commands from the Pi
Pico GNDPi GND (pin 6)Common ground (both are 3.3 V logic)
Pico USBPower only, from a separate source or the Pi USB portKeep one power source for the Pico at a time
Pi 5Power supply and SD cardRaspberry Pi OS

Code

A Linux board such as the Pi is good at networks, databases and web pages but cannot promise exact timing, and a microcontroller such as the Pico does the opposite, so each does what it is best at. The two talk over a UART with simple text lines of JSON. The Pico code is MicroPython; copy it to the Pico as main.py with Thonny. The Pi side needs the serial port turned on: run sudo raspi-config, then Interface Options, Serial Port, answer No to a login shell and Yes to the serial hardware. Both boards are 3.3 V, so wire them directly, and join the grounds. The Pico here reads its built-in temperature sensor so no extra sensor is needed; swap in your own sensor later. The example web page has no login, so use it only on a home network and never open it to the internet. Raspberry Pi OS (Bookworm or newer) with Python 3.

# ===== File 1: main.py on the Pico (MicroPython) =====
# Sends the Pico's internal temperature as a JSON line every 2 seconds and switches the onboard LED on commands from the Pi.
from machine import UART, Pin, ADC
import time, json

uart = UART(0, baudrate=115200, tx=Pin(0), rx=Pin(1))
led = Pin("LED", Pin.OUT)            # Pin("LED") works on the Pico and Pico W
sensor = ADC(4)                      # internal temperature sensor

def read_temp():
    v = sensor.read_u16() * 3.3 / 65535
    return 27 - (v - 0.706) / 0.001721

last = time.ticks_ms()
buf = b""
while True:
    if uart.any():
        buf += uart.read()
        while b"\n" in buf:
            line, buf = buf.split(b"\n", 1)
            cmd = line.strip()
            if cmd == b"LED ON": led.value(1)
            elif cmd == b"LED OFF": led.value(0)
    if time.ticks_diff(time.ticks_ms(), last) > 2000:
        last = time.ticks_ms()
        uart.write(json.dumps({"temp_c": round(read_temp(), 1), "t": time.time()}) + "\n")

# ===== File 2: bridge.py on the Pi 5 (needs: pip install pyserial flask in a virtual environment) =====
import serial, json, sqlite3, threading, time
from flask import Flask, jsonify

port = serial.Serial("/dev/serial0", 115200, timeout=1)
db = sqlite3.connect("readings.db", check_same_thread=False)
db.execute("CREATE TABLE IF NOT EXISTS r (ts REAL, temp REAL)")

def reader():
    while True:
        line = port.readline().decode(errors="ignore").strip()
        if not line:
            continue
        try:
            d = json.loads(line)
            db.execute("INSERT INTO r VALUES (?, ?)", (time.time(), d["temp_c"]))
            db.commit()
        except (ValueError, KeyError):
            pass                              # ignore half lines

threading.Thread(target=reader, daemon=True).start()
app = Flask(__name__)

@app.route("/")
def latest():
    rows = db.execute("SELECT ts, temp FROM r ORDER BY ts DESC LIMIT 20").fetchall()
    return jsonify(rows)

@app.route("/led/<state>", methods=["POST"])
def led(state):
    port.write(b"LED ON\n" if state == "on" else b"LED OFF\n")
    return "ok"

app.run(host="0.0.0.0", port=8000)

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Pico runningPi receives a line every 2 seconds
DatabaseGrows by one row per reading
Web pageLists the latest 20 readings
LED commandPico LED switches

If it does not work

Nothing arrives

Swap TX and RX and check the shared ground.

Garbled text

Check both use 115200 baud.

Permission denied on serial

Add your user to the dialout group.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the pi plus Pico co-processor?

Raspberry Pi 5, Raspberry Pi Pico H, SanDisk microSD card 32 GB (A1, Class 10), Raspberry Pi 27 W USB-C power supply and Jumper wires male to female (40 pcs).

How long does the pi plus Pico co-processor take to build?

About 180 minutes for a intermediate maker, in 7 steps.

How do I know the pi plus Pico co-processor works?

Pico running: Pi receives a line every 2 seconds. Database: Grows by one row per reading. Web page: Lists the latest 20 readings.

Nothing arrives: what should I check?

Swap TX and RX and check the shared ground.

Garbled text: what should I check?

Check both use 115200 baud.

Permission denied on serial: what should I check?

Add your user to the dialout group.