This post is intended to help begineers to interface GSM Modem with RaspberryPi and send data through serial port.
Note: Programs are written in Python Language. For C++ examples please contact our Technical support section at http://www.elementzonline.com
Connect a USB to Serial converter to the RaspberryPi USB port. A compatible USB to Serial converter can be obtained from this link.
Create a new file named serial_test.py by typing the following command
nano serial_test.py
write the following lines to the file
author: dhanish
company: Elementz Engineers Guild Pvt Ltd
Created on: Tue Aug 12 20:17:12 2014″””
import time
ser.flush()
ser.write(‘ATD9020XXXXXX;\r’) # AT command to call a number using GSM Modem — Edit here
#ser.read(2) # read 2 bytes of data from the serial port
time.sleep(10) # wait for 10 secondsser.write(‘ATH\r’) # Hold the call
ser.close() # close the serial port
And finally save the file using Ctrl+O and Ctrl+X
Run the following command in the terminal
python serial_test.py
External Links:
Elementz Github channel for RasperryPi sample codes.
Ebay Link — SIM900A Modem
Ebay Link — USB2Serial Converter
how to send a sms using AT commands
Hello Hussain,
You may use AT+CMGS=”phonenumber” for the purpose
after that you can read ‘>’ symbol.
After printing your message to the terminal send ser.write(26) // ctrl+z
We will be updating this post by providing a sample code to send SMS soon.
command not on terminal
please provide python code
I connected the GSM module to my Raspberry Pi using USB to serial converter. I connected TXD of USB to serial converter to TXD of SIM900, RXD of converter to RXD of sim900 and VDD to 5v , GND to GND.
I have an LED called NWK constantly blinking for every 3 seconds. I send the echo command
ser.write(“ATE0\r”)
response = ser.readlines(None)
print response
I get the result printed as simply this [ ]
I run the code you’ve given in the page and it does not make any call. Is there anything I should set up?
Sir, you should connect RXD of USB2Serial to TXD of GSM Modem and TXD of Serial to RXD of GSM Modem. Also check if you can make a call to the modem and see whether a ring sound, so that network connection can be ensured.
I connected the way you told me to and it is working. I send Echo command and it returns OK.
I call SIM card number and the GSM module starts the buzzer whenever it rings. I try your code and I get the following
[‘\r\n’, ‘NO CARRIER\r\n’, ‘\r\n’, ‘OK\r\n’]
What does this mean and how should I rectify it?
Hello Srinivas,
It seems that you don’t have enough balance to make a call,( correct me if it was a silly observation). Assuming there is no network issue as you have said that the ring buzzer is responding whenever you make a call to the module.
hi,
i want to send text sms using gsm AT commands
please provide the code in python in windows
Hello Rajju,
You can find code for sending commands to GSM Modem. It is implemented as a separate class which can be imported to your main code. An example code is also provided. You have to change the COM port number in the code.
https://github.com/elementzonline/RaspberryPi-Sample-Codes/tree/master/GSM_class
Please note that the above code is not maintained anymore. So please understand the code and do necessary modification yourself.
hi
itz showing an error “import timeser=serial.Serial(‘/dev/ttyUSB0′,9600,timeout=1)”
invalid syntax
Sorry, it was a typo. Code is now edited. See if it works.
import timser=serial.Serial(‘/dev/ttyUSB0’,9600,timeout=1) it’s showing syntax error
plz help
There was a mistake in the code pasted.
import time
ser=serial.Serial(‘/dev/ttyUSB0′,9600,timeout=1)
should be used instead. Please see the edited code above.
Will this board work with Beaglebone Black if we connect it with the UART ports of Beaglebone?
Hello Shaheen,
The UART pins of BB can be connected to the GSM Modem, directly to the TTL pins provided on the module.
Will this board work with Beaglebone Black if we connect it with the UART ports of Beaglebone??
Will this board work with Beaglebone Black if we connect it with the UART ports of Beaglebone??
How to connect Speaker to SIM900 module there are pins which indicating SP- and SP+. How to use these pins for speaker for Ring indicator in standalone condition.
hello,i want to send an MMS using GSM and RPI,i am new in RPI,plz help me,thanks in advance
Hello Sir,
I tested over hyper terminal and I am unable to get any response on it.
I am able to call the SIM.
Hi Dhruvin,
Please check whether your serial port is working correctly. Make an echo test(short Rx and Tx of your serial port- you should get the characters which are typed in the terminal ). Also ensure that you have connected the GSM Modem UART correctly. Rx of GSM to Tx of PC and Tx of GSM to Rx of PC. Make sure you are using TTL-TTL or RS232-RS232 level communication(do not connect TTL-RS232).
As given in the documentation, can I make an http call from my raspberry using GPRS?
Can you please provide an example for GPRS?
Hi,
i am connecting a raspberry pi to gsm sim900 module. i made a set up by connecting pi to LCD and gsm module to pi by connecting wires.. i.e tx, rx, gnd. and giving power to gsm module all LED’s are working fine. I am executing the code you are given above. but it could not make any call to sim inserted into gsm module neither get any output. pls help me in this.
Did you use the RX and TX of the Raspberry Pi or used any USB to Serial converter? It is better to use a USB to serial as the RX and TX of the RPi is used as serial console for linux in RPi by default. If you are using the USB to Serial computer try interfacing with a computer. You may use our testing utility for this.
https://elementztechblog.wordpress.com/2014/06/16/interfacing-sim900a-to-computer/
Really staightforward.. Use pyserial. Send data to the serial port. You can use USB to Serial, or builtin Debug Serial pins.
Did you use the RX and TX of the Raspberry Pi or used any USB to Serial converter? It is better to use a USB to serial as the RX and TX of the RPi is used as serial console for linux in RPi by default. If you are using the USB to Serial computer try interfacing with a computer. You may use our testing utility for this.
https://elementztechblog.wordpress.com/2014/06/16/interfacing-sim900a-to-computer/
Actually we are working on project consisting of LCD monitor(PC display),GSM module and raspberry pi..
so can you tell me how to display message on LCD monitor instead of mobile phone using HDMI protocol
Hi Shrilesh,
You may use a HDMI to VGA converter for this purpose.
can u pls help me i am beginner with raspberry pi and i wish to make calling and sending sms using gsm modem i dont used it all so i need a complete connection setup and python script hope u geniuses can help me to get through this situation
I hope our wiki page will help you for getting started. Please see the link below.
http://elementzonline.com/wiki/SIM900A_RS232_V1.2
Sir actually i would like to connect my raspberry pi with gsm modem(not the gsm module for pi) in the best way can u suggest the best connection with raspberry pi what should i do .things i had is raspberry pi,normal gsm sim 900a (not the ADDON) and i reqiire a full connection diagram with python script
I had reffered the link which you had provide but how could i connect it with pi.the connection now i had given are
1.connected usb to serial converter from raspberry usb port to rs 232(the diagram that the site provided at the top).
2.connected 5v vco of gsm to raspberry pi 5v out and connected gnd of gsm with raspberry pi gnd
Note: i dont know whwther there is a requirement for external supply of 5v 1a to gsm
Sir is my connections enough to interface the gsm modem with raspberry pi or any other connection required if required you please mention those necessary connections
ser=serial.Serial(‘/dev/ttyUSB0’,9600,timeout=1) giving error
what does ‘/dev/ttyUSB0’ indicates??
Hi gents can anyone help me please.
I would like to connect my raspberry pi2 model B with gsm modem(cell phone) and connect it with AC, can anyone help me with please? equipments required and the full connection diagram with python script.
celciosoares@gmail.com
Hi there,
Please see the sample code provided which will work with Raspberry Pi. Please see our Wiki page for more details
http://elementzonline.com/wiki/SIM900A_RS232_Modem#Connecting_with_RaspberryPi
Hey, great tutorial but I’m having a small problem, probably stupid. It took me a long time to get ttyUSB0 show up in /dev/. Now when I run the code, I get the following exception –
serial.serialutil.SerialException: Could not open port /dev/ttyUSB0: [Errno 6] No such device or address: ‘/dev/ttyUSB0’
I could really use your help.
It is not ‘o’ in ttyUSB’0′. Type ‘dmesg’ in terminal to find the com port name.
I know it’s a 0(zero). I ran dmesg and everytime I connect it, it gets connected to ttyUSB0 but then it gets disconnected from ttyUSB0 automatically even though the bridge is still connected. 😦
Make sure the cable is good and there is no loose coupling
Yeah, thanks. That was the issue 🙂
Hello Sir,
i want to interface GSM and Risberry Pi through USB to USB. IS it possible? if yes then send me code for that
Thanks
You need the USB to serial converter for that. Code is in the blog itself.
how to connect with raspberry pi using tx and rx pins
Use raspberry PI Rx to GSM TX and Rpi TX to GSM Rx. Ground should be made common. Use TTL levels only.
hi we r interfacing respberry pi with gsm as wireless notice bord is there any commands to display the popup messages if its there please send me
Please help me…..
i connected GSM SIM900 with Raspberry pi using Serial cable to USB ,Working All Very Well
But i enter command on putty as a AT+CMGL=”ALL” showing all message
But I want code for Python Language how to write commad in python and print message in python programming……Its very Urgent Please Help me
Use the code in the below link as a starting point
https://github.com/elementzonline/RaspberryPi-Sample-Codes/blob/master/GSM_class/gsm_class_test.py
Hi,I want to connect sim908 module to my raspberry pi3.How i connect.Do you have any tutorial based on sim908 and raspberry pi.
Connect to serial pins of raspberry pi
Hi; I use code ,but error
Traceback (most recent call last):
File “test1.py”, line 1, in
import serial
ImportError: No module named serial
You need to install serial library.
Whenever you get an error in import statement in python, it simply means you havent install that library.
sudo apt-get install python-serial
pip install python-serial
I like your post. It is really interesting. But using AT commands you can just make a call and hang up incoming call. But for the communication between two ends raspberry pi is not useful. It requires some extra functionalities which are not available in raspberry pi system.
Yes.I agree with your statement.
We had try alot but it can’t run for ongoing call for user to listen for audio and text to speech.Actually raspberry with gsm modem is working bt only in 1 way handshake.
Because it need some extra hardware for telephonic serail port and connection.
Yes its true becuase same error is also showing here..