Seeed Studio GPRS Shield v2 Using AT Commands

Seeed Studio GPRS Shield v2 Using AT Commands © MIT

This example walks through connecting a Seeed Studio GPRS Shield to the Hologram cellular network using raw AT commands.

  • 3,523 views
  • 1 comment
  • 3 respects

Components and supplies

About this project

Introduction

This tutorial will walk through connecting an Arduino Uno to the Hologram cellular network using the Seeed Studio GPRS shield.

Before starting, make sure you have the following components available:

  • USB A to B cable
  • 12V 1A power adapter
  • Hologram SIM card
  • Arduino-compatible computer with USB (Windows, Mac, Linux – make sure you can run the Arduino Software)

Set up the SIM and shield

Activate your SIM on the Hologram dashboard.

Punch out the Hologram SIM and slide it into the slot on the back of the GPRS shield. To open the slot, you may need to slide the case slightly horizontal, in the direction of the β€œOPEN” arrow.

Insert the SIM so that the metal connectors will touch when you close the case. After shutting the case, make sure to lock it by sliding it slightly horizontal in the direction of the β€œLOCK” arrow.

Stack and connect the GPRS shield on top of the Arduino

Connect your computer to the Arduino via USB

A green light should illuminate on top of the GPRS shield. You may also want to plug in the power adapter at this time.

Power on the GPRS shield using the small button on the side. Hold the button down for 2 seconds, then release. A red light will illuminate to tell you that the shield is on.

A green light will start flashing next to the red light, about once every second – this flash rate tells us that the device is attempting to connect to the cell network.

After about 5-10 seconds, the green light should slow down to a flash rate of about once every 3 seconds – this tells us that the device has connected to a cell network.

Uploading the demo sketch

Next, boot up the Arduino Software. For help getting the Arduino software up and running with your device, detailed step-by-step installation instructions are in the Arduino Guide.

Copy and paste the demo sketch provided below. This is a modified sketch of the Seeed Studio GPRS source code example found here (reference this for another example of how to send an SMS). This modified sketch has just filled in the Hologram APN and test URL for you.

For an example of modem debugging with AT commands, use the sketch here to manually enter troubleshooting commands found here.

Upload the sketch, found at the bottom of this project, to the Arduino and open the serial monitor.

Configure the baud rate to 19200, with a carriage return appended to the end of each command:

Enter β€˜h’ into the terminal at the top of the serial monitor to run the test-HTTP script.

Watch your Arduino request our test http page over cellular connectivity!

Final output should look something like this:

AT+CSQ
+CSQ: 10,0
OK
AT+CGATT?
+CGATT: 1
OK
AT+SAPBR=3,1,"CONTYPE","GPRS"
OK
AT+SAPBR=3,1,"APN","hologram"
OK
AT+SAPBR=1,1
OK
AT+HTTPINIT
OK
AT+HTTPPARA="URL","hologram/test.html"
OK
AT+HTTPPARA="CID",1
OK
AT+HTTPACTION=0
OK
+HTTPACTION:0,200,79
AT+HTTPREAD
+HTTPREAD:79
<html><head><title>It works</titleAT+HTTPTERM
OK

Code

Code snippet #1C/C++
Arduino sketch showing raw AT commands for a Seed Studio GPRS Shield with a Hologram.io SIM
/*
Note: this code is a demo for how to use a gprs shield to send
an http request to a test website (using the Hologram APN).

To communicate with the Arduino via terminal, set
the outgoing baud rate to 19200, and set line endings to
carriage return.

Then, in order to initiate the demo http request, enter
'h' into the terminal at the top of the serial monitor.
*/

#include <SoftwareSerial.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()
{
  // Input 'h' to run the test HTTP program
  if (Serial.available())
    switch(Serial.read())
    {
      case 'h':
        SubmitHttpRequest();
        break;
    }
  if (mySerial.available())
    Serial.write(mySerial.read());
}

// SubmitHttpRequest()
//
// Note: the time of the delays are very important
void SubmitHttpRequest()
{
  // Query signal strength of device
  mySerial.println("AT+CSQ");
  delay(100);

  ShowSerialData();

  // Check the status of Packet service attach. '0' implies device is not attached and '1' implies device is attached.
  mySerial.println("AT+CGATT?");
  delay(100);

  ShowSerialData();

  // Set the SAPBR, the connection type is using gprs
  mySerial.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");
  delay(1000);

  ShowSerialData();

  // Set the APN
  mySerial.println("AT+SAPBR=3,1,\"APN\",\"hologram\"");
  delay(4000);

  ShowSerialData();

  // Set the SAPBR, for detail you can refer to the AT command manual
  mySerial.println("AT+SAPBR=1,1");
  delay(2000);

  ShowSerialData();

  // Init the HTTP request
  mySerial.println("AT+HTTPINIT");

  delay(2000);
  ShowSerialData();

  // Set HTTP params, the second param is the website to request
  mySerial.println("AT+HTTPPARA=\"URL\",\"hologram.io/test.html\"");
  delay(1000);

  ShowSerialData();

  //Set the context ID
  mySerial.println("AT+HTTPPARA=\"CID\",1");
  delay(1000);

  ShowSerialData();

  // Submit the request
  mySerial.println("AT+HTTPACTION=0");
  // The delay is very important, the delay time is base on the
  // return time from the website, if the return data is very
  // large, the time required might be longer.
  delay(10000);

  ShowSerialData();

  // Read the data from the accessed website
  mySerial.println("AT+HTTPREAD");
  delay(10000);

  ShowSerialData();

  // Close the HTTP connection and display the data
  mySerial.println("AT+HTTPTERM");
  delay(100);
}

// ShowSerialData()
// This is to show the data from gprs shield, to help
// see how the gprs shield submits an http request.
void ShowSerialData()
{
  while(mySerial.available()!=0)
    Serial.write(mySerial.read());
}

Comments

Similar projects you might like

LTE Cellular Shield for Arduino with Voice!

by Timothy Woo

  • 12,246 views
  • 9 comments
  • 19 respects

Unicorn Finder (Kid Tracker for Techie Parents)

Project tutorial by Team Hologram

  • 6,822 views
  • 2 comments
  • 19 respects

Use Losant on a Cellular Arduino

by Moheeb Zara

  • 2,843 views
  • 1 comment
  • 8 respects

Autonomous Line Follower with Seeed Shield Bot 1.2 and ARTe

Project showcase by stefano_maugeri

  • 1,052 views
  • 0 comments
  • 2 respects
Add projectSign up / Login