1
votes

Hey so I have arduino uno and a sim808 with gps antenna and gsm antenna. So here's the sample code:

#include <DFRobot_sim808.h>
#include <SoftwareSerial.h>

#define PIN_TX    3
#define PIN_RX    4
SoftwareSerial mySerial(PIN_TX,PIN_RX);
//DFRobot_SIM808 sim808(&mySerial);//Connect RX,TX,PWR,

DFRobot_SIM808 sim808(&mySerial);

void setup() {
  //mySerial.begin(9600);
  Serial.begin(9600);

  //******** Initialize sim808 module *************
  while(!sim808.init()) { 
      delay(1000);
      Serial.print("Sim808 init error\r\n");
  }

  //************* Turn on the GPS power************
  if( sim808.attachGPS())
      Serial.println("Open the GPS power success");
  else 
      Serial.println("Open the GPS power failure");

}

void loop() {
   //************** Get GPS data *******************
   if (sim808.getGPS()) {
    Serial.print(sim808.GPSdata.year);
    Serial.print("/");
    Serial.print(sim808.GPSdata.month);
    Serial.print("/");
    Serial.print(sim808.GPSdata.day);
    Serial.print(" ");
    Serial.print(sim808.GPSdata.hour);
    Serial.print(":");
    Serial.print(sim808.GPSdata.minute);
    Serial.print(":");
    Serial.print(sim808.GPSdata.second);
    Serial.print(":");
    Serial.println(sim808.GPSdata.centisecond);
    Serial.print("latitude :");
    Serial.println(sim808.GPSdata.lat);
    Serial.print("longitude :");
    Serial.println(sim808.GPSdata.lon);
    Serial.print("speed_kph :");
    Serial.println(sim808.GPSdata.speed_kph);
    Serial.print("heading :");
    Serial.println(sim808.GPSdata.heading);
    Serial.println();

    //************* Turn off the GPS power ************
    sim808.detachGPS();
  }

}

So I'm always getting a result of "sim808 init error" here's the result

I don't know what the problem is but I do hope that the sim808 isn not broken because it has light in STA(status) and in NET(network) that is slowly blinking but there's no light in PPS(gps) I don't know what's the problem I'm really really confused.

2

2 Answers

0
votes

You must use pins 7 and 8 of the Arduino as Tx and Rx. With the 3 and 2 you have selected it will not work for you.

0
votes
//mySerial.begin(9600);

This line just below the void setup must be a code part not comment, delete the

'//'   
  mySerial.begin(9600);
  Serial.begin(9600);

Also 6th line

//DFRobot_SIM808 sim808(&mySerial);//Connect RX,TX,PWR,
must be part of code not comment, delete the '//'

Try again as

DFRobot_SIM808 sim808(&mySerial);//Connect RX,TX,PWR,

It should work, since it is a cold start it might take time, if you had problem again correcting those comment lines into code, just swap the pins