Hi guys,
A bit of background info: i’ve made a information display unit for my 4 wheel drive, using the Venus gps with sma connector. it displays among other things, Latitude and Longitude in decimal degrees, Eg, -36.76453, 145.74653… everything works great except i need to convert this info to Degrees, Minutes, Seconds, eg -36° 76’ 53, 145° 74’ 53. to correspond with the paper maps i have. i know i need to do some maths, here’s an example of how to do it i found.
DM.m = Degrees, Minutes, Decimal Minutes (eg. 45°22.6333)
D.d = Degrees, Decimal Degrees (eg. 45.3772°)
DMS = Degrees, Minutes, Seconds (eg. 45°22’38")
D.d → DM.m (45.3772 → 45°22.6333
Multiply .d by 60 to get M.m (.3772*60=22.6333)
DM.m → DMS (45°22.6333 → 45°22’38")
Multiply .m by 60 to get S(.6333*60=38)
My question is: how do i put this in my sketch?
I know i need to use the “Latitude” and “Longitude” values and use the above method to convert it before sending it to the LCD. i hope that makes sense.
// necessary libraries
#include <TinyGPS.h> //GPS
#include <LiquidCrystal.h>
#include <OneWire.h> //for temp sensor
#include <Wire.h>
#include <LSM303DLH.h> //compass
#include <DHT.h> //temp humidity sensor
#define DHTPIN 30 // DHT sensor pin
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE);
LSM303DLH compass;
const int heading_min = 0; // sensor minimum,
const int heading_max = 359;
// The parameters in the brackets define which digital output pins connect to
// (in order) LCD pins: RS, enable, D4, D5, D6, and D7.
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
LiquidCrystal lcd2(12, 10, 5, 4, 3, 2); //second display
//---------------------------GPS------------------------------------------------------
#define GPSBAUD 9600 // baud rate of our GPS module. Change for your GPS module if different
TinyGPS gps; // Create an instance of the TinyGPS object
void getgps(TinyGPS &gps); // This is where you declare prototypes for the functions that will be
// using the TinyGPS library.
Serial1.begin(GPSBAUD); // setup sketch for data output speed of GPS module
lcd.begin(20, 4);
lcd2.begin(20, 4);
lcd.clear();
//lcd2.clear();
lcd.setCursor(2,1);
lcd.print(“Waiting for lock”);
}
void loop()
{
GPS_LOC ( );
Batt_V_I ( );
OutTemp ( );
Compass ( );
TempHumidSensor ( );
}
int GPS_LOC( )
{
while(Serial1.available()) // While there is data on the RX pin…
{
int c = Serial1.read(); // load the data into a variable…
if(gps.encode(c)) // if there is a new valid sentence…
{
getgps(gps); // then grab the data.
}
}
}
void getgps(TinyGPS &gps) // The getgps function will get and print the values we want.
{
float latitude, longitude, fix_age; // Define the variables that will be used
gps.f_get_position(&latitude, &longitude); // You can now print variables latitude and longitude
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Latitude : "); lcd.print(latitude,5);
lcd.setCursor(0,1);
lcd.print("Longitude: "); lcd.print(longitude,5);
lcd.setCursor(0,2);
lcd.print("Altitude : ");
lcd.print(gps.f_altitude());lcd.print(“m”);
lcd.setCursor(0,3);
lcd.print("Speed: ");
lcd.print(gps.f_speed_kmph(),0); //lcd.print(“k”);
lcd.setCursor(11,3);
lcd.print("Sats: ");
lcd.print(gps.satellites());
//Serial.print("HDOP: "); Serial.println(gps.hdop());
}
(had to delete some of my sketch to make it fit in this post)
Thanks for helping!