0% found this document useful (0 votes)
10 views37 pages

Wiki Gps Gprs GSM Module v3

The document provides detailed information about the GPS/GPRS/GSM Module V3.0 from DFRobot, including its specifications, pinout, and tutorials for operating the module via USB and Arduino. It covers how to send messages, make phone calls, and control the module's functions, along with troubleshooting tips and sample code. The module supports quad-band GSM/GPRS and GPS technology, enabling seamless tracking and communication capabilities for various applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views37 pages

Wiki Gps Gprs GSM Module v3

The document provides detailed information about the GPS/GPRS/GSM Module V3.0 from DFRobot, including its specifications, pinout, and tutorials for operating the module via USB and Arduino. It covers how to send messages, make phone calls, and control the module's functions, along with troubleshooting tips and sample code. The module supports quad-band GSM/GPRS and GPS technology, enabling seamless tracking and communication capabilities for various applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

GPS/GPRS/GSM Module V3.

0 (SKU:TEL0051)
From Robot Wiki

Contents
1 Introduction
2 Specification
3 Pin Out
4 Tutorial
4.1 How to drive the GSM
Mode via USB port
4.1.1 GSM mode &
GPS mode Selection
4.1.2 Network
indication
4.1.3 How to Send a
message
4.1.4 Ways to send
Ctrl +Z in Coolterm
4.1.5 How to Make a
phone call
4.2 How to drive the GPS
Mode via USB port
4.3 How to drive the GSM Mode via Arduino board
4.3.1 How to Send a message
4.3.2 How to Control your Arduino via SMS
4.3.3 How to Make a phone call
4.4 How to drive the GPS Mode via Arduino board
5 GPS Sample Code
6 Trouble shooting
7 Version history

Introduction
This is a GPS/GPRS/GSM shield from DFRobot. This shield with a Quad-band GSM/GPRS engine works on
frequencies EGSM 900MHz/DCS 1800MHz and GSM850 MHz/PCS 1900MHz. It also supports GPS
technology for satellite navigation. It's possible for your robot and control system to send messages and use the
GSM network.
It is controlled via AT commands(GSM07.07 ,07.05 and SIMCOM enhanced AT Commands). And the design of
this shield allows you to drive the GSM & GPS function directly with the computer and the Arduino Board. It
includes a high-gain SMD antenna for GPS & GSM.

This GPS/GPRS/GSM shield uses an embedded SIM908 chip from SIMCom.Featuring an industry-standard
interface and GPS function, the combination of both technologies allows goods, vehicles and people to be tracked
seamlessly at any location and anytime with signal coverage.

Specification
Power supply: 6-12v
Low power consumption (100mA@7v - GSM mode)
Quad-Band 850/900/1800/1900MHz
GPRS multi-slot class 10
Support GPS technology for satellite navigation
Embeded high-gain SMD antennas for GPS & GSM
Directly support 4*4 button pad
USB/Arduino control switch
Board Surface:Immersion Gold
Size: 81x70mm

Pin Out
NOTE: Two jumper caps of GPS/GSM UART SELECTION have been changed to a switch."Take off the jumper caps"
"slid the switch in the middle".

More details about switches:

Switch S1: PC upload program to


Arduino board/PC communicates
with GPS/GPRS/GSM Module(
Arduino programming/module
communication).

Switch S2: GPS/GPRS/GSM


Module directly connects with PC
through USB port or module
communicates with Arduino board,
which communicates with
PC(USB/Arduino serial communication).

Tutorial
Hardwares prepare:

1. Arduino Uno
2. GPS/GPRS/GSM Module V3.0
3. SIM Card
4. Earphone & Microphone
5. External power supply via the power jack

