Get started with MicroPython
Note
The xbee.atcmd() method does not support the following AT commands: IS, AS, ED, ND, or DN.
The following is example code that queries and sets a variety of AT commands using xbee.atcmd():
import xbee
# Set the NI string of the radio
xbee.atcmd("NI", "XBee3 module")
# Configure a destination address using two different data types
xbee.atcmd("DH", 0x0013A200)
xbee.atcmd("DL", b'\x12\x25\x89\xF5')
# Read some AT commands and display the value and data type:
print("\nAT command parameter values:")
commands =["DH", "DL", "NI", "CK"]
for cmd in commands:
val = xbee.atcmd(cmd)
print("{}: {:20} of type {}".format(cmd, repr(val), type(val)))
This example code outputs the following:
AT command parameter values:
DH: b'\x00\x13\xa2\x00'
DL: b'\x12%\x89\xf5'
NI: 'XBee3 module'
CK: 65535
Note
Parameters that store values larger than 16-bits in length are represented as bytes. Python
attempts to print out ASCII characters whenever possible, which can result in some unexpected
output (such as the "%" in the above output). If you want the output from MicroPython to match
XCTU, you can use the following example to convert bytes to hex:
dl_value = xbee.atcmd("DL")
hex_dl_value = hex(int.from_bytes(dl_value, 'big'))
MicroPython networking and communication examples
This section provides networking and communication examples for using MicroPython with the XBee 3
Zigbee RF Module.
Zigbee networks with MicroPython
For small networks, it is suitable to use MicroPython on every node. However, there are some inherit
limitations that may prevent you from using MicroPython on some heavily trafficked nodes:
When running MicroPython, any received messages will be stored in a small receive queue. This
n
queue only has room for 4 packets and must be regularly read to prevent data loss. For
networks that will be generating a lot of traffic, the data aggregator may need to operate in
API mode in order to capture all incoming data.
MicroPython does not have support for all of the XBee API frame types, particularly for source
n
routing. If you are planning to operate with a network of more than 40 nodes, Digi highly
recommends that you operate with the aggregator in API mode and implement source routing.
Digi XBee® 3 Zigbee® RF Module
MicroPython networking and communication examples
# Hex
# Bytes
of type <class 'bytes'>
of type <class 'bytes'>
of type <class 'str'>
of type <class 'int'>
29
Need help?
Do you have a question about the XBee 3 ZigBee and is the answer not in the manual?