from machine import UART, Pin
import time
# Correct pin configuration for UART0 (default UART on Pico)
uart = UART(0, baudrate=9600, tx=Pin(0), rx=Pin(1)) # TX=GP0, RX=GP1
def send_command(command):
"""Send an AT command to the SIM800L."""
print(f"Sending command: {command}")
uart.write(command + '\r\n') # Send command with CRLF termination
time.sleep(1) # Wait for response
read_response()
def read_response():
"""Read the response from the SIM800L."""
if uart.any(): # Check if there's data to read
response = uart.read().decode('utf-8') # Read and decode the response
print(f"Response: {response}")
else:
print("No response received.")
def simulate_response(command):
"""Simulate SIM800L response for specific commands."""
if command == "AT":
return "OK"
elif command == "AT+CSQ":
return "+CSQ: 20,99" # Example signal strength response
elif command == "AT+CREG?":
return "+CREG: 0,1" # Example network registration response
else:
return "ERROR"
# Main loop
while True:
user_input = input("Enter AT command: ") # Get user input from REPL or terminal
send_command(user_input)
mock_response = simulate_response(user_input) # Generate mock response
uart.write(mock_response + '\r\n')
print(f"Simulated Response: {mock_response}")