
CD-PC Website Arduino GPS Speedo

Description:
Makes from a small oled display and a gps module a speedo metre.
If you have DST then you can switch between summer and winter time on a pin (change pinDST to the right pin). GPS times are GMT times so add or subtract your timezone by changing the GMTOffset.
Code works on a Arduino Uno v3
Code:
/* Original from http://gathering.tweakers.net/forum/list_messages/1596164 */
#include <Wire.h>
#include <GOFi2cOLED.h>
#include <TinyGPS++.h>
TinyGPSPlus gps;
GOFi2cOLED GOFoled;
char GMTOffset = 1; //set offset too GMT
unsigned char pinDST = 2; //DST (pin D2)
unsigned char pinKmph = 3; //kmph or mph (pin D3)
static void smartDelay(unsigned int ms)
{
unsigned long start = millis();
do
{
while (Serial.available())
gps.encode(Serial.read());
} while (millis() - start < ms);
}
static void printTime(TinyGPSTime &t)
{
char sz[10];
int hour = t.hour() + GMTOffset;
if (digitalRead(pinDST) == 0){hour++;}
if (hour > 23) {hour -= 24;}
sprintf(sz, "%02d:%02d:%02d", hour, t.minute(), t.second());
GOFoled.print(sz);
}
void setup()
{
pinMode(pinDST, INPUT); // set pin to input
pinMode(pinKmph, INPUT); // set pin to input
digitalWrite(pinDST, HIGH); // turn on pullup resistors
digitalWrite(pinKmph, HIGH); // turn on pullup resistors
//default address is 0x3D. 0x3c
GOFoled.init(0x3D);
// init done
Serial.begin(9600);
}
void loop(void)
{
GOFoled.clearDisplay();
//GOFoled.setTextColor(WHITE);
//GOFoled.setBrightness()
//show sattelites
GOFoled.setTextSize(1);
GOFoled.setCursor(0, 0);
GOFoled.print("Satellites: ");
GOFoled.print(gps.satellites.value());
//speed text
if(digitalRead(pinKmph)==0){
GOFoled.setCursor(92, 0);
GOFoled.print("[km/h]");
}else{
GOFoled.setCursor(98, 0);
GOFoled.print("[Mph]");
}
//show time
GOFoled.setTextSize(2);
GOFoled.setCursor(15, 11);
printTime(gps.time);
//show speed
GOFoled.setCursor(0, 0);
GOFoled.setTextSize(5);
GOFoled.setCursor(45, 30);
if(digitalRead(pinKmph)==0){
GOFoled.print(round(gps.speed.kmph()));
}else{
GOFoled.print(round(gps.speed.mph()));
}
GOFoled.display();
smartDelay(500);
}
Picture:
Status: Final.
Last page update: 24-10-2015