GSM GPS shield for Arduino
Published on 2/17/2017 5:59:43 PM
Description
<style>.e_editor{font:14px/24px Arial,'microsoft yahei','Times New Roman','b8bf53';}.e_editor div,e_editor p,e_editor td,e_editor th,e_editor li{font-weight:inherit;font-size:inherit;font-style:inherit;font-family:inherit;}.e_editor ul{margin:-10px 0 20px;}.e_editor li{padding:5px 0;}.e_table{width:96%;border-collapse:collapse;empty-cells:show;}.e_table th,.e_table td{padding:5px;border:2px solid #eee;}.e_img{padding:10px 0;text-align:center;}.e_p{line-height:20px;padding:0 0 20px;text-indent:0em;}</style> <div class="e_editor"> <div class="e_p"> Shield for Arduino designed and based on the module GSM/GPRSSIM900 or the GSM/GPRS & GPS moduleSIM908, to make calls, voice and data connections via GPRS. </div> <div class="e_p"> <strong>HARDWARE INNOVATIONS</strong> </div> <div class="e_p"> This new version (old Arduino GSM shield) has several new hardware features, that allow maximum customization and provide many configurations. </div> <div class="e_p"> We begin with the supply circuit a simple LM7805. To work, it is necessary to provide an input voltage between 7.5V and 12V. As shown in the circuit diagram, the input voltage, after being stabilized at 5 V, is reduced to 4.3 V by using a diode and provide power to modules that need a voltage between the 3.2 and 4.8 V. During the operations such as the use of GPRS, the module absorbs a current of about 1 A, therefore it is necessary that the power source is able to provide this current intensity. </div> <div class="e_p"> An important technical feature is the serial adapter for the communication between the GSM module and Arduino. To reduce the tension has been used a simple voltage divider, while for raising the voltage from the GSM module to Arduino we chose a MOSFET BS170. </div> <div class="e_p"> The news that is immediately evident is the presence of two jacks for audio. With a microphone and a headset with a 3.5 mm jack (just the standard headphones for computers), <strong>you can make a voice call</strong> !! </div> <div class="e_p"> To preserve compatibility with the Arduino Mega, we changed the selection method for the serial communication. The two different serial communication modes (hardware or software) are selectable by jumper, leaving the user the choice between the two configurations ( for serial software in this new version we adopted pins 2 and 3) or possibly use the pin to your choice with a simple wire connection. With this solution you can use the Arduino Mega using two of the four serial that it has, or possibly carry out the communication through a serial software via two pins of your choice. </div> <div class="e_p"> Always to preserve maximum flexibility and customization, there are some pins on the back of PCB, which allow to make the connections from the Arduino digital ports and the control signals data flow (CTS, RTS) or alerts for incoming calls or unread SMS (RI). In this new version, you can then disable these connections to save inputs or outputs pins. </div> <div class="e_p"> Comparing the new card with the previous one, you can see the presence of two connectors on the top.These additional connections allow the use of the shield also with the new small breakout for SIM900 and SIM908. The new module Simcom SIM908, is characterized by the presence of a GPS with 42 channels. </div> <div class="e_p"> The scenery offered by this new module SIMCOM, in addition to GSM GPRS shield, it is quite remarkable: the creation of a GPS tracking device that can communicate the location via the Internet (or SMS) is now available to everyone, avoiding all the problems due to assembly and low-level programming. </div> <div class="e_p"> A further feature of this new version, concerns the presence of a supercap for circuit dedicated to the RTC (Real Time Clock). Inside the SIM900, as well as the SIM908, there is a circuit that is responsible for updating the clock even without power. </div> <div class="e_p"> <strong>GSM GPS SHIELD SCHEMATICS</strong> </div> <div class="e_p"> [CODE] </div> <div class="e_p"> R1: 10 kohm </div> <div class="e_p"> R2: 10 kohm </div> <div class="e_p"> R3: 10 kohm </div> <div class="e_p"> R4: 10 kohm </div> <div class="e_p"> C1: 100 nF </div> <div class="e_p"> C2: 470 µF 25 VL </div> <div class="e_p"> C3: 100 nF </div> <div class="e_p"> C4: 220 µF 16 VL </div> <div class="e_p"> C5: 47 pF </div> <div class="e_p"> C6: 47 pF </div> <div class="e_p"> C7: 47 pF </div> <div class="e_p"> C8: 47 pF </div> <div class="e_p"> C9: 47 pF </div> <div class="e_p"> C10: 47 pF </div> <div class="e_p"> C11: 220 µF 16 VL </div> <div class="e_p"> C12: 100 nF </div> <div class="e_p"> CRCT: 0,1F </div> <div class="e_p"> U1: 7805 </div> <div class="e_p"> T1: BS170 </div> <div class="e_p"> D1: 1N4007 </div> <div class="e_p"> P1: Microswitch </div> <div class="e_p"> MIC: jack 3,5 mm </div> <div class="e_p"> SPK: jack 3,5 mm </div> <div class="e_p"> [/CODE] </div> <div class="e_p"> <strong>SOFTWARE INNOVATIONS</strong> </div> <div class="e_p"> The software library related to the GSM GPRS shield has been updated. The library is open-source and uses the hosting service Google Projec . The library is constantly updated and improved with the addition of new features, so please check that you always have the latest release. </div> <div class="e_p"> The main enhancement is the TPC/IP communication support through GPRS. </div> <div class="e_p"> With a simple function, you can connect Arduino to internet using the APN (Access Point Name) you choose. After that we will automatically get an IP address by the provider. </div> <div class="e_p"> To establish communication you must define which device performs the function of the server (still waiting for some connection), such as that client (requires a connection to the server according to the information you want to achieve) and that leads to exchange data . </div> <div class="e_p"> In the library there are two functions that allow us to set the device to listen on a particular port for connections (server), or to establish a connection based on the server address and port chosen (client) . </div> <div class="e_p"> Once connected, you can send the data, which can be command strings or just the data you want to monitor, for this action there is a high-level function, which simplifies the management. </div> <div class="e_p"> <strong>LIBRARY FUNCTIONS GSM GPRS</strong> </div> <div class="e_p"> First, you must have the folder libraries, in the root directory of the Arduino, the folderGSM_GPRScontaining all the functions you can use. </div> <div class="e_p"> Now if you want to change the serial port, through the jumper, you have to modify the fileGSM.cpp. </div> <div class="e_p"> To save memory, we decided to divide the functions into different classes contained in different files, to allow you to include or not the code parts needed, thus going to save memory RAM, leaving it free for the rest of the program. For the basic operation is always necessary to include filesSIM900.handSoftwareSerial.h, while depending on the needs you may includecall.h(for call handling),sms.h(for sending, receiving and saving SMS) andinetGSM.h(containing functions related to HTTP, and GPRS). </div> <div class="e_p"> <strong>SIM900.h</strong> </div> <div class="e_p"> You should always include this file. It contains the basic functions for starting and configuring the GSM module. Simply call the functions using “GSM.” As a prefix. </div> <div class="e_p"> <table> <tbody> <tr> <td> int gsm.begin(int baudrate) </td> <td> Turn the power on and sets the baud rate for communication. </td> <td> gsm.TurnOn(9600); </td> </tr> <tr> <td> void SimpleRead() </td> <td> Reads a byte from the serial buffer. </td> <td> gsm.SimpleRead(); </td> </tr> <tr> <td> void SimpleWrite(char* cmd) </td> <td> Writes the string (or an integer) on the serial port. </td> <td> gsm.SimpleRead(“AT+CSQ”); </td> </tr> <tr> <td> char SendATCmdWaitResp (char const* AT_cmd_string, uint16_t start_comm_tmout, uint16_t max_interchar_tmout, char const* response_string,byte no_of_attempts) </td> <td> Sends an AT command passed as a parameter, controlling the time of timeout for the receipt of a response and between one character and another. After receiving the response, compares it with that expected, if different resends the command for the set number of times.The possible outputs are shown below, with the relative enumeration. AT_RESP_ERR_NO_RESP or -1: No response received.AT_RESP_ERR_DIF_RESP or 0: Response different from that expected.AT_RESP_OK or 1: The response contains the expected string. </td> <td> If (gsm.SendATCmdWaitResp (“AT”,500,50,”OK”,3)== AT_RESP_OK) <div class="e_p"> Serial.println(“OK”); </div> </td> </tr> </tbody> </table> </div> <div class="e_p"> <strong>call.h</strong> </div> <div class="e_p"> In case you want to make a call, or simply refuse to answer an incoming call, you must use this class. To use these functions simply instantiate the object in the sketch. The functions listed in the table below refers to an object created with the following command at the beginning of the sketch:CallGSM call; </div> <div class="e_p"> <table> <tbody> <tr> <td> void Call(char* number_string) </td> <td> Makes a call to the number contained in the string </td> <td> call.Call(“+393471234567”) </td> </tr> <tr> <td> void PickUp(void) </td> <td> During an incoming call, it responds and activates the audio communication. </td> <td> call.PickUp(); </td> </tr> <tr> <td> void HangUp(void) </td> <td> During an active call, hang up and disables audio communication. </td> <td> call.HangUp(); </td> </tr> <tr> <td> byte CallStatus(void); </td> <td> Returns the state about the phone calls.The possible output byte are listed under the following names:CALL_NONE or 0: No call.CALL_INCOM_VOICE or 1: An incoming call.CALL_ACTIVE_VOICE or 2: Active Call. </td> <td> If (call.CallStatus()== CALL_ACTIVE_VOICE) <div class="e_p"> Serial.println(“CALL ACTIVE”); </div> </td> </tr> <tr> <td> byte CallStatusWithAuth (char* phone_number, byte first_authorized_pos, byte last_authorized_pos); </td> <td> Unlike the previous distinguish if the active call, or incoming belongs to a number stored on the SIM in a position between the start and end, passed as parameters. The possible output byte are listed under the following names:CALL_NONE or 0: No call.CALL_INCOM_VOICE_AUTH or 3: Incoming call from a number authenticated. CALL_INCOM_VOICE_NOT_AUTH or 4: Incoming call from a number not authenticated. </td> <td> If (call.CallStatusWithAuth() == CALL_INCOM_VOICE_AUTH) <div class="e_p"> Serial.println (“INCOMING CALL FROM A AUTH NUMBER”); </div> </td> </tr> </tbody> </table> </div> <div class="e_p"> <strong>SMS.h</strong> </div> <div class="e_p"> For managing text messages must use this special class. As before, it is necessary to recall it within the sketch and then instantiate an object. For example, in the following functions refers to an object created at the beginning of the sketch, with the command SMSGSM sms; </div> <div class="e_p"> <table> <tbody> <tr> <td> char SendSMS(char *number_str, char *message_str) </td> <td> Using the following command is sent an SMS to the number contained in the first string passed as a parameter with the text in the second. </td> <td> sms.SendSMS (“+393471234567” , ”Hello Arduino”); </td> </tr> <tr> <td> char SendSMS(byte sim_phonebook_position, char *message_str) </td> <td> Send an SMS as before, where instead of the string is passed to the recipient’s contact position stored on the SIM. </td> <td> sms.SendSMS(1,”Hello Arduino”); </td> </tr> <tr> <td> char GetSMS(byte position, char *phone_number, char *SMS_text, byte max_SMS_len) </td> <td> Reads the SMS stored on the SIM in the position passed as a parameter, saving the sender’s number in the first string passed in the second and the content of specified length. </td> <td> char number[13]; <div class="e_p"> char text[200]; </div> <div class="e_p"> sms.GetSMS(1,number,text,200); </div> </td> </tr> </tbody> </table> </div> <div class="e_p"> <strong>inetGSM.h</strong> </div> <div class="e_p"> In this class are included functions to connect and manage communications via HTTP protocol. In the following examples was an object created with the commandInetGSM inet; </div> <div class="e_p"> <table> <tbody> <tr> <td> int httpGET(const char* server, int port, const char* path, char* result, int resultlength) </td> <td> Send a GET request to the specified server on the specified port, requiring a certain path and saving the response to a string of the specified length. Returns the number of bytes read. </td> <td> char text[200]; <div class="e_p"> inet.httpGET (“www.open-electronics.org”, 80,”/”,text,200); </div> </td> </tr> <tr> <td> int httpPOST(const char* server, int port, const char* path, const char* parameters, char* result, int resultlength) </td> <td> Send a POST request to the specified server on the specified port, requiring a certain path, passing the parameters set and saving the response string of the specified length. Returns the number of bytes read. </td> <td> char text[200]; <div class="e_p"> inet.httpGET (“www.open-electronics.org”, 80,”/”,text,200); </div> </td> </tr> <tr> <td> int attachGPRS(char* domain, char* dom1, char* dom2) </td> <td> Initiates the connection using the GPRS APN passed as the first parameter. The second and third arguments are two strings that contain the username and password. If no authentication is required, just pass the last two strings empty. </td> <td> inet.attachGPRS (“internet.wind”,””,””); </td> </tr> <tr> <td> int deattachGPRS(void) </td> <td> Disconnects the module from the GPRS network. </td> <td> inet.deattachGPRS(); </td> </tr> <tr> <td> int connectTCP(const char* server, int port) </td> <td> Establishes a connection as a client to the server passed as a parameter on the port defined by the second parameter. </td> <td> inet.connectTCP (“www.open-electronics.org”, 80); </td> </tr> <tr> <td> int disconnectTCP(void) </td> <td> Closes the communication with the server. </td> <td> inet.disconnectTCP(); </td> </tr> <tr> <td> int connectTCPServer(int port) </td> <td> Puts the module listens on the specified port waiting for a connection from a client. </td> <td> inet.connectTCPServer(80); </td> </tr> <tr> <td> boolean connectedClient(void) </td> <td> Returns true if a client is connected to the module, otherwise false. </td> <td> inet.connectedClient(); </td> </tr> </tbody> </table> </div> <div class="e_p"> <strong>EXAMPLE FOR CALLS AND SMS WITH THE GSM GPRS SHIELD</strong> </div> <div class="e_p"> Let us now, step by step, our first sketch to use the shield using the Arduino IDE version 1.00. We will write a program that when it receives a call from a preset number (stored in a specific location on the SIM), rejects the call and sends an SMS in response to the caller with the value read from an input. </div> <div class="e_p"> First you have to extract the files from the compressed folder within the Library folder libraries contained within the installation folder of Arduino. </div> <div class="e_p"> To first load the libraries using the following commands </div> <div class="e_p"> #include “SIM900.h” </div> <div class="e_p"> #include <SoftwareSerial.h> </div> <div class="e_p"> Then load, uncomment properly, the files related to classes containing functions that we want to use for the management of phone calls and SMS. </div> <div class="e_p"> #include “sms.h” </div> <div class="e_p"> #include “call.h” </div> <div class="e_p"> We will perform the initialization procedure in the setup. Set the pin to read the value which will then be sent via SMS, configure the serial communication and initialize the module with the functiongsm.begin, and set the baud rate (usually for proper communication of data through GPRS is advisable not rise above 4800 baud). </div> <div class="e_p"> At this point we enter the heart of the program, which will periodically check the status of incoming calls. To do this within the cycle loop will use the functioncall.CallStatusWithAuthsaving the byte returned. In the case of incoming or in progress call, the sender (or recipient) number is stored in the string number. </div> <div class="e_p"> Compared with the value storedCALL_INCOM_VOICE_AUTH, which describes an incoming call by a number in that set, we reject the call using theGSM.Hangupand after waiting 2 seconds, read the input value and send the message.The value read is an integer and must be first converted into a string using the functionitoa. </div> <div class="e_p"> Let us remember to insert a delay, inside the loop function, to ensure that the module is interrogated at intervals of not less than a second. Commands sent in rapid sequence could corrupt the stability of the module. </div> <div class="e_p"> If we do not receive the result of proper initialization, you will need to check the power supply. Remember that it is recommended to use an external power source because the only power supplied by the USB port is not enought. </div> <div class="e_p"> If the power is found to be correct, you should check that the fileGSM.cpp, in the library are declared properly pin for the serial. Basically the new version uses pins 2 and 3, while the old version used pins 4 and 5. </div> <div class="e_p"> #define _GSM_TXPIN_ 2 </div> <div class="e_p"> #define _GSM_RXPIN_ 3 </div> <div class="e_p"> The full program is as follows: </div> <div class="e_p"> #include "SIM900.h" #include <SoftwareSerial.h> //carichiamo i file necessari allo sketch #include "sms.h" #include "call.h" CallGSM call; SMSGSM sms; char number[20]; byte stat=0; int value=0; int pin=1; char value_str[5]; void setup() { pinMode(pin,INPUT); Serial.begin(9600); Serial.println("GSM GPRS Shield"); //init the module if (gsm.begin(2400)) Serial.println("\nstatus=READY"); else Serial.println("\nstatus=IDLE"); }; void loop() { stat=call.CallStatusWithAuth(number,1,3); if(stat==CALL_INCOM_VOICE_AUTH){ call.HangUp(); delay(2000); value=digitalRead(1); itoa(value,value_str,10); sms.SendSMS(number,value_str); } delay(1000); }; </div> <div class="e_p"> <strong>EXAMPLE FOR INTERNET</strong> </div> <div class="e_p"> We analyze one of the examples contained within the library to connect Arduino to the internet with GPRS connection. </div> <div class="e_p"> We will make a program capable of receiving HTML content from a web page and save the first 50 characters. </div> <div class="e_p"> Because we use only the functions relating to the Internet and HTTP, we load in addition to the standard library file, the fileinetGSM.h </div> <div class="e_p"> Instantiate an object management functions </div> <div class="e_p"> InetGSM inet; </div> <div class="e_p"> and as before we execute the initialization routine. Then we establish a GPRS connection. In this step you need to run the command “AT+CIFSR” that requires the provider the IP address assigned to the GSM module. This step is important. Some providers garantee the connection only if previously it’s made this request. Through the functiongsm.WhileSimpleReadcontained in the GSM class, we read the entire contents of the buffer. Once emptied the buffer, the sketch will go to the following functions. </div> <div class="e_p"> At this point we are connected, we have to establish a TCP connection with the server, send a GET request to a web page and store the contents of the response in a previously declared array. All this is done by the functionHttpGetin classinetGSM. In addition to the server and port (80 in the case of HTTP protocol), we have to indicate the path which contains the requested page. </div> <div class="e_p"> Obviously if we wish to save a greater number of characters of the answer, it is sufficient to initialize a string of larger dimensions, taking care not to saturate the RAM is made available by Arduino, otherwise we risk getting abnormal behavior, such as stalls or restarts. </div> <div class="e_p"> #include "SIM900.h" #include <SoftwareSerial.h> #include "inetGSM.h" InetGSM inet; char msg[50]; int numdata; char inSerial[50]; int i=0; boolean started=false; void setup() { Serial.begin(9600); Serial.println("GSM Shield testing."); if (gsm.begin(2400)){ Serial.println("\nstatus=READY"); started=true; } else Serial.println("\nstatus=IDLE"); if(started){ if (inet.attachGPRS("internet.wind","", "")) Serial.println("status=ATTACHED"); else Serial.println("status=ERROR"); delay(1000); gsm.SimpleWriteln("AT+CIFSR"); delay(5000); gsm.WhileSimpleRead(); numdata=inet.httpGET("www.google.com", 80, "/", msg, 50); Serial.println("\nNumero di byte ricevuti:"); Serial.println(numdata); Serial.println("\nData recived:"); Serial.println(msg); } }; void loop() { }; </div> <div class="e_p"> The shield has various connectors to accept more GSM/GPRS modules manufactured by SIMCOM and mounted on breakout board. In addition to the popular SIM900, our new shield for Arduino supports the recent SIM908, which is an evolution and aims to capture the market of GSM/GPRS quad-band providing a variety of additional features that make it unique, especially in the field of low-cost products. The SIM908 implements a GPS with 42 channels, characterized by an excellent accuracy and by a very reduced time required to perform the first fix (1 second in mode “hot start” and 30 seconds with the mode “cold start”). </div> <div class="e_p"> This module can be used powered by a lithium battery, and can charge it, greatly simplifying this process that would require dedicated hardware. </div> <div class="e_p"> The SIM908 has two serial, used one for the GSM and the other for the GPS. More exactly, the first serial interface is provided with a UART which belongs to the lines TXD, RXD, DTR, which go outside through the contacts, respectively, 12, 14, 10 of connector; for the GPS, instead, the serial is GPSTXD (contact 4) and GPSRXD (pin 5). The first serial port is actually intended for total control of SIM908, then it can also configure the GPS receiver and ask him to provide data on the location, the number of satellites hooked, etc. From the second serial port (GPSTXD / GPSRXD) instead, go out continuously strings in standard NMEA GPS system. </div> <div class="e_p"> <strong>THE GSM SHIELD LIBRARY</strong> </div> <div class="e_p"> Providing also use the SIM908, the library for the management of this module has been modified to provide a quick access to all the new features made available, the new library is derived from that used for the SIM900 module, and is available on the Internet at http://code.google.com/p/gsm-shield-arduino/ . </div> <div class="e_p"> Note that you can use the new library for managing mobile SIM900, provided you do not call functions dedicated to SIM908. While it is completely compatible using the sketch for the version without GPS with this new one. </div> <div class="e_p"> Let’s consider some new features introduced: first of all has been added the functionForceON();used to check the status of the module and to force the power on. The SIM908 supports the charge of lithium batteries, the module can be started to perform the charger without the management of the GSM network. If we want to avoid this mode and make sure it’s really turned on then you need to call the function mentioned above. </div> <div class="e_p"> gsm.forceON(); </div> <div class="e_p"> Intended for the use of GPS (and battery), we made a class which you can instantiate an object with GPSGSM gps, after including its # include files “gps.h“, in order to invoke their functions by prefixing “GSM.” to the desired function. </div> <div class="e_p"> This subdivision into different files is designed to minimize RAM usage: in fact, for example, all the variables used by the class on the GPS will not be allocated in memory will not be included if the relevant files using#include “gps.h”.This allows you to choose which variables to use. </div> <div class="e_p"> As already mentioned, also for the management of the battery there ara functions which enable the measurement of the voltage and battery temperature; for practical reasons, occupying little memory, these have been included in the class of GPS. For use them, after including the file#include “gps.h”you must instantiate the object related with GPSGSM gps. In the next sections will show the control functions of the GPS and battery. </div> <div class="e_p"> <strong>HOW TO USE THE SIM908 GPS</strong> </div> <div class="e_p"> Before using GPS, you need to make a small set-up: first let’s make a bridge on jumper J1 on the SIM908 Breakout (cod. FT971). </div> <div class="e_p"> The bridge on J1 enables power to the GPS antenna. </div> <div class="e_p"> This serves to bring power to the active GPS antenna. Next, load the sketch example (in the examples directory) calledGSM_GPRS_GPS_Library_AT(or evenGSM_GPRSLibrary_AT) and once launched and completed initialization send the following commands: </div> <div class="e_p"> AT </div> <div class="e_p"> AT+CGPSPWR=1 </div> <div class="e_p"> AT+CGSPRST=0 </div> <div class="e_p"> We wait a minute, at which point the GPS should be working, to verify </div> <div class="e_p"> continue sending the command: </div> <div class="e_p"> AT+CGPSINF=0 </div> <div class="e_p"> If you can see the coordinates, it means that everything is working and we can proceed with the standard use by the implemented functions. </div> <div class="e_p"> <table> <tbody> <tr> <td> char attachGPS() </td> <td> Follow the steps to activate the GPS: turn on the power and set the mode to “hot start”. </td> <td> gps.attachGPS() </td> </tr> <tr> <td> char deattachGPS() </td> <td> power off, disabling the power supply to save energy. </td> <td> gps.deattachGPS() </td> </tr> <tr> <td> char getStat() </td> <td> Check the GPS status, the possible outputs are:0: GPS not started.1: Fix not performed (can be caused by a signal of poor quality).2: Fix 2D run.3: Fix 3D executed. </td> <td> char stat; <div class="e_p"> stat=gps.getStat(); </div> <div class="e_p"> if(stat==3) </div> <div class="e_p"> Serial.println(“FIXED”); </div> </td> </tr> <tr> <td> char getPar(char* str_long, char* str_lat, char* str_alt, char* str_time, char* speed); </td> <td> Save in variables, respectively, longitude, latitude, altitude, time and speed. </td> <td> char lon[10]; <div class="e_p"> char lat[10]; </div> <div class="e_p"> char alt[10]; </div> <div class="e_p"> char time[15]; </div> <div class="e_p"> char vel[10]; </div> <div class="e_p"> gps.getPar(lon,lat,alt,time,vel); </div> </td> </tr> </tbody> </table> </div> <div class="e_p"> Now we proceed with a simple example that allows us to understand how to get the coordinates from the GPS module SIM908 mounted on the shield, the firmware is described here: </div> <div class="e_p"> #include "SIM900.h" #include <SoftwareSerial.h> #include "gps.h" GPSGSM gps; char lon[10]; char lat[10]; char alt[10]; char time[15]; char vel[10]; char stat; boolean started=false; void setup() { //Serial connection. Serial.begin(9600); Serial.println("GSM GPRS GPS Shield"); if (gsm.begin(2400)){ Serial.println("\nstatus=READY"); gsm.forceON(); started=true; } else Serial.println("\nstatus=IDLE"); if(started){ if (gps.attachGPS()) Serial.println("status=GPSON"); else Serial.println("status=ERROR"); delay(20000); stat=gps.getStat(); if(stat==1) Serial.println("NOT FIXED"); else if(stat==0) Serial.println("GPS OFF"); else if(stat==2) Serial.println("2D FIXED"); else if(stat==3) Serial.println("3D FIXED"); delay(5000); gps.getPar(lon,lat,alt,time,vel); Serial.println(lon); Serial.println(lat); Serial.println(alt); Serial.println(time); Serial.println(vel); } }; void loop() { }; </div> <div class="e_p"> <strong>THE BATTERY</strong> </div> <div class="e_p"> In order to use the lithium battery as the power source for our FT971 module that houses the SIM908 (note: the SIM900 is not able to manage the barrery charge) is sufficient to close the bridge on this shield called withCHRGand set onVEXTthe second bridge near the battery connector. </div> <div class="e_p"> Through the two library functions is possible to obtain the percentage of remaining charge, the battery voltage and the voltage read by the temperature sensor. In the case of applications poorly ventilated, with prolonged periods of work and in climatic conditions not exactly optimal, it is advisable to monitor this value to make sure that the battery works within the limits for a correct operation. The temperature can be calculated according to the relationship voltage/temperature sensor. </div> <div class="e_p"> It is also possible to set the module so that automatically determine if the battery is working outside the permissible range, with consequent shutdown of the same. </div> <div class="e_p"> To activate this mode, you need to send the command: </div> <div class="e_p"> AT+CMTE=1 </div> <div class="e_p"> To disable it you have to send the command: </div> <div class="e_p"> AT+CMTE=0 </div> <div class="e_p"> While to know which mode is configured must issue the command: </div> <div class="e_p"> AT+CMTE? </div> <div class="e_p"> To know the exact syntax of the functions and their return refer to Table: </div> <div class="e_p"> <table> <tbody> <tr> <td> char getBattInf(char* str_perc, char* str_vol); </td> <td> Save the remaining battery in percentage terms, and battery voltage. </td> <td> char str_perc[5]; <div class="e_p"> char str_vol[6]; </div> <div class="e_p"> gps.getBattInf(str_perc,str_vol); </div> <div class="e_p"> Serial.print(“BATTERY: ”); </div> <div class="e_p"> Serial.print(str_perc); </div> <div class="e_p"> Serial.println(“%”); </div> </td> </tr> <tr> <td> char getBattTVol(char* str_vol); </td> <td> Saves the voltage value of the temperature sensor. </td> <td> char str_Tvol[6]; <div class="e_p"> gps.getBattTVol(str_Tvol); </div> <div class="e_p"> Serial.println(str_Tvol); </div> </td> </tr> </tbody> </table> </div> <div class="e_p"> Also in this case we see how to implement these functions in a sketch, referring to this sketch, which contains the corresponding code. </div> <div class="e_p"> #include "SIM900.h" #include <SoftwareSerial.h> #include "inetGSM.h" #include "gps.h" GPSGSM gps; char perc[5]; char volt[6]; char tvolt[6]; long prevmillis=millis(); int interval=10000; void setup() { Serial.begin(9600); Serial.println("GSM GPRS GPS Shield."); if (gsm.begin(4800)){ Serial.println("\nstatus=READY"); gsm.forceON(); } else Serial.println("\nstatus=IDLE"); }; void loop() { if(millis()-prevmillis>interval){ gps.getBattInf(perc,volt); gps.getBattTVol(tvolt); Serial.print("Battery charge: "); Serial.print(perc); Serial.println("%"); Serial.print("Battery voltage: "); Serial.print(volt); Serial.println(" mV"); Serial.print("Temperature sensor voltage: "); Serial.print(tvolt); Serial.println(" mV"); Serial.println(""); prevmillis=millis(); } } </div> <div class="e_p"> <strong>DEBUG MODE GSM & GPS SHIELD</strong> </div> <div class="e_p"> During the use of the shield, sometimes you fail to get the desired results without understanding why, for help, libraries can be configured to provide output some debug messages during the execution of functions called. Inside the file GSM.h there is the following line: </div> <div class="e_p"> //#define DEBUG_ON </div> <div class="e_p"> Uncomment it, you are going to enable this mode, commenting, no diagnostic message will be shown on the serial output. </div> <div class="e_p"> <strong>HOW TO USE THE GSM & GPS SHIELD WITH ARDUINO MEGA</strong> </div> <div class="e_p"> For problems with the RAM, or simply for projects that require a larger number of input/output, we can use with the GSM/GPRS & GPS shield the Arduino Mega. Thanks to four serial port, we can use one of these instead of the serial software to communicate with the shield. </div> <div class="e_p"> With the latest release, the library can be used completely with Arduino Mega. You must open the fileGSM.hand select the tab used appropriately commenting lines of code. </div> <div class="e_p"> Using the shield with Arduino Mega we comment as follows: </div> <div class="e_p"> //#define UNO </div> <div class="e_p"> #define MEGA </div> <div class="e_p"> If we want to use Arduino UNO: </div> <div class="e_p"> #define UNO </div> <div class="e_p"> //#define MEGA </div> <div class="e_p"> Similarly, also the fileHWSerial.h, must be configured. As before, we see the first example for Arduino Mega: </div> <div class="e_p"> #define MEGA </div> <div class="e_p"> Using the fileHWSerial.his not necessary to define the possible use with Arduino Uno, as implemented in the class it is only used by the hardware serial. </div> <div class="e_p"> The library uses the serialSerial0(TX 1 RX 0) for external communication and the serialSerial1(RX 18 TX 19) to communicate with SIM900 and SIM908. Nothing prevents you replace every occurrence ofSerial1withSerial2or one that you prefer. </div> <div class="e_p"> Please note that to use the serial hardware you need to create the connection between the shield and Arduino Mega using a bridge: the TX pin of the shield must be connected to TX1 18 and the RX pin with the RX1 19. </div> </div>
96
comment
All comments
Unknown
2275
0
96
Rules about cashback: 1. Valid time: ALLPCB cashback activity will end on April 1st. 2. Capped amount: The capped amount of cashback for each account is $5,000. Each order can get a maximum of $2,000 cashback. That means every author can get $5,000 max. 3. Cashback range: The cashback activity only covers the corresponding PCB order. The order amount for other combined payment products will be invalid. 4. Clicking your own promotional link will be invalid. The same email address, shipping address, contact information, and phone number are all recognized as the same account. 5. ALLPCB has the final interpretation right of the cashback activity.
ALLPCB will donate 2% to the author for this promotion link.