Skip to content

#5.2 Using Python

Croke edited this page May 4, 2018 · 4 revisions

In order to call or send SMSs from our mobile, We have to send AT commands to the GSM module. We used Minicom for trying new commands and checking how they work but for developing an interface which allows us to call and control in an easy way the GSM module we are going to use a python library, Serial. This library is included in Raspbian, ot use it only importing it is needed.

#import serial

Once we have imported it, we have to create a serial object.

self.serial = serial.Serial('/dev/ttyS0', 19200, timeout=5)

'/dev/ttyS0’ is the serial tty. In Raspberry Pi 3 it is not set-up by default. if during installation you added enable_uart=1 in /boot/config.txt file, you should see the ttyS0. In order to send commands to the GSM module, we have to write the command in the serial we can use the write function for that. Don't forget to add the carriage return and the line feed.

serial.write(“<command>\r\n”)

Commands are the same as Minicom, the only difference is about don't forget carriage return and line feed at the end of the command. These are some examples of use like:

AT+CPIN=XXXX: Introduce PIN number of the SIM card.
ATDXXXXXXXXX;: Call XXXXXXXXX, don't forget the semicolon.
ATH: end call.

Next: User Interface