I am using an iPhone, hm-10 Bluetooth module, Arduino uno, and Sparkfun GPS shield.
I have gotten the Bluetooth and GPS to work separately and have gotten the GPS to send data to the serial monitor.
I recently got them to work together in the sense that it recognizes that there is a GPS attached, but I can not get the coordinates to print in a value display on blynk.
My goal is to eventually plot the GPS coordinates on the blynk map but for now just sending the coordinates is great.
It recognizes the GPS when it is in UART mode.
Any help/feedback is appreciated!
This is my code:
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial
#include <TinyGPS++.h>
#include <SoftwareSerial.h>
#include <BlynkSimpleSerialBLE.h>
char auth[] = "92067b9f7b604a70a309ad21c5";
SoftwareSerial SerialBLE(10, 11); // RX, TX
BlynkTimer timer;
TinyGPSPlus gps;
int RXPin = 2;
int TXPin = 3;
int GPSBaud = 4800;
void myTimerEvent()
{
// You can send any value at any time.
// Please don't send more that 10 values per second.
while (Serial.available() > 0)
if (gps.encode(Serial.read()))
{
displayInfo();
Blynk.virtualWrite(V1, Serial.read() )
}
if (millis() > 5000 && gps.charsProcessed() < 10) //off
{
//Serial.println(F("No GPS detected"));
Serial.println(3);
while (true);
}
else //on
{
displayInfo();
Blynk.virtualWrite(V1, Serial.read() )
digitalWrite(4, HIGH);
}
}
void setup()
{
// Debug console
Serial.begin(4800);
SerialBLE.begin(9600);
Blynk.begin(SerialBLE, auth);
/*Serial.println("Waiting for connections...");
Serial.println(F("DeviceExample.ino"));
Serial.println(F("A simple demonstration of TinyGPS++ with an attached GPS module"));
Serial.print(F("Testing TinyGPS++ library v. ")); Serial.println(TinyGPSPlus::libraryVersion());
Serial.println(F("by Mikal Hart"));
Serial.println();*/
timer.setInterval(1000L, myTimerEvent);
pinMode(4, OUTPUT);
}
void loop()
{
Blynk.run();
timer.run(); // Initiates BlynkTimer
}
void displayInfo()
{
Serial.print(F("Location: "));
if (gps.location.isValid())
{
Serial.print(gps.location.lat(), 6);
Serial.print(F(","));
Serial.print(gps.location.lng(), 6);
}
else
{
Serial.print(F("INVALID"));
}
Serial.print(F(" Date/Time: "));
if (gps.date.isValid())
{
Serial.print(gps.date.month());
Serial.print(F("/"));
Serial.print(gps.date.day());
Serial.print(F("/"));
Serial.print(gps.date.year());
}
else
{
Serial.print(F("INVALID"));
}
Serial.print(F(" "));
if (gps.time.isValid())
{
int num = gps.time.hour() - 5;
if (gps.time.hour() < 10) Serial.print(F("0"));
Serial.print(num);
Serial.print(F(":"));
if (gps.time.minute() < 10) Serial.print(F("0"));
Serial.print(gps.time.minute());
Serial.print(F(":"));
if (gps.time.second() < 10) Serial.print(F("0"));
Serial.print(gps.time.second());
Serial.print(F("."));
if (gps.time.centisecond() < 10) Serial.print(F("0"));
Serial.print(gps.time.centisecond());
}
else
{
Serial.print(F("INVALID"));
}
Serial.println();
}