Example: Use The Time Module; Example: At Commands Using Micropython - Digi XBee 3 ZigBee User Manual

Rf module
Table of Contents

Advertisement

Get started with MicroPython
5. If the code is correct, press Ctrl+D to run the code; "Hello World" should print.
Note
If you want to exit paste mode without running the code, or if the code did not copy
correctly, press Ctrl+C to cancel and return to the normal MicroPython >>> prompt).
Example: use the time module
The time module is used for time-sensitive operations such as introducing a delay in your routine or a
timer.
The following time functions are supported by the XBee 3 Zigbee RF Module:
ticks_ms() returns the current millisecond counter value. This counter rolls over at
n
0x40000000.
ticks_diff() compares the difference between two timestamps in milliseconds.
n
sleep() delays operation for a set number of seconds.
n
sleep_ms() delays operation for a set number of milliseconds.
n
sleep_us() delays operation for a set number of microseconds.
n
Note
The standard time.time() function cannot be used, because this function produces the number
of seconds since the epoch. The XBee3 module lacks a realtime clock and cannot provide any date or
time data.
The following example exercises the various sleep functions and uses ticks_diff() to measure
duration:
import time
start = time.ticks_ms()
time.sleep(1)
time.sleep_ms(500)
time.sleep_us(1000)
delta = time.ticks_diff(time.ticks_ms(), start)
print("Operation took {} ms to execute".format(delta))

Example: AT commands using MicroPython

AT commands control the XBee 3 Zigbee RF Module. The "AT" is an abbreviation for "attention", and
the prefix "AT" notifies the module about the start of a command line. For a list of AT commands that
can be used on the XBee 3 Zigbee RF Module, see
MicroPython provides an atcmd() method to process AT commands, similar to how you can use
Command mode
or API frames.
The atcmd() method accepts two parameters:
1. The two character AT command, entered as a string.
2. An optional second parameter used to set the AT command value. If this parameter is not
provided, the AT command is queried instead of being set. This value is an integer, bytes object,
or string, depending on the AT command.
Digi XBee® 3 Zigbee® RF Module
# Get the value from the millisecond counter
# sleep for 1 second
# sleep for 500 milliseconds
# sleep for 1000 microseconds
AT
commands.
MicroPython examples
28

Advertisement

Table of Contents
loading

Table of Contents