Challenger RP2040 LTE CircuitPython startup example

Here’s a short example on how to start the modem up using CircuitPython. This example will start the modem and wait for the AT command to return a valid response.

import board
import busio
import digitalio
import time

print ("Test program start !")

# LED
led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT

# SARA LDO enable control signal
sara_pwr = digitalio.DigitalInOut(board.SARA_PWR)
sara_pwr.direction = digitalio.Direction.OUTPUT
# Make sure the modem is fully restarted
sara_pwr.value = 0
time.sleep(1)
sara_pwr.value = 1

# Power on button
sara_btn = digitalio.DigitalInOut(board.SARA_BTN)
sara_btn.direction = digitalio.Direction.INPUT
sara_btn.pull = digitalio.Pull.UP

# Reset pin
sara_rst = digitalio.DigitalInOut(board.SARA_RST)
sara_rst.direction = digitalio.Direction.INPUT
sara_rst.pull = digitalio.Pull.UP

# Perform a SARA power on sequence
print ("Powering the SARA modem on.")
sara_btn.direction = digitalio.Direction.OUTPUT
sara_btn.value = 0
time.sleep(0.15)
sara_btn.direction = digitalio.Direction.INPUT
sara_btn.pull = digitalio.Pull.UP
# A short delay is required here to allow the modem to startup
time.sleep(1)
print ("Reset done, waiting for modem to start.")

uart = busio.UART(tx=board.SARA_TX, rx=board.SARA_RX, rts=board.SARA_RTS, cts=board.SARA_CTS, baudrate=115200, timeout=0.25)

print ("Starting test sequence")
to_count = 20
while to_count:
    uart.write(bytes("AT\r\n", 'utf-8'))
    result = uart.readline();
    print (".", end="")
    if type(result) == bytes:
        if result.decode('utf-8').startswith("AT"):
            result = uart.readline();
            if result.decode('utf-8').startswith("OK"):
                break
    result = uart.readline()
    to_count -= 1
    
if not to_count:
    print ("\nThe modem did not start correctly!")
else:
    print ("\nModem started !")