Hi guys,
A bit of background info: i've made a information display unit for my 4 wheel drive, that displays among other things, Latitude and Longitude in decimal degrees, Eg, -36.76453, 145.74653.. but i if need to convert this info to Degrees, Minutes, Seconds, eg -36° 76' 53, 145° 74' 53. i know i need to do some maths, here's and example 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)
and here is my sketch.
// 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.// -------------------------BATTERY VOLTAGE --------------------------------------------
int batteryPin = A0; // analog pin 0
int battery2Pin = A1;int BattanalogIn = A2;
float BattsensorValue;
float BattoutputValue;const float referenceVolts = 5; // the default reference on a 5-volt board
const float resistorFactor = 327; // 327 = 1023 x r2 / (r1+r2) r1 = 10000ohm r2 = 4700ohm// --------------------------Outside temp sensor --------------------------------------------------
int DS18S20_Pin = 22; //DS18S20 Signal pin on digital 22
OneWire ds(DS18S20_Pin); // on digital pin 22void setup()
{dht.begin();
Wire.begin();
compass.enableDefault();
// Calibration values. Use the Calibrate example program to get the values for
// your compass.
compass.m_min.x = -1038; compass.m_min.y = -831; compass.m_min.z = -662;
compass.m_max.x = +639; compass.m_max.y = +797; compass.m_max.z = 837;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!