I have just built a UNO together with a GP3906 shield from Sparkfun together with an OLED 1309 display and whilst all the functions work the timing is off.
By which I mean it sometimes misses the seonds every now and then. As you can see I'm using outputs for the last 5 seconds to light leds part of another project but even if I remove that part from the program it has no effect.
Could one of the many fine experts here shed any light on why this maybe happening please?
#include <U8glib.h>
U8GLIB_SSD1309_128X64 u8g(13, 11, 10, 9); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9
#include <TinyGPS++.h> // Include the TinyGPS++ library
TinyGPSPlus tinyGPS; // Create a TinyGPSPlus object
#define GPS_BAUD 9600 // GPS module baud rate. GP3906 defaults to 9600.
#include <SoftwareSerial.h>
#define ARDUINO_GPS_RX 7 // GPS TX, Arduino RX pin
#define ARDUINO_GPS_TX 6 // GPS RX, Arduino TX pin
SoftwareSerial ssGPS(ARDUINO_GPS_TX, ARDUINO_GPS_RX); // Create a SoftwareSerial
#define gpsPort ssGPS
//#define SerialMonitor Serial
int ledPin1 = 2;
int ledPin2 = 3;
int ledPin3 = 4;
int ledPin4 = 5;
int ledPin5 = A0;
int ledPin6 = A1;
void setup()
{
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, OUTPUT);
// SerialMonitor.begin(9600);
gpsPort.begin(GPS_BAUD);
}
void titlepage() {
u8g.setFont(u8g_font_fub11);
u8g.setColorIndex(1); // Instructs the display to draw with a pixel on.
u8g.drawStr( 0, 13, "Satellites:");
u8g.drawStr( 0, 33, "Date:");
u8g.drawStr( 0, 58, "Time:");
enum {BufSize=6}; // If a is short use a smaller number, eg 5 or 6
char buf[BufSize];
snprintf (buf, BufSize, "%d", tinyGPS.satellites.value());
u8g.drawStr(84, 13, buf);
snprintf (buf, BufSize, "%02d", tinyGPS.date.day());
u8g.drawStr(42, 33, buf);
snprintf (buf, BufSize, "%02d", tinyGPS.date.month());
u8g.drawStr(64, 33, buf);
snprintf (buf, BufSize, "%02d", tinyGPS.date.year());
u8g.drawStr(90, 33, buf);
snprintf (buf, BufSize, "%02d", tinyGPS.time.hour());
u8g.drawStr(46, 58, buf);
snprintf (buf, BufSize, "%02d", tinyGPS.time.minute());
u8g.drawStr(68, 58, buf);
snprintf (buf, BufSize, "%02d", tinyGPS.time.second());
u8g.drawStr(90, 58, buf);
}
void leds(){
if ((tinyGPS.time.second())== 55) {digitalWrite(2,HIGH);
} else {digitalWrite(2,LOW);}
if ((tinyGPS.time.second())== 56) {digitalWrite(3,HIGH);
} else {digitalWrite(3,LOW);}
if ((tinyGPS.time.second())== 57) {digitalWrite(4,HIGH);
} else {digitalWrite(4,LOW);}
if ((tinyGPS.time.second())== 58) {digitalWrite(5,HIGH);
} else {digitalWrite(5,LOW);}
if ((tinyGPS.time.second())== 59) {digitalWrite(A0,HIGH);
} else {digitalWrite(A0,LOW);}
if ((tinyGPS.time.second())== 00) {digitalWrite(A1,HIGH);
} else {digitalWrite(A1,LOW);}
}
void draw(){
titlepage();
}
static void smartDelay(unsigned long ms)
{
unsigned long start = millis();
do
{
while (gpsPort.available())
tinyGPS.encode(gpsPort.read()); // Send it to the encode function
} while (millis() - start < ms);}
void loop()
{
{ u8g.firstPage();
do { draw();
}while(u8g.nextPage());
leds();
}
smartDelay(1000);
}