fixes
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
# Board examples
|
||||
|
||||
These examples connect a MicroPython board to the hardware UART exposed by a
|
||||
Meshtastic radio. The radio must have its serial module enabled in `PROTO` mode at
|
||||
115200 baud.
|
||||
|
||||
| Board | Example | MicroPython UART | TX pin | RX pin |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| Seeed Studio XIAO RP2040 | `xiao_rp2040.py` | UART0 | D6 / GPIO0 | D7 / GPIO1 |
|
||||
| Raspberry Pi Pico / Pico W | `raspberry_pi_pico.py` | UART0 | GP0 | GP1 |
|
||||
| Generic ESP32 | `esp32.py` | UART2 | GPIO17 | GPIO16 |
|
||||
|
||||
## Wiring
|
||||
|
||||
UART signals cross between the two boards:
|
||||
|
||||
```text
|
||||
MicroPython board TX -> radio RX
|
||||
MicroPython board RX <- radio TX
|
||||
MicroPython board GND --- radio GND
|
||||
```
|
||||
|
||||
Both ends must use 3.3 V UART logic. Do not connect the power pins unless you have
|
||||
confirmed the voltage and current requirements for both boards. Meshtastic radio UART
|
||||
pin names vary by model and may need to be configured in the radio firmware.
|
||||
|
||||
## Run an example
|
||||
|
||||
Install MicroMesh, copy the matching example to the board as `main.py`, and reset it:
|
||||
|
||||
```sh
|
||||
mpremote mip install package.json
|
||||
mpremote fs cp examples/xiao_rp2040.py :main.py
|
||||
mpremote reset
|
||||
```
|
||||
|
||||
Each example requests the node configuration, listens for text messages, and broadcasts
|
||||
one greeting after configuration completes. Remove the `mesh.sendText(...)` line for a
|
||||
receive-only application.
|
||||
@@ -0,0 +1,36 @@
|
||||
"""MicroMesh example for a generic ESP32 development board.
|
||||
|
||||
Wiring (cross TX and RX):
|
||||
ESP32 GPIO17 / UART2 TX -> Meshtastic radio RX
|
||||
ESP32 GPIO16 / UART2 RX <- Meshtastic radio TX
|
||||
ESP32 GND --- Meshtastic radio GND
|
||||
|
||||
Change the pin numbers when GPIO16 or GPIO17 is unavailable on your board.
|
||||
"""
|
||||
|
||||
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:
|
||||
print("from !%08x: %s" % (
|
||||
packet.from_, packet.decoded.payload.decode("utf-8", "replace")
|
||||
))
|
||||
|
||||
|
||||
uart = UART(2, baudrate=115200, tx=Pin(17), rx=Pin(16), timeout=0, rxbuf=1024)
|
||||
mesh = SerialInterface(uart, on_packet=on_packet, on_log=print)
|
||||
mesh.connect()
|
||||
|
||||
hello_sent = False
|
||||
while True:
|
||||
mesh.poll()
|
||||
if mesh.config_complete and not hello_sent:
|
||||
mesh.sendText("hello from ESP32")
|
||||
hello_sent = True
|
||||
sleep_ms(10)
|
||||
@@ -0,0 +1,34 @@
|
||||
"""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:
|
||||
print("from !%08x: %s" % (
|
||||
packet.from_, packet.decoded.payload.decode("utf-8", "replace")
|
||||
))
|
||||
|
||||
|
||||
uart = UART(0, 115200, tx=Pin(0), rx=Pin(1), timeout=0, rxbuf=1024)
|
||||
mesh = SerialInterface(uart, on_packet=on_packet, on_log=print)
|
||||
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)
|
||||
@@ -0,0 +1,75 @@
|
||||
"""MicroMesh example for the Seeed Studio XIAO RP2040.
|
||||
|
||||
Wiring (cross TX and RX):
|
||||
XIAO D6 / GPIO0 / TX -> Meshtastic radio RX
|
||||
XIAO D7 / GPIO1 / RX <- Meshtastic radio TX
|
||||
XIAO GND --- Meshtastic radio GND
|
||||
"""
|
||||
|
||||
from machine import Pin, UART
|
||||
from time import sleep_ms, ticks_diff, ticks_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:
|
||||
try:
|
||||
text = packet.decoded.payload.decode("utf-8")
|
||||
except UnicodeError:
|
||||
text = repr(packet.decoded.payload)
|
||||
print("from !%08x: %s" % (packet.from_, text))
|
||||
|
||||
|
||||
def on_receive(message):
|
||||
variant = message.WhichOneof("payload_variant")
|
||||
print("radio message:", variant or "unknown")
|
||||
|
||||
|
||||
def on_error(error, payload):
|
||||
print("skipping undecodable radio frame:", error)
|
||||
print("frame bytes:", payload.hex())
|
||||
|
||||
|
||||
print("MicroMesh starting on XIAO RP2040")
|
||||
print("UART0: D6/GPIO0 TX -> radio RX")
|
||||
print("UART0: D7/GPIO1 RX <- radio TX")
|
||||
print("UART0: 115200 baud; common GND required")
|
||||
|
||||
uart = UART(
|
||||
0,
|
||||
baudrate=115200,
|
||||
tx=Pin(0), # XIAO D6
|
||||
rx=Pin(1), # XIAO D7
|
||||
timeout=0,
|
||||
rxbuf=1024,
|
||||
)
|
||||
|
||||
mesh = SerialInterface(
|
||||
uart,
|
||||
on_receive=on_receive,
|
||||
on_packet=on_packet,
|
||||
on_log=lambda line: print("radio log:", line),
|
||||
on_error=on_error,
|
||||
)
|
||||
mesh.connect()
|
||||
print("configuration requested; id=%08x" % mesh.config_id)
|
||||
|
||||
hello_sent = False
|
||||
last_status = ticks_ms()
|
||||
while True:
|
||||
mesh.poll()
|
||||
if mesh.config_complete and not hello_sent:
|
||||
print("radio configuration complete; sending greeting")
|
||||
mesh.sendText("hello from XIAO RP2040")
|
||||
hello_sent = True
|
||||
now = ticks_ms()
|
||||
if ticks_diff(now, last_status) >= 5000:
|
||||
if mesh.config_complete:
|
||||
print("connected; %d nodes known" % len(mesh.nodes))
|
||||
else:
|
||||
print("waiting for radio data; check TX/RX, GND, baud, and PROTO mode")
|
||||
last_status = now
|
||||
sleep_ms(10)
|
||||
Reference in New Issue
Block a user