I still don't know what "BCD::bcd_t n" and "print(n.digit.hi)" does.
But i switch the LCD library to U8g2 because the other one has not much font choices.
With U8g2 it works.
I wonder if there is something to improve it.
The output to Serial1 should be as fast as possible so that the delay of receiving/decoding the time and sending it to the server (RPi) is as short as possible.
My concern is that writing to the LCD does introduce some lag.
/**************************************************************
* CONNECTION Pro Micro *
***************************************************************
LCD GND <> GND
LCD VCC <> 3.3V
LCD CLK/SCLK/SCK <> D15 SCK
LCD DIN/DN/MOSI/DATA <> D16 MOSI
LCD DC/"D/C" <> D9
LCD CE/CS/SCE <> D8
LCD RST <> D7
DCF77 Receiver DCF <> D21
DCF77 Monitor LED <> D6
**************************************************************/
#include <dcf77.h> // Get it here: github.com/udoklein/dcf77
#include <U8g2lib.h> // Get it here: github.com/olikraus/u8g2
/**************************************************************
* LCD 5110 (U8g2lib) SETUP *
**************************************************************/
const unsigned int CLOCK_PIN = 15, DATA_PIN = 16, CS_PIN = 8, DC_PIN = 9, RESET_PIN = 7;
U8G2_PCD8544_84X48_1_4W_HW_SPI u8g2 = U8G2_PCD8544_84X48_1_4W_HW_SPI(U8G2_R0, CS_PIN, DC_PIN, RESET_PIN); // HW SPI
/**************************************************************
* DCF77 SETUP *
**************************************************************/
const uint8_t dcf77_sample_pin = 21; // D21 == A3
const uint8_t dcf77_inverted_samples = 1;
const uint8_t dcf77_pin_mode = INPUT_PULLUP; // enable internal pull up
const uint8_t dcf77_monitor_pin = 6;
uint8_t sample_input_pin() {
const uint8_t sampled_data =
dcf77_inverted_samples ^ digitalRead(dcf77_sample_pin);
digitalWrite(dcf77_monitor_pin, sampled_data);
return sampled_data;
}
/**************************************************************
* MISC SETUP *
**************************************************************/
#define DEBUG 1 // Set to 1 for USB serial output
// Define unused pins
const uint8_t pin[] = {2, 3, 5, 14}; // Array of unused digital pins
const uint8_t pinA[] = {A0, A1, A2, A6, A10}; // Array of unused analog pins
uint8_t pinCount = sizeof(pin) / sizeof(pin[0]); // Count unused digital pins
uint8_t pinACount = sizeof(pinA) / sizeof(pinA[0]); // Count unused analog pins
/**************************************************************
* SETUP *
**************************************************************/
void setup() {
for (uint8_t i = 0; i < pinCount; i++) {
pinMode(pin[i], INPUT_PULLUP); // Set unused digital pins as input and HIGH
}
for (uint8_t i = 0; i < pinACount; i++) {
pinMode(pinA[i], INPUT_PULLUP); // Set unused analog pins as input and HIGH
}
pinMode(dcf77_monitor_pin, OUTPUT);
pinMode(dcf77_sample_pin, dcf77_pin_mode);
DCF77_Clock::setup();
DCF77_Clock::set_input_provider(sample_input_pin);
startupTasks(); // Run tasks
}
void startupTasks() {
#ifdef DEBUG
Serial.begin(9600);
#endif // END DEBUG
Serial1.begin(9600, SERIAL_7E2);
u8g2.begin();
u8g2.enableUTF8Print();
u8g2.setContrast(135);
// Wait till clock is synced
for (uint8_t state = Clock::useless;
state == Clock::useless || state == Clock::dirty;
state = DCF77_Clock::get_clock_state()) {
// wait for next sec
Clock::time_t now;
DCF77_Clock::get_current_time(now);
#ifdef DEBUG
// render one dot per second while initializing
static uint8_t count = 0;
Serial.print('.');
++count;
if (count == 60) {
count = 0;
Serial.println();
}
#endif // END DEBUG
}
}
void paddedPrintUSB(BCD::bcd_t n) {
Serial.print(n.digit.hi);
Serial.print(n.digit.lo);
}
void paddedPrint(BCD::bcd_t n) {
Serial1.print(n.digit.hi);
Serial1.print(n.digit.lo);
}
void LCDpaddedPrint(BCD::bcd_t n) {
u8g2.print(n.digit.hi);
u8g2.print(n.digit.lo);
}