Import led-driver app: pico/ and esp32/ layout
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
34
esp32/src/main.py
Normal file
34
esp32/src/main.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""
|
||||
XIAO ESP32-C6: ESPNOW -> UART passthrough to Pico.
|
||||
Receives messages via ESPNOW, forwards them unchanged to UART (GPIO17).
|
||||
UART at 921600 baud. LED on GPIO15 blinks on activity.
|
||||
"""
|
||||
import network
|
||||
import espnow
|
||||
import machine
|
||||
import time
|
||||
|
||||
# UART: TX on GPIO17 -> Pico RX, max baud for throughput
|
||||
UART_BAUD = 921600
|
||||
uart = machine.UART(1, baudrate=UART_BAUD, tx=17)
|
||||
led = machine.Pin(15, machine.Pin.OUT)
|
||||
|
||||
# WLAN must be active for ESPNOW (no need to connect)
|
||||
sta = network.WLAN(network.WLAN.IF_STA)
|
||||
sta.active(True)
|
||||
sta.disconnect()
|
||||
|
||||
e = espnow.ESPNow()
|
||||
e.active(True)
|
||||
# No peers needed to receive; add_peer() only for send()
|
||||
|
||||
# Recv timeout 0 = non-blocking
|
||||
print("ESP32: ESPNOW -> UART passthrough, %d baud" % UART_BAUD)
|
||||
while True:
|
||||
mac, msg = e.irecv(0)
|
||||
if msg:
|
||||
uart.write(msg)
|
||||
led.value(1)
|
||||
else:
|
||||
led.value(0)
|
||||
time.sleep_ms(1)
|
||||
Reference in New Issue
Block a user