BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Blynk GPS Tracker with Sim800L and Neo 6M V2 multiple software serial devices problem with simple timer

arduino
#1

Hi
i have problem with code when i use arduino mega and hardware serial everythings is ok but i need to use arduino nano in my project. when i use nano in project the code freeze in void setup>Blynk.begin.

note : when i deleted simpletimer or blynk timer from code sim800 can connect to server.

please help how i can fix this problem.
thanks.

#define BLYNK_PRINT Serial
#define TINY_GSM_MODEM_SIM800
#define BLYNK_HEARTBEAT 10
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>
#include <TinyGPS++.h>
#include <SimpleTimer.h>

char auth[] = "*******************************";              //Your Project authentication key
char apn[]  = "*************";
char user[] = "";
char pass[] = "";

#include <SoftwareSerial.h>

const int GSMrxPin = 9; 
const int GSMtxPin = 10;

SoftwareSerial SerialAT(GSMrxPin, GSMtxPin); // RX, TX
const int GPSrxPin = 7;
const int GPStxPin = 8;

SoftwareSerial GPSSerial(GPSrxPin, GPStxPin); // RX, TX

/*
#define SerialAT  Serial1
#define GPSSerial Serial2
*/

const int GSMBaud = 9600; 
const int GPSBaud = 9600;
const int ResetPin = 2;
const int move_index = 1;       // fixed location for now
unsigned int spd;       //Variable  to store the speed
unsigned int sats;      //Variable to store no. of satellites response
String bearing;  //Variable to store orientation or direction of GPS

SimpleTimer timer;

TinyGPSPlus gps; // The TinyGPS++ object
TinyGsm modem(SerialAT);
WidgetMap myMap(V0);  // V0 for virtual pin of Map Widget


void setup()
{
  ResetVoid();
  delay(1000);
  Serial.begin(9600);
  delay(100);
  GPSSerial.begin(GPSBaud);
  delay(100);
  SerialAT.begin(GSMBaud);
  delay(100);
  Serial.println("Initializing modem...");
  modem.restart();
  Blynk.begin(auth, modem, apn, user, pass);
  timer.setInterval(5000L, checkGPS); // every 5s check if GPS is connected, only really needs to be done once

}

void checkGPS(){

  if (gps.charsProcessed() < 10)
  {
    Serial.println(F("No GPS detected: check wiring."));
      Blynk.virtualWrite(V4, "GPS ERROR");  // Value Display widget  on V4 if GPS not detected
  }

}

void ResetVoid(){
  
  digitalWrite(ResetPin, HIGH);
  delay(1000);
  digitalWrite(ResetPin, LOW);
  delay(1000);
  
}

void displayInfo()
{ 

  if (gps.location.isValid() ) 
  {
    
    float latitude = (gps.location.lat());     //Storing the Lat. and Lon. 
    float longitude = (gps.location.lng()); 
    
    Serial.print("LAT:  ");
    Serial.println(latitude, 6);  // float to x decimal places
    Serial.print("LONG: ");
    Serial.println(longitude, 6);
    Blynk.virtualWrite(V1, String(latitude, 6));   
    Blynk.virtualWrite(V2, String(longitude, 6));  
    myMap.location(move_index, latitude, longitude, "Peugeot 207");
    spd = gps.speed.kmph();               //get speed
       Blynk.virtualWrite(V3, spd);
       
       sats = gps.satellites.value();    //get number of satellites
       Blynk.virtualWrite(V4, sats);

       bearing = TinyGPSPlus::cardinal(gps.course.value()); // get the direction
       Blynk.virtualWrite(V5, bearing);               
      
    
  }
}

void loop()
{
    while (GPSSerial.available() > 0) 
    {
      // sketch displays information every time a new sentence is correctly encoded.
      if (gps.encode(GPSSerial.read()))
        displayInfo();
  }
  Blynk.run();
  timer.run();
}
0 Likes

#2

You may not have the option to use multiple SoftwareSerial ports… at least not with the basic library…

https://www.arduino.cc/en/Reference/softwareSerial

image

0 Likes

#3

thanks for reply

0 Likes