Category: GSM,GPS


 

In the previous post part-1 I explained the initial setup of starting a Server on PC on a port , setting the Windows firewall to allow the port for external communication , PORT FORWARDING set up in the Router config, etc..

https://alselectro.wordpress.com/2016/09/25/gsm-connecting-to-a-server-on-a-port-by-tcpip-part-1/

In this part 2 I’ll show a practical demo of sending Temperature data to the Server.

As given in part 1 , start a server on distant PC on port 350 & do the port forwarding settings in Router config as explained.

A LM35 sensor is connected to pin A0 of Arduino & a GSM SIM900A is connected to pins 7 , 8 , Gnd of Arduino. As Soft Serial library is used in the code , pins 7 & 8 are declared as soft Rx & Tx.

The Rx pin goes to Tx of GSM , Tx connected to Rx of GSM , GND is made common.An external power source of 12v 1A is used for the GSM.

Download the Arduino code HERE

————————————-

#include <SoftwareSerial.h>
SoftwareSerial myGsm(7,8);
float temp;
int tempPin = 0;
void setup()
{
myGsm.begin(9600);
Serial.begin(9600);
delay(500);

myGsm.println(“AT+CIPSHUT”);
delay(1000);
printSerialData();

myGsm.println(“AT+CIPMUX=0”);
delay(2000);
printSerialData();

myGsm.println(“AT+CGATT=1”);
delay(1000);
printSerialData();

myGsm.println(“AT+CSTT=\”bsnlnet\”,\”\”,\”\””);//setting the APN,username & password
delay(5000);
printSerialData();

myGsm.println();
myGsm.println(“AT+CIICR”);
delay(6000);
printSerialData();

myGsm.println(“AT+CIFSR”); //get IP address
delay(2000);
printSerialData();

myGsm.println(“AT+CIPSTART=\”TCP\”,\”122.178.80.228\”,\”350\””);
delay(5000);
printSerialData();
delay(5000);

myGsm.println(“AT+CIPSEND”);
delay(2000);
printSerialData();

sendtemp();
delay(3000);
myGsm.println(“AT+CIPCLOSE”);
printSerialData();

myGsm.println(“AT+CIPSHUT”);
delay(1000);
printSerialData();
}

void loop()
{
}

void printSerialData()
{
while(myGsm.available()!=0)
Serial.write(myGsm.read());
}

 

void sendtemp()
{
temp = analogRead(tempPin);
temp = temp * 0.48828125;
Serial.print(“TEMPERATURE = “);
Serial.print(temp);
Serial.print(“*C”);
Serial.println();
delay(5000);
myGsm.println(temp);
delay(3000);
printSerialData();
myGsm.write(0x1A);
delay(3000);
printSerialData();

}

———————————————-

The Analog pin A0 is assigned as tempPin to read the LM 35 sensor data.

Initially any previous IP connection is SHUT  using the command

AT+CIPSHUT

This is essential to start a fresh TCP/IP comnnection.

Single IP connection mode is set by

AT+CIPMUX=0

GPRS is attached using

AT+CGATT=1

Task is started with the command

AT+CSTT=”APN”,”USER NAME”,”PASSWORD”

The Access Point Name of the mobile service provider can be known  by placing the SIM on your Android mobile. It’s shown under

Settings  –> More..  –>  Cellular Networks –> Access Point Names

In my case the APN is bsnlnet , user name & password are empty

AT+CSTT=”bsnlnet”,””,””

 

Then we bring up the Wireless connection with GPRS using

AT+CIICR

This takes a little moment , so a delay of 6 secs is a must in the code.

The IP address assigned by GPRS is obtained by

AT+CIFSR

Now we start up TCP connection with Server IP address & Port number of distant server

AT+CIPSTART=”TCP”,”122.178.80.228″,”350”

Once the connection is established , we send data using

AT+CIPSEND

A CTRL+Z is required to send data which is executed using hex 1A

 

Upload the code to Arduino & open the Serial monitor to watch the AT commands executed

tcp_list

 

Following is the screen shot at the Server side.

 

Image 3

 

 

cooltext753793315

Advertisements

This tutorial is of 2 parts.

First part explains the following :

–Starting a Server on your PC  & start listening on a port (say 350) . For this we use SOCKET TEST or HERCULES software

— Once the port is listening , we test communication locally using PuTty

— Windows Firewall setting has to be done for a NEW INBOUND RULE allowing port 350 for communication.

— For connecting to this port from external world , PORT FORWARDING to be done in Router’s Virtual Server setting so that any contact to the public IP is routed to the PORT 350 .

 

Second part is practical demo using GSM SIM900 or ESP8266 with Arduino.

 

The following picture shows my simple home network connections.A BINATONE make Router is used to connect to the Internet provider Airtel Broadband.The IP address of the Router is

192.168.1.1

which is the Gateway IP address used to access the settings on Router.My Laptop is connected over WIFI to this Router.The Router assigns a local IP address to my PC which is

192.168.1.150

Apart from these, the Internet Provider assigns a Public IP to my Network which is

122.178.80.228

This is the IP by which external world can contact my network.

Note that all these IP addresses are DYNAMIC & changes every time I power up the Router.

In another post I’ll explain how to make these IP addresses STATIC , so that the IP remain the same always.

set1

 

All the Network Tools I’ve used for this demo can be downloaded HERE.

Let us start  a server on port 350 using the SOCKET TEST tool.

This tool allows us to start a server easily.Click on the SERVER Tab & then feed in the port number where you want to listen.

Click on START LISTENING.

soc1

Now the server is up & running.It starts listening on port 350.

Remember to avoid the standard ports like 80 ( http) , 21 (FTP), 23 (TELNET), 22 (SSH) ,etc which are well known ports ,pre assigned for the particular protocol.

The dynamic range of port number you can assign goes up to 65535 or 2^16-1 (16 bits).

The IP address of the router can be known from the command window

RUN –> CMD –> ipconfig

The Default Gateway IP is the address of the Router.

RUN1

 

LOCAL TESTING TOOLS (optional)

 

Once the port is assigned for the server , you can use the ADVANCED PORT SCANNER tool to verify the port on the particular IP.

In the screen shot below you can see that the port number 350 is discovered as a TCP Server port on my PC whose local IP is 192.168.1.150

 

port_scanner

While the port scanner is scanning , you get messages on your SOCKET TEST window.

Here you can see the Port scanner software connecting to the port & then disconnecting after scanning.

port_message

 

Alternatively you can use a PUTTY serial port tool to test local communication.

Select the connection type as RAW & provide the host IP which is 192.168.1.150 & thtn the port number 350

putty1

Click on open , to see the New client connection on the Socket test window.

putty4

 

Now you can test two way communication between  socket test (server) & putty ( client).

putty2

 

WINDOWS FIREWALL SETTINGS

 

The Windows Firewall settings has to be done to allow the port 350 to listen from outside.

Open the Windows Firewall & Advanced Security window.

Click on Inbound Rules & then New Rule.

windows1

 

Select the Rule Type as PORT & in the next screen select protocol as TCP.

Under Specified local ports feed the port number as 350

windows2

 

Under Action window select Allow the Connection

Next window is Profile window , here tick mark all – Domain,Public & Private.

Provide a name to the Rule & save it.

Now your PORT 350 is allowed to listen by the Windows Firewall.

windows3

 

PORT FORWARDING

This step is final where you redirect the incoming request to the port number of local IP where the server is started.

Here my local PC’s IP is 192.168.1.150   &  server is started on port 350.

Anyone from external world connecting to my public IP has to be directed to the port 350 on local IP 192.168.1.150.

This is called PORT FORWARDING , which is very widely used in CCTV Remote viewing & in Gaming.

The setting has to be done in your Router.

Type in the Gateway IP of your Router , here it is 192.168.1.1 , on your browser & provide the user name & password.

Here is an excellent website showing all screen shots of almost all Routers in the world

https://portforward.com/router.htm

 

Mine is BINATONE Router.

You’ve to search for something called VIRTUAL SERVER on the router setting.

 

ROUTER1

 

For my Router it’s hidden under ADVANCED SETUP –> NAT –> VIRTUAL SERVER

For more details you can visit the above portforward link

Create a new Virtual server listing by entering the

— Port number , which is 350 .Enter same number at all fields like start & stop.

— Local IP address , here you provide the IP where server is started , 192.168.1.150

— save the listing

router3

 

Once saved , the port number 350 is open to outside world.

Online port open test tools are available

www.canyouseeme.org

www.yougetsignal.com

 

Once you open the link , your public IP will be automatically shown.

Fill in the PORT number to be checked & click on CHECK button.

If you see SUCCESS , then you’re done with PORT FORWARDING

 

canyou1

 

port_open

 

Following is the list of AT commands used by the GSM SIM900A to contact the server.

This is for part 2 of the post.PART 2 LINK HERE

gsm1

gsm2

cooltext753793315   cooltext753790696

 

 

This post is on retrieving particular Data from a web page using SIM900A & Arduino.

For e.g we shall retrieve the Blog Status hits of my blog in which you’re reading this.

We’ve to create an API link for this data so that data can be retrieved using SIM900A.

To create API link we use the THINGSPEAK.com website.

First let us read the XPATH details of the data wanted as below :

The procedure is related to Google Chrome WebBrowser

 

Image 1

 

Right click on the data to be retrieved & click on INSPECT .

 

inspect

 

A highlighted code will be displayed on which Right click & then select COPY  –> COPY XPATH

XPATH

 

The copied XPATH detail has to be used in THINSPEAK account to create the API link.

Open your thingspeak account & click on APPS –> THINGHTTP

 

thing1

Click on NEW THINGSPEAK to create a new “thing”.

thing2

 

You can provide a suitable Name for the App & under URL provide the website link from where you want the data from.

Method is GET & version is 1.1

thing3

 

Scroll down to bottom & under the PARSE STRING field paste the XPATH copied from the website.

thing4

Click on SAVE & you see the API LINK generated.

thing5

 

You can use this API link in your browser to confirm the data retrieved.

Image 15

Now let us see the practical application using SIN900A GSM & ARDUINO.

The connections between Arduino & GSM are :

Rx of GSM —> pin 8 (Tx) of Arduino   (since we use the SoftSerial in Arduino code , we declare pins 7 & 8 for Serial communication)

Tx of GSM –> pin 7 (Rx) of Arduino

GND –> GND

A separate power source is required for the GSM.

Following are the AT commands used

http

DOWNLOAD Arduino code HERE

————————————————————

#include <SoftwareSerial.h>
SoftwareSerial myGsm(7,8);

void setup()
{
myGsm.begin(9600);
Serial.begin(9600);
delay(500);

myGsm.println(“AT+CGATT=1”);
delay(200);
printSerialData();

myGsm.println(“AT+SAPBR=3,1,\”CONTYPE\”,\”GPRS\””);//setting the SAPBR,connection type is GPRS
delay(1000);
printSerialData();

myGsm.println(“AT+SAPBR=3,1,\”APN\”,\”\””);//setting the APN,2nd parameter empty works for all networks
delay(5000);
printSerialData();

myGsm.println();
myGsm.println(“AT+SAPBR=1,1”);
delay(10000);
printSerialData();

myGsm.println(“AT+HTTPINIT”); //init the HTTP request
delay(2000);
printSerialData();

myGsm.println(“AT+HTTPPARA=\”URL\”,\”http://api.thingspeak.com/apps/thinghttp/send_request?api_key=VV7WQ9DS19E2BNNI\””);// setting the httppara,
//the second parameter is the website from where you want to access data
delay(1000);
printSerialData();

myGsm.println();
myGsm.println(“AT+HTTPACTION=0”);//submit the GET request
delay(8000);//the delay is important if the return datas are very large, the time required longer.
printSerialData();
myGsm.println(“AT+HTTPREAD=0,20”);// read the data from the website you access
delay(3000);
printSerialData();

myGsm.println(“”);
delay(1000);
myGsm.println(“AT+HTTPTERM”);// terminate HTTP service
printSerialData();

}

void loop()
{
}

void printSerialData()
{
while(myGsm.available()!=0)
Serial.write(myGsm.read());
}

—————————————————————-

AT+CGATT=1  enables the GPRS CONNECTION

AT+SAPBR is used to declare the Connection Type as GPRS

& Then the APN –Access Point Name of the mobile service provider is given.

An empty string also will work.Or you can slide the SIM into your Android mobile

under Settings –. More –> Cellular Networks  –> Access Point Names

you get the APN details

AT+SAPBR=1,1  enables the GPRS & APN settings & then HTTP is initialized with AT+HTTPINIT

HTTP parameters are then provided as “URL” & the API link we created earlier.

Note to use HTTP ( not HTTPS) in the link, as we use AT commands for HTTP only here.

AT+HTTPACTION=0 enables GET action

The GSM respons with

+HTTPACTION:0,200,12

Here 0 means GET action & 200 means OK , 12 bytes are retrieved.

If you get 600 instaed of 200 ,then it means a Network Error.

AT+HTTPREAD command is used to read the Data.

 

Image 11

cooltext753793315   cooltext753790696

 

A6 GSM  is introduced by the makers of ESP8266 , AI-THINKER.

The module is much cheaper than SIM900 & connections are quite simple.In this post we shall see how to connect with Arduino to make a call & send SMS.

A mobile adapter is enough to power up the A6 GSM module.The Vcc pin of GSM must be looped with PWR_KEY pin.This acts as a chip enable.You can leave this connected or remove after a moment.The module just requires a HIGH trigger at PWR_KEY pin while started.

A valid SIM is used at the back side of the module.The SIM slot provided is for a Micro SIM.If you ‘ve a Nano SIM you need to use a converter to fit the slot.

The RxD pin of A6 GSM is connected to Tx of Arduino

The TxD pin of A6 goes to Rx of Arduino.

GND pin of A6 to GND of Arduino.

 

Connection

 

 

PIN_DETAILS_A6

Initial TESTING

Power up the module & then after a moment make a call to the SIM number used in the GSM module from another phone.If you get the RING Back tone , it means the module is ready.As there is no LED indication provided , this initial step is required to confirm working.

 

Making a CALL

 

Connect the USB cable of PC to Arduino & upload this code for making a call.Remember to disconnect connections at Rx/Tx before uploading the code.

Image 1

 

The mobile number to be called is stored in an Array of char variable.

In the void setup() code we begin Serial communication at 9600 baud.Though the default baud rate of A6 GSM is 115200 , it is effective to use 9600 baud .

ATD command followed by the number to be called is used to make a call.

A semicolon at the end is not a must as in SIM900.The call will be made even if you do not use a semicolon.

After a delay of 8 secs ATH command is sent to terminate the call.

You can open the Serial monitor of Arduino & watch the AT commands landing.You should set the baud rate as 9600 in the Serial monitor as well.

The void loop() function is left empty.In case you try the code inside loop , the call will be repeatedly

made for ever.

 

Sending SMS

Now let us see the method to send SMS.

Following screenshot shows the code for sending SMS.

Image 2

 

DOWNLOAD Arduino code HERE

AT+CMGF=1

which will allow you to read and write SMS messages as strings instead of hexadecimal characters.

Serial.println is used to send the AT command with a New line (Enter).

After a delay of 2 seconds next command

AT+CMGS=”phone_no.”

is sent.The target phone number is to be given within double quotes. Note the usage of

Serial.write(0x22)  which is the ASCII equivalent for double quotes.

0D followed by 0A are the ASCII equivalents for  CARRIAGE RETURN & LINE FEED.

The delay of 2 seconds is a must after setting the GSM to text mode AT+CMGF=1

Try this code without the delay , you won’t get response.

After the 0D , 0A a delay of 2 seconds is provided & then the message to be sent is given.

CTRL+Z is finally given to send the message.

This is provided by the ASCII equivalent 1A or char(26)

Watch this video :

 

 

cooltext753793315    cooltext753790696

 

After the huge success of the ESP8266 IOT modules , the AI-THINKER company now introduces the new GSM Module A6.In near future this module will be available at half the price of SIM900.

 

GSM_3

 

This is mini GSM / GPRS core development board based on GPRS A6 module. It supports dual-band GSM/GPRS network, available for GPRS and SMS message data remote transmission.
The board features compact size and low current consumption. With power saving technique, the current consumption is as low as 3mA in sleep mode.

Features:
– Working frequency: quad-band network, 850 / 900 / 1800 / 1900MHz
– Working voltage: 4.5~5.5V DC (On-board voltage regulator circuit supply power for A6 module)
– Working current: maximum of 2A
– Sleep current: 5mA
– Onboard Micro SIM card holder, you can install Micro SIM card
– Onboard Micro USB interface for external power supply
– Communication Interface: TTL serial port
– Baud rate: 115200bps and it can also be set by AT command.
– Interface logic voltage: 3.3V
– Make and answer phone calls using a headset and electret microphone.
– Send and receive SMS messages.
– Send and receive GPRS data (TCP/IP, HTTP, etc.) .

PIN DETAILS OF A6 GSM :

PINOUT_ALS

 

To test the module we make use of an USB-TTL module built on CP2102 .

CP2102

 

The connections between A6 GSM & CP2102 module are :

A6 GSM             USB-TTL Board

———-       ————

UART_TXD    —>  Rx

UART_RXD    —>  Tx

GND            –>    GND

The A6 GSM can be powered up with a cell phone charger for which a mini usb socket is provided at the back side.Its advisable to use 5v 2Amp adapter.

Insert a valid SIM to the SIM holder seen at the bottom side of the module.

 

A6_BACK

 

Connect the USB-TTL board to the PC & open the Device Manager to note the COM port alloted.

Open the TERMINAL Software & select this port .Select baud rate as 115200 & click connect.

TERMINAL SOFTWARE Download

 

ter1

 

The GSM module takes around 10 secs to boot up & finally you get CREG 1.

Now you can type in AT commands.The GSM A6 module requires a Carriage Return after every AT command .You can tick mark the CR found at the bottom right of Terminal before sending any command.Or you can make use of the SET MACROS function .Here you store the AT commands followed by $ sign & then 0D .

The $ sign is to Append & the 0D is the ASCII for Carriage Return.

ser3

AT commands are stored in M1,M2,M3,… as shown in screen shot above.

Now if you click on M1 , AT command is sent with CR & you get OK response.

Clicking M2 will send ATDxxxx to dial a number . The semicolon after the number is not a must as in SIM900.

ATH disconnects the call.

To send SMS

AT+CMGF=1  to set the TEXT Mode

AT+CMGS=”phone_no.”

Now you get a  >   symbol & the module waits for you to type in the message.

After typing the test message a CTRL+Z is to be sent .This is done by appending 1A which is the ASCII for the CTRL+Z

Watch this demo video :

 

 

 

 

http://www.alselectro.com/gsm-a6-board.html

http://www.alselectro.com/gsm-a6-full-kit-with-lcd—keypad.html

 

cooltext753793315    cooltext753790696

GSM–Handling Received SMS

This post is intended to illustrate the received SMS by a GSM module like SIM900.AT commands to handle the received SMS are explained in detail.

We shall use a SIM900 module on RS232 breakout board & an USB-UART converter board to connect it to the PC.

Following is the setup to test received SMS using SIM900.

Image 9

A terminal software like PUTTY is used to read out the COM port where GSM is connected to PC through USB-UART board.

As you connect the USB-UART board to PC ,the PC allots a COM port which can be seen under Device manager.Open the PUTTY terminal & set this to read the serial port.

 

Image 10

Open the Putty terminal & type in AT .If your modem settings & connections are fine you get an OK response from the modem.

Preferred Storage Area

————————-

To select the Storage area for SMS type in

AT+CPMS  command .This sets the Preferred Message Storage area.

To know the Message areas supported by our GSM ,enter the AT command

AT+CPMS=?

Image 1

As seen above ,our modem returns all 3 message storage areas as SM , which refers to the Message storage area on the SIM card.

The first SM specifies the message storage area that will be used while Reading or Deleting SMS.

The second SM specifies the area that will be used when sending SMS from message storage or writing SMS  to storage.

The third SM specifies the preferred message storage area for storing newly received SMS.

In our case ,SM is the preferredstorage area for all SMS functions , Read , Send & Receive.

The other storage areas are ME (storage area on GSM Modem/Mobile phone) ,   MT (read from all storage area associated with GSM),   BM (incoming Broadcast message storage area) ,   SR  (status report)   &  TA (Terminal adapter )

 

To know the SMS Service center address (SMSC)

AT+CSCA?

The mobile network operator’s service center number will be displayed.

 

Image 2

The number 145 in +CSCA is the address type .145 refers to International number starting with +.

SMS Modes

————-

The next AT command

AT+CSMS=?

reports the SMS modes supported by the GSM. 0 is for Text mode & 1 is for Protocol Data Unit (PDU) mode.Our modem reports (0,1)  supporting both SMS modes.

To check if your modem supports the text mode, you can try the following command:

AT+CMGF=1

If the modem responds with “OK” this text mode is supported. It is  possible to send only simple text messages in this mode.

To know the current message format use the command

AT+CMGF?

 

Reading Messages from Storage Area

———————————

To read messages from SIM storage type in

AT+CPMS=”SM”

Image 3

 

The Modem responds with + CPMS: followed by Used space & Maximum space.

In our modem there are currently 2 messages in memory (used space ) & maximum storage capacity is for 30 messages.

To list out all messages in the SM storage  type in

AT+CMGL=”ALL”

The modem responds with a list of all messages in the storage area.

Image 4

 

+CMGL: 1  is the Memory Index number used to read or delete message

“REC READ”  is the status message.If the message is not Read it shows REC UNREAD

“+91xxx “    is the phone number from where the message originated.

“,”    Next column is the reference number of the message.Generally this field is empty.

“13/09/19…”  is the Date & time of received SMS in yy/mm/dd,hh:mm : ss format

Finally the actual message in text format is displayed.

 

To list out a particular  message , use the CMGR command with the index number of the message to be read.

AT+CMGR=2   to list the message at index 2

AT+CMGR=4   to list the message at index 4

Image 5

 

Deleting Messages

———————-

To delete a message use CMGD command with the index number of message to be deleted.

AT+CMGD=1    to delete the message at index 1.

Image 6

You can issue the command AT+CMGL=”ALL” to see that the message at index 1 is deleted.

To delete all the messages in the storage area there is no such command like AT+CMGD=”ALL”.

Use the following notation to delete all messages.

AT+CMGD=1,4

1 is the Index value & 4 is the flag value

To know the index & flag values allowed

AT+CMGD=?

Image 7

1 to 30 can be assigned to index parameter & all five flag values from 0 to 4 are supported.

By default flag value is 0 which means “Delete message at location <index>”

Flag value 1 – Delete all READ messages ,ignoring value of index.

Flag value 2 – Delete all READ & SEND messages.

Flag value 3 – Delete all Read,Sent & Unsent messages.

Flag value 4 –Delete all messages.

 

Image 8

You can see from above screen shot that all messages are deleted after issuing AT+CMGD=1,4.

 

AT+CNMI – New message indication to Terminal Equipment TE.

Selects procedure how receiving of new messages from the network is indicated to the TE.

The following command sets the indicators for receiving an SMS message.

 

AT+CNMI=1,1,0,0,0 Set the new message indicators.

AT+CNMI=<mode>,<mt>,<bm>,<ds>,<bfr>

 

<mode>=1 discard unsolicited result codes indication when TA – TE link is reserved.

=2 controls processing of unsolicited result codes & forward them directly to Terminal Equipment TE

 

<mt>=1 SMS-DELIVERs are delivered to the SIM and routed using unsolicited code.

<bm>=0 no cell broadcast message indications are routed to the TE.

 

<ds>=0 no SMS-STATUS-REPORTs are routed.

 

<bfr>=0 Terminal Adapter ( TA) buffer of unsolicited result codes defined within this command is flushed to the TE (Terminal equipment).

 

The following command saves the SMS settings. Once the SMS commands have been saved, the initialization commands do not need to be sent again until they are changed.

 

AT+CSAS

toSave SMS settings. This may take up to 10 seconds.

 

Watch this support video :

Handling Received SMS with SIM900 GSM

GPS Receiver Module–Part 2

 

Part 1 – GPS theory  here

 

SKYTRAQ GPS-634 Module

 

There are numerous GPS modules available in the market.

In this post, I am going to use GPS-634R module manufactured by SKYTRAQ , a Taiwan based leading GPS Chipset manufacturer.

GPS-634R is a highly integrated smart GPS module with a ceramic GPS patch antenna. The antenna is connected to the module via an LNA – Low Noise Amplifier.

The module is with 51 channel acquisition engine and 14 channel track engine, which be capable of receiving signals from up to 65 GPS satellites and transferring them into the precise position and timing information that can be read over either UART port or RS232 serial port.

Both of the LVTTL-level and RS232 signal interface are provided on the interface connector, supply volt is 3.6 to 6v DC.The module can be used with your Desktop PC, Laptop, or a microcontroller. It supports the NMEA 0183 protocol, as do many GPS modules.

 

gps-634r            Image 1

We are going to start by connecting the module to our PC using an Evaluation Board shown below:

This board will allow you to use a standard 12v AC adapter and a 9 pin Serial cable to connect the GPS module to your PC or Laptop.In Laptops you don’t have a Serial port.Make use of an USB to UART board to connect to USB port.

We shall use a board made by NSK Electronics ,which uses a CP2102 Siicon Labs USB –UART IC, a reliable one.

Connect the GPS module to the breakout board.Only we need 3 wires Vcc (pin 1),GND (pin 2) & the TX (Serial Data out). The TX wire should be connected to Rx pin on the board.

The 9 pin D connector of the breakout board is connected to the USB-UART converter using a Serial cable (straight one not cross).The USB connector of USB-UART board is then connected to the Laptop using a A-B USB cable.

Provide a 12v DC adapter to the break out board.The power LED will glow.

At the bottom of the GPS Module a status LED glows.This LED glows still (always On) in Non-Fix mode & starts blinking once the GPS module is outdoor and has started tracking.

We shall make use of a Terminal Software COOLTERM to read out the COM port where GPS is connected.

 

 

Image 2

 

Open up the Device Manager & note down the port number allotted to the USB-UART board.

 

Image3

 

Now open the Terminal software COOTERM . You can download it here

Click on Options & then under Serial port select the port allotted to your USB-UART board as seen in the Device Manager.The other settings are Baud Rate –9600, Data Bits – 8 , Parity –None  &  Stop Bits – 1  (9600 8 N 1) .

 

Image4

 

If you click CONNECT button you can see your GPS in action & NMEA Sentences flying out.

 

Image 45

 

 

 

gps1

 

The $GPRMC Sentence  is the most useful one and contains the position fix.

 

$GPRMC,054006.999,A,1059.8519,N,07657.4794,E,000.0,166.0,120313,,,A*66

GP is the Prefix for GPS followed by RMC which is Recommended Minimum Sentence.

All data are separated by Commas.

054006.999 is the current time in Greenwich Mean Time (not your local time). In this example it is 05 Hours 40 Minutes 06 Seconds & .999 MilliSeconds.

Next is the STATUS CODE : “ A “ means Active & GPS HAS GOT A fix.” V” means Void or Data Invalid

Next 4 pieces of Data are Geo Location Data.

1059.8519,N -> Latitude 10 Degrees , 59.8519 decimal minutes NORTH

07657.4794,E -> Longitude 76 Degrees ,57.4794 decimal minutes EAST.

 

Next Data is Ground Speed in Knots.In this example I’m indoor & not moving.So it is 000.0

Next Data is Tracking Angle 166.0

Next Data is the DATE of FIX 120313 means 12th of March ,2013

Next 2 commas indicate Empty field.One is for Time in secs since last DGPS updated & the other is DGPS station ID number.In this example both fields are empty.

Finally a checksum data is presented which starts with an “*” symbol followed by 2 Hex digits.

 

Now we shall use a GPS STUDIO Software called TRIMBLE to view the MAP.

Download TRIMBLE GPS STUDIO from  here

http://trl.trimble.com/dscgi/ds.py/Get/File-484972/TrimbleStudio.exe

 

Click Disconnect in  the COOLTERM window to close the port.

Start up TRIMBLE STUDIO

If Windows Firewall blocks Trimble , click Allow Access to start TRIMBLE.

Under New Connection Select the port COM6 (allotted to USB-UART).

Image6

 

In the next window select the Baud Rate as 9600 ,Parity – None , Data Bits – 8 ,& Stop Bits –1

 

Image7

Click OK.

Now you can see the individual data like Latitude,Longitude,Date ,Time , etc.. are extracted from the NMEA sentences & displayed in their respective boxes.

To see the NMEA sentences click  Monitor – > View RAW Data.

To view the MAP click on Map button at the right top of the Monitor screen.

The position of the GPS is seen as a Red Dot .To see Satellite or Terrain Views you can click on the respective buttons.

If the GPS is fixed in a Car , the Red dot will move on the map following the movement of the Car.

 

trimble1

 

Now let us take the GPS setup into a Car.

DSC00528      DSC00521

This is the  whole setup we are taking into a car.

A 9V battery is enough to power up the GPS module.The GPS module is connected to Laptop using an USB-UART board.Trimble Studio is started and the COM port of USB-UART board is entered into the port settings of Trimble Studio.

 

 

DSC00534      DSC00524

 

The GPS Module is placed at the front of Dash Board to get a clear sky view. A Reliance Data card is used for providing Internet connectivity.

Below is the screen shot of the Map plotted according to the movement of the Car.

CARGPS

 

Watch this video  :

 

GPS MODULE – SKYTRAQ 634–Testing & plotting MAP

 

 

For availability of this GPS module & break out board contact :

 

cooltext753793315       cooltext753790696

 

In this series of posts I shall demonstrate the usage of GPS Receiver module .I shall make it in 3 parts.

1. First part explains the theory of GPS & make you understand the Jargons / Specifications used in     GPS technology.

2. In Second part  I shall show you how to interface a GPS module to your PC & read the NMEA Sentences using a Terminal Software COOLTERM & a GPS TRIMBLE STUDIO software.A support Video gives you a better understanding.

3. Third part explains how to interface a GPS with Arduino

Let us start with first part of GPS theory :

gps3

 

The Global Positioning System (GPS), is a satellite based radio navigation system owned by the United States Government and operated by the United States Air Force. GPS is funded and controlled by the U. S. Department of Defense (DOD).

The outstanding performance of GPS over decades has earned the confidence of millions of civil and military users worldwide.

Global Positioning System (GPS) module is used to get Position,Altitude,as well as Speed,Date & Time on UTC.

It uses the standard NMEA protocol (National Marine Electronics Association) to transmit the position data via serial port.

GPS provides specially coded satellite signals that can be processed in a GPS receiver, enabling the receiver to compute position, velocity and time.For anyone with a GPS receiver, the system will provide location and time. GPS provides accurate location and time information for an unlimited number of people in all weather, day and night, anywhere in the world.

GPS system comprises of 3 segments : SPACE , CONTROL & USER SEGMENTS.

      Space Segment            ControlSegment               UserSegment

      SPACE  Segment (SS)               CONTROL     (CS)              USER  SEGMENT (US)

 

The Space Segment of the system consists of the GPS satellites. These Space Vehicles (SVs) send radio signals from space.The nominal GPS Operational Constellation consists of   24 satellites that orbit the earth in 12 hours.

GPS satellites transmit two low power radio signals, designated L1 and L2. Civilian GPS uses the L1 frequency of 1575.42 MHz in the UHF band. L2 ( 1.2276 GHz  ) is used in Military.The L1 carrier is modulated with the Coarse/Acquisition (C/A) code and Navigation Message, used for PPS and SPS, and the military P-code, used for PPS only. The L2 carrier is modulated only with the military P-code.

The GPS system provides two navigational services, the military Precise Positioning Service (PPS), and the civilian Standard Positioning Service (SPS).

The 24 satellites that make up the GPS space segment are orbiting the earth about 12,000 miles above us. They are constantly moving, making two complete orbits in less than 24 hours. These satellites are travelling at speeds of roughly 7,000 miles an hour.

GPS satellites are powered by solar energy & they have backup batteries onboard .

The Control Segment consists of a system of tracking stations located around the world.The Master Control facility is located at SCHRIEVER AFB ( Air Force Base ) in Colorado.

           afb

The Master Control station uploads ephemeris and clock data to the SVs. The SVs then send subsets of the orbital ephemeris data to GPS receivers over radio signals.

The GPS User Segment consists of the GPS receivers and the user community. GPS receivers convert SV signals into position, velocity, and time estimates. Four satellites are required to compute the four dimensions of X, Y, Z (position) and Time.

 

Each satellite continually transmits messages that include

The time the message was transmitted

Precise orbital information (the ephemeris)

The general system health and rough orbits of all GPS satellites (the almanac).

 

A GPS receiver must be locked on to the signal of at least three of the 24 satellites to calculate a 2D position (latitude and longitude) and track movement.

With four or more satellites in view, the receiver can determine the user’s 3D position (latitude, longitude and altitude). Once the user’s position has been determined, the GPS unit can calculate other information, such as speed, bearing, track, trip distance, distance to destination, sunrise and sunset time and more

GPS Receivers give output data as standard ASCII text at either 4800 baud or 9600 baud and can be easily read by the serial port on any microcontroller.

 

Developments

GPS satellites now on orbit are aging quickly and users are demanding more capability. To sustain and modernize the constellation, the U.S. Air Force is building the next generation satellite system, known as GPS III.

Indian Regional Navigational Satellite System (IRNSS-1) is under development autonomously by ISRO & will launch seven satellites for navigation.Full constellation is planned to be realized around 2014.

The Chinese have already launched  The BeiDou Navigation Satellite System (BDS) .

Specification Terms Explained :

An important specification is the UPDATE RATE, which indicates How often the GPS recalculates & reports its position.The standard is 1HZ ,i.e., only once per second. 5 & even 10HZ update rates are available.Faster Update Rate means there will be more NMEA sentence flying out of the module.

Next specification is the Number Of Channels.

The number of channels that your module runs will affect your time to first Fix.Since the modules doesn’t know which satellites are in view,the more channels you have,the faster you’ll find a fix.

12 or 14 channels track engine will work just fine for tracking.

The satellites (SVs) broadcast two types of data, Almanac and Ephemeris. Almanac data is course orbital parameters for all SVs. Each SV broadcasts Almanac data for all SVs. This Almanac data is not very precise and is considered valid for up to several months.

Ephemeris data is very precise orbital and clock correction for each SV and is necessary for precise positioning. Each SV broadcasts ONLY its own Ephemeris data. The validity of this data is dictated by the particular satellite and may be valid up to 4 to 6 hours. Each set of ephemeris data gives a "fit" indication which tells how long the particular Ephemeris data is valid. The Ephemeris data is broadcast by each SV every 30 seconds so GPS receivers have frequent opportunities to receive and log this essential information.

If you look up the specification of any GPS module ,you come across terms like Cold Start,Hot Start  & Warm Start.

Cold Start is performed every time when the GPS module is turned off without backup power supply connected. It is the longest starting time out of the three and usually takes 35 seconds in average under open sky environment. During Cold Start, almanac and ephemeris data has to be downloaded first from the GPS satellites to GPS module before a position fix can be acquired.

Assuming that a proper backup power source is provided, GPS module will perform Hot Start if the GPS module is powered on any time within the 2-hour time frame after GPS was previously turned off, as the ephemeris and almanac data is still stored inside the its flash memory.

Warm Start is performed if the above module is started after the 2-hour time frame, as part of its satellite data has to be refreshed.

 

NMEA

The GPS receiver outputs data in National Marine Electronics Association (NMEA) format .The idea of NMEA is to send a line of data called a SENTENCE.

The standard sentences have a two letter prefix that defines the device that uses that sentence type. For GPS receivers the prefix is GP , which is followed by a three letter sequence that defines the sentence contents.

In addition NMEA permits hardware manufactures to define their own proprietary sentences for whatever purpose they see fit. All proprietary sentences begin with the letter P and are followed with 3 letters that identifies the manufacturer controlling that sentence. For example a Garmin sentence would start with PGRM and Magellan would begin with PMGN.

Each sentence begins with a ‘$’ and ends with a carriage return/line feed sequence and can be no longer than 80 characters of visible text (plus the line terminators). The data is contained within this single line with data items separated by commas.

The data itself is just ASCII text and may extend over multiple sentences in certain specialized instances but is normally fully contained in one variable length sentence. The data may vary in the amount of precision contained in the message. For example time might be indicated to decimal parts of a second or location may be show with 3 or even 4 digits after the decimal point.

Programs that read the data should only use the commas to determine the field boundaries and not depend on column positions. There is a provision for a checksum at the end of each sentence which may or may not be checked by the unit that reads the data. The checksum field consists of a ‘*’ and two hex digits representing an 8 bit exclusive OR of all characters between, the ‘$’ and ‘*’.

 

$GPRMC NMEA Sentence

 

The $GPRMC Sentence is the most useful one and contains the position fix. An example is

$GPRMC,054006.999,A,1059.8519,N,07657.4794,E,000.0,166.0,120313,,,A*66

GP is the Prefix for GPS followed by RMC which is Recommended Minimum Sentence.

All data are separated by Commas.

054006.999 is the current time in Greenwich Mean Time (not your local time). In this example it is 05 Hours 40 Minutes 06 Seconds & .999 MilliSeconds.

Next is the STATUS CODE : “ A “ means Active & GPS HAS GOT A fix.” V” means Void or Data Invalid

Next 4 pieces of Data are Geo Location Data.

1059.8519,N   -> Latitude 10 Degrees , 59.8519 decimal minutes NORTH

07657.4794,E  -> Longitude 76 Degrees ,57.4794 decimal minutes EAST.

Next Data is Ground Speed in Knots.In this example I’m indoor & not moving.So it is 000.0

Next Data is Tracking Angle 166.0

Next Data is the DATE of FIX  120313 means 12th of March ,2013

Next 2 commas indicate Empty field.One is for Time in secs since last DGPS updated & the other is DGPS station ID number.In this example both fields are empty.

Finally a checksum data is presented which starts with an “*” symbol followed by 2 Hex digits.

Other important sentences are

GPGGA ,which provides the current FIX data

GPGSA – Overall Satellite status Data , 3D,2D Fix details &  PRN ( satellites are identified by the receiver by means of Pseudo Random Numbers.)

GPGSV – Detailed Satellite Data

GPVTG – Vector Track on speed over the Ground.

GPRTE – Route Message

For more details of NMEA Sentences visit

http://www.gpsinformation.org/dale/nmea.htm

ARDUINO with GSM

 

In this workshop we shall see how to control a GSM board with ARDUINO

Hardware required :

ARDUINO UNO board                      GSM 300 or 900 board

12v DC adapter for GSM board           Connecting wires

 

GSM1

 

The connection is simple.We shall use the Hardware Serial port of ARDUINO (pin 0 & pin 1).

Pin 0 (RX) of Arduino is connected to RX pin of GSM

Pin 1 (TX) of Arduino is connected to TX pin of GSM

General Rule is always TX to Rx  &  Rx to Tx.But the GSM board I’m using has a MAX232 level converter IC & the Tx ,Rx printed on board is that of MAX232’s T1 IN & R1 OUT.

Do not get confused .Always ensure that

Rx of Arduino (pin 0) goes to pin 11 (T1 IN) of Max232

Tx of Arduino (pin 1) goes to pin 12 (R1 OUT) of Max 232.

As we use TTL level logic we need not bother about the presence of 232 IC.

Do not power the GSM from Arduino.Use a separate adapter of minimum 1Amp rating.

Make GND pins of both GSM & Arduino common.

To start with place a valid SIM to the holder on the GSM board.Connect the power adapter to GSM.

Now dial a call from another phone  to the SIM number & ensure that you get a Ring back tone .

This is the initial test to confirm that your GSM is ready to accept commands from Arduino.

 

Making a Call from GSM

 

First we shall see how to Dial a number.

We make use of AT commands to control a GSM.

Here are the Steps you do for making a call

1.Wake up GSM by giving AT command .

2.Dial a number using command   ATDphone_no;       ATD followed by phone number & a Semicolon.

3.Now the call is made.To hang the call feed ATH command.

The above steps are converted to code as below:

—————————————————————-

//Code for Dialling a number

char phone_no[]=”9443303461”;

void setup()

{

Serial.begin(9600);  //Open Serial Connection at baudrate 9600

delay(2000);

Serial.println(“AT”); // Wake up GSM

Serial.print(“ATD”); //Dial the phone number using ATD command

Serial.print(phone_no);

Serial.println(“;”); // Semicolon is a must at the end

delay(10000);

Serial.println(“ATH”); // After a delay of 5 secs Hang the call

}

void loop()

{

// empty loop.If you enter the above code here,the call will be made FOR EVER repeatedly.

//Take Caution while coding under loop.At some condition you’ve to terminate the Call

}

 

 

——————————————————————–

 

Please note that you’ve to disconnect GSM from Arduino while Uploading the code to Arduino .

While issuing ATH command use Serial.println & not Serial.print.This println is to send Carriage

Return after the ATH command.Note the reasonable amount of Delay (10secs) used after issuing the ATD command.

This delay is mandatory for GSM to respond.

 

 

Sending SMS from GSM

 

Now we shall see the procedure to send SMS through GSM.

1.Wake up GSM by sending AT command

2.The GSM should be put on Text mode by feeding command  AT+CMGF=1

3.Now give command        AT+CMGS=”Mobile_number”

4.Verify whether the Modem responds with a   >   character

5.After getting > symbol ,feed your Message to SMS.

6.Press CTRL+Z  to send the SMS.

The above steps are coded for Arduino to handle  automatically

————————————————————————–

//Code to send SMS from Arduino

int timesTosend=1;
int count=0;
char phone_no[]=”9443303461″;  //phone number

void setup()
{
Serial.begin(9600);  //Open Serial connection at baud 9600
delay(2000);
Serial.println(“AT+CMGF=1”); //set GSM to text mode
delay(200);
}

void loop()
{
while(count<timesTosend){
delay(1500);
Serial.print(“AT+CMGS=\””);
Serial.print(phone_no);
Serial.println(“\””);
while (Serial.read()!=’>’);
{
Serial.print(“Test Message from Arduino GSM….HELLO..!!!”);  //SMS body
delay(500);
Serial.write(0x1A);  // sends ctrl+z end of message
    Serial.write(0x0D);  // Carriage Return in Hex
Serial.write(0x0A);  // Line feed in Hex

//The 0D0A pair of characters is the signal for the end of a line and beginning of another.
delay(5000);
}
count++;
}

}

———————————————————————————

Feed the above code in Arduino IDE & upload it.Do not forget to Disconnect GSM from Arduino

while uploading the code.

If you copy & paste the above code,you may get compile error.Type in the code wherever error is indicated.

Note the usage of Hex codes  0x1A for sending ctrl+z

0x0D for Carriage Return  & 0x0A for LineFeed.

Watch this Video on making a Call &Sending SMS using Arduino & GSM :

Sending SMS through Arduino & GSM

 

 

The GSM & ARDUINO boards are available at :

 

cooltext753793315     cooltext753790696

GSM Tutorial

In this tutorial I shall demonstrate the usage of  GSM board to send SMS.

GSMGSM2

Materials required for this workshop are :

Hardware:

1.GSM Module Board with an active SIM card.

2.12V DC 1A adapter for GSM power supply.

3.USB – UART converter with RS232 straight cable and USB cable.

Software:

1.Serial Communication software PuTTY . Download it from

http://putty.en.softonic.com/

or you can use the inbuilt Hyper Terminal software in case your PC’s OS is XP.It is located in Programs>Accessories>Communication.

While using Hyper terminal remember the following settings:

Under File –> Properties –> Settings    click ASCII setup and check mark “Echo typed characters locally”.Otherwise you can’t see what you type.

Another software is  “Terminal” from    http://realterm.sourceforge.net/  .Terminal  is a simple serial port terminal emulation program.

I prefer to use PuTTY as it is trouble free standalone program and response is faster than others.

To start with insert the SIM card into the holder at the back of the board.

Connect the 12v DC supply to the board.Connect the board to your PC’s serial port using a RS232 cable.In case you use the USB port , then a USB – UART board is required.

USB1  USB to UART board

As soon as you connect the DC power to the board ,the green Power LED glows and then the red Signal LED flashes intermittently.Now make a call to the SIM number inserted in the board.You can hear  the ring back tone in the caller phone  and the Ring green LED flashes according to the Ring.Now your GSM board is ready to communicate.

Now open the Control panel –>Device Manager of your PC   and expand the Ports(COM&LPT) to verify the port connection.If you are using a RS232 cable directly to PC ,it will be COM1. Else it will be different (in our case it is COM6).

DMANAGER

Double click the downloaded PuTTY .

Enter COM6  under serial line and baud rate 9600 under Speed.

Select connection type as Serial. Provide a name and save the session.

putty31

Now select the saved session and click Open to fire up the TERMINAL.

For the terminal to communicate with the GSM board  AT commands are used.

AT is abbreviation of ATtention.There are Basic and Extended AT commands.Basic AT commands do not start with a “ + “  like ATD, ATA,ATH,…

Extended AT commands start with  “ + “. All GSM AT commands are extended commands. e.g  AT+CMGS ,  AT+CMGR , AT+CMGF ,…

To start with type  AT  (uppercase preferred) and hit Enter.

GSM board will respond with OK.

Type AT+CPIN?  and hit enter to know whether SIM is inserted.

To dial a number type  ATD9001234567;

ATD followed by the mobile number & then a SEMICOLON .Hit enter to make a Call.To disconnect type ATH.

To send SMS type AT+CMGF=1

Modem confirms with OK that it changes to Text mode.

Then type  AT+CMGS=”mobile.no”

After the > symbol type your message and press ctrl+z  to send the SMS.

at

For a more detailed tutorial of SMS and AT commands visit

http://www.developershome.com/sms

Following are some of the most frequently used AT commands :

AT+CGMI                            To get the manufacturer’s ID

AT+CMGF=1                        Switch to text mode before sending SMS

AT+CMGS=”mobile.no”       Send SMS after typing the message & pressing ctrl+z

ATD999xxx1234;                  Dial to the mobile number provided

ATH                                         Disconnect the call

AT+CMSS                               Send SMS from storage

AT+CMGR                              Read one SMS at a time

AT+CMGD=1                         Delete a Message.

AT+CMGL=”ALL”                 Read all SMS messages in the storage area

AT+CMGL                              List SMS messages

AT+CSCA?                             To know the service center address of  GSM provider

To send SMS to multiple numbers you have to write message to memory and then use CMSS command many times. Here is the procedure:

AT+CMGF=1                                           — enable Text mode

OK

AT+CMGW=”9443312345”                       —CMGW writes message to Memory

>Test Message<ctrl+z>

GSM responds as +CMGW:3  OK  where 3 is the index number specifying the location of SMS message.

AT+CMSS=3,”NEXT_MOBILE_NO.”     –  use CMSS to send message from Storage.

AT+CMSS=3,”New_Mobile_no.”

Like this you can use the index number of message and send it to multiple phones.

Watch this video of GSM Board demo,usage of Putty as Terminal and AT command usage to communicate with GSM :

GSM Tutorial from Saravana Electronics