Hello) Sorry for my english, but i need your help)
I’m trying to use Arduino Leonardo with Ai-thinker A7 Gps/Gprs module.
I would like to assembly Car Gps/Gprs tracking system)
But i cant make this works together.
GPRS module on speed 115200 connected to Rx/Tx pins. Gps tx connected via softwareserial to pin (8,9).
I can send AT commands to the modem/ I can connect to Blynk server.
But it wont connect to blynk and send my coordinates at one time.
Please I need your help. I spend one week and it wont works(((((
Here is my sketch:
//#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
//#define BLYNK_HEARTBEAT 30
#define TINY_GSM_MODEM_A7
#include <SoftwareSerial.h>
#include <TinyGsmClient.h>
#include <BlynkSimpleSIM800.h>
#include <TinyGPS++.h>
#include <SimpleTimer.h>
SimpleTimer timer;
WidgetMap myMap(V0);
//WidgetLED led1(V10);
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
const char auth[] = "e9b1c9ab24b74cd5bda8cd2264c6b89f";
// Your GPRS credentials
// Leave empty, if missing user or pass
const char apn[] = "internet.mts.ru";
const char user[] = "";
const char pass[] = "";
int spd; //Variable to store the speed
int sats; //Variable to store no. of satellites response
String accur; //accuracy
int alt; //altitude
int hours;
int minutes;
unsigned int move_index;
// Hardware Serial on Mega, Leonardo, Micro
#define SerialAT Serial1
// or Software Serial on Uno, Nano
//#include <SoftwareSerial.h>
SoftwareSerial ss (8, 9); // RX, TX
TinyGPSPlus gps;
TinyGsm modem(SerialAT);
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);
}
Serial.println();
}
void senddata()
{
float latitude = (gps.location.lat()); //Storing the Lat. and Lon.
float longitude = (gps.location.lng());
Blynk.virtualWrite(V1, String(latitude, 6));
Blynk.virtualWrite(V2, String(longitude, 6));
myMap.location(move_index, latitude, longitude, "GPS_Location");
spd = gps.speed.kmph(); //get speed
Blynk.virtualWrite(V3, spd);
Serial.println(spd);
sats = gps.satellites.value(); //get number of satellites
Blynk.virtualWrite(V4, sats);
accur = gps.hdop.value();
Blynk.virtualWrite(V8, accur);
void setup()
{
// Set console baud rate
Serial.begin(115200);
delay(10);
// Set GSM module baud rate
SerialAT.begin(115200);
delay(2000);
ss.begin(9600);
delay(2000);
SerialAT.print("AT+GPS=1");
delay(2000);
// Restart takes quite some time
// To skip it, call init() instead of restart()
//Serial.println("Initializing modem...");
modem.restart();
String modemInfo = modem.getModemInfo();
//Serial.print("Modem: ");
Serial.println(modemInfo);
delay(3000);
Blynk.begin(auth, modem, apn, user, pass);
timer.setInterval(3000, senddata);
//timer.setInterval(5000, Updata);
//timer.setInterval(900000, checkGPS);
//timer.setInterval(3000, blinkLedWidget);
}
void loop()
{
while (ss.available() > 0)
{
if (gps.encode(ss.read()))
displayInfo();
}
Blynk.run();
timer.run();
//Blynk.virtualWrite(V19, ss);
}
All the Baudrates have to match of course. Does the GPS work when simply attached to a serial port? You could try a very simple sketch with Blynk to confirm the GPS is working. E.g. try and put it on the hardware port to see if it works and simply do a reading a couple times a second in the loop with delay and without modem, Blynk etc.