I have a Digi XBee 3 Cellular LTE-M/NB-IoT modem, it is installed on a XBIB-U-DEV development board and has a SIM card installed. All works properly and passes all the original hello world tutorials.
I am trying to simulate data coming in on the UART and having an action occur when I see a certain number of bytes. But I cannot get it to read any input at all. I am new to this so it could just be a newb mistake. Below is my code, if anyone can see the issue please point me in the direction of tutorials or a fix?
I load the code through file manager in xctu
open a console in xctu
type to fill the tx buffer (which I believe is the UART?)
no response
Thanks in advance
import sys
import machine
from machine import UART # load UART resources
import time
Pin definitions
repl_button = machine.Pin(machine.Pin.board.D0, machine.Pin.IN, machine.Pin.PULL_UP)
led = machine.Pin(machine.Pin.board.D4, machine.Pin.OUT)
local variables
flagValue = 50 # how many bytes make up a complete record
activeBuffer = bytearray(50) # buffer the size of a data record and check string
print(“Waiting for UART Data Stream…”) # Give feedback to inform user
uart = UART(1, baudrate=115200) # create UART object for radio
print(“Created UART”) # Give feedback to inform user
while True:
# If button 5 is pressed, drop to REPL
# this gives us an exit while testing
if repl_button.value() == 0: # if the user has hit the correct button, we set this as top left
print(“Dropping to REPL”) # update UI
sys.exit() # leave the app entirely
if uart.any() == 1: # if there's 50 or more bytes to read
print("We have 1 bytes") # Give feedback to inform user
if uart.any() == 2: # if there's 50 or more bytes to read
print("We have 2 bytes") # Give feedback to inform user
if uart.any() > 2: # if there's 50 or more bytes to read
print("We have > 2 bytes") # Give feedback to inform user
if uart.any() >= flagValue: # if there's 50 or more bytes to read
print("We have 50 bytes") # Give feedback to inform user
# Turn LED on and then off
led.value(1)
time.sleep_ms(500)
led.value(0)
time.sleep_ms(500)
bytes_read = uart.readinto(activeBuffer) # read the data into the buffer
led(1) # turn off the led
break # leave the loop