Connect Your Arduino To Cellular Via Hologram's Network

Connect Your Arduino To Cellular Via Hologram's Network
Tutorials
Pat Hogan
June 3, 2015

NOTE: An updated version of this tutorial is available in our Documentation (/blog/arduino-on-cellular).

So far we’ve written a couple tutorials for connecting your Raspberry Pi (/blog/raspberry-pi-on-cellular) and BeagleBone (http://konekt.io/blog/connect-beaglebone-to-cellular-network/) to a cellular network. Behold, the final microcontroller in this epic three part series: the Arduino. If you backed our Kickstarter (https://www.kickstarter.com/projects/konekt/konekt-dash-cellular-dev-kit-free-global-data-plan), 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

  • Arduino Uno v3 (http://www.arduino.cc/en/Main/ArduinoBoardUno)*
  • Seeed Studio GPRS shield v3 (http://www.seeedstudio.com/depot/GPRS-Shield-V30-p-2333.html)*
  • USB A to B cable*
  • 12V 1A power adapter*
  • Konekt SIM card*
  • Arduino-compatible computer with USB (Windows, Mac, Linux – make sure you can run the Arduino Software (http://www.arduino.cc/en/Main/Software))

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

beautiful new hardware

  1. Register your SIM on the Konekt.io portal here (https://dashboard.konekt.io/frontend/#/app/activate_devices)
  2. The SIM number is the long number printed on the back of the white card (also printed directly on the SIM itself)

You found it!

  1. Punch out the Konekt SIM and slide it into the slot on the back of the GPRS shield
  2. To open the slot, you may need to slide the case slightly horizontal, in the direction of the “OPEN” arrow.
  3. Make sure the SIM is inserted so that the metal connectors will touch when the case is closed.
  4. After shutting the case, make sure to lock it by sliding it slightly horizontal in the direction of the “LOCK” arrow.

open

shut

  1. Stack and connect the GPRS shield on top of the Arduino

connect it!

Lookin' good!

  1. Connect your computer to the Arduino via USB
  2. A green light should illuminate on top of the GPRS shield.
  3. You may also want to plug in the power adapter at this time.

Connected

  1. Power on the GPRS shield (tiny button on the side)
  2. Hold the button down for 2 seconds, then release. A red light will illuminate to tell you that the shield is on.
  3. 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.
  4. 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.

Green light

Green and red lights

  1. Boot up the Arduino Software (http://www.arduino.cc/en/Main/Software)
  2. For help getting the Arduino software up and running with your device, detailed step-by-step installation instructions can be found here (http://www.arduino.cc/en/Guide/HomePage).
  3. Copy and paste the demo sketch I’ve provided below
  4. This is a modified sketch of the Seeed Studio GPRS source code example found here (http://www.seeedstudio.com/wiki/GPRS_Shield_V1.0#A_Simple_Source_Code_Examples) (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 (http://www.seeedstudio.com/wiki/GPRS_Shield_V1.0#Getting_Started_-_Fun_with_AT_Commands) to manually enter troubleshooting commands found here (http://m2msupport.net/m2msupport/data-call-at-commands-to-set-up-gprsedgeumtslte-data-call/).
  5. [c language="++"]/*Note: this code is a demo for how to use a gprs shield to sendan http request to a test website (using the Konekt APN).In order to communicate with the Arduino via terminal, make surethe outgoing baud rate is set to 19200, and that a carriage returnis 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 importantvoid 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());}[/c]</softwareserial.h>
  6. Upload the sketch to the Arduino and open the serial monitor
  7. Make sure the baud rate is set to 19200, with a carriage return appended to the end of each command.

screenshot of code

  1. Enter ‘h’ into the terminal at the top of the serial monitor to run the test-HTTP script
  2. Watch your Arduino request our test http page over cellular connectivity!
  3. Note: Some of the commands may take up to 10s to complete.
  4. Final output should look something like this:
  5. 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</title></head></html>



    OK

I hope this was helpful. As always, leave any comments or questions down below or on our community forum (https://community.konekt.io/). You can also view all of our additional tutorials here (http://konekt.io/blog/category/tutorials/). Thanks!

Get started with Hologram today

  • Talk to an IoT expert
  • Receive a free SIM
  • Customize your plan