2026-07-31 23:46:37 -07:00
|
|
|
"""MicroMesh example for Raspberry Pi Pico and Pico W.
|
|
|
|
|
|
|
|
|
|
Wiring (cross TX and RX):
|
|
|
|
|
Pico GP0 / UART0 TX -> Meshtastic radio RX
|
|
|
|
|
Pico GP1 / UART0 RX <- Meshtastic radio TX
|
|
|
|
|
Pico GND --- Meshtastic radio GND
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from machine import Pin, UART
|
|
|
|
|
from time import sleep_ms
|
|
|
|
|
|
|
|
|
|
from micromesh import PortNum, SerialInterface
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def on_packet(packet):
|
|
|
|
|
if packet.WhichOneof("payload_variant") != "decoded":
|
|
|
|
|
return
|
|
|
|
|
if packet.decoded.portnum == PortNum.TEXT_MESSAGE_APP:
|
2026-08-01 01:14:46 -07:00
|
|
|
try:
|
|
|
|
|
text = packet.decoded.payload.decode("utf-8")
|
|
|
|
|
except UnicodeError:
|
|
|
|
|
text = repr(packet.decoded.payload)
|
|
|
|
|
print("from !%08x: %s" % (packet.from_, text))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def on_error(error, payload):
|
|
|
|
|
print("skipping undecodable radio frame:", error, "(%d bytes)" % len(payload))
|
2026-07-31 23:46:37 -07:00
|
|
|
|
|
|
|
|
|
|
|
|
|
uart = UART(0, 115200, tx=Pin(0), rx=Pin(1), timeout=0, rxbuf=1024)
|
2026-08-01 01:14:46 -07:00
|
|
|
mesh = SerialInterface(uart, on_packet=on_packet, on_log=print, on_error=on_error)
|
2026-07-31 23:46:37 -07:00
|
|
|
mesh.connect()
|
|
|
|
|
|
|
|
|
|
hello_sent = False
|
|
|
|
|
while True:
|
|
|
|
|
mesh.poll()
|
|
|
|
|
if mesh.config_complete and not hello_sent:
|
|
|
|
|
mesh.sendText("hello from Raspberry Pi Pico")
|
|
|
|
|
hello_sent = True
|
|
|
|
|
sleep_ms(10)
|