|
/************************************************************************* |
|
PROJECT NAME: Bharat Pi NavIC Shield test firmware |
|
AUTHOR: Bharat Pi |
|
CREATED DATE: 26/03/2024 |
|
COPYRIGHT: BharatPi @MIT license for usage on Bharat Pi boards |
|
VERSION: 2.0 |
|
|
|
DESCRIPTION: NavIC get latlong and other navigation parameters using Bharat Pi NavIC tracker shield. |
|
|
|
REVISION HISTORY TABLE: |
|
------------------------------------------ |
|
Date | Firmware Version | Comments |
|
------------------------------------------ |
|
26/03/2024 - 1.0 - Initial release with Lat long and other nav parameters. Prints to serial monitor. |
|
05/08/2024 - 2.0 - Switched to Hardware serial as the software serial had issues with baud rates, |
|
- Added Google maps link so that lat long can be viewed from URL printed on serial monitor |
|
|
|
*************************************************************************/ |
|
|
|
#include <TinyGPS++.h> |
|
#include <HardwareSerial.h> |
|
|
|
// ✅ Updated to match your wiring |
|
#define GPS_RX_PIN 16 // GPS TX → ESP32 RX |
|
#define GPS_TX_PIN 17 // GPS RX ← ESP32 TX |
|
|
|
TinyGPSPlus gps; |
|
HardwareSerial gpsSerial(2); // Using UART2 |
|
|
|
void setup() { |
|
Serial.begin(115200); |
|
gpsSerial.begin(115200, SERIAL_8N1, GPS_RX_PIN, GPS_TX_PIN); |
|
delay(5000); |
|
|
|
Serial.println("\n\n\n**********************************************************************************"); |
|
Serial.println(" Bharat Pi NavIC Shield Test Program"); |
|
Serial.println(" Connected via UART2: GPIO16 (RX), GPIO17 (TX)"); |
|
Serial.println(" Please wait while the NavIC module latches to satellites."); |
|
Serial.println(" Red LED (PPS) will blink once it latches."); |
|
Serial.println(" Ensure clear sky visibility."); |
|
Serial.println("**********************************************************************************\n"); |
|
Serial.println(" Awaiting for NavIC satellite signal latching...\n\n"); |
|
} |
|
|
|
void loop() { |
|
while (gpsSerial.available() > 0) { |
|
if (gps.encode(gpsSerial.read())) { |
|
if (gps.location.isValid()) { |
|
float latitude = gps.location.lat(); |
|
float longitude = gps.location.lng(); |
|
String date = String(gps.date.day()) + "/" + String(gps.date.month()); |
|
String time = String(gps.time.hour()) + ":" + String(gps.time.minute()); |
|
double speedKnots = gps.speed.knots(); |
|
float courseDeg = gps.course.deg(); |
|
double altitudeMts = gps.altitude.meters(); |
|
uint32_t satellites = gps.satellites.value(); |
|
double hdop = gps.hdop.hdop(); |
|
|
|
Serial.print("Lat: "); Serial.println(latitude, 7); |
|
Serial.print("Long: "); Serial.println(longitude, 7); |
|
Serial.print("View on Google Maps: "); |
|
Serial.println("http://maps.google.com/maps?q=" + String(latitude, 7) + "," + String(longitude, 7)); |
|
Serial.print("Speed (knots): "); Serial.println(speedKnots, 2); |
|
Serial.print("Course (°): "); Serial.println(courseDeg, 2); |
|
Serial.print("Altitude (m): "); Serial.println(altitudeMts, 2); |
|
Serial.print("Satellites: "); Serial.println(satellites); |
|
Serial.print("HDOP: "); Serial.println(hdop, 2); |
|
Serial.println("\n-----------------------------\n"); |
|
} |
|
} |
|
} |
|
} |