Hello
I'm currently trying to build a clock which is based on GPS neo 6m and a Real Time Clock DS1307 and want to display it all on 6 pieces of 8x8 LED matrix.
GPS gets fix without a problem, and passes it to RTC when i print data on serial port. My problems begin when i try to display digits on matrices (8x8). GPS suddenly doesn't get any fix. I tried bringing it outside to have a clear view of sky but it didn't help.
I'm new here and started my project just recently. I lost a week trying to solve the problem, but had no luck.
Here's my code. It's a bit rough since i tried a lot of things to get it work.
#include <TinyGPS.h>
#include <SoftwareSerial.h>
#include <TimeLib.h>
#include <DS1307RTC.h>
#include "max7219.h"
#define NBR_MTX 6
TinyGPS gps;
MAX7219 max7219=MAX7219(7,6,5, NBR_MTX);
SoftwareSerial mySerial(10, 11);
const int led_pin = 13;
volatile byte sat, minuta, sekunda;
unsigned long Age;
volatile int syncCounter = 0;
int timer1_counter;
tmElements_t clockElements;
void setMatrix();
int Sat=0, Minuta=0, Sekunda=0;
void setup()
{
Serial.begin(115200);
mySerial.begin(9600);
pinMode(led_pin, OUTPUT);
setMatrix();
noInterrupts(); // disable all interrupts
TCCR1A = 0;
TCCR1B = 0;
timer1_counter = 59286; //preload timer 65536-16MHz/256/10Hz
TCNT1 = timer1_counter; // preload timer
TCCR1B |= (1 << CS12); // 256 prescaler
TIMSK1 |= (1 << TOIE1); // enable timer overflow interrupt
interrupts();
}
ISR(TIMER1_OVF_vect) // interrupt service routine
{
TCNT1 = timer1_counter; // preload timer
// printData();
syncCounter++;
}
void loop()
{
// RTC.read(clockElements);
// Serial.print(clockElements.Hour); Serial.print(":");
// Serial.print(clockElements.Minute); Serial.print(":");
// Serial.print(clockElements.Second); Serial.println();
RTC.read(clockElements);
Sat = int(clockElements.Hour);
Minuta = int(clockElements.Minute);
Sekunda = int(clockElements.Second);
// printData();
while (mySerial.available())
{
int c = mySerial.read();
gps.encode(c);
}
gps.crack_datetime(NULL, NULL, NULL, &sat, &minuta, &sekunda, NULL, &Age);
if (syncCounter == 10)
{
GPSsync();
Serial.print(sat); Serial.print(":");
Serial.print(minuta); Serial.print(":");
Serial.print(sekunda); Serial.println();
syncCounter = 0;
}
}
void setMatrix()
{
for (int i=0; i< NBR_MTX; i++){
max7219.shutdown(i,false);
max7219.setIntensity(i,5);
max7219.clearDisplay(i);
}
max7219.clearAll();
}
void GPSsync()
{
if( Age != TinyGPS::GPS_INVALID_FIX_TIME && Age<2000)
{
clockElements.Hour = sat;
clockElements.Minute = minuta;
clockElements.Second = sekunda;
RTC.write(clockElements);
static boolean output = HIGH;
digitalWrite(led_pin, output);
output = !output;
}
}
void printData()
{
max7219.setChar(0, char(sekunda%10));
max7219.setChar(1, char(sekunda/10));
max7219.setChar(2, char(minuta%10));
max7219.setChar(3, char(minuta/10));
max7219.setChar(4, char(sat%10));
max7219.setChar(5, char(sat/10));
}