Skip to content

Instantly share code, notes, and snippets.

@gdunstone
Created January 12, 2019 10:43
Show Gist options
  • Save gdunstone/72e5a062d22988459874c2f49372fe7d to your computer and use it in GitHub Desktop.
Save gdunstone/72e5a062d22988459874c2f49372fe7d to your computer and use it in GitHub Desktop.
arduino gps speedo.
#include <Adafruit_SSD1306.h>
#include <NMEAGPS.h>
Adafruit_SSD1306 display(128, 64, &Wire, 4);
static NMEAGPS gps;
void setup() {
Serial.begin( 9600 );
// SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
// Show initial display buffer contents on the screen --
// the library initializes this with an Adafruit splash screen.
display.clearDisplay();
drawStartup();
// Clear the buffer
display.clearDisplay();
display.display();
display.setTextSize(4); // Normal 1:1 pixel scale
display.setTextColor(WHITE); // Draw white text
display.cp437(true); // Use full 256 char 'Code Page 437' font
}
void drawStartup(void) {
display.clearDisplay();
for(int16_t i=0; i<display.height()/2; i+=2) {
display.drawRect(i, i, display.width()-2*i, display.height()-2*i, WHITE);
display.display(); // Update screen with each newly-drawn rectangle
delay(3);
}
delay(250);
}
bool onoff = false;
void loop() {
display.clearDisplay();
while (gps.available( Serial )) {
gps_fix fix = gps.read();
display.setCursor(3, 3);
display.setTextSize(1);
char buf[22];
sprintf(buf, "(%02i) <%02i:%02i:%02i>", fix.satellites, fix.dateTime.hours,fix.dateTime.minutes, fix.dateTime.seconds);
for (size_t i = 0; i < 15; i++) display.write(buf[i]);
char str_temp[6];
sprintf(str_temp, "%03ikm/h", int(fix.speed_kph()));
str_temp[5] = '\0';
display.setCursor(6, 18);
display.setTextSize(4);
for (size_t i = 0; i < 5; i++) display.write(str_temp[i]);
onoff = !onoff;
if (onoff) display.invertDisplay();
display.display();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment