1

I have a Raspberry Pi 3 running Raspbian Stretch I've connected it to an Elemnt Engineerz Guild SIM900a GSM modem via the GPIO. I can't get it to send an SMS

  • I connected gnd and 5v to gnd and 5v respectively between the Pi and the modem
  • I connected pin 14 on the Pi to Rx on the modem
  • I connected pin 15 on the pi to Tx on the modem

I have the interface tab of Pi Configuration like this:

Serial Port -> on
Serial Console -> off

my /boot/config.txt file includes these two lines:

enable_uart=1
dtoverlay=pi3-disable-bt

ls -l /dev | grep serial returns

lrwxrwxrwx 1 root root           7 Aug  8 15:31 serial0 -> ttyAMA0 
lrwxrwxrwx 1 root root           5 Aug  8 15:31 serial1 -> ttyS0

This is my python code:

#!/usr/bin/env python
import serial    
import os, time

ser = serial.Serial(
  port = '/dev/serial0',
  baudrate = 9600,
  timeout = 1
)

print('disabling echo')
ser.write(str.encode('ATE0\r'))
print(ser.readline())
print(ser.readline())
time.sleep(1)

print('text format for messages')
ser.write(str.encode('AT+CMGF=1\r'))
print(ser.readline())
print(ser.readline())
time.sleep(1)

print('send text message')
ser.write(str.encode('AT+CMGS="XXXXXXXXXX"\ntest message\r'))
print(ser.readline())
print(ser.readline())

ser.close()

I put my phone number where the X's are

And this is the output:

disabling echo
b'ATE0\r\r\n'
b'OK\r\n'
text format for messages
b'\r\n'
b'OK\r\n'
send text message
b'\r\n'
b'ERROR\r\n'

I really need to get this sending SMS messages, but the messages don't go through. The response is an error and when I've tried doing this sort of thing from the terminal I've got error code 3, which means operation not allowed. I've put the SIM into my phone and used it to send an SMS successfully. So why am I getting error 3 for sending SMS?

  • The official sample code here suggests waiting between sending the AT+CMGS="NUMBER" command and the actual message. It also says that you should have \r between that command and the message text, but you have \n. Can you try those changes? (Not posted as an answer yet, because I can't try it myself without this hardware.) – Moshe Katz Feb 18 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.