Difference between revisions of "GPRS GSM GPS Shield (SIMCOME- SIM808)"

From MakerFabsWiki
Jump to: navigation, search
(Interface Function)
(Usage)
Line 65: Line 65:
 
[[File:GPRS GSM GPS Shield (SIMCOME- SIM808) USB.jpg|500px]]<br>
 
[[File:GPRS GSM GPS Shield (SIMCOME- SIM808) USB.jpg|500px]]<br>
 
⑤ Power on the SIM808 shield by the POWER_KEY ( sometime you can control it by the software control ( Arduino D9 PIN))<br>
 
⑤ Power on the SIM808 shield by the POWER_KEY ( sometime you can control it by the software control ( Arduino D9 PIN))<br>
 
== Usage ==
 
=== Hardware installation ===
 
 
==== 1.Insert an Micro SIM card to SIM Card Holder ====
 
6 Pin Holder for SIM Cards. Both 1.8 volts and 3.0 volts SIM Cards are supported by SIM808 - the SIM card voltage type is automatically detected.<BR>
 
[[File:Inserting the SIM Card into the holder4.jpg |500px]] [[File:Inserting the SIM Card into the holder3.jpg |500px]]
 
 
====2.Connect the Antenna====
 
A miniature coaxial RF connector is present on the SIM808 GPRS/GSM+GPS Shield board to connect with a GSM Antenna. The connector present on the SIM808 GPRS/GSM+GPS Shield is called a [http://en.wikipedia.org/wiki/Hirose_U.FL U.FL connecto].The GSM Antenna supplied with the GPRS Shield has an [http://en.wikipedia.org/wiki/SMA_connector SMA connector] (and not an RP-SMA connector) on it.The connection topology is shown in the diagram below:<br>
 
[[File:GPRS+GSM+GPS Shield antenna pad2.jpg|850px]]  [[File:GPRS+GSM+GPS Shield antenna pad3.jpg|800px]]
 
<br>
 
 
====3.Plug to Arduino/Crowduino====
 
The GPRS+GSM+GPS Shield, like any other well designed shield, is stackable as shown in the photo below.<BR>
 
[[File:Plug SIM808 GPRS GSM+GPS to arduino.jpg|800px]]
 
 
====Turn on the SIM808 GPRS/GSM+GPS shield ====
 
There is two ways to turn on the SIM808 GPRS/GSM+GPS Shield.<BR>
 
1. Turn on through Hardware. Press the the 'POWERKEY' for few seconds until Power-on indicator(Green) is on.<br>
 
[[File:GPRS+GSM+GPS PowerKEY.jpg|800px|POWERONkey]] <br>
 
2. Turn on through Software. If the JP is soldered,run the following code, the SIM808 will POWER on or POWER off.<br>
 
<pre>
 
int Powerkey = 9;
 
void setup() {               
 
  pinMode(Powerkey, OUTPUT);  // initialize the digital pin as an output. 
 
  power();                    //power on the sim808 or power down the sim808
 
}
 
void loop()
 
{
 
 
}
 
 
void power(void)
 
{
 
  digitalWrite(Powerkey, LOW);
 
  delay(1000);              // wait for 1 second
 
  digitalWrite(Powerkey, HIGH);
 
}
 
</pre>
 
 
====Serial Port(UART) Communication====
 
The SIM808 GPRS/GSM+GPS Shield is used UART protocol to communicate with an Arduino/Arduino clone; Users can use jumpers to connect (RX,TX) of the shield to either Software Serial(D8,D7) or Hardware Serial(D1,D0) of the Arduino.Detailed information is showed as the following picture:
 
[[File:Coms1.jpg|frame|center]]
 
<center>'''Selectalbe GPRS+GSM+GPS Shield Communication Port'''</center>
 
 
=== Power Down the GPRS Shield  ===
 
The GPRS Shield can be turned off by following ways:
 
*<font color="red">'''1, Normal power down procedure''':</font> Turn off the GPRS shield by using '''Hardware Triger'''; Press the '''ON/OFF Button''' about <font color="red">one seconds</font>. 
 
[http://www.magicmeshoffer.com magic mesh] The power down scenarios illustrates as following figure:
 
[[File:ONd.jpg|800px|center]]
 
<center>'''Figure of Timing of turning off GPRS Shield using Hardware Triger'''</center>
 
*<font color="red">'''2, Normal power down procedure''':</font> If <font color="red">JP</font> is soldered, then give <font color="red">Digital Pin 9</font>  of the Arduino(act as Software Triger) a Turn off Impulse can turn off the GPRS Shield. The power down scenarios illustrates as following figure:
 
[[File:Pwrd.jpg|800px|center]]
 
<center>'''Figure of Timing of turning off GPRS Shield using Software Triger'''</center>
 
<font color="red">The following code is power down subroutine for Arduino if using software triger:</font>
 
 
<pre>
 
int Powerkey = 9;
 
void setup() {               
 
  pinMode(Powerkey, OUTPUT);  // initialize the digital pin as an output. 
 
  power();                    //power on the sim808 or power down the sim808
 
}
 
void loop()
 
{
 
 
}
 
 
void power(void)
 
{
 
  digitalWrite(Powerkey, LOW);
 
  delay(1000);              // wait for 1 second
 
  digitalWrite(Powerkey, HIGH);
 
}
 
</pre>
 
 
 
*<font color="red">'''3, Normal power down procedure''':</font> Turn off the GPRS shield by sending AT command '''"AT+CPOWD=1"''' to SIM808 module.
 
 
When GPRS Shield power dowm in '''Normal power down procedure''', the procedure lets the SIM808 log off from the network and allows the software to enter into a secure state and save data before completely disconnecting the power supply. Before the completion of the power down procedure the SIM808 will send out result code:
 
 
'''NORMAL POWER DOWN'''
 
 
*<font color="red">'''4, Over-voltage or Under-voltage Power Down''':</font> The module software monitors VBAT voltage constantly.
 
①If the voltage ≤ 3.5V, the following URC will be reported:
 
 
'''UNDER-VOLTAGE WARNNING'''
 
 
②If the voltage ≥ 4.3V, the following URC will be reported:
 
 
'''OVER-VOLTAGE WARNNING'''
 
 
③If the voltage < 3.4V, the following URC will be reported,and the module will be automativally powered down.
 
 
'''UNDER-VOLTAGE POWER DOWN'''
 
 
④If the voltage > 4.4V, the following URC will be reported,and the module will be automativally powered down.
 
 
'''OVER-VOLTAGE POWER DOWN'''
 
 
*<font color="red">'''5, Over-temperature or Under-temperature Power Down''':</font> SIM900 will constantly monitor the temperature of the module.
 
①If the temperature > +80℃, the following URC will be reported:
 
 
'''+CMTE:1'''
 
 
②If the temperature < -30℃, the following URC will be reported:
 
 
'''+CMTE:-1'''
 
 
③If the temperature > +85℃, the following URC will be reported,and the module will be automativally powered down.
 
 
'''+CMTE:2'''
 
 
④If the temperature < -40℃, the following URC will be reported,and the module will be automativally powered down.
 
 
'''+CMTE:-2'''
 
 
When the GPRS Shield encounters POWER DOWN scenario, the AT commands can not be executed. The SIM808 logs off from network and enters the <font color="red">POWER DOWN mode</font>, only the RTC is still active. POWER DOWN can also be indicated by STATUS LED(<font color="blue">Blue</font>), which is off in this mode.
 
 
<font color="red">
 
Note:
 
*To monitor the temperature, users can use the “'''AT+CMTE'''” command to read the temperature when GPRS Shield is powered on.
 
</font>
 
 
=== Upload Sketch to Arduino ===
 
 
[[File:Grpsaurduinouart1.jpg|600px|center]]
 
 
<center>'''Data Stream among Computer, Arduino and GPRS Shield'''</center>
 
 
The following sketch configures Arduino/Arduino clone as serial link between PC and the GPRS Shield<font color="red">(Jumpers on SWserial side)</font>. PC would need a serial terminal software to communicate with it - Window's built-in HyperTerminal, Arduino IDE's Serial Monitor, [http://musicshield.googlecode.com/files/sscom32E.exe Serial Terminals(sscom32)] or [http://sites.google.com/site/terminalbpp/ Bray++ Terminal].
 
 
After uploading the sketch to the Arduino board, press the ON/OFF button on the GPRS Shield to turn it on; Now you can see what you get on the serial terminal and the status of the three indicator LEDs, then communicate with your Shield.
 
<pre>
 
//Serial Relay - Arduino will patch a
 
//serial link between the computer and the GPRS Shield
 
//at 19200 bps 8-N-1
 
//Computer is connected to Hardware UART
 
//GPRS Shield is connected to the Software UART
 
 
#include <SoftwareSerial.h>
 
 
SoftwareSerial GSMSerial(7, 8);
 
 
void setup()
 
{
 
GSMSerial.begin(19200);              // the GPRS/GSM baud rate 
 
Serial.begin(19200);                // the GPRS/GSM baud rate 
 
}
 
 
void loop()
 
{
 
if(Serial.available())
 
 
GSMSerial.print((char)Serial.read());
 
 
else  if(GSMSerial.available())
 
 
Serial.print((char)GSMSerial.read());
 
}
 
</pre>
 
 
[[File:SIM808 gprs gsm shield AT.jpg |500px]]<br>
 
<font color="red">
 
Note:
 
*The "AT" or "at" prefix must be set at the beginning of each Command line. To terminate a Command line enter <CR>.
 
</font>
 
 
 
==== Set Baud and Enable Charging Function ====
 
It is recommended to execute this process when first time to use the module. In the Serial Monitor columns of following tables, input of AT commands are in back, module returns values are in orange.
 
{| class="wikitable" cellpadding="0"
 
! scope="col" width="50" | Serial Monitor
 
! scope="col" width="100" | Description
 
|-
 
| AT <br /><span style="color: rgb(242,133,0)">OK</span> || Send command “AT” to synchronize baud rate. Serial port of module is by default set at auto-baud mode, and in this mode, it will not output any indications when the module is on.
 
|-
 
| AT+IPR=9600<br /><span style="color: rgb(242,133,0)">OK</span>|| Set baud rate at 9600bps, supports baud rate from 1200bps to 115200bps.
 
|-
 
| AT+ECHARGE=1<br /><span style="color: rgb(242,133,0)">OK</span>|| Send command “AT+ECHARGE=1” to enable battery charging function. By default the charging function is closed.
 
|-
 
| AT&W<br /><span style="color: rgb(242,133,0)">OK</span>|| Save parameter setting.
 
|-
 
| AT+CPOWD=1<br /><span style="color: rgb(242,133,0)">NORMAL POWER DOWN</span>||Power down the module.
 
|-
 
| <span style="color: rgb(242,133,0)">RDY<br />+CFUN: 1<br />GPS Ready<br />+CPIN: READY<br />Call Ready<br />SMS Ready</span>||Turn on the module again by the power button, it will response status about GPS and GSM.
 
|-
 
| AT+CBC<br /><span style="color: rgb(242,133,0)"> +CBC: 1,96,4175 <br /> OK</span>||Inquire charging status and remaining battery capacity.
 
|-
 
| AT+CSQ <br /><span style="color: rgb(242,133,0)"> +CSQ: 14,0 <br /> OK</span>||Inquire GSM signal quality.
 
|-
 
|}
 
 
==== GNSS AT Command ====
 
 
{| class="wikitable" cellpadding="0"
 
! scope="col" width="11" | AT Command
 
! scope="col" width="700" | Description
 
|-
 
| AT+CGNSPWR || GNSS power conntrol
 
|-
 
| AT+CGNSSEQ || Define the last NMEA sentence that paresed
 
|-
 
| AT+CGNSINF || GNSS navigation information parsed from NMEA sentences
 
|-
 
| AT+CGNSURC || GNSS navigation, GEO-fences and speed alarm URC report 
 
|-
 
| AT+CGNSCMD || Send command to GNSS
 
|-
 
| AT+CGNSTST || Send data received from GNSS to AT UART
 
|-
 
|}
 
 
More information you can refer the [http://www.elecrow.com/wiki/index.php?title=File:SIM800_Series_GNSS_Application_Note_V1.00.pdf SIM800 Series_GNSS_Application Note V1.00].
 
 
=== Examples ===
 
==== Sending SMS: using Software UART  ====
 
<pre>
 
 
#include <SoftwareSerial.h>
 
 
SoftwareSerial mySerial(7, 8);
 
 
void setup()
 
{
 
mySerial.begin(19200);  //Default serial port setting for the GPRS modem is 19200bps 8-N-1
 
mySerial.print("\r");
 
delay(1000);                    //Wait for a second while the modem sends an "OK"
 
mySerial.print("AT+CMGF=1\r");    //Because we want to send the SMS in text mode
 
delay(1000);
 
 
//mySerial.print("AT+CSCA=\"+919032055002\"\r");  //Setting for the SMS Message center number, 
 
//delay(1000);                                  //uncomment only if required and replace with
 
//the message center number obtained from
 
//your GSM service provider.
 
//Note that when specifying a tring of characters
 
// " is entered as \"
 
 
mySerial.print("AT+CMGS=\"+9184460xxxx\"\r");    //Start accepting the text for the message
 
//to be sent to the number specified.
 
//Replace this number with the target mobile number.
 
delay(1000);
 
mySerial.print("Hello,Elecrow!\r");  //The text for the message
 
delay(1000);
 
mySerial.write(0x1A);  //Equivalent to sending Ctrl+Z
 
}
 
 
void loop()
 
{
 
//We just want to send the SMS only once, so there is nothing in this loop.
 
//If we put the code for SMS here, it will be sent again and again and cost us a lot.
 
}
 
</pre>
 
==== Making a call: using Software UART  ====
 
<pre>
 
 
#include <SoftwareSerial.h>
 
 
SoftwareSerial mySerial(7, 8);
 
 
void setup()
 
{
 
mySerial.begin(19200);              // the GPRS baud rate 
 
Serial.begin(19200);              // the GPRS baud rate 
 
delay(2000);
 
mySerial.println("ATDxxxxxxxxx;"); // xxxxxxxxx is the number you want to dial. 
 
 
if(mySerial.available())
 
 
Serial.print((unsigned char)mySerial.read());
 
 
 
delay(10000);
 
delay(10000);
 
 
mySerial.println("ATH"); //End the call.
 
if(mySerial.available())
 
 
Serial.print((unsigned char)mySerial.read());
 
}
 
 
 
void loop()
 
{
 
//Do nothing
 
}
 
</pre>
 
==== Using AT Commands to Control GPIO and PWM pins ====
 
<font color="red">
 
Note: GPIOs,PWMs and ADC of the SIM808 module are all 2V8 logic.
 
</font>
 
<pre>
 
#include <SoftwareSerial.h>
 
 
SoftwareSerial mySerial(7, 8);
 
 
void setup()
 
{
 
mySerial.begin(19200);              // the GPRS baud rate 
 
delay(2000);
 
}
 
 
void loop()
 
{
 
mySerial.println("AT+SPWM=0,63,100");// set PWM 1 PIN
 
 
mySerial.println("AT+SGPIO=0,2,1,1");// set GPIO 5 PIN to 1
 
mySerial.println("AT+SGPIO=0,3,1,1");// set GPIO 6 PIN to 1
 
delay(1000); 
 
 
mySerial.println("AT+SGPIO=0,2,1,0");// set GPIO 5 PIN to 0
 
mySerial.println("AT+SGPIO=0,3,1,0");// set GPIO 6 PIN to 0
 
delay(1000);   
 
}
 
</pre>
 
 
=== A Simple Source Code Example ===
 
The demo code below is for the Xduino to send SMS message/dial a voice call/submit a http request to a website and upload datas to the pachube. It has been tested on Arduino Duemilanove but will work on any compatible variant, plesse note that this sketch uses the sorfware UART of ATmega328P. please follow the following steps for running this sketch.
 
# With the GPRS Shield removed, download this sketch into your Arduino.
 
# Disconnect the Xduino from USB port to remove power source.
 
# Set the Serial Port jumpers on the GPRS Shield in SWserial position, to use the Soft Serial port of Arduino.
 
# Connect the antenna to the GPRS Shield and insert the SIM Card.
 
# Mount the GPRS Shield on Arduino.
 
# Connect the Arduino to the computer by USB, and fire up your favorite serial terminal software on computer, choose the COM port for Arduino, set it to operate at 19200 8-N-1.
 
# Type command in the terminal to execute different function, threr are 4 functions in the demo:
 
##If you input 't', the demo will send a SMS message to another cellphone which you set(you need set the number in the code);
 
## If you input 'd', the program  will dial a call to the other cellphone that you set(it is also need you set in the code );
 
## If you input 'h', it will submit a http request to a web that you want to access(it need you set the web adress in the code), it will return a string from the website if it goes correctly;
 
## If you input 's', it will upload the datas to the pachube(for detail you can refer to the explanation in the code). I strongly recommend you input 'h' before input 's', because uploading datas to the pachube need do some setting, after execute the function of submit a http request, the setting will be set.
 
# If the program returns error in the terminal after you typed the command, don't worry, just try input the command again.
 
<br>
 
<pre>
 
/*Note: this code is a demo for how to using gprs shield to send sms message, dial a voice call and
 
send a http request to the website, upload data to pachube.com by TCP connection,
 
 
The microcontrollers Digital Pin 7 and hence allow unhindered
 
communication with GPRS Shield using SoftSerial Library.
 
IDE: Arduino 1.0 or later
 
Replace the following items in the code:
 
1.Phone number, don't forget add the country code
 
2.Replace the Access Point Name
 
3. Replace the Pachube API Key with your personal ones assigned
 
to your account at cosm.com
 
* Modified by keen
 
* Date: 18/03/2017
 
* Note: Only fix bug
 
*/
 
 
 
#include <SoftwareSerial.h>
 
#include <String.h>
 
 
SoftwareSerial mySerial(7, 8);
 
 
void setup()
 
{
 
mySerial.begin(19200);              // the GPRS baud rate 
 
Serial.begin(19200);    // the GPRS baud rate
 
delay(500);
 
}
 
 
void loop()
 
{
 
//after start up the program, you can using terminal to connect the serial of gprs shield,
 
//if you input 'q' in the terminal, the program will execute  GetSignalQuality(),it will show the signal quality,
 
//if you input 't' in the terminal, the program will execute SendTextMessage(), it will show how to send a sms message,
 
//if input 'd' in the terminal, it will execute DialVoiceCall(), etc.
 
 
if (Serial.available())
 
switch(Serial.read()){
 
 
case 'q':
 
GetSignalQuality();
 
break;
 
case 't':
 
SendTextMessage();
 
break;
 
case 'd':
 
DialVoiceCall();
 
break;
 
case 'h':
 
SubmitHttpRequest();
 
break;
 
case 's':
 
Send2Pachube();
 
break;
 
}
 
if (mySerial.available())
 
Serial.write(mySerial.read());
 
}
 
///GetSignalQuality()
 
///get the signal quality of GSM model.
 
void GetSignalQuality(){
 
    String response = "";
 
    long int time = millis(); 
 
    Serial.println("Getting the sinal quality...");
 
    Serial.println("Tips:+CSQ: XX,QQ : It means the Signal Quality poorly when the XX is '99'!");
 
    mySerial.println("AT+CSQ");   
 
    while( (time+2000) > millis()){
 
        while(mySerial.available()){     
 
          response += char(mySerial.read());
 
        } 
 
      }   
 
      Serial.print(response);   
 
}
 
 
///SendTextMessage()
 
///this function is to send a sms message
 
void SendTextMessage()
 
{
 
mySerial.print("\r");
 
delay(1000);                    //Wait for a second while the modem sends an "OK"
 
mySerial.print("AT+CMGF=1\r");    //Because we want to send the SMS in text mode
 
delay(1000);
 
mySerial.print("AT+CMGS=\"+8613760419846\"\r");    //Start accepting the text for the message
 
//to be sent to the number specified.
 
//Replace this number with the target mobile number.
 
delay(1000);
 
mySerial.print("Hello,Elecrow!\r");  //The text for the message
 
delay(1000);
 
mySerial.write(0x1A);  //Equivalent to sending Ctrl+Z
 
}
 
 
///DialVoiceCall
 
///this function is to dial a voice call
 
void DialVoiceCall()
 
{
 
mySerial.println("ATD + +8613760419846;");//dial the number
 
delay(100);
 
mySerial.println();
 
}
 
 
///SubmitHttpRequest()
 
///this function is submit a http request
 
///attention:the time of delay is very important, it must be set enough
 
void SubmitHttpRequest()
 
{
 
mySerial.println("AT+CSQ");
 
delay(100);
 
 
ShowSerialData();// this code is to show the data from gprs shield, in order to easily see the process of how the gprs shield submit a http request, and the following is for this purpose too.
 
 
mySerial.println("AT+CGATT?");
 
delay(100);
 
 
ShowSerialData();
 
 
mySerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");//setting the SAPBR, the connection type is using gprs
 
delay(1000);
 
 
ShowSerialData();
 
 
mySerial.println("AT+SAPBR=3,1,\"APN\",\"CMNET\"");//setting the APN, the second need you fill in your local apn server
 
delay(4000);
 
 
ShowSerialData();
 
 
mySerial.println("AT+SAPBR=1,1");//setting the SAPBR, for detail you can refer to the AT command mamual
 
delay(5000);
 
 
ShowSerialData();
 
 
mySerial.println("AT+HTTPINIT"); //init the HTTP request
 
 
delay(3000);
 
ShowSerialData();
 
 
mySerial.println("AT+HTTPPARA=\"URL\",\"www.google.com.hk\"");// setting the httppara, the second parameter is the website you want to access
 
delay(3000);
 
 
ShowSerialData();
 
 
mySerial.println("AT+HTTPACTION=0");//submit the request
 
delay(10000);//the delay is very important, the delay time is base on the return from the website, if the return datas are very large, the time required longer.
 
//while(!mySerial.available());
 
 
ShowSerialData();
 
 
mySerial.println("AT+HTTPREAD");// read the data from the website you access
 
delay(300);
 
 
ShowSerialData();
 
 
mySerial.println("");
 
delay(100);
 
}
 
 
///send2Pachube()///
 
///this function is to send the sensor data to the pachube, you can see the new value in the pachube after execute this function///
 
void Send2Pachube()
 
{
 
mySerial.println("AT+CGATT?");
 
delay(100);
 
 
ShowSerialData();
 
 
mySerial.println("AT+CSTT=\"CMNET\"");//start task and setting the APN,
 
delay(1000);
 
 
ShowSerialData();
 
 
mySerial.println("AT+CIICR");//bring up wireless connection
 
delay(300);
 
 
ShowSerialData();
 
 
mySerial.println("AT+CIFSR");//get local IP adress
 
delay(2000);
 
 
ShowSerialData();
 
 
mySerial.println("AT+CIPSPRT=0");
 
delay(3000);
 
 
ShowSerialData();
 
 
mySerial.println("AT+CIPSTART=\"tcp\",\"api.cosm.com\",\"8081\"");//start up the connection
 
delay(2000);
 
 
ShowSerialData();
 
 
mySerial.println("AT+CIPSEND");//begin send data to remote server
 
delay(8000);
 
ShowSerialData();
 
String humidity = "1031";//these 4 line code are imitate the real sensor data, because the demo did't add other sensor, so using 4 string variable to replace.
 
String moisture = "1242";//you can replace these four variable to the real sensor data in your project
 
String temperature = "30";//
 
String barometer = "60.56";//
 
mySerial.print("\"method\": \"put\",\"resource\": \"/feeds/43634/\",\"params\"");//here is the feed you apply from pachube
 
delay(500);
 
ShowSerialData();
 
mySerial.print(": ,\"headers\": \"X-PachubeApiKey\":");//in here, you should replace your pachubeapikey
 
delay(500);
 
ShowSerialData();
 
mySerial.print(" \"_cXwr5LE8qW4a296O-cDwOUvfddFer5pGmaRigPsiO0");//pachubeapikey
 
delay(500);
 
ShowSerialData();
 
mySerial.print("jEB9OjK-W6vej56j9ItaSlIac-hgbQjxExuveD95yc8BttXc");//pachubeapikey
 
delay(500);
 
ShowSerialData();
 
mySerial.print("Z7_seZqLVjeCOmNbEXUva45t6FL8AxOcuNSsQS\",\"body\":");
 
delay(500);
 
ShowSerialData();
 
mySerial.print(" \"version\": \"1.0.0\",\"datastreams\": ");
 
delay(500);
 
ShowSerialData();
 
mySerial.println("[\"id\": \"01\",\"current_value\": \"" + barometer + "\",");
 
delay(500);
 
ShowSerialData();
 
mySerial.println("\"id\": \"02\",\"current_value\": \"" + humidity + "\",");
 
delay(500);
 
ShowSerialData();
 
mySerial.println("\"id\": \"03\",\"current_value\": \"" + moisture + "\",");
 
delay(500);
 
ShowSerialData();
 
mySerial.println("\"id\": \"04\",\"current_value\": \"" + temperature + "\"],\"token\": \"lee\"");
 
 
 
delay(500);
 
ShowSerialData();
 
 
mySerial.println((char)26);//sending
 
delay(5000);//waitting for reply, important! the time is base on the condition of internet
 
mySerial.println();
 
 
ShowSerialData();
 
 
mySerial.println("AT+CIPCLOSE");//close the connection
 
delay(100);
 
ShowSerialData();
 
 
}
 
void ShowSerialData()
 
{
 
while(mySerial.available()!=0)
 
Serial.write(mySerial.read());
 
}
 
</pre>
 
<br clear="all">
 
 
&nbsp;
 
 
=== Using Sms to Control an LED Status ===
 
 
This example is controbuted by MChobby, for more information please visit: http://mchobby.be/wiki/index.php?title=SmsCommand
 
 
Send a SMS message "on" or "off" from your cellphone to the GPRS Shield to control the Digital Pin 13(LED) Status.
 
<font color="red">
 
 
* The default Buffer of Rx in SoftwareSerial.h is 32/64, you may experience some data lose while the returns of SIM808 are many(Receiving SMS/TCPIP), you can try to change the Buffer of Rx in SoftwareSerial.h into
 
'''#define _SS_MAX_RX_BUFF''' ''128'' // RX buffer size
 
 
</font>
 
 
<pre>
 
 
#include <SoftwareSerial.h>
 
 
SoftwareSerial mySerial(7, 8);
 
 
// EN: String buffer for the GPRS shield message
 
 
String msg = String("");
 
// EN: Set to 1 when the next GPRS shield message will contains the SMS message
 
 
int SmsContentFlag = 0;
 
 
// EN: Pin of the LED to turn ON and OFF depending on the received message
 
 
int ledPin = 13;
 
 
// EN: Code PIN of the SIM card (if applied)
 
 
//String SIM_PIN_CODE = String( "XXXX" );
 
 
void setup()
 
{
 
  mySerial.begin(19200);              // the GPRS baud rate 
 
  Serial.begin(19200);                // the GPRS baud rate
 
 
  // Initialize la PIN
 
  pinMode( ledPin, OUTPUT );
 
  digitalWrite( ledPin, LOW );
 
}
 
 
void loop()
 
{
 
    char SerialInByte;
 
 
    if(Serial.available())
 
    {
 
      mySerial.print((unsigned char)Serial.read());
 
    } 
 
    else  if(mySerial.available())
 
    {
 
        char SerialInByte;
 
        SerialInByte = (unsigned char)mySerial.read();
 
 
        // EN: Relay to Arduino IDE Monitor
 
 
 
        Serial.print( SerialInByte );
 
 
        // -------------------------------------------------------------------
 
        // EN: Program also listen to the GPRS shield message.
 
 
 
        // -------------------------------------------------------------------
 
 
        // EN: If the message ends with <CR> then process the message
 
     
 
        if( SerialInByte == 13 ){
 
          // EN: Store the char into the message buffer
 
       
 
          ProcessGprsMsg();
 
        }
 
        if( SerialInByte == 10 ){
 
            // EN: Skip Line feed
 
 
        }
 
        else {
 
          // EN: store the current character in the message string buffer
 
 
          msg += String(SerialInByte);
 
        }
 
    } 
 
}
 
 
// EN: Make action based on the content of the SMS.
 
//    Notice than SMS content is the result of the processing of several GPRS shield messages.
 
 
void ProcessSms( String sms ){
 
  Serial.print( "ProcessSms for [" );
 
  Serial.print( sms );
 
  Serial.println( "]" );
 
 
  if( sms.indexOf("on") >= 0 ){
 
    digitalWrite( ledPin, HIGH );
 
    Serial.println( "LED IS ON" );
 
    return;
 
  }
 
  if( sms.indexOf("off") >= 0 ){
 
    digitalWrite( ledPin, LOW );
 
    Serial.println( "LED IS OFF" );
 
    return;
 
  }
 
}
 
 
// EN: Send the SIM PIN Code to the GPRS shield
 
 
//void GprsSendPinCode(){
 
//  if( SIM_PIN_CODE.indexOf("XXXX")>=0 ){
 
//    Serial.println( "*** OUPS! you did not have provided a PIN CODE for your SIM CARD. ***" );
 
//    Serial.println( "*** Please, define the SIM_PIN_CODE variable . ***" );
 
//    return;
 
// }
 
//  mySerial.print("AT+CPIN=");
 
// mySerial.println( SIM_PIN_CODE );
 
}
 
 
// EN: Request Text Mode for SMS messaging
 
 
void GprsTextModeSMS(){
 
  mySerial.println( "AT+CMGF=1" );
 
}
 
 
void GprsReadSmsStore( String SmsStorePos ){
 
  // Serial.print( "GprsReadSmsStore for storePos " );
 
  // Serial.println( SmsStorePos );
 
  mySerial.print( "AT+CMGR=" );
 
  mySerial.println( SmsStorePos );
 
}
 
 
// EN: Clear the GPRS shield message buffer
 
 
void ClearGprsMsg(){
 
  msg = "";
 
}
 
 
// EN: interpret the GPRS shield message and act appropiately
 
 
void ProcessGprsMsg() {
 
  Serial.println("");
 
  Serial.print( "GPRS Message: [" );
 
  Serial.print( msg );
 
  Serial.println( "]" );
 
 
//  if( msg.indexOf( "+CPIN: SIM PIN" ) >= 0 ){
 
//    Serial.println( "*** NEED FOR SIM PIN CODE ***" );
 
//    Serial.println( "PIN CODE *** WILL BE SEND NOW" );
 
//    GprsSendPinCode();
 
//  }
 
 
  if( msg.indexOf( "Call Ready" ) >= 0 ){
 
    Serial.println( "*** GPRS Shield registered on Mobile Network ***" );
 
    GprsTextModeSMS();
 
  }
 
 
  // EN: unsolicited message received when getting a SMS message
 
  // FR: Message non sollicité quand un SMS arrive
 
  if( msg.indexOf( "+CMTI" ) >= 0 ){
 
    Serial.println( "*** SMS Received ***" );
 
    // EN: Look for the coma in the full message (+CMTI: "SM",6)
 
    //    In the sample, the SMS is stored at position 6
 
    int iPos = msg.indexOf( "," );
 
    String SmsStorePos = msg.substring( iPos+1 );
 
    Serial.print( "SMS stored at " );
 
    Serial.println( SmsStorePos );
 
 
    // EN: Ask to read the SMS store
 
    GprsReadSmsStore( SmsStorePos );
 
  }
 
 
  // EN: SMS store readed through UART (result of GprsReadSmsStore request) 
 
  if( msg.indexOf( "+CMGR:" ) >= 0 ){
 
    // EN: Next message will contains the BODY of SMS
 
    SmsContentFlag = 1;
 
    // EN: Following lines are essentiel to not clear the flag!
 
    ClearGprsMsg();
 
    return;
 
  }
 
 
  // EN: +CMGR message just before indicate that the following GRPS Shield message
 
  //    (this message) will contains the SMS body
 
 
  if( SmsContentFlag == 1 ){
 
    Serial.println( "*** SMS MESSAGE CONTENT ***" );
 
    Serial.println( msg );
 
    Serial.println( "*** END OF SMS MESSAGE ***" );
 
    ProcessSms( msg );
 
  }
 
 
  ClearGprsMsg();
 
  // EN: Always clear the flag
 
 
  SmsContentFlag = 0;
 
}
 
</pre>
 
  
 
==The usage of GPS Function==
 
==The usage of GPS Function==

Revision as of 09:15, 27 October 2017

Introduction

This GPRS GSM GPS Shield based on the SIM808 GSM GPRS GPS all-in-one cellular phone module. You can add location-tracking, voice, text, SMS and data to your project. This shield fits right over your Arduino or Maduino, it is easy to use. This shield fits right over your Arduino or compatible. At the heart is a powerful GSM cellular module (we use the latest SIM808) with integrated GPS. The module is controlled by AT command via UART and supports 3.3V and 5V logical level.

Model: OAS808SIM
GPRS GSM GPS Shield (SIMCOME- SIM808).jpg

Features

  • Quad-band 850/900/1800/1900MHz - connect onto any global GSM network with any 2G SIM (in the USA, T-Mobile is suggested)
  • Fully-integrated GPS
  • Make and receive voice calls using a headset or an external 32Ω speaker + electret microphone
  • Send and receive SMS message
  • AT command interface with "auto baud" detection
  • Send and receive GPRS data (TCP/IP, HTTP, etc.)
  • GPS L1 C/A code
  • 22 tracking /66 acquisition channels
  • Tracking: -165 dBm
  • Cold starts : -148 dBm
  • Time-To-First-Fix:Cold starts-32s (typ.),Hot starts-1s (typ.),Warm starts-5s (typ.)
  • Accuracy: approx 2.5 meters

Interface Function

GPRS GSM GPS Shield (SIMCOME- SIM808) 2.JPG GPRS GSM GPS Shield (SIMCOME- SIM808) 3.JPG

Connectors:

  • Headset jack-This is a 'standard' TRRS 3.5mm phone headset jack with stereo earphone and mono microphone. Any 'iPhone' or 'Android' compatible (but not iPhone original) should work.
  • uFL GSM connector-This is the GSM Antenna connector, an antenna is required to use the SIM808 shield!
  • uFL GPS connector-This is the GPS Antenna connector, an antenna is required if you want to get GPS readings!
  • uFL BT connector- This is the Bluetooth Antenna connector, in this version, there no have the Bluetooth function.
  • SIM Connector:A 2G Mini SIM card is required to use the module. You can buy it in any cell phone shop. It must be a 2G GSM card.
  • VRTC Battery holder:Power supply for RTC.

LEDs

  • PWR –Power light
  • 1PPS –This is the 'pulse per second' output of the GPS
  • Status – Power on status. Lit when the Cell module is booted and running
  • NetLight – Network status. You can use this for checking the current state without sending an AT command
  • 64ms on, 800ms off - the module is running but hasn't made connection to the cellular network yet
  • 64ms on, 3 seconds off - the module has made contact with the cellular network and can send/receive voice and SMS
  • 64ms on, 300ms off - the GPRS data connection you requested is active

By watching the blinks you can get a visual feedback on whats going on. POWER_KEY

  • Power on or power off the SIM808.

Pins usage on Arduino

  • D0 - Used if you select hardware serial port to communicate with SIM808
  • D1 - Used if you select hardware serial port to communicate with SIM808
  • D7 - Used if you select software serial port to communicate with SIM808
  • D8 - Used if you select software serial port to communicate with SIM808
  • D9 - Used for software control the Power ON or Power OFF of the SIM808

Usage

On its own, this shield can't do anything. It requires a microcontroller like an Arduino to drive it! You will also need some required accessories to make SIM808 shield work.
SIM Card! A 2G Mini SIM card is required to do anything on the cellular network. US AT&T no longer sells 2G SIMs and will shut off their 2G network, so for American customers we recommend any T-Mobile or reseller (TING, SIMPLE mobile, etc) that uses the T-Mobile network.

Assembly

Attaching Antennas: GSM antenna is required to use the Cellular module. If you want to use GPS as well, a passive GPS antenna is also required.
GPRS GSM GPS Shield (SIMCOME- SIM808) ANT.jpg
SIM Card:
Insert a mini SIM card(GPS does work without a SIM)
GPRS GSM GPS Shield (SIMCOME- SIM808) SIM.jpg
③ Connect the headset to the headset jack.(when you make a call you may need to use it)
GPRS GSM GPS Shield (SIMCOME- SIM808) HEA.jpg
④ Plug to Arduino or Maduino, connect the USB to the PC.
GPRS GSM GPS Shield (SIMCOME- SIM808) USB.jpg
⑤ Power on the SIM808 shield by the POWER_KEY ( sometime you can control it by the software control ( Arduino D9 PIN))

The usage of GPS Function

Print the GPS(GNSS) data with serial port

Note!!! The below usege just suitable for the SIM808 GPRS/GSM+GPS Shield v1.1,becaus the main IC SIM808 was the new version:S2-1060C-21F02.

AT Commands Examples

800px

Demo code of get the GPS information:

/*
 * Created by Island
 * Modified by keen 
 * Date: 17/03/2017
 */
#include <SoftwareSerial.h>
#define DEBUG true
SoftwareSerial mySerial(7,8); 
        
void setup(){
  Serial.begin(9600);
  mySerial.begin(9600); 
  getgps();
}

void loop(){
   sendData( "AT+CGNSINF",1000,DEBUG);   
}

void getgps(void){
   sendData( "AT+CGNSPWR=1",1000,DEBUG); 
   sendData( "AT+CGPSINF=0",1000,DEBUG); 
}

void sendData(String command, const int timeout, boolean debug){
    String response = "";    
    mySerial.println(command); 
    delay(5);
    if(debug){
    long int time = millis();   
    while( (time+timeout) > millis()){
      while(mySerial.available()){       
        response += char(mySerial.read());
      }  
    }    
      Serial.print(response);
    }    
}

The result of get the GPS information.

500px

The AT commands Bluetooth Function

AT comands Description
AT+BTPOWER=1 Turn on Bluetooth
AT+BTHOST? Query the module name and address
AT+BTSCAN=1,10 Search nearby Bluetooth devices, search time is 10S
AT+BTPAIR=0,1 Request matching
AT + BTPAIR = 1,1 Responds to a connection request
AT + BTGETPROF = 1 Get the services provided by paired Bluetooth devices
AT + BTCONNECT = 1, 4 Active connection to Bluetooth devices
AT + BTSPPSEND = 5 send 5 byte data

Examples

Bluetooth Communication:using Software UART

Note

1.Download a Bluetooth serial assistant(Bluetooth SPP) on your phone.

2.Open the Serial Monitor and Note print informations.

3.How to ensure your BT ID number:

700px

/*
 This example....
 created 16 March 2017
 by Keen & Island
 */
#include <SoftwareSerial.h>
#define SWdebug true
#define HDdebug true
SoftwareSerial GSMSerial(7,8); 

boolean init_flag = true;
String BTname = "Elecrow";  //For example: Modify Bluetooth name as "Elecrow".
String TestTEXT="12345";

void setup(){
  Serial.begin(19200);
  GSMSerial.begin(19200); 
  delay(1000);
  Open_BTpower();              // Turn on Bluetooth
  Current_BThost_Name();       // Show current bluetooth host name
  Hardware_print("Please note:.....",HDdebug);
  Hardware_print("Is the first connection? yes/no",HDdebug);
  Hardware_print("Answer:(yes/no)",HDdebug);
}

void Open_BTpower(){
  Hardware_print("Reset Bluetooth Power status",HDdebug);
  Hardware_print("Tips: if show:AT+BTPOWER=0 ERROR is normal, it means the power has been reset...",HDdebug);
  sendData( "AT+BTPOWER=0",1000,SWdebug);   // Reset Bluetooth status
  Hardware_print("Turn on Bluetooth",HDdebug);
  sendData( "AT+BTPOWER=1",2000,SWdebug);   // Turn on Bluetooth
}

void Current_BThost_Name(){
  Hardware_print("Current bluetooth name is:",HDdebug);
  String command = "AT+BTHOST?";
  sendData( command,1000,SWdebug);   //Show SIM 808 BT Host and address.
}

void Change_BThost_Name(String BThostName){
  String command = "AT+BTHOST="+BThostName; //Change SIM 808 BT name
  Hardware_print("Change bluetooth name....",HDdebug);
  sendData( command,2000,SWdebug);
  Hardware_print("The new bluetooth name is:",HDdebug);
  sendData( "AT+BTHOST?",1000,SWdebug);  //Show SIM 808 BT Host
}

void BTscan(){
  String command = "AT+BTSCAN=1,10";
  Hardware_print("Looking for nearby Bluetooth.......",HDdebug);
  Hardware_print("Tips: Scanning the Bluetooth and it will show on the Serial Monitor after about 30S",HDdebug);
  Hardware_print("Notes:Setting your phone Bluetooth can be search. At the same time, open your Bluetooth SPP... ",HDdebug);
  Hardware_print("      If your phone receives a request, please confirm it...",HDdebug);
  Hardware_print("      Make sure your phone BT ID is 1, if not ,please try again...",HDdebug);
  sendData( command,30000,SWdebug);
}

void Clear_BT_list_device(){
  Hardware_print("Tips: if show:AT+BTUNPAIR=0 ERROR is normal, it means the list has been reset...",HDdebug);
  sendData( "AT+BTUNPAIR=0",1000,SWdebug); //Clear BT list
  delay(1000);
}

void Connect_BT_device(){
  delay(1000);
  String command1 = "AT+BTPAIR=0,1"; //Matching Bluetooth device(ID:1)
  sendData( command1,4000,SWdebug);
  Hardware_print("Tips: If show:AT+BTPAIR=0,1 ERROR,please try again...",HDdebug);
  String command2 = "AT+BTPAIR=1,1";//Response request
  sendData( command2,2000,SWdebug);
  delay(1000);
  sendData( "AT+BTGETPROF=1",10000,SWdebug);  //Get paired bluetooth device support services
  Hardware_print("Tips: If show:AT+BTGETPROF=1 ERROR,please try again...",HDdebug);
  delay(3000);
  String command3 = "AT+BTCONNECT=1,4";      //Use SPP services
  sendData( command3,3000,SWdebug);
  delay(3000);
}

void Hardware_print(String data, boolean debug){
  if(debug){
    Serial.println(data);
  }
}

void sendData(String command, const int timeout, boolean debug){
    String comdata = "";    
    GSMSerial.println(command); 
    long int time = millis();   
    while( (time+timeout) > millis()){
      while(GSMSerial.available()){       
        comdata += char(GSMSerial.read());
      }  
    }    
    if(debug){
      Serial.print(comdata);
    }    
}

void init_BT(){
    if(init_flag){
      while(1){
         if (Serial.available()>0){
            if (Serial.find("yes")){
               Change_BThost_Name(BTname);  // Modify Bluetooth name
               Clear_BT_list_device();      // Reset the BT device list
               BTscan();                    // Scan Bluetooth
               Connect_BT_device();
              }else { 
                sendData( "AT+BTCONNECT=1,4",5000,SWdebug);
                Hardware_print("Tips: And now you can use Bluetooth SSP communicate with Serial Monitor.",HDdebug);
                Hardware_print("      On the Serial Monitor, string (TestTEXT) will be send after you enter 'send'...",HDdebug);
                delay(1000);
              } break;
          }
      }
      init_flag=false;
    }
}

void com_data_judgment(){
  
  if (Serial.available()){
    if (Serial.find("send")){
      Hardware_print("Tips:Enter 'send' on Serial Monitor,the String (TestTEXT) will be send...",HDdebug);
      sendData( "AT+BTSPPSEND=5",3000,SWdebug);  //Send 5 bytes length text
      sendData(TestTEXT,3000,SWdebug);           // Send test TEXT info
      delay(1000);
    }
  }
  if(GSMSerial.available())  //Print information from SIM808
    Serial.print((char)GSMSerial.read());
}
void loop(){
  init_BT();
  com_data_judgment();
}

FAQ

You can list you question here or contact with techsupport@elecrow.com for technology support.

How to buy

You can click here to buy SIM808 GPRS/GSM+GPS Shield.

How to upgrade bluetooth function

Please refer to this tutorial

Resources