hi guys,
I am in a middle of a project and have a problem with DCF77 module.
I have 2 adafruit 7 segment displays connected and everything works like a charm, i get dcf77 signal in 2 minutes on average, everything syncs and works. As soon as i add 3rd 7 seg display, dcf77 stops synchronizing.
Here is my code, i have commented out some parts for troubleshooting but the code doesnt seem to be a problem.
#include "TimeLib.h"
#include "DCF77.h"
#include "Wire.h"
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"
#include "RTClib.h"
#include "Adafruit_Sensor.h"
#include "Adafruit_BME280.h"
#define DCF_PIN 2 // Connection pin to DCF 77 device
#define DCF_INTERRUPT 0 // Interrupt number associated with pin
#define PIN_LED 22 // LED signalin that the DCF77 signal has been aquired
#define PIN_LED2 23 // LED (red) signaling loss of signal. Trigers every hour at :00 to update the signal status
#define PIN_LED_monday 24 // LED on if monday
#define PIN_LED_tuesday 25 // LED on if tuesday
#define PIN_LED_RTC_online 26 // Led on if RTC is online and battery OK
#define PIN_LED_RTC_offline 27 // Led on if RTC is offline or battery dead
#define SEALEVELPRESSURE_HPA (1013.25)
DCF77 DCF = DCF77(DCF_PIN,DCF_INTERRUPT, false); // "false" is used for ELV DCF77 receivers as they have inverted signal
Adafruit_BME280 bme;
RTC_DS3231 rtc;
Adafruit_7segment display1 = Adafruit_7segment();
Adafruit_7segment display2 = Adafruit_7segment();
Adafruit_7segment display3 = Adafruit_7segment();
Adafruit_7segment display4 = Adafruit_7segment();
Adafruit_7segment display5 = Adafruit_7segment();
Adafruit_7segment display6 = Adafruit_7segment();
Adafruit_7segment display7 = Adafruit_7segment();
int _hours;
int _minutes;
int _seconds;
int _days;
int _months;
int _years;
int WeekDay =0;
int DOW; // day of week
float _temp;
int roundtemp;
float _pressure;
int roundpressure;
float _humidity;
int roundhumidity;
int tensofdegrees, singledegrees, millidegrees;
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
int hours, minutes, tensofhours, tensofminutes, tensofseconds, seconds, days, tensofdays, months, tensofmonths, years, tensofyears, hundredsofyears, thousandsofyears;
unsigned long lastupdate = now();
unsigned long currenttime = now();
//==============================================================================
// SETUP
//==============================================================================
void setup()
{
Wire.begin();
DCF.Start();
Serial.begin(9600);
pinMode(PIN_LED, OUTPUT);
pinMode(PIN_LED2, OUTPUT);
pinMode(PIN_LED_monday, OUTPUT);
pinMode(PIN_LED_tuesday, OUTPUT);
pinMode(PIN_LED_RTC_online, OUTPUT);
pinMode(PIN_LED_RTC_offline, OUTPUT);
display1.begin(0x70);
display2.begin(0x71);
display3.begin(0x72);
display4.begin(0x73);
display5.begin(0x74);
display6.begin(0x75);
display7.begin(0x77);
rtc.begin();
if (! rtc.begin()) {
Serial.println("RTC is NOT running.");
} else {
Serial.println("RTC is running.");
DateTime now = rtc.now();
setTime(now.unixtime()); //Set system clock from ds3231 once.
}
/*
if (!bme.begin(0x76)) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
*/
}
int update = 0;
//==============================================================================
// LOOP
//==============================================================================
void loop()
{
if(minute() == 0) { update = 0; } //check every hour (at xx:00 minutes) to start a new cycle, it only resets the LEDs to update signal status
if (update ==0) // when the dcf77 signal is not established yet
{
digitalWrite(PIN_LED2, HIGH);
digitalWrite(PIN_LED, LOW);
}
time_t DCFtime = DCF.getTime(); // Check if new DCF77 time is available
if (DCFtime!=0)
{
Serial.print("DCF77 signal received and time updated! - @ ");
setTime(DCFtime);
rtc.adjust(DCFtime); //Set ds3231 from system clock.
lastupdate = now();
currenttime = now();
digitalWrite(PIN_LED, HIGH); // turns on LED that shows signal has been received and clock updated
update = 1;
}
if (update ==1)
{
digitalWrite(PIN_LED2, LOW); // LED2 (red) turns off when signal is successfully received
}
show_displays();
}
//==============================================================================
// SHOW DISPLAYS
//==============================================================================
void show_displays(){
// Day Of The Week LEDs
if (DOW == 5) {
digitalWrite(PIN_LED_monday, HIGH); //monday
} else {
digitalWrite(PIN_LED_monday, LOW); //monday
}
if (DOW == 6) {
digitalWrite(PIN_LED_tuesday, HIGH); //tuesday
} else {
digitalWrite(PIN_LED_tuesday, LOW); //monday
}
// if RTC is disconnected a red LED will turn on, otherwise yellow LED is on.
if (! rtc.begin()) {
digitalWrite(PIN_LED_RTC_offline, HIGH);
digitalWrite(PIN_LED_RTC_online, LOW);
} else {
digitalWrite(PIN_LED_RTC_offline, LOW);
digitalWrite(PIN_LED_RTC_online, HIGH);
}
//=============================
// DATE & TIME
//=============================
DateTime now = rtc.now();
_hours = now.hour();
_minutes = now.minute();
_seconds = now.second();
_days = now.day();
_months = now.month();
_years = now.year();
DOW = now.dayOfTheWeek();
// define time and date
hours = _hours % 10;
tensofhours = _hours / 10;
minutes = _minutes % 10;
tensofminutes = _minutes / 10;
seconds = _seconds % 10;
tensofseconds = _seconds / 10;
days = _days % 10;
tensofdays = _days / 10;
months = _months % 10;
tensofmonths = _months / 10;
years = _years % 10;
tensofyears = (_years /10)%10;
hundredsofyears = (_years /100)%10;
thousandsofyears = (_years /1000)%10;
// define each digit - 0 is the first left, 2 is decimal dots.
display1.writeDigitNum(0, tensofhours);
display1.writeDigitNum(1, hours);
display1.writeDigitNum(3, tensofminutes);
display1.writeDigitNum(4, minutes);
display1.drawColon(true);
display1.writeDisplay();
display2.writeDigitNum(0, tensofseconds);
display2.writeDisplay();
display2.writeDigitNum(1, seconds);
display2.writeDisplay();
display3.writeDigitNum(0, tensofdays);
display3.writeDigitNum(1, days,true);
display3.writeDigitNum(3, tensofmonths);
display3.writeDigitNum(4, months,true);
display3.writeDisplay();
display7.writeDigitNum(0, thousandsofyears);
display7.writeDigitNum(1, hundredsofyears);
display7.writeDigitNum(3, tensofyears);
display7.writeDigitNum(4, years);
display7.writeDisplay();
}
Any thoughts would be highly appreciated.
Many thanks,
Alek