KAG Tech
Posts: 44
Joined: Mon Jun 21, 2021 7:11 am

send an sms using sim800l and raspberry pi pico on thonny

Tue Jul 27, 2021 7:12 am

hey, please assist on how to send an sms using sim800l and raspberry pi pico on thonny. below is a program we tried in order to achieve our outcome .we are beginners and your help and assistance will be highly appreciated.

Code: Select all

import time
from machine import UART, Pin
import uasyncio as asyncio
gsm = machine.UART(0, 115200)
uart = UART(0, 115200)

#Speak with SIM800 -> gets AT command return as response
def SIM800(command):
    AT_command = command + "\r\n"
    ser.write(str(AT_command).encode('ascii'))
    time.sleep(1)
    if ser.inWaiting() > 0:
        echo = ser.readline() #waste the echo
        response_byte = ser.readline()
        response_str = response_byte.decode('ascii')
        return (response_str)
    else:
        return ("ERROR")

#checks if SIM800L is speaking and returns it as response
def wait_for_SIM800():
    echo = ser.readline()  # waste the echo
    response_byte = ser.readline()
    response_str = response_byte.decode('ascii')
    return (response_str)


#Receives the message and phone number and send that message to that phone number
def send_message(message, recipient):
    ser.write(b'AT+CMGS="'+27733166980 + recepient.encode() + b'"\r')
    time.sleep(0.5)
    ser.write(message.encode() + b"\r")
    time.sleep(0.5)
    ser.write(bytes([26]))
    time.sleep(0.5)
    print ("Message sent to customer")
    time.sleep(2)
    ser.flushInput()  # clear serial data in buffer if any


hippy
Posts: 10594
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: send an sms using sim800l and raspberry pi pico on thonny

Tue Jul 27, 2021 12:19 pm

Some indication of what results you get, where and how it diverges from what was expected, might help others help you to determine what is going wrong.

You can substitute your SIM800 with a PC running a terminal emulator so you can check what it is receiving, send back responses to check the code handles those correctly.

You can control the SIM800 from a PC using a terminal emulator so you can check how it responds to commands sent.

KAG Tech
Posts: 44
Joined: Mon Jun 21, 2021 7:11 am

Re: send an sms using sim800l and raspberry pi pico on thonny

Tue Jul 27, 2021 2:16 pm

we have tested the AT commands on putty and everything responded back with the correct feedback.
With the program attached above ,after running we are not receiving no errors or any feeedback on the shell terminal or either an sms to the number provided.

we have also tested the AT COMMANDS on the shell terminal of the thonny and only the AT+CMGS COMMAND(SMS COMMAND )won't do.

hippy
Posts: 10594
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: send an sms using sim800l and raspberry pi pico on thonny

Tue Jul 27, 2021 4:39 pm

It may possibly be a case of having to add print("Got here...") between each line so you can see where it's stalling or hanging, is and isn't going.

Return to “MicroPython”