Overview

A simple GPS clock with a 9V battery power supply and a small OLED display was built. It only shows time, date, position and speed. When the system is off, time is kept, since a back up battery is installed on the backside of the gps module.

Components

  • Arduino nano
  • GPS breakout board
  • 128×32 OLED display
  • RTC DS3231
  • power button
  • 9V power supply

Wiring

simplegps_bb

Coding

Most parts of the code come from the Adafruit sketch: (sketchbooks/libraries/Adafruit_LED_backpack_library/clock_sevenseg_gps).

Here is the code:

#include „SPI.h“
#include <SoftwareSerial.h>
#include <Wire.h>
#include „Adafruit_GFX.h“
#include „Adafruit_GPS.h“
#include „Adafruit_SSD1306.h“

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

// Set to false to display time in 12 hour format, or true to use 24 hour:
#define TIME_24_HOUR true
#define HOUR_OFFSET 2
#define DISPLAY_ADDRESS 0x70

SoftwareSerial gpsSerial(8, 7);
Adafruit_GPS gps(&gpsSerial);

int h1,h2,m3,m4,s5,s6,d1,d2,d3,d4;

void setup() {
Serial.begin(115200);
Serial.println(„Clock starting!“);

// Setup the display.)
display.begin(0x3C);
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println(„simple gps“);
display.setTextSize(1);
display.print(„arduino“);
display.display();
delay(2000);

gps.begin(9600);

// Configure GPS to onlu output minimum data (location, time, fix).
gps.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);

// Use a 1 hz, once a second, update rate.
gps.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ);

// Enable the interrupt to parse GPS data.
enableGPSInterrupt();
}

void loop() {
// Loop function runs over and over again to implement the clock logic.
// Check if GPS has new data and parse it.
if (gps.newNMEAreceived()) {
gps.parse(gps.lastNMEA());
}

int hours = gps.hour + HOUR_OFFSET;
int date = gps.month*100+gps.day;
int year = gps.year;

int speeds = gps.speed * 1.852;
if (hours < 0) {
hours = 24+hours;
}
if (hours > 23) {
hours = 24-hours;
}
int minutes = gps.minute;
int seconds = gps.seconds;

int displayValue = hours*100 + minutes;

if (!TIME_24_HOUR && hours > 11) {
displayValue -= 1200;
}
display.clearDisplay();
display.setTextColor(WHITE);
display.setTextSize(1);
display.setCursor(0,0);

h1=displayValue/1000;
displayValue-=h1*1000;
h2=displayValue/100;
displayValue-=h2*100;
m3=displayValue/10;
m4=displayValue%10;
s5=seconds/10;
s6=seconds%10;

d1=date/1000;
date-=d1*1000;
d2=date/100;
date-=d2*100;
d3=date/10;
d4=date%10;

display.print(h1);display.print(h2);display.print(„:“);display.print(m3);display.print(m4);display.print(„:“);display.print(s5);display.print(s6);display.print(“ „);display.print(d1);display.print(d2);display.print(„/“);display.print(d3);display.print(d4);display.print(„/“);display.print(year);

display.setCursor(0,8);

display.print(„Lat:“);
display.print(gps.lat);
display.print(“ „);
display.print(gps.latitude/100, 3);

display.setCursor(0,16);
display.print(„Lon:“);
display.print(gps.lon);
display.print(“ „);
display.print(gps.longitude/100, 3);

display.setCursor(0,24);
display.print(„speed:“);display.print(speeds);display.print(„kmh“);
display.display();
}

SIGNAL(TIMER0_COMPA_vect) {
// Use a timer interrupt once a millisecond to check for new GPS data.
// This piggybacks on Arduino’s internal clock timer for the millis()
// function.
gps.read();
}

void enableGPSInterrupt() {
// Function to enable the timer interrupt that will parse GPS data.
// Timer0 is already used for millis() – we’ll just interrupt somewhere
// in the middle and call the „Compare A“ function above
OCR0A = 0xAF;
TIMSK0 |= _BV(OCIE0A);
}

Result

With the red button the system can be turned on and off.

gps2

 

 

Advertisements