Skip to content

Instantly share code, notes, and snippets.

@tomasinouk
Created January 8, 2022 04:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomasinouk/1eec8ad0d5f89e9c7cacb1b1745426c1 to your computer and use it in GitHub Desktop.
Save tomasinouk/1eec8ad0d5f89e9c7cacb1b1745426c1 to your computer and use it in GitHub Desktop.
Testing communication with SARA R410M on iLab Challenger Board
import board
import busio
import digitalio
import time
uart = busio.UART(board.SARA_TX,board.SARA_RX,rts=board.SARA_RTS, cts=board.SARA_CTS, baudrate=115200,timeout=5)
# For most CircuitPython boards:
led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT
# Do a HW reset by applying a low pulse to the reset line for 1mSec
# bool Challenger2040LTEClass::doPowerOn() {
# bool ret;
# digitalWrite(PIN_SARA_PWR, HIGH); // Make sure LDO is on
# delay(100); // let the power stabilize
# pinMode(PIN_SARA_ON, OUTPUT); // Pull power on control low
# delay(150); // For 150mS
# pinMode(PIN_SARA_ON, INPUT_PULLUP); // before releasing it again.
# delay(1000); // Now wait for 1 second
# SARA_SERIAL_PORT.begin(DEFAULT_SARA_BAUDRATE);
# serialPortConfigured = true;
# ret = isAlive(); // Makie sure the modem is
# // up and running
#
# delay(250); // Allow for any extra characters
# // before flushing the input buffer
# while(SARA_SERIAL_PORT.available()) SARA_SERIAL_PORT.read();
#
# return ret;
# }
#
#
#
# SARA_BTN == PIN_SARA_ON
RESET_PIN = digitalio.DigitalInOut(board.SARA_RST)
RESET_PIN.direction = digitalio.Direction.OUTPUT
sara_pwr_on = digitalio.DigitalInOut(board.SARA_BTN)
def doPowerOn():
time.sleep(0.1)
sara_pwr_on.direction = digitalio.Direction.OUTPUT
time.sleep(0.15)
sara_pwr_on.switch_to_input(pull=digitalio.Pull.UP)
time.sleep(1)
def resetModem(resetPin):
led.value = True # set RGB to blue
# toggle RST pin
resetPin.value = 1
time.sleep(0.1)
print(sara_pwr_on.value)
resetPin.value = 0
time.sleep(0.15)
print(sara_pwr_on.value)
resetPin.value = 1
# time.sleep(1)
for x in range(0,5): # wait 5 seconds for modem to startup
led.value = False # blink RGB
time.sleep(0.5)
led.value = True
time.sleep(0.5)
led.value = False
print(sara_pwr_on.value)
# print(f"-= Reset Sara modem =-")
# print(f"-= and wait 5 sec. =-")
# resetModem(RESET_PIN)
print("Doing PowerOn")
doPowerOn()
print("Sending AT")
uart.write(bytes(f"AT\n","ascii"))
time.sleep(0.2)
while True:
byte_read = uart.read(1) # Read one byte over UART lines
if byte_read is None:
# Nothing read.
continue
if byte_read is not None:
# Start of message. Start accumulating bytes, but don't record the ";".
message = []
print(byte_read)
unit_present = True
message_started = True
continue
if message_started:
print("In message started")
if byte_read in [b'\r', b'\n'] :
print("Got carrige return")
# End of message. Don't record the "\r or \n".
# Now we have a complete message. Convert it to a string, and split it up.
print(message)
message_parts = "".join(message) #.split(",")
print(message_parts)
message_started = False
else:
# Accumulate message byte.
print(f"Accumulating {byte_read}")
message.append(chr(byte_read[0]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment