Get started with MicroPython Example: debug the secondary UART
Digi XBee® 3 Cellular LTE Cat 1 AT&T Smart Modem User Guide
43
Note You can easily copy and paste code from the online version of this guide. Use caution with the
PDF version, as it may not maintain essential indentations.
Now you have a system based on the XBee Smart Modem that sends an SMS in response to a certain
input, in this case a simple button press.
Note If you have problems pasting the code, see Syntax error at line 1. For SMS failures, see Error
Failed to send SMS.
Example: debug the secondary UART
This sample code is handy for debugging the secondary UART. It simply relays data between the
primary and secondary UARTs.
from machine import UART
import sys, time
def uart_init():
u = UART(1)
u.write('Testing from XBee\n')
return u
def uart_relay(u):
while True:
uart_data = u.read(-1)
if uart_data:
sys.stdout.buffer.write(uart_data)
stdin_data = sys.stdin.buffer.read(-1)
if stdin_data:
u.write(stdin_data)
time.sleep_ms(5)
u = uart_init()
uart_relay(u)
You only need to call uart_init() once.
Call uart_relay() to pass data between the UARTs.
Send Ctrl-C to exit relay mode.
When done, call u.close() to close the secondary UART.
Exit MicroPython mode
To exit MicroPython mode:
1.
In the XCTU MicroPython Terminal, click the green Close button .
2. Click Close at the bottom of the terminal to exit the terminal.
3.
In XCTU's Configuration working mode , change AP API Enable to another mode and click
the Write button . We recommend changing to Transparent mode [0], as most of the
examples use this mode.