rpi pico_serial communication via usb - dwilson2547/wiki_demo GitHub Wiki
For serial communication over USB between your Raspberry Pi Pico and computer, you have several options:
MicroPython automatically sets up USB serial communication:
-
Flash MicroPython to your Pico (download
.uf2
from raspberrypi.org) -
Connect via serial terminal on your computer:
- Windows: Use PuTTY, Tera Term, or Windows Terminal
-
macOS/Linux: Use
screen
,minicom
, orpicocom
# Linux/macOS examples
screen /dev/ttyACM0 115200
# or
picocom /dev/ttyACM0 -b 115200
# Windows (check Device Manager for COM port)
# Use PuTTY with COM3, COM4, etc. at 115200 baud
- Python code on Pico:
import sys
import time
while True:
# Read from computer
if sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
line = input()
print(f"Received: {line}")
# Send to computer
print("Hello from Pico!")
time.sleep(1)
Similar to MicroPython but with slightly different syntax:
import supervisor
import time
while True:
if supervisor.runtime.serial_bytes_available:
data = input()
print(f"Got: {data}")
print("CircuitPython here!")
time.sleep(1)
For more control and performance:
#include <stdio.h>
#include "pico/stdlib.h"
int main() {
stdio_init_all();
printf("Pico serial ready!\n");
while (true) {
char input = getchar_timeout_us(0);
if (input != PICO_ERROR_TIMEOUT) {
printf("You typed: %c\n", input);
}
printf("Hello from C!\n");
sleep_ms(1000);
}
return 0;
}
To communicate from your computer:
import serial
import time
# Adjust port name for your system
ser = serial.Serial('/dev/ttyACM0', 115200, timeout=1) # Linux/macOS
# ser = serial.Serial('COM3', 115200, timeout=1) # Windows
while True:
# Send data to Pico
ser.write(b"Hello Pico!\n")
# Read response from Pico
if ser.in_waiting > 0:
response = ser.readline().decode('utf-8').strip()
print(f"Pico says: {response}")
time.sleep(1)
- Windows: Check Device Manager → Ports (COM & LPT)
-
Linux: Usually
/dev/ttyACM0
or/dev/ttyUSB0
-
macOS: Usually
/dev/cu.usbmodem*
or/dev/tty.usbmodem*
The MicroPython approach is usually the quickest to get started with. Which method would you prefer to use?