Page 1 of 1

send an sms using sim800l and raspberry pi pico on thonny

Posted: Wed Aug 04, 2021 7:47 am
by KAG Tech0262
Hey guys,we are working with the sim8ool and raspberry pi pico on micropython thonny, the aim is to send an alarm notification using the raspberry Pico PI( on Micropython) and a SIM800L GSM Module. We have successfully tested the AT commands on the SIM800 using Thonny(on the shell Terminal) and have managed to send an SMS using AT commands on the shell terminal aswell. so now we have written a program on the script(we will attach how it looks) in order to send and SMS when an alarm is triggered.

The objective of the program is, when the sensor is triggered , feedback should be printed on the shell that an alarm is triggered,while an LED will also blink to show that an alarm is being triggered and at the same time wake the sim800l to send an SMS notification.

The problem we are experiencing is that, when the sensor is triggered, the SMS programmed part is not responding ,only the led blinks and feedback is received on the shell terminal, that an alarm is triggered. we are not sure if we have programmed correctly for the SMS to be sent or not, we are beginners in micropython but please assist further in that regard.

Code: Select all

from machine import UART, Pin
import uasyncio as asyncio
import time
import utime


uart = UART(0, 9600)
test_led = machine.Pin(8, machine.Pin.OUT)
sensor_dig2_pir5 = machine.Pin(15, machine.Pin.IN, machine.Pin.PULL_DOWN)


CR    = chr(13)
CTRLZ = ('\x1A')
QUOTE = chr(34)

def SIM800(command):
    AT_command = command + "\r\n"
    print ("done")
    ser.write(str(AT_command).encode('ascii'))
    time.sleep(1)
    print ("commands ready")

def pir_handler(pin):
    if pin.value():
            if pin is sensor_dig2_pir5:
                print("Alarm!sensor triggered!")
                test_led.value(1)
                utime.sleep(0.2)
                def send_message(message, reciepient):
                    uart.write('AT+CMGF=1\x1A')
                    uart.read()
                    print("sim ready")
        
                    uart.write('AT+CMGS="+27733166980"\x1AHello User\x1A')
                    uart.read()
                    print("sent")
                
            
            test_led.value(0)
        
sensor_dig2_pir5.irq(trigger=machine.Pin.IRQ_RISING, handler=pir_handler)



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

Posted: Wed Aug 04, 2021 9:03 am
by davef
Where does send_message get called? Being fairly new to Micropython myself I don't understand the line:

Code: Select all

                def send_message(message, reciepient):
 
Is the indentation correct?

Is there another file that calls send_message() and SIM800()?

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

Posted: Wed Aug 04, 2021 9:59 am
by KAG Tech0262
hey ,we didn't get any errors after running ,we only got a feedback after triggering the sensor...we are beginners on micropython and we are also not sure if we have written our whole script correctly.

Code: Select all

>> %Run -c $EDITOR_CONTENT
>>> Alarm!sensor triggered!
Alarm!sensor triggered!
Alarm!sensor triggered!
Alarm!sensor triggered!
Alarm!sensor triggered!
Alarm!sensor triggered!
Alarm!sensor triggered!
Alarm!sensor triggered!
Alarm!sensor triggered!
Alarm!sensor triggered!
Alarm!sensor triggered!

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

Posted: Wed Aug 04, 2021 11:08 am
by davef
Because you don't get a message in your IDE ... print("sim read")

For your code :

Code: Select all

def pir_handler(pin):
    if pin.value():
            if pin is sensor_dig2_pir5:
                print("Alarm!sensor triggered!")
                test_led.value(1)
                utime.sleep(0.2)
                def send_message(message, reciepient):
                    uart.write('AT+CMGF=1\x1A')
                    uart.read()
                    print("sim ready")
        
                    uart.write('AT+CMGS="+27733166980"\x1AHello User\x1A')
                    uart.read()
                    print("sent")
  
              test_led.value(0)
Try:

Code: Select all

def pir_handler(pin):
    if pin.value():
            if pin is sensor_dig2_pir5:
                print("Alarm!sensor triggered!")
                test_led.value(1)
                utime.sleep(0.2)
#                def send_message(message, reciepient):
                uart.write('AT+CMGF=1\x1A')
                uart.read()
                print("sim ready")
        
                uart.write('AT+CMGS="+27733166980"\x1AHello User\x1A')
                uart.read()
                print("sent")
              
            test_led.value(0)
Also, why are you doing:

Code: Select all

import uasyncio as asyncio
maybe you plan to use it later?