Connect Your Arduino To Cellular Via Hologram’s Network

/ Written By Pat Hogan

NOTE: An updated version of this tutorial is available in our Documentation.

So far we’ve written a couple tutorials for connecting your Raspberry Pi and BeagleBone to a cellular network. Behold, the final microcontroller in this epic three part series: the Arduino.

If you backed our Kickstarter, you’re probably aware that we offered an Arduino package. For those that selected that package, this is the tutorial for you – taking you from out-the-box, to requesting web pages over cellular, all in a single how-to.

Some differences between the Arduino and BeagleBone/Raspberry Pi:

  • The Arduino communicates via a USB A to B cable (provided in Kickstarter package), not via micro-USB or SD card.
  • The provided cell modem comes as a separate GPRS shield that mounts completely on top of the Arduino, it’s not connected as a USB peripheral.

A major caveat I came across in my testing:

  • The power consumed by the GPRS shield, in conjunction with the Arduino, may exceed the available power provided by USB connection alone – especially during spikes of cellular activity. This would cause my GPRS shield to power off in the middle of HTTP requests on some occasions. As a result, we will be providing a 12V 1A power adapter in each Arduino package, which should be more than enough to satisfy any power-hungry Arduino projects, while being within the limits of recommended power specifications.

Ingredients:

Items with a * are included in the Konekt Dash Kickstarter Arduino Maker Kit

Instructions:

Note: If you are using a different cellular shield than the one provided in our Kickstarter package, these instructions should still be compatible, so long as the modem can be controlled using the standard AT command set: GSM 07.07 & 07.05 and Enhanced – SIMCOM AT Commands.

  1. Unpack your beautiful new hardware
    arduino_unpack
  1. Register your SIM on the Konekt.io portal here
    • The SIM number is the long number printed on the back of the white card (also printed directly on the SIM itself).

    arduino_sim

  1. Punch out the Konekt 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.
    • Make sure the SIM is inserted so that the metal connectors will touch when the case is closed.
    • After shutting the case, make sure to lock it by sliding it slightly horizontal in the direction of the “LOCK” arrow.

    arduino_sim_open arduino_sim_close

  1. Stack and connect the GPRS shield on top of the Arduino
    arduino_stack_open arduino_stack_close
  1. 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.

    arduino_usb

  1. Power on the GPRS shield (tiny 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.

    button_off arduino_button_on

  1. Boot up the Arduino Software
    • For help getting the Arduino software up and running with your device, detailed step-by-step installation instructions can be found here.
  1. Copy and paste the demo sketch I’ve provided below
    • This is a modified sketch of the Seeed Studio GPRS source code example found here (reference this for an additional example of how to send an SMS). My modified sketch has simply filled in the Konekt APN and test url for you.
      • For additional modem debugging with AT commands, use the sketch here to manually enter troubleshooting commands found here.
    /*
    Note: this code is a demo for how to use a gprs shield to send
    
    an http request to a test website (using the Konekt APN).
    
    In order to communicate with the Arduino via terminal, make sure
    the outgoing baud rate is set to 19200, and that a carriage return
    is appended to the end of each command.
    
    Then, in order to initiate the demo http request, simply 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\",\"apn.konekt.io\"");
      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\",\"konekt.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());
    }
    
  1. Upload the sketch to the Arduino and open the serial monitor
    • Make sure the baud rate is set to 19200, with a carriage return appended to the end of each command.

    arduino_software

  1. Enter ‘h’ into the terminal at the top of the serial monitor to run the test-HTTP script
  1. Watch your Arduino request our test http page over cellular connectivity!
    • Note: Some of the commands may take up to 10s to complete.
    • 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","apn.konekt.io"
    
    OK
    AT+SAPBR=1,1
    
    OK
    AT+HTTPINIT
    
    OK
    AT+HTTPPARA="URL","konekt.io/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
    

I hope this was helpful. As always, leave any comments or questions down below or on our community forum. You can also view all of our additional tutorials here. Thanks!