Difference between revisions of "Arduino GPRS Shield"

From Geeetech Wiki
Jump to: navigation, search
(Upload Sketch to Arduino)
Line 172: Line 172:
 
#Connect the Arduino Duemilanove (or Seeeduino) to your computer using a USB cable.  
 
#Connect the Arduino Duemilanove (or Seeeduino) to your computer using a USB cable.  
 
#The ATmega328P microcontroller on Duemilanove board has only one UART which is used for communicating with the PC. What we need is an Arduino Sketch running inside the ATmega328P that would emulate a second serial port (UART) using software on the digital pins D8 and D7 and patch through all the communication between this second software serial port and the actual hardware serial port. By doing this, all the data coming from the computer (connected to the actual hardware UART) would be routed to the GPRS Shield (connected to software UART) then, we would be able to issue AT commands to control the GPRS Shield. The block diagram outlining this scheme is shown below.
 
#The ATmega328P microcontroller on Duemilanove board has only one UART which is used for communicating with the PC. What we need is an Arduino Sketch running inside the ATmega328P that would emulate a second serial port (UART) using software on the digital pins D8 and D7 and patch through all the communication between this second software serial port and the actual hardware serial port. By doing this, all the data coming from the computer (connected to the actual hardware UART) would be routed to the GPRS Shield (connected to software UART) then, we would be able to issue AT commands to control the GPRS Shield. The block diagram outlining this scheme is shown below.
 +
 +
For developing such a program, we require to use the SoftwareSerial library included in the libraries of Arduino 1.0 already and the demo code below.
 +
 +
//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 GPRS(7, 8);
 +
unsigned char buffer[64]; // buffer array for data recieve over serial port
 +
int count=0;    // counter for buffer array
 +
void setup()
 +
{
 +
  GPRS.begin(19200);              // the GPRS baud rate 
 +
  Serial.begin(19200);            // the Serial port of Arduino baud rate.
 +
}
 +
void loop()
 +
{
 +
  if (GPRS.available())              // if date is comming from softwareserial port ==> data is comming from gprs shield
 +
  {
 +
    while(GPRS.available())          // reading data into char array
 +
    {
 +
      buffer[count++]=GPRS.read();    // writing data into array
 +
      if(count == 64)break;
 +
  }
 +
    Serial.write(buffer,count);            // if no data transmission ends, write buffer to hardware serial port
 +
    clearBufferArray();              // call clearBufferArray function to clear the storaged data from the array
 +
    count = 0;                      // set counter of while loop to zero
 +
  }
 +
  if (Serial.available())            // if data is available on hardwareserial port ==> data is comming from PC or notebook
 +
    GPRS.write(Serial.read());      // write it to the GPRS shield
 +
}
 +
void clearBufferArray()              // function to clear buffer array
 +
{
 +
  for (int i=0; i<count;i++)
 +
    { buffer[i]=NULL;}                  // clear all index of array with command NULL
 +
}
  
 
== Examples ==
 
== Examples ==

Revision as of 03:44, 20 November 2012

Introduction

GPRS1.jpg GPRS2.jpg

The GPRS Shield is based on SIM900 module from SIMCOM and compatible with Arduino and its clones. The GPRS Shield provides you a way to communicate using the GSM cell phone network. The shield allows you to achieve SMS, MMS, GPRS and Audio via UART by sending AT commands (GSM 07.07 ,07.05 and SIMCOM enhanced AT Commands). The shield also has the 12 GPIOs, 2 PWMs and an ADC of the SIM900 module(They are all 2V8 logic) present onboard.

Features

  • Quad-Band 850 / 900/ 1800 / 1900 MHz - would work on GSM networks in all countries across the world.
  • GPRS multi-slot class 10/8
  • GPRS mobile station class B
  • Compliant to GSM phase 2/2+
  • Class 4 (2 W @ 850 / 900 MHz)
  • Class 1 (1 W @ 1800 / 1900MHz)
  • Control via AT commands - Standard Commands: GSM 07.07 & 07.05 | Enhanced Commands: SIMCOM AT Commands.
  • Short Message Service - so that you can send small amounts of data over the network (ASCII or raw hexadecimal).
  • Embedded TCP/UDP stack - allows you to upload data to a web server.
  • RTC supported.
  • Selectable serial port.
  • Speaker and Headphone jacks
  • Low power consumption - 1.5mA(sleep mode)
  • Industrial Temperature Range - -40°C to +85 °C

Specifications

Application Ideas

  • M2M (Machine 2 Machine) Applicatoions.
  • Remote control of appliances.
  • Remote Weather station or a Wireless Sensor Network.
  • Vehicle Tracking System with a GPS module.

Cautions

  • Make sure your SIM card is unlocked.
  • The product is provided as is without an insulating enclosure. Please observe ESD precautions specially in dry (low humidity) weather.
  • The factory default setting for the GPRS Shield UART is 19200 bps 8-N-1. (Can be changed using AT commands).