It is recommended you to supply 7~12v power via the power jack. When using the GSM mode, the module
requires an external power. But the power consumption is not high,just 200mA@7v, when calling.
Module driver pin jumpers: Applying the Module Pin Jumpers(J10-J12) will allocate Pin 3,4,5 for driving the
module. Removing the jumpers will release the above Pins, and you could connect the driver pins to the other digital
pins on your board to avoid the pin conflict.Read more (http://www.dfrobot.com/forum/index.php?
topic=17186.msg21374#msg21374)

How to drive the GSM Mode via USB port

1. If your module works, the indicator Start LED will light up, this means that the module is running correctly.
The LED marked "NET" is used to drive a network status indication LED.
2. Send the AT commands to the module by using Coolterm (http://freeware.the-meiers.org/CoolTermWin.zip)
(or use the Arduino serial monitor).

Note: If you want to program the Arduino, please disconnect the coolterm to release the communication p

GSM mode & GPS mode Selection

Except using UART selection jumper caps, you could switch GSM and GPS function with the IO pins also. Please
remove the jumper caps connected for hardware UART selection first!

Enable GPS mode & disable GSM mode:

digitalWrite(4,LOW);//Enable GPS mode


digitalWrite(3,HIGH);//Disable GSM mode

Enable GSM mode & disable GPS mode:

digitalWrite(3,LOW);//Enable GSM mode


digitalWrite(4,HIGH);//Disable GPS mode

Network indication

State SIM908 behavior


Off SIM908 is not running
64ms On/ 800ms Off SIM908 not registered the network
64ms On/ 3,000ms Off SIM908 registered to the network
64ms On/ 300ms Off PPS GPRS communication is established
Following the steps included in the sketch below first!

?
// Product name: GPS/GPRS/GSM Module V3.0
// # Product SKU : TEL0051
1 // # Version : 0.1
2
3 // # Description:
4 // # The sketch for driving the gsm mode via the USB interface
5
6 // # Steps:
7 // # 1. Turn the S1 switch to the Prog(right side)
8 // # 2. Turn the S2 switch to the USB side(left side)
9 // # 3. Take off the GSM/GPS jumper caps from the Uart select
10// # 4. Upload the sketch to the Arduino board(Make sure turn off other
11Serial monitor )
12// # 5. Turn the S1 switch to the comm(left side)
13// # 7. RST the board
14
15// # wiki link-
16http://www.dfrobot.com/wiki/index.php/GPS/GPRS/GSM_Module_V3.0_(SKU:TEL0051)
17
18voidsetup()
19 {
20 //Init the driver pins for GSM function
21 pinMode(3,OUTPUT);
22 pinMode(4,OUTPUT);
23 pinMode(5,OUTPUT);
24 //Output GSM Timing
25 digitalWrite(5,HIGH);
26 delay(1500);
27 digitalWrite(5,LOW);
28 }
29 voidloop()
30 {
31 // Use these commands instead of the hardware switch 'UART select' in order to
32enable each mode
33 // If you want to use both GMS and GPS. enable the required one in your code and
34disable the other one for each access.
35 digitalWrite(3,LOW);//enable GSM TX、RX
digitalWrite(4,HIGH);//disable GPS TX、RX
}

How to Send a message


Steps:

1. Send:AT
2. Send:AT+CMGF=1 (set the message to text format)
3. Send:AT+CMGS="XXXXX" (xxxx is the number of receiver )
4. After you see ‘<’ then send the message you want to say
5. press 'ctrl+z'(If you want to cancle,you can press Esc)

NOTE: Please do some settings as Recommended settings before connection.


If you have trouble sending Ctrl+Z, please refers to Ways to send Ctrl +Z in Coolterm

Then you will see

After several seconds,the receiver will get a message from this shield

Ways to send Ctrl +Z in Coolterm

1. After typing the message text, press enter key, it will show:
'Enter' after text finished

Then, in the input area, pressing Ctrl+Z will send out the single ctrl character successfully as be

After press Ctrl+Z

2. Ctrl characters can also be sent out in their hexadecimal format, in which form 1A is the value of Ctrl+Z:

Sending Ctrl+Z with in hexadecimal format

How to Make a phone call

Steps:

1. Send:AT
2. Send:ATDXXXXXXX;(xxxxxxx is the number of receiver,don't forget the ;)

Then you will see


After several seconds,the receiver will get a phone call from this shield

Some AT commands

ATH : Hang up the phone


ATA : Answer the phone

How to drive the GPS Mode via USB port

You should take the module outdoor, so that you can get the GPS datas

?
// Product name: GPS/GPRS/GSM Module V3.0
1 // # Product SKU : TEL0051
2 // # Version : 0.1
3
4 // # Description:
5 // # The sketch for driving the gps mode via the USB interface
6
7 // # Steps:
8 // # 1. Turn the S1 switch to the Prog(right side)
9 // # 2. Turn the S2 switch to the USB side(left side)
10// # 3. Plug the GSM/GPS jumper caps to the GSM side
11// # 4. Upload the sketch to the Arduino board(Make sure turn off other
12Serial monitor )
13// # 5. Turn the S1 switch to the comm(left side)
14// # 7. RST the board until the START led is on
15
16// # wiki link-
17http://www.dfrobot.com/wiki/index.php/GPS/GPRS/GSM_Module_V3.0_(SKU:TEL0051)
18
19voidsetup()
20 {
21 //Init the driver pins for GSM function
22 pinMode(3,OUTPUT);
23 pinMode(4,OUTPUT);
24 pinMode(5,OUTPUT);
25 //Output GSM Timing
26 digitalWrite(5,HIGH);
27 delay(1500);
28 digitalWrite(5,LOW);
29 }
30 voidloop()
31 {
32 digitalWrite(3,HIGH);//disable GSM TX、RX
33 digitalWrite(4,HIGH);//disable GPS TX、RX
}

Steps:

1. Send:AT
2. Send:AT+CGPSIPR=9600 (set the baud rate)
3. Send:AT+CGPSPWR=1 (turn on GPS power supply)
4. Send:AT+CGPSRST=1 (reset GPS in autonomy mode)

Then you can see


Plug the jumper caps back to the GPS side.Then you will see as the following
For location of the data received, please refer to Location Mapping (GPRMC)
(http://www.sanav.com/gps_tracking/webtrac-4/maps/MapLocationGPRMC.aspx)

How to drive the GSM Mode via Arduino board

How to Send a message

?
// Product name: GPS/GPRS/GSM Module V3.0
1
// # Product SKU : TEL0051
2
// # Version : 0.1
3
4
// # Description:
5
// # The sketch for driving the gsm mode via the Arduino board
6
7
// # Steps:
8
// # 1. Turn the S1 switch to the Prog(right side)
9
// # 2. Turn the S2 switch to the Arduino side(left side)
10
// # 3. Take off the GSM/GPS jumper caps from the Uart select
11
// # 4. Upload the sketch to the Arduino board
12
// # 5. Turn the S1 switch to the comm(left side)
13// # 6. Plug the jumper caps back to GSM side
14// # 7. RST the board
15
16// # wiki link-
17http://www.dfrobot.com/wiki/index.php/GPS/GPRS/GSM_Module_V3.0_(SKU:TEL0051)
18
19byte gsmDriverPin[3] = {
20 3,4,5};//The default digital driver pins for the GSM and GPS mode
21//If you want to change the digital driver pins
22//or you have a conflict with D3~D5 on Arduino board,
23//you can remove the J10~J12 jumpers to reconnect other driver pins for the module!
24voidsetup()
25{
26 //Init the driver pins for GSM function
27 for(inti = 0 ; i < 3; i++){
28 pinMode(gsmDriverPin[i],OUTPUT);
29 }
30 digitalWrite(5,HIGH);//Output GSM Timing
31 delay(1500);
32 digitalWrite(5,LOW);
33 digitalWrite(3,LOW);//Enable the GSM mode
34 digitalWrite(4,HIGH);//Disable the GPS mode
35 delay(2000);
36 Serial.begin(9600); //set the baud rate
37 delay(5000);//call ready
38 delay(5000);
39 delay(5000);
40}
41
42voidloop()
43{
44 Serial.println("AT"); //Send AT command
45 delay(2000);
46 Serial.println("AT");
47 delay(2000);
48 //Send message
49 Serial.println("AT+CMGF=1");
50 delay(1000);
51 Serial.println("AT+CMGS=\"15800449871\"");//Change the receiver phone number
52 delay(1000);
53 Serial.print("HELLO");//the message you want to send
54 delay(1000);
55 Serial.write(26);
56 while(1);
57}
You can see:

After several seconds,the receiver will get a message from this shield

How to Control your Arduino via SMS

Follow the forum discussion with more coding examples and options on this link Click Me!
(http://www.dfrobot.com/forum/index.php?topic=945.msg4514#msg4514)

?
// Product name: GPS/GPRS/GSM Module V3.0
// # Product SKU : TEL0051

// # Description:
// # The sketch for controling the GSM/GPRS/GPS module via SMS.
1
// # Steps:
2
// # 1. Turn the S1 switch to the Prog(right side)
3
// # 2. Turn the S2 switch to the USB side(left side)
4
// # 3. Plug the GSM/GPS jumper caps to the GSM side
5
// # 4. Upload the sketch to the Arduino board(Make sure turn off other
6
Serial monitor )
7
// # 5. Turn the S1 switch to the comm(left side)
8 // # 6. Turn the S2 switch to the Arduino(right side)
9 // # 7. RST the board until the START led is on(make sure you have >6V power
10supply)
11// # 8. Plug the long side of LED into pin 8 and short side into GND
12// # 9. Start sending "LH" and "LL" to your board to turn LED on and off.
13
14/*
15 * created: 2013-11-14
16 * by: Grey
17 * Version: 0.3
18 * Attention: if you send the wrong SMS command to the module, just need to press
19RST.
20 * This version can't watch the module status via the serial monitor, it only
21display the Arduino command.
22 * If you want to watch the status,use the SoftwareSerial or the board with another
23serial port plese.
24 */
25
26
27
28byte gsmDriverPin[3] = {
29 3,4,5};//The default digital driver pins for the GSM and GPS mode
30//If you want to change the digital driver pins
31//or you have a conflict with D3~D5 on Arduino board,
32//you can remove the J10~J12 jumpers to reconnect other driver pins for the module!
33intledpin = 8;
34charinchar;
35voidsetup()
36{
37 //Init the driver pins for GSM function
38 for(inti = 0 ; i < 3; i++){
39 pinMode(gsmDriverPin[i],OUTPUT);
40 }
41 pinMode(ledpin,OUTPUT);
42 Serial.begin(9600); //set the baud rate
43 digitalWrite(5,HIGH); //Output GSM Timing
44 delay(1500);
45 digitalWrite(5,LOW);
46 digitalWrite(3,LOW); //Enable the GSM mode
47 digitalWrite(4,HIGH); //Disable the GPS mode
48 delay(2000);
49 delay(5000); //call ready
50 delay(5000);
51 Serial.println("AT+CMGD=1,4"); //Delete all SMS in box
52}
53
54voidloop()
55{
56 if(Serial.available()>0)
57 {
58 inchar=Serial.read();
59 if(inchar=='T')
60 {
61 delay(10);
62 inchar=Serial.read();
63 if(inchar=='I') //When the GSM module get
64the message, it will display the sign '+CMTI "SM", 1' in the serial port
65 {
66 delay(10);
67 Serial.println("AT+CMGR=1"); //When Arduino read the
68sign, send the "read" AT command to the module
69 delay(10);
70 }
71 }
72 elseif(inchar=='L')
73 {
74 delay(10);
75 inchar=Serial.read();
76 if(inchar=='H') //Thw SMS("LH") was
77display in the Serial port, and Arduino has recognize it.
78 {
79 delay(10);
80 digitalWrite(ledpin,HIGH); //Turn on led
81 delay(50);
82 Serial.println("AT+CMGD=1,4"); //Delete all message
83 delay(500);
84 }
85 if(inchar=='L') //Thw SMS("LH") was display
86in the Serial port, and Arduino has recognize it.
87 {
88 delay(10);
89 digitalWrite(ledpin,LOW); //Turn off led
90 delay(50);
91 Serial.println("AT+CMGD=1,4"); //Delete all message
92 delay(500);
}
}
}
}
When you send the SMS "LH" to the module, it WILL turn led on; when you send the SMS "LL", it will be turned
off.

How to Make a phone call

?
// Product name: GPS/GPRS/GSM Module V3.0
1
// # Product SKU : TEL0051
2
// # Version : 0.1
3
4
// # Description:
5
// # The sketch for driving the gsm mode via the Arduino board
6
7
// # Steps:
8
// # 1. Turn the S1 switch to the Prog(right side)
9
// # 2. Turn the S2 switch to the Arduino side(left side)
10
// # 3. Take off the GSM/GPS jumper caps from the Uart select
11
// # 4. Upload the sketch to the Arduino board
12
// # 5. Turn the S1 switch to the comm(left side)
13
// # 6. Plug the jumper caps back to GSM side
14
// # 7. RST the board
15
16
// # wiki link-
17
http://www.dfrobot.com/wiki/index.php/GPS/GPRS/GSM_Module_V3.0_(SKU:TEL0051)
18
19
byte gsmDriverPin[3] = {
20
3,4,5};//The default digital driver pins for the GSM and GPS mode
21
//If you want to change the digital driver pins
22
//or you have a conflict with D3~D5 on Arduino board,
23
//you can remove the J10~J12 jumpers to reconnect other driver pins for the module!
24
25
voidsetup()
26
{
27
//Init the driver pins for GSM function
28
for(inti = 0 ; i < 3; i++){
29
pinMode(gsmDriverPin[i],OUTPUT);
30
}
31
digitalWrite(5,HIGH);//Output GSM Timing
32
delay(1500);
33
digitalWrite(5,LOW);
34
digitalWrite(3,LOW);//Enable the GSM mode
35
digitalWrite(4,HIGH);//Disable the GPS mode
36
delay(2000);
37
Serial.begin(9600); //set the baud rate
38
delay(5000);//call ready
39
40 delay(5000);
41 delay(5000);
42}
43
44voidloop()
45{
46 Serial.println("AT");//Send AT command
47 delay(2000);
48 Serial.println("AT");
49 delay(2000);
50 //Make a phone call
51 Serial.println("ATD15902808530;");//Change the receiver phone number
52 while(1);
}

You can see:

After several seconds,the receiver will get a phone call from this shield

How to drive the GPS Mode via Arduino board

?
// Product name: GPS/GPRS/GSM Module V3.0
// # Product SKU : TEL0051
1 // # Version : 0.1
2
3 // # Description:
4 // # The sketch for driving the gps mode via the Arduino board
5
6 // # Steps:
7 // # 1. Turn the S1 switch to the Prog(right side)
8 // # 2. Turn the S2 switch to the Arduino side(left side)
9 // # 3. Take off the GSM/GPS jumper caps from the Uart select
10 // # 4. Upload the sketch to the Arduino board
11 // # 5. Turn the S1 switch to the comm(left side)
12 // # 6. Remove the jumpers(old version) or set the UART select switch to
13 middle.
14 // # 7. RST the board
15
16 // # If you get 'inf' values, go outdoors and wait until it is connected.
17 // # wiki link-
18 http://www.dfrobot.com/wiki/index.php/GPS/GPRS/GSM_Module_V3.0_(SKU:TEL0051)
19
20 doubleDatatransfer(char*data_buf,charnum)//convert the data to the float type
21 { //*data_buf:the data
22 array
23 doubletemp=0.0; //the number of the right of a decimal
24 point
25 unsigned chari,j;
26
27 if(data_buf[0]=='-')
28 {
29 i=1;
30 //process the data array
31 while(data_buf[i]!='.')
32 temp=temp*10+(data_buf[i++]-0x30);
33 for(j=0;j<num;j++)
34 temp=temp*10+(data_buf[++i]-0x30);
35 //convert the int type to the float type
36 for(j=0;j<num;j++)
37 temp=temp/10;
38 //convert to the negative numbe
39 temp=0-temp;
40 }
41 else//for the positive number
42 {
43 i=0;
44
45 while(data_buf[i]!='.')
46 temp=temp*10+(data_buf[i++]-0x30);
47 for(j=0;j<num;j++)
48 temp=temp*10+(data_buf[++i]-0x30);
49 for(j=0;j<num;j++)
50 temp=temp/10 ;
51 }
52 returntemp;
53 }
54
55 charID()//Match the ID commands
56 {
57 chari=0;
58 charvalue[6]={
59 '$','G','P','G','G','A' };//match the gps protocol
60 charval[6]={
61 '0','0','0','0','0','0' };
62
63 while(1)
64 {
65 if(Serial.available())
66 {
67 val[i] = Serial.read();//get the data from the serial interface
68 if(val[i]==value[i]) //Match the protocol
69 {
70 i++;
71 if(i==6)
72 {
73 i=0;
74 return1;//break out after get the command
75 }
76 }
77 else
78 i=0;
79 }
80 }
81 }
82
83 voidcomma(charnum)//get ','
84 {
85 charval;
86 charcount=0;//count the number of ','
87
88 while(1)
89 {
90 if(Serial.available())
91 {
92 val = Serial.read();
93 if(val==',')
94 count++;
95 }
96 if(count==num)//if the command is right, run return
97 return;
98 }
99
100}
101voidUTC()//get the UTC data -- the time
102{
103 chari;
104 chartime[9]={
105 '0','0','0','0','0','0','0','0','0'
106 };
107 doublet=0.0;
108
109 if( ID())//check ID
110 {
111 comma(1);//remove 1 ','
112 //get the datas after headers
113 while(1)
114 {
115 if(Serial.available())
116 {
117 time[i] = Serial.read();
118 i++;
119 }
120 if(i==9)
121 {
122 i=0;
123 t=Datatransfer(time,2);//convert data
124 t=t+80000.00;//convert to the chinese time GMT+8 Time zone
125 Serial.println(t);//Print data
126 return;
127 }
128 }
129 }
130}
131voidlatitude()//get latitude
132{
133 chari;
134 charlat[10]={
135 '0','0','0','0','0','0','0','0','0','0'
136 };
137
138
139 if( ID())
140 {
141 comma(2);
142 while(1)
143 {
144 if(Serial.available())
145 {
146 lat[i] = Serial.read();
147 i++;
148 }
149 if(i==10)
150 {
151 i=0;
152 Serial.println(Datatransfer(lat,5),5);//print latitude
153 return;
154 }
155 }
156 }
157}
158voidlat_dir()//get dimensions
159{
160 chari=0,val;
161
162 if( ID())
163 {
164 comma(3);
165 while(1)
166 {
167 if(Serial.available())
168 {
169 val = Serial.read();
170 Serial.write(val);
171 Serial.println();
172 i++;
173 }
174 if(i==1)
175 {
176 i=0;
177 return;
178 }
179 }
180 }
181}
182voidlongitude()//get longitude
183{
184 chari;
185 charlon[11]={
186 '0','0','0','0','0','0','0','0','0','0','0'
187 };
188
189 if( ID())
190 {
191 comma(4);
192 while(1)
193 {
194 if(Serial.available())
195 {
196 lon[i] = Serial.read();
197 i++;
198 }
199 if(i==11)
200 {
201 i=0;
202 Serial.println(Datatransfer(lon,5),5);
203 return;
204 }
205 }
206 }
207}
208voidlon_dir()//get direction data
209{
210 chari=0,val;
211
212 if( ID())
213 {
214 comma(5);
215 while(1)
216 {
217 if(Serial.available())
218 {
219 val = Serial.read();
220 Serial.write(val); //Serial.println(val,BYTE);
221 Serial.println();
222 i++;
223 }
224 if(i==1)
225 {
226 i=0;
227 return;
228 }
229 }
230 }
231}
232voidaltitude()//get altitude data
233{
234 chari,flag=0;
235 charalt[8]={
236 '0','0','0','0','0','0','0','0'
237 };
238
239 if( ID())
240 {
241 comma(9);
242 while(1)
243 {
244 if(Serial.available())
245 {
246 alt[i] = Serial.read();
247 if(alt[i]==',')
248 flag=1;
249 else
250 i++;
251 }
252 if(flag)
253 {
254 i=0;
255 Serial.println(Datatransfer(alt,1),1);//print altitude data
256 return;
257 }
258 }
259 }
260}
261voidsetup()
262{
263 pinMode(3,OUTPUT);//The default digital driver pins for the GSM and GPS mode
264 pinMode(4,OUTPUT);
265 pinMode(5,OUTPUT);
266 digitalWrite(5,HIGH);
267 delay(1500);
268 digitalWrite(5,LOW);
269
270 digitalWrite(3,LOW);//Enable GSM mode
271 digitalWrite(4,HIGH);//Disable GPS mode
272 delay(2000);
273 Serial.begin(9600);
274 delay(5000);//GPS ready
275
276 Serial.println("AT");
277 delay(2000);
278 //turn on GPS power supply
279 Serial.println("AT+CGPSPWR=1");
280 delay(1000);
281 //reset GPS in autonomy mode
282 Serial.println("AT+CGPSRST=1");
283 delay(1000);
284
285 digitalWrite(4,LOW);//Enable GPS mode
286 digitalWrite(3,HIGH);//Disable GSM mode
287 delay(2000);
288
289 Serial.println("$GPGGA statement information: ");
290}
291voidloop()
292{
293 while(1)
294 {
295 Serial.print("UTC:");
296 UTC();
297 Serial.print("Lat:");
298 latitude();
299 Serial.print("Dir:");
300 lat_dir();
301 Serial.print("Lon:");
302 longitude();
303 Serial.print("Dir:");
304 lon_dir();
305 Serial.print("Alt:");
306 altitude();
307 Serial.println(' ');
Serial.println(' ');
}
}

GPS Sample Code


This code introduces some testing features and useful code. It's mainly coded for Leonardo devices using the
second serial port to handle GSM/GPS communications while USB serial port is left for debugging purposes. Data
from GPS is parsed and stored on variables to be used freely on your code.

?
1 /********************* start of gps_gsm_sim908.h ***********************/
2
3 /*
4 * by 2013-08-02
5 * test on Leonardo
6 * Serial1 to GPS
7 *
8 */
9
10 //debug
11 //#define DEBUG
12
13 #include <Arduino.h>
14
15
16 #define gps_enable() digitalWrite (4, LOW)
17 #define gps_disable() digitalWrite (4, HIGH)
18
19 #define gsm_enable() digitalWrite (3, LOW)
20 #define gsm_disable() digitalWrite (3, HIGH)
21
22 #define GPS_BUF_SIZE 500
23 #define GGA_NUM 15
24 #define RMC_NUM 14
25
26 //
27 char*gga_table[GGA_NUM] = {
28 "Message ID", //0
29 "UTC Time", //1
30 "Latitude", //2
31 "N/S Indicator", //3
32 "Longitude", //4
33 "E/W Indicator", //5
34 "Position Fix Indicator", //6
35 "Satellites Used", //7
36 "HDOP", //8
37 "MSL Altitude", //9
38 "Units(M)", //10
39 "Geoid Separation", //11
40 "Units", //12
41 "Diff.Ref.Station ID", //13
42 "Checksum", //14
43 };
44
45 //
46 char*gprmc_table[RMC_NUM] = {
47 "Message ID", //0
48 "UTC Time", //1
49 "Status", //2
50 "Latitude", //3
51 "N/S Indicator", //4
52 "Langitude", //5
53 "E/W Indicator", //6
54 "Speed Over Ground", //7
55 "Course Over Ground", //8
56 "Date", //9
57 "Magnetic Variation", //10
58 "East/West Indicator", //11
59 "Mode", //12
60 "Checksum", //13
61 };
62
63
64 //save data from GPS
65 uint8_t gps_buf[GPS_BUF_SIZE];
66
67 //save pointer of gga block
68 uint8_t* gga_p[GGA_NUM];
69 uint8_t* gprmc_p[RMC_NUM];
70
71 // check sum using xor
72 uint8_t checksum_xor (uint8_t *array, uint8_t leng) {
73 uint8_t sum = array[0];
74 for(uint8_t i=1; i<leng; i++) {
75 sum ^= array[i];
76 }
77 returnsum;
78 }
79
80
81 //
82 voidstart_gps () {
83 digitalWrite (5, HIGH);
84 delay (1500);
85 digitalWrite (5, LOW);
86 delay (1500);
87
88 gsm_enable ();
89 gps_disable ();
90
91 delay (2000);
92 #ifdef DEBUG
93 Serial.println ("waiting for GPS! ");
94 #endif
95
96 Serial1.println ("AT");
97 #ifdef DEBUG
98 Serial.println ("Send AT");
99 #endif
100 delay (1000);
101 Serial1.println ("AT+CGPSPWR=1");
102 #ifdef DEBUG
103 Serial.println ("Send AT+CGPSPWR=1");
104 #endif
105 delay (1000);
106 Serial1.println ("AT+CGPSRST=1");
107 #ifdef DEBUG
108 Serial.println ("Send AT+CGPSRST=1");
109 #endif
110 delay (1000);
111
112 gsm_disable ();
113 gps_enable ();
114
115 delay (2000);
116 #ifdef DEBUG
117 Serial.println ("$GPGGA statement information: ");
118 #endif
119}
120
121// read data to gps_buf[] from GPS
122staticintgps_read () {
123 uint32_t start_time = millis ();
124 while(!Serial1.available ()) {
125 if(millis() - start_time > 1500) {
126 #ifdef DEBUG
127 Serial.println ("restart GPS......");
128 #endif
129 start_gps ();
130 }
131 }
132 for(inti=0; i<GPS_BUF_SIZE; i++) {
133 delay (7);
134 if(Serial1.available ()) {
135 gps_buf [i] = Serial1.read ();
136 } else{
137 #ifdef DEBUG
138 Serial.print ("read ");
139 Serial.print (i);
140 Serial.println (" character");
141 #endif
142 return1;
143 }
144 }
145 #ifdef DEBUG
146 Serial.println ("error! data is so big!");
147 #endif
148 return0;
149}
150
151//test head of gps_buf[] if is "$GPGGA" or not
152staticintis_GPGGA () {
153 chargga_id[7] = "$GPGGA";
154 for(inti=0; i<6; i++)
155 if(gga_id[i] != gps_buf[i])
156 return0;
157 return1;
158}
159
160//
161staticuint8_t get_gga_leng () {
162 uint8_t l;
163 for(l=0; l<GPS_BUF_SIZE && gps_buf[l] != 0x0d ; l++);
164 returnl;
165}
166
167// build gga_p[] by gps_buf
168staticvoidbuild_gga_p () {
169 intp,b;
170 for(p=b=0; p<GGA_NUM && b<GPS_BUF_SIZE; p++,b++) {
171 gga_p[p] = (gps_buf+b);//
172 if(gps_buf[b] == ',')
173 continue;
174 for(b++; b<GPS_BUF_SIZE && gps_buf[b]!=','; b++);
175 }
176}
177
178//test if fix
179intgps_gga_is_fix (void) {
180 if(gga_p[6][0] == '1')
181 return1;
182 else
183 return0;
184}
185
186//get gga checksum
187staticuint8_t gps_gga_checksum () {
188 uint8_t sum = 0;
189 if(gga_p[14][0] != '*')
190 return0;
191 if(gga_p[14][2] >= '0'&& gga_p[14][2] <= '9')
192 sum = gga_p[14][2] - '0';
193 else
194 sum = gga_p[14][2] - 'A'+ 10;
195 if(gga_p[14][1] >= '0'&& gga_p[14][1] <= '9')
196 sum += (gga_p[14][1] - '0') * 16;
197 else
198 sum += (gga_p[14][1] - 'A'+ 10) * 16;
199 returnsum;
200}
201
202//check sum of gga
203staticintchecksum_gga () {
204 uint8_t sum = checksum_xor (gps_buf+1, get_gga_leng ()-4);
205 returnsum - gps_gga_checksum ();
206}
207
208// set gga, change ',' to '\0'
209staticvoidgps_gga_set_str () {
210 inti;
211 for(i=0; gps_buf[i] != 0x0d && i<GPS_BUF_SIZE; i++)
212 if(gps_buf[i] == ',')
213 gps_buf[i] = '\0';
214 //gps_buf[i] = '\0';
215}
216
217//
218intgps_get_gga (void) {
219 intstat = 0;
220 if(gps_read ()) {
221 if(is_GPGGA ()) {
222 build_gga_p (); // build *gga_p[] by gps_buf
223 gps_gga_set_str ();
224 if(checksum_gga () == 0)
225 stat = 0;
226 else
227 stat = 1;
228 } else
229 stat = 2;
230 } else
231 stat = 3;
232
233 returnstat;
234}
235
236
237//get UTC second
238uint8_t gps_gga_utc_ss () {
239 return(gga_p[1][4]-'0')*10+gga_p[1][5]-'0';
240}
241
242//get UTC minute
243uint8_t gps_gga_utc_mm () {
244 return(gga_p[1][2]-'0')*10+gga_p[1][3]-'0';
245}
246
247//get UTC hour
248uint8_t gps_gga_utc_hh () {
249 return(gga_p[1][0]-'0')*10+gga_p[1][1]-'0';
250}
251
252//return UTC Time string, hhmmss
253char* gps_gga_utc_s () {
254 return(char*)gga_p[1];
255}
256
257//get latitude
258doublegps_gga_lat () {
259 returnatof((char*)gga_p[2]);
260}
261
262//get latitude
263char* gps_gga_lat_s () {
264 return(char*)gga_p[2];
265}
266
267//get longitude
268doublegps_gga_long () {
269 returnatof((char*)gga_p[4]);
270}
271
272//get longitude
273char* gps_gga_long_s () {
274 return(char*)gga_p[4];
275}
276
277//get HDOP
278doublegps_gga_HDOP () {
279 returnatof((char*)gga_p[8]);
280}
281
282//get HDOP
283char* gps_gga_HDOP_s () {
284 return(char*)gga_p[8];
285}
286
287//get N/S
288char* gps_gga_NS () {
289 return(char*)gga_p[3];
290 /*
291 if (gga_p[3][0] == '\0')
292 return '0';
293 else if (gga_p[3][0] == 'N' || gga_p[3][0] == 'S')
294 return gga_p[3][0];
295 else
296 return '?';
297 */
298}
299
300//get E/W
301char* gps_gga_EW () {
302 return(char*)gga_p[5];
303 /*
304 if (gga_p[5][0] == '\0')
305 return '0';
306 else if (gga_p[5][0] == 'E' || gga_p[5][0] == 'W')
307 return gga_p[5][0];
308 else
309 return '?';
310 */
311}
312
313//
314doublegps_gga_MSL () {
315 returnatof((char*)gga_p[9]);
316}
317
318//
319char* gps_gga_MSL_s () {
320 return(char*)gga_p[9];
321}
322
323//get gpggpa Geoid Separation
324doublegps_gga_geoid_sep () {
325 returnatof((char*)gga_p[11]);
326}
327
328//get gpggpa Geoid Separation
329char* gps_gga_geoid_sep_s () {
330 return(char*)gga_p[11];
331}
332
333#ifdef DEBUG
334//
335voidgps_gga_print () {
336 for(inti=0; i<GPS_BUF_SIZE && gps_buf[i]!=0xd; i++)
337 Serial.print ((char)gps_buf[i]);
338 Serial.println ();
339}
340#endif
341
342/*
343void send_string (char* numble, char*string) {
344 char num_buf[25];
345 sprintf (num_buf, "AT+CMGS=\"%s\"", numble);
346 gsm_enable ();
347 gps_disable ();
348 delay (2000);
349 Serial1.println ("AT");
350 delay (200);
351 Serial1.println ("AT");
352 delay (200);
353 Serial1.println ("AT+CMGF=1");
354 delay (200);
355 Serial1.println (num_buf);
356 delay (200);
357 Serial1.println (string);
358 Serial1.write (26);
359}
360*/
361
362// set mobile numble
363voidgsm_set_numble (char*numble) {
364 charnum_buf[25];
365 sprintf(num_buf, "AT+CMGS=\"%s\"", numble);
366 gsm_enable ();
367 gps_disable ();
368 delay (2000);
369 Serial1.println ("AT");
370 delay (200);
371 Serial1.println ("AT");
372 delay (200);
373 Serial1.println ("AT+CMGF=1");
374 delay (200);
375 Serial1.println (num_buf);
376 delay (200);
377}
378
379// send message to mobile
380voidgsm_send_message (char*message) {
381 Serial1.println (message);
382}
383
384//
385voidgsm_end_send () {
386 Serial1.write (26);
387 delay (200);
388 gsm_disable ();
389 gps_enable ();
390 delay (2000);
391}
392
393
394//
395voidgps_init () {
396 pinMode (3, OUTPUT);
397 pinMode (4, OUTPUT);
398 pinMode (5, OUTPUT);
399
400}
401
402/********************* end of gps_gsm_sim908.h ***********************/

sample code with gps_gsm_sim908.h

?
1 /********************* start of sample code *************************/
2
3 /*
4 * created: 2013-08-02
5 * by: lisper ([email protected])
6 * Version: 0.1
7 * test gps gsm on Leonardo &XBEE R3
8 *
9 */
10
11 // #ifndef DEBUG
12 // #define DEBUG
13 // #endif
14
15 #include "gps_gsm_sim908.h"
16
17 //
18 voidsetup () {
19 gps_init (); //init GPS pin
20
21 #ifdef DEBUG
22 Serial.begin (9600); //serial0 connect computer
23 while(!Serial);
24 #endif
25
26 Serial1.begin (9600); //serial1 connect GPS
27 while(!Serial1);
28
29 #ifdef DEBUG
30 Serial.println ("start GPS! ");
31 #endif
32
33 start_gps (); //open GPS
34 }
35
36 //
37 voidloop () {
38 intstat = gps_get_gga (); // read data from GPS, return 0 is ok
39 #ifdef DEBUG
40 Serial.println ("gps_get_gga () return stat:");
41 Serial.println (stat); //for test
42 #endif
43
44 if(stat == 0 || stat == 1) {
45 if(gps_gga_is_fix ()) { //true if fix
46 //send_message ("18501683475", gps_gga_utc_s ());
47 gsm_set_numble ("18501683475"); //
48 gsm_send_message (gps_gga_utc_s ());
49 gsm_send_message (gps_gga_EW ());
50 gsm_send_message (gps_gga_NS ());
51 gsm_send_message (gps_gga_lat_s ());
52 gsm_send_message (gps_gga_long_s ());
53 gsm_end_send ();
54 while(1);
55 }
56 }
57
58 //
59 switch(stat) {
60 case0:
61 #ifdef DEBUG
62 Serial.println ("data checksum is ok");
63 #endif
64 break;
65 case1:
66 #ifdef DEBUG
67 Serial.println ("GPGGA ID is error!");
68 #endif
69 break;
70 case2:
71 #ifdef DEBUG
72 Serial.println ("data is error!");
73 #endif
74 break;
75 }
76
77 #ifdef DEBUG
78 Serial.println ("$GPGGA data:");
79 gps_gga_print (); //for test
80 #endif
81
82
83
84 /*
85 if (gps_gga_is_fix () == 0) //check if is fix
86 Serial.println ("can't fix! please go outside!");
87 else {
88 Serial.println ("ok! is fix!");
89
90 Serial.println ("gps_gga_utc_hh ()");
91 Serial.println (gps_gga_utc_hh ());
92 Serial.println ("gps_gga_utc_mm ()");
93 Serial.println (gps_gga_utc_mm ());
94 Serial.println ("gps_gga_utc_ss ()");
95 Serial.println (gps_gga_utc_ss ());
96
97 Serial.println ("gps_gga_NS ()");
98 Serial.println (gps_gga_NS (), 6);
99 Serial.println ("gps_gga_EW ()");
100 Serial.println (gps_gga_EW (), 6);
101
102 Serial.println ("gps_gga_lat ()");
103 Serial.println (gps_gga_lat (), 6);
104 Serial.println ("gps_gga_long ()");
105 Serial.println (gps_gga_long (), 6);
106 Serial.println ("gps_gga_HDOP ()");
107 Serial.println (gps_gga_HDOP (), 6);
108 Serial.println ("gps_gga_MSL ()");
109 Serial.println (gps_gga_MSL (), 6);
110 Serial.println ();
111 }
112 */
113}
114
115
116/********************* end of sample code *************************/

Trouble shooting
Check external battery power levels, the shield needs extra power.
Check signal range, best to be on an area with full coverage.
Signal for GPS has best performance on a clear direct line of sight with sky, even better with less buildings
around.
GPS needs time to connect to at least 4 satellites to output data.

AT command tester by one of our contributors.


(http://www.dfrobot.com/wiki/index.php/AT_command_tester)

Version history
GPS/GPRS/GSM Module V2.0 (SKU:TEL0051)
(http://www.dfrobot.com/wiki/index.php/GPS/GPRS/GSM_Module_V2.0_(SKU:TEL0051))

Go Shopping GPS/GPRS/GSM Shield V3.0 (Arduino Compatible)(SKU:TEL0051)


(http://www.dfrobot.com/index.php?route=product/product&filter_name=gps&product_id=673)

Retrieved from "http://www.dfrobot.com/wiki/index.php?


title=GPS/GPRS/GSM_Module_V3.0_(SKU:TEL0051)&oldid=26181"
Categories: Product Manual TEL Series Shield

This page was last modified on 10 March 2014, at 12:41.


This page has been accessed 19,272 times.

You might also like