Hello!
I am making a project that shows the blynk the position of the person. For this I use an Arduino (for the test an Arduino Uno), a SIM800L and a Neo-6M. The connection with SIM800L only works fine, but when I add the Neo-6M GPS to it, it is constantly trying to reconnect to Blynk, and I don’t know where the fault may be.
This is my code:
#define BLYNK_PRINT Serial
// Select your modem:
#define TINY_GSM_MODEM_SIM800
#include <TinyGsmClient.h>
#include <BlynkSimpleTinyGSM.h>
#include <SoftwareSerial.h>
#include <TinyGPS++.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "eXpnCZPuW3iA9g6lYFmnXpNwJGwvwvrb";
// Your GPRS credentials
// Leave empty, if missing user or pass
char apn[] = "inet.es";
char user[] = "";
char pass[] = "";
// Hardware Serial on Mega, Leonardo, Micro
//#define SerialAT Serial1
// or Software Serial on Uno, Nano
SoftwareSerial SerialAT(2, 3); // RX, TX
TinyGsm modem(SerialAT);
SoftwareSerial Serial2(4, 5 ); // RX, TX
TinyGPSPlus gps;
WidgetMap myMap(V0);
BlynkTimer timer;
int pointIndex = 1;
void setup()
{
// Debug console
Serial.begin(115200);
delay(10);
//Set GPS module baud rate
Serial2.begin(9600);
Serial.println("neogps serial initialize");
delay(10);
// Set GSM module baud rate
SerialAT.begin(9600);
delay(3000);
// Restart takes quite some time
// To skip it, call init() instead of restart()
Serial.println("Initializing modem...");
modem.restart();
// Unlock your SIM card with a PIN
modem.simUnlock("0244");
Blynk.begin(auth, modem, apn, user, pass, "MYPRIVATEIP", MYPORT);
}
void loop()
{
while(Serial2.available())
{
if (gps.encode(Serial2.read()))
{
sendToBlynk();
}
}
Blynk.run();
Blynk.virtualWrite(V4, "KAIXO!!!");
}
void sendToBlynk()
{
if (gps.location.isValid() )
{
//get latitude and longitude
float latitude = (gps.location.lat());
float longitude = (gps.location.lng());
//get
float speed = gps.speed.kmph();
//get number of satellites
float satellites = gps.satellites.value();
//Serial.print("Latitude: ");
//Serial.println(latitude, 6);
//Serial.print("Longitude: ");
//Serial.println(longitude, 6);
//Serial.print("Speed: ");
//Serial.println(speed, 6);
Blynk.virtualWrite(V1, String(latitude, 6));
Blynk.virtualWrite(V2, String(longitude, 6));
myMap.location(pointIndex, latitude, longitude, "GPS_Location");
Blynk.virtualWrite(V3, speed);
}
}