Hardware Diagram

Getting Started

Indicator LEDs

There are three indicator LEDs(PWR(Green), Staus(Blue), Netlight(Red)) on the GPRS Shield, users can know about the working state of the shield based on the three indicator LEDs. Detailed information please refer to the following table:

Indicator LEDs.jpg

Power Up and Power Down the GPRS Shield

Power Up the GPRS Shield

The GPRS Shield can be turned on by two ways:

  • 1, Hardware Triger; Press the ON/OFF Button about two seconds.The power up scenarios illustrates as following figure:

GPRS ONs.jpg

  • 2, Software Triger; If use this way to power up the GPRS Shield, JP need to be soldered, then Digital Pin 9 of the Arduino will act as Software Triger port and Digital Pin 9 can not be use as other purpose. Then give Digital Pin 9 a Turn on Impulse can power up the GPRS Shield. The power up scenarios illustrates as following figure:

GPRS Pwrs.jpg

The following code is power up subroutine for Arduino if using software triger:

void powerUp()
{
 pinMode(9, OUTPUT); 
 digitalWrite(9,LOW);
 delay(1000);
 digitalWrite(9,HIGH);
 delay(2000);
 digitalWrite(9,LOW);
 delay(3000);
}

When power on procedure completes, the SIM900 will send out following result code to indicate the GPRS shield is ready to operate; When set as fixed baud rate, the SIM900 will send out result code: RDY This result code does not appear when auto baud rate is active.

Power Down the GPRS Shield

The GPRS Shield can be turned off by following ways:

  • 1, Normal power down procedure: Turn off the GPRS shield by using Hardware Triger; Press the ON/OFF Button about two seconds.

The power down scenarios illustrates as following figure:

Gprspowerdown.jpg

2, Normal power down procedure: If JP is soldered, then give Digital Pin 9 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:

GprsPwrd1.jpg

The following code is power down subroutine for Arduino if using software triger:

void powerDown()
{
 pinMode(9, OUTPUT); 
 digitalWrite(9,LOW);
 delay(1000);
 digitalWrite(9,HIGH);
 delay(2000);
 digitalWrite(9,LOW);
 delay(3000);
}
  • 3, Normal power down procedure:Turn off the GPRS shield by sending AT command “AT+CPOWD=1” to SIM900 module.

When GPRS Shield power dowm in Normal power down procedure, the procedure lets the SIM900 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 SIM900 will send out result code: NORMAL POWER DOWN


  • 4, Over-voltage or Under-voltage Automatic Power Down: SIM900 will constantly monitor the voltage applied on the VBAT.

①If the voltage ≤ 3.3V, the following URC will be presented:


UNDER-VOLTAGE WARNNING

②If the voltage ≥ 4.7V, the following URC will be presented:

OVER-VOLTAGE WARNNING

③The uncritical voltage range is 3.2V to 4.8V. If the voltage > 4.8V or < 3.2V, SIM900 will be automatic power down soon. If the voltage < 3.2V, the following URC will be presented:

UNDER-VOLTAGE POWER DOWN

④If the voltage > 4.8V, the following URC will be presented:

OVER-VOLTAGE POWER DOWN

  • 5, Over-temperature or Under-temperature Automatic Power Down: SIM900 will constantly monitor the temperature of the module.

①If the temperature > 80℃, the following URC will be presented:

+CMTE:1

②If the temperature < -30℃, the following URC will be presented:

+CMTE:-1

③The uncritical temperature range is -40℃ to +85℃. If the temperature > +85℃ or < -40℃, the module will be automatic power down soon. If the temperature > +85℃, the following URC will be presented:

+CMTE:2

④If the temperature < -40℃, the following URC will be presented:

+CMTE:-2

When the GPRS Shield encounters POWER DOWN scenario, the AT commands can not be executed. The SIM900 logs off from network and enters the POWER DOWN mode, only the RTC is still active. POWER DOWN can also be indicated by STATUS LED(Blue), which is off in this mode.

Note:

  • To monitor the temperature, users can use the “AT+CMTE” command to read the temperature when GPRS Shield is powered on.
  • To monitor the supply voltage, users can use the “AT+CBC” command which includes a parameter: voltage value(in mV) when GPRS Shield is powered on.

Serial Port(UART) Communication

The GPRS 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:

GPRSComs.jpg

Note:

  • Users can use “AT+IPR=?” command to see supported baudrate, it will response a list of supported baudrate.
  • Users can use “AT+IPR=x”(x is value of supported baudrate) to set a fixed baud rate and save the configuration to non-volatile flash memory.


Upload Sketch to Arduino

Grpsaurduinouart.jpg

The following sketch configures Arduino/Arduino clone as serial link between PC and the GPRS Shield(Jumpers on SWserial side). PC would need a serial terminal software to communicate with it - Window's built-in HyperTerminal, Arduino IDE's Serial Monitor, Serial Terminals(sscom32) or 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

The GPRS Shield comes with all the accessories that you need to get started with sending data over the GSM network except an Arduino board and a GSM SIM Card. If you want to make voice calls, you would also require a headset with microphone.

Step 1: Creating a test setup for the GPRS Shield

AT Commands are simple textual commands sent to the GPRS modem over its serial interface (UART), so you can use any serial terminal software to communicate with it.

Note: Almost all the AT commands should be sent followed by carriage return and you need to select the "+CR"option in the serial port terminal.To experiment with AT commands, you would require a way to power up and communicate with your GPRS Shield. The best way to do this using an Arduino Duemilanove board.

  1. Follow the previously described hardware installation steps to set up the hardware system;
  2. Make sure the GPRS_TX & GPRS_RX jumpers on the GPRS Shield are mounted in SWSerial position - that is we want GPRS_TX to be connected to D7(RX) and GPRS_RX to D8(TX).
  3. Connect the Arduino Duemilanove (or Seeeduino) to your computer using a USB cable.
  4. The ATmega328P microcontroller on Duemilanove board has only one UART which is used for communicating with the PC. What we need is an Arduino Sketch running inside the ATmega328P that would emulate a second serial port (UART) using software on the digital pins D8 and D7 and patch through all the communication between this second software serial port and the actual hardware serial port. By doing this, all the data coming from the computer (connected to the actual hardware UART) would be routed to the GPRS Shield (connected to software UART) then, we would be able to issue AT commands to control the GPRS Shield. The block diagram outlining this scheme is shown below.

For developing such a program, we require to use the SoftwareSerial library included in the libraries of Arduino 1.0 already and the demo code below.

//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 GPRS(7, 8);
unsigned char buffer[64]; // buffer array for data recieve over serial port
int count=0;     // counter for buffer array 
void setup()
{
 GPRS.begin(19200);               // the GPRS baud rate   
 Serial.begin(19200);             // the Serial port of Arduino baud rate.
}
void loop()
{
 if (GPRS.available())              // if date is comming from softwareserial port ==> data is comming from gprs shield
 {
   while(GPRS.available())          // reading data into char array 
   {
     buffer[count++]=GPRS.read();     // writing data into array
     if(count == 64)break;
 }
   Serial.write(buffer,count);            // if no data transmission ends, write buffer to hardware serial port
   clearBufferArray();              // call clearBufferArray function to clear the storaged data from the array
   count = 0;                       // set counter of while loop to zero
 }
 if (Serial.available())            // if data is available on hardwareserial port ==> data is comming from PC or notebook
   GPRS.write(Serial.read());       // write it to the GPRS shield
}
void clearBufferArray()              // function to clear buffer array
{
 for (int i=0; i<count;i++)
   { buffer[i]=NULL;}                  // clear all index of array with command NULL
}

Examples

  • The default Buffer of Rx in NewSoftSerial.h is 32, you may experience some data lose while the returns of SIM900 are many(Receiving SMS/TCPIP), you can try to change the Buffer of Rx in NewSoftSerial.h into
#define _NewSS_MAX_RX_BUFF 128 // RX buffer size

Sending SMS: using Software UART

#include <NewSoftSerial.h>

NewSoftSerial 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=\"+861032055002\"\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("Hi from Getech!\r");   //The text for the message
 delay(1000);
 mySerial.print(26,BYTE);  //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.
}

Making a call: using Software UART

#include <NewSoftSerial.h>

NewSoftSerial 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
}

Using AT Commands to Control GPIO and PWM pins

Note: GPIOs,PWMs and ADC of the SIM900 module are all 2V8 logic

#include <NewSoftSerial.h>

NewSoftSerial mySerial(7, 8);

void setup()
{
 mySerial.begin(19200);               // the GPRS baud rate   
 Serial.begin(19200);               // the GPRS baud rate   
 delay(2000);
}

void loop()
{
 mySerial.println("AT+SPWM=1,63,100");// set PWM 1 PIN
 mySerial.println("AT+SPWM=2,63,50");// set PWM 2 PIN

 mySerial.println("AT+SGPIO=0,1,1,1");// set GPIO 1 PIN to 1
 mySerial.println("AT+SGPIO=0,12,1,1");
 delay(1000);  

 mySerial.println("AT+SGPIO=0,1,1,0");// set GPIO 1 PIN to 0
 mySerial.println("AT+SGPIO=0,12,1,0");
 delay(1000);    
}

Schematics

GPRSshield_sch.pdf

Resources

SIM900 AT Commands Manual v1.03.pdf

SIM900_hd_v1.06.pdf

SIM900_TCP/IP Application Note

Si5902BDC - Dual N-Channel 30 V (D-S) MOSFETs (used for 2.8V <> 5.0V translation for Serial Interface)

NewSoftLibrary

Serial Terminals(sscom32)

How to buy

GPRS Shield can be ordered through the Getech store. Its product page is located here