Get started with MicroPython
On the board you see DIO0 written below SW2, to the left of the button. This represents the pin that
the button is connected to.
In MicroPython, you will create a pin object for the pin that is connected to the SW2 button. When you
create the pin object, the DIO0 pin is called D0 for short.
The loop continuously checks the value on that pin and once it goes to 0 (meaning the button has been
pressed) a print() call prints the message Button pressed! to the screen.
At the MicroPython >>> prompt, copy the following code and enter it into MicroPython using
mode
and then run it:
# Import the Pin module from machine, for simpler syntax.
from machine import Pin
# Create a pin object for the pin that the button "SW2" is connected to.
dio0 = Pin("D0", Pin.IN, Pin.PULL_UP)
# Give feedback to inform user a button press is needed.
print("Waiting for SW2 press...")
# Create a WHILE loop that checks for a button press.
while (True):
if (dio0.value() == 0):
print("Button pressed!")
break
# When you press SW2, you should see "Button pressed!" printed to the screen.
# You have successfully performed an action in response to a button press!
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.
Note
If you have problems pasting the code, see
Digi XBee3 Cellular LTE-M Global Smart Modem User Guide
# Once pressed.
# Print message once pressed.
# Exit the WHILE loop.
Example: code a request help button
Syntax error at line
1.
paste
51
Need help?
Do you have a question about the XB3-C-A2-UT series and is the answer not in the manual?