What is GOBLIN 2?

GOBLIN 2 is a development card designed to be autonomous from the “Internet of Things", it has a module to control the charge of a Li-Po battery of 3.7V to 4.2V, which it can charge through a solar cell or a Micro-USB.
GOBLIN 2 is compatible with Arduino and ATMEL Studio, versatile in connectivity and ready for remote communication.

It also has a micro-controller ATMEGA328P, 5 analogue ports and 10 digital ones, which only 5 work as a PWM, it also integrates connectivity for each RS-485 protocol and voltage outputs of 24V, 5V and 3.3V that are ideal for industrial sensors or sensors with analog/digital signal.

Its design for the “Internet of Things” is thanks to the SIM5320A that incorporates a Dual-BAND link UMTS/HSDPA TO 850/1900MHz and Quad-Band GSM/GPRS/ EDGE to 850/900/1800/1900mhz and so it can have the connectivity with web servers through any cellular web.

As the module SIM5320A is added, it is available in its outputs to be connected to a keyboard, microphone/speakers and USB to explode the cellular web, to the reach of your needs and innovations.

On this guide you'll learn how to setup the GOBLIN 2 to send data to Ubidots.

If you desire read more about the hardware of the GOBLIN 2, please go to the following link

Requirements

Hardware setup

The GLOBLIN 2 has amazing features, so you have to know it well to be able to create incredibles IoT projetcs in just few minutes.

To start, please go to the "Quick start" of the VERSE Technology Team, and check the documatation step by step. It's importat read it carefully to make sure that everthing it's gonna be perfect!

Ubidots setup

Firstably, go to your Ubidots account. If you don't have one,  create one here

1.- Go to device section cliking on the "Device" tab.

2.- Create a new device, just press "Add Device".

Once the device is  created, you should see something like this:

3.- Enter to the device just created to add a  new variable. Select "Add variable".

Assign a name for the variable, in this case we decided call it "sensor". Also, on the icon below you'll able to know the Variable ID, you'll  need it on the code. 

4.- Also, you'll need the TOKEN. Click on your "username" and select API Credentials:

Copy and paste it into your code.

Arduino setup

As we said before the GOBLIN 2 is compatible with Arduino and ATMEL Studio. On this guide we decided to setup the GOBLIN 2 with the Arduino  IDE .

One of the common question is "Which board should I use?" Very simple! Just select the Arduino/Genuino UNO

We're going to provide you with an example code to start sending data to Ubidots; if you are familiar with or want to explore about it, check out our API reference here.

You have to add some parameters from your  Ubidots account to the code, like the token and variable ID, also need your mobile operator’s APN. Go to the step "Ubidots setup" to know where could you find the parametes needed.

To add the APN please go to this line on the code and change it for the one from your mobile operator:

NOTE: Make sure of the  "Switch 2" position, it should be in the “PROGRAM” position (slide to its right). That's important because enables the programming mode for ATMEL-328P. With this, we can communicate with the microcontroller from the PC and upload programs from the Arduino IDE

With the following program you'll be able to send data to the Ubidots cloud using the variable ID:

#include <SoftwareSerial.h>                           

SoftwareSerial SIM5320(5, 4);                                                   //RX, TX
#define ONE_WIRE_BUS 10                                                         //PIN DS18B20


char    BUFFER_USART;                                                           //BUFFER RX
String  token = "PUT_YOUR_TOKEN_HERE"; //TOKEN UBIDOTS
String  id    = "PUT_VARIABLE_ID_HERE"; //ID VARIABLE UBIDOTS

void setup() {
  pinMode(5, OUTPUT);                              //PIN ON SIM5320
  SIM5320.begin(9600);
  SIM5320_ON();                                    //ON SIM5320
  delay(10000);
  SETUP_SIM5320();                                 //START SIM5320
}

void loop() {

  WEB();                                           //SEND JSON UBIDOTS
  delay(15000);                                    //SAMPLE TIME
}
///////////////////////////////////////////////////////////////////////////
ISR (USART_RX_vect)
{
  BUFFER_USART = UDR0;                               // READ THE BUFFER RX
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void WEB()                                  
{
  int LONG_JSON = 15;
  int SEND = 209;
   
  float temp = 20.0;
  SIM5320.println(F("AT+CIPOPEN=0,\"TCP\",\"things.ubidots.com\",80"));  //
  delay(5000);
  SIM5320.print("AT+CIPSEND=0,");  //
  delay(50);
  SIM5320.println(SEND);  //
  delay(600);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  SIM5320.print(F("POST /api/v1.6/variables/"));
  delay(50);
  SIM5320.print(id);
  delay(50);
  SIM5320.println(F("/values  HTTP/1.1"));
  delay(50);
  SIM5320.println(F("Content-Type: application/json"));
  delay(50);
  SIM5320.print(F("Content-Length:"));
  delay(50);
  SIM5320.println(LONG_JSON);
  delay(50);
  SIM5320.print(F("X-Auth-Token: "));
  delay(50);
  SIM5320.println(token);
  delay(50);
  SIM5320.println(F("Host: things.ubidots.com"));
  delay(50);
  SIM5320.println("");
  ///////////////////////////////////////////////////////////////
  SIM5320.print("{\"value\":");
  delay(10);
  SIM5320.print(temp,2);
  delay(50);
  SIM5320.println("}");
  delay(50);
  SIM5320.write(0x1A);
  delay(5000);
  SIM5320.println(F("AT+CIPCLOSE=0"));
  delay(4000);

}

void SIM5320_ON()          
{
  digitalWrite(5, HIGH);
  delay(2000);//                            
  digitalWrite(5, LOW);
  delay(2000);
}
/////////////////////////////////////////////////////////////////////////////
void SETUP_SIM5320()
{
  SIM5320.println(F("AT+CFUN=1"));                      //SIM5320 WORKING WITH ALL THE FEATURES
  delay(250);

  SIM5320.println(F("AT+CNMP=2"));                      //AUTOMATIC MODE
  delay(250);

  SIM5320.println(F("AT+CVAUXV=61"));                   //3.0V OUTPUT VOLTAGE
  delay(250);

  SIM5320.println(F("AT+CNBP=0x0000000004000000"));     //3G 850MHZ TELCEL 0x0000000004000000 hspda     2G 1900MHZ TELCEL AT+CNBP=0x0000000000200000 edge
  delay(500);

  SIM5320.println(F("AT+CSQ"));                         //SIGNAL LEVEL
  delay(250);

  SIM5320.println(F("AT+CREG?"));          
  delay(250);

  SIM5320.println(F("AT+COPS?"));
  delay(250);
 
  SIM5320.println(F("AT+CGSOCKCONT=1,\"IP\",\"internet.movistar.com.co\""));
  delay(250);

  SIM5320.println(F("AT+CNSMOD?"));                     //MUESTRA EN QUE RED ESTA TRABAJANDO
  delay(250);

  SIM5320.println(F("AT+CSOCKSETPN=1"));
  delay(250);

  SIM5320.println(F("AT+CIPMODE=0"));
  delay(250);

  SIM5320.println(F("AT+CNBP?"));
  delay(250);

  SIM5320.println(F("AT+NETOPEN"));
  delay(8000);

  SIM5320.println(F("AT+IPADDR"));                       //IP
  delay(500);

  SIM5320.println(F("AT+CGSN"));                         //IMEI
  delay(500);
}

Also if you desire, you can use this example code to send data to ubidots using the device and variable label: 

#include <SoftwareSerial.h>                           

#define token "PUT_YOUR_TOKEN_HERE" //TOKEN UBIDOTS

SoftwareSerial SIM5320(5, 4);                                                   //RX, TX

char    BUFFER_USART;                                                           //BUFFER RX
                                 
String devLabel = "goblin-2";                       // LABLE DEVICE - UBIDOTS
String varLabel = "humidity";                     // LABEL VARIABLE - UBIDOTS

int sensor = A0;                                  // DECLARED PIN
 
void setup() {
  pinMode(5, OUTPUT);                              //PIN ON SIM5320
  pinMode(sensor, INPUT);                          // PIN AS AN INPUT
  SIM5320.begin(9600);          
  SIM5320_ON();                                    //ON SIM5320
  delay(10000);
  SETUP_SIM5320();                                 //START SIM5320                    
}

void loop() {
  WEB();                                           //SEND JSON UBIDOTS
  delay(15000);                                    //SAMPLE TIME
}
///////////////////////////////////////////////////////////////////////////
ISR (USART_RX_vect)
{
  BUFFER_USART = UDR0;                               // READ THE BUFFER RX
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void WEB()                                  
{
  char buffer_tmp[8];
  int LONG_JSON =13;                   // LENGTH OF JSON, e.i: {"humidity":}
  int SEND = 214;                      // NUMBER OF CHARACTERS TO SEND (HEADER + JSON)
   
  float   hum  = analogRead(sensor);  // ANALOG SENSOR READ

  dtostrf(hum,4,2, buffer_tmp);       // FLOAT A CHAR ARRAY
  String  hum_s = buffer_tmp;         // CONVERT THE FLOAT HUM TO STRING SO WE CAN CALCULATE THE LENGTH

  SEND+=LONG_JSON+hum_s.length();     // NUMBER OF CHARACTER TO SEND (HEADER + JSON + SENSOR FLOAT (DYNAMIC))
  LONG_JSON+=hum_s.length();          // lENGTH JSON FIXED CHARACTERS + ANALOG SENSOR DYNAMICS

 
  SIM5320.println(F("AT+CIPOPEN=0,\"TCP\",\"things.ubidots.com\",80"));  //
  delay(5000);
  SIM5320.print("AT+CIPSEND=0,");  //
  delay(50);
  SIM5320.println(SEND);  //
  delay(600);
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////  
  SIM5320.print(F("POST /api/v1.6/devices/"));
  delay(50);
  SIM5320.print(devLabel);
  delay(50);
  SIM5320.println(F(" HTTP/1.1"));
  delay(50);
  SIM5320.println(F("Host: things.ubidots.com"));
  delay(50);
  SIM5320.println(F("User-Agent: GOBLIN-2/1.0"));
  delay(50);
  SIM5320.print(F("X-Auth-Token: "));
  delay(50);
  SIM5320.println(token);
  delay(50);
  SIM5320.println(F("Connection: close"));
  delay(50);
  SIM5320.println(F("Content-Type: application/json"));
  delay(50);
  SIM5320.print(F("Content-Length:"));
  delay(50);
  SIM5320.println(LONG_JSON);
  delay(50);
  SIM5320.println("");
  ///////////////////////////////////////////////////////////////
  SIM5320.print("{\"" + varLabel + "\":" +hum_s+ "}\r\n\r\n");                //{"humidity":}  13 STATIC CHARACTER
  delay(50);
  SIM5320.write(0x1A);
  delay(6000);
 
}

void SIM5320_ON()          
{
  digitalWrite(5, HIGH);                                                // TURN ON THE SIM WITH A PULSE ON-OFF (USING PIN 5)
  delay(2000);//                            
  digitalWrite(5, LOW);
  delay(2000);
}
/////////////////////////////////////////////////////////////////////////////
void SETUP_SIM5320()
{
  SIM5320.println(F("AT+CFUN=1"));                      //SIM5320 WORKING WITH ALL THE FEATURES
  delay(250);

  SIM5320.println(F("AT+CNMP=2"));                      //AUTOMATIC MODE
  delay(250);

  SIM5320.println(F("AT+CVAUXV=61"));                   //3.0V OUTPUT VOLTAGE
  delay(250);

  SIM5320.println(F("AT+CNBP=0x0000000004000000"));     //3G 850MHZ TELCEL 0x0000000004000000 hspda     2G 1900MHZ TELCEL AT+CNBP=0x0000000000200000 edge
  delay(500);

  SIM5320.println(F("AT+CSQ"));                         //SIGNAL LEVEL
  delay(250);

  SIM5320.println(F("AT+CREG?"));          
  delay(250);

  SIM5320.println(F("AT+COPS?"));
  delay(250);
 
  SIM5320.println(F("AT+CGSOCKCONT=1,\"IP\",\"internet.movistar.com.co\""));  // MOBILE OPERATOR'S APN
  delay(250);

  SIM5320.println(F("AT+CNSMOD?"));                     //SHOW THE NETWORK
  delay(250);

  SIM5320.println(F("AT+CSOCKSETPN=1"));
  delay(250);

  SIM5320.println(F("AT+CIPMODE=0"));
  delay(250);

  SIM5320.println(F("AT+CNBP?"));
  delay(250);

  SIM5320.println(F("AT+NETOPEN"));
  delay(8000);

  SIM5320.println(F("AT+IPADDR"));                       //IP
  delay(500);

  SIM5320.println(F("AT+CGSN"));                         //IMEI
  delay(500);
}

Once the code is flashed into the GOBLIN 2, open the serial monitor to visuals the AT commands response. Remember to change the position of switch 2 to the “SIM_AT+” position (slide to its left). This enables the communication mode with the SIM5320A from the PC, and is used to send commands AT+ straight from a serial monitor, such as Arduino IDE, to the cellular network.

Once the STATUS NET led is bliking, you should start receiving the response into the serial monitor:

Now, you're receiving data into your Ubidots account:

It's you time to create and amazing dashboard for visualize your data. If you don't know how to do it take a look of this video.

If you want to learn more about the GOBLIN 2 and Ubidots take a look of this video tutorials to make an amazing IoT project!

Did this answer your question?