🛠 Avoir une console série sur une carte sans pont USB (UART0)

RP2040 (generic board / chip) · debutant · Schéma : IMG-rp2040-generic-debutant-2-rp2040-console-serie-uart.svg — carte RP2040 générique reliée à un adaptateur USB-TTL : GP0 TX vers RX de l'adaptateur, GP1 RX vers TX, masses communes, terminal série à 115200 bauds

Objectives

A minimalist RP2040 board (Zero, bridgeless Pico-clone) has no dedicated USB-to-serial chip: the MicroPython REPL or printf go through the RP2040's native USB. But when USB is occupied (HID device mode, battery power) or the USB pins are not soldered, the solution is UART: the RP2040 has two UARTs routable to any GPIO (RP2040 datasheet). You will wire up a USB↔TTL adapter and get an independent debug console.

Hardware

Complete code

# main.py — REPL et print sur UART0 (GP0=TX, GP1=RX), 115200 bauds
from machine import UART, Pin
import time

# Sur le port rp2, l'UART0 matériel est déjà écouté par le REPL :
# un simple reset suffit souvent à obtenir le REPL sur GP0/GP1.
# Pour un flux applicatif dédié :
uart = UART(0, baudrate=115200, tx=Pin(0), rx=Pin(1))
uart.write('Carte RP2040 prete (UART0 115200 8N1)\r\n')

compteur = 0
while True:
    compteur += 1
    uart.write('tick %d\r\n' % compteur)
    if uart.any:                      # données reçues du PC
        data = uart.read
        uart.write('recu: %s\r\n' % data.decode(errors='replace'))
    time.sleep_ms(500)

Expected verification

In your serial terminal (115200 8N1, picocom, PuTTY, Thonny), the tick N lines scroll by; a typed character is echoed back. Then open the MicroPython REPL on this UART (Ctrl-C): import machine works — you have a full shell without USB. The rp2 port's UART REPL runs at 115200 by default (MicroPython RP2 quickref).

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials