Came up with a code using ESP8266 + DS3231 RTC module + Gen4-uLCD70DT to do the following :
1. Show the (Line 1) Day of Week / (Line 2 ) HH : MM : SS / (Line 3) DD : MM: YYYY
2. Once everyday at midnight log on to the NTP server and update the RTC so that once started this clock needs no correction
3. Dim the display from 10PM to 6AM and also based on ambient light.
The whole code is tried out and works fine with the display as a Serial Slave . So what is the problem ??
I am worried about the screen burn in particularly in the Day of Week and Month and Year fields. These are going to be there static for long periods. So is my worry genuine first ??
If so I plan to over come as below but not sure if any will help :
A. Change the colour of the concerned static fields once every hour
B. Shift position of the static fields by about 5 pixels horizontally once every hour ( something like a Windows screen saver )
C. Enable the display based on a PushButton or a hand wave with additional sensors for a few seconds and then sleep. ( would hate to do this !!)
Any inputs for above issue ??
For those who want to see the code its here :
1. Show the (Line 1) Day of Week / (Line 2 ) HH : MM : SS / (Line 3) DD : MM: YYYY
2. Once everyday at midnight log on to the NTP server and update the RTC so that once started this clock needs no correction
3. Dim the display from 10PM to 6AM and also based on ambient light.
The whole code is tried out and works fine with the display as a Serial Slave . So what is the problem ??
I am worried about the screen burn in particularly in the Day of Week and Month and Year fields. These are going to be there static for long periods. So is my worry genuine first ??
If so I plan to over come as below but not sure if any will help :
A. Change the colour of the concerned static fields once every hour
B. Shift position of the static fields by about 5 pixels horizontally once every hour ( something like a Windows screen saver )
C. Enable the display based on a PushButton or a hand wave with additional sensors for a few seconds and then sleep. ( would hate to do this !!)
Any inputs for above issue ??
For those who want to see the code its here :
Code:
#include <Wire.h> #include <Diablo_Const4D.h> #include <Diablo_Serial_4DLib.h> #include <ESP8266WebServer.h> #include <ESP8266WiFi.h> #include <ESP8266WiFiMulti.h> #include <WiFiUdp.h> #include <NTPtimeESP.h> #define DisplaySerial Serial #define DS3231_Address 0x68 #define DS3231_Sec_Reg 0x00 #define DS3231_Cnt_Reg 0x0E #define DS3231_UpDateFlag 0x08 byte pulseLED = 0; byte linkOffLED = 14; byte linkOnLED = 13; byte spareLED = 12; byte reset4D = 15; boolean debug = false; // true = more status messages boolean intrpt ; char dayString[10]; char monthString[10]; char timeString[15]; char monthYearString[25]; byte ntpMonth, ntpDate, ntpDay, ntpHour, ntpMinute, ntpSecond ; byte rtcMonth, rtcDate, rtcDay, rtcHour, rtcMinute, rtcSecond, rtcToday ; byte rtcYear; byte ntpYear; unsigned long upDateMillis = millis(), upDateInterval = 1000; unsigned long dateChkMillis = millis(), dateChkInterval = 30000; IPAddress timeServerIP; ESP8266WebServer server(80); WiFiUDP udp; ESP8266WiFiMulti wifiMulti; NTPtime NTPch("asia.pool.ntp.org"); // Choose server pool as required strDateTime dateTime; Diablo_Serial_4DLib Display(&DisplaySerial); const int NTP_PacketSize = 48; byte packetBuffer[ NTP_PacketSize]; char* ntpServerName = "asia.pool.ntp.org"; // NTP Time server unsigned int localPort = 2390; void setup() { Serial.begin(9600) ; Display.TimeLimit4D = 5000 ; Wire.begin() ; delay(1000) ; pinMode(pulseLED, OUTPUT); pinMode(linkOffLED, OUTPUT); pinMode(linkOnLED, OUTPUT); pinMode(spareLED, OUTPUT); pinMode(reset4D, OUTPUT); digitalWrite(reset4D, LOW); delay(100); digitalWrite(reset4D, HIGH); delay (3500); connectMultiWiFi( ); if (WiFi.status() == WL_CONNECTED ) { digitalWrite(linkOnLED, HIGH); digitalWrite(linkOffLED, LOW); delay(2000); } else { digitalWrite(linkOnLED, LOW); digitalWrite(linkOffLED, HIGH); delay(2000); } Display.gfx_ScreenMode(LANDSCAPE); // Fix the orientation Display.gfx_Cls(); //Clear the screen } void loop() { if (millis() - upDateMillis > upDateInterval) { upDateMillis = millis(); updateWiFiStatus() ; readRtcTime(); sprintf ( timeString, "%02u:%02u:%02u", rtcHour, rtcMinute, rtcSecond ); int century = 20; sprintf( monthYearString, "%02u-%02u-%2u%2u", rtcDate, rtcMonth, century, rtcYear); updateGenie(); // Display update } if ( millis() - dateChkMillis > dateChkInterval ) // In case WifI router down, avoid checking too frequently... { dateChkMillis = millis(); if (rtcDate != rtcToday) // Has the date changed ?? { if ( WiFi.status() != WL_CONNECTED ) { connectMultiWiFi(); // Connect WiFi if link dropped } getNtpDateTime(); // WiFi is connected... synch with NTP. } } } void connectMultiWiFi( ) { wifiMulti.addAP("wireless1"); // add Wi-Fi networks you want to connect to wifiMulti.addAP("wirelss2"); wifiMulti.addAP("wireless3"); if (debug ) WiFi.printDiag(Serial); digitalWrite(linkOnLED, HIGH); digitalWrite(linkOffLED, HIGH); // ... Give ESP 10 seconds to connect to station. unsigned long startTime = millis(); while (wifiMulti.run() != WL_CONNECTED && millis() - startTime < 10000) { delay(500); //Wait for the Wi-Fi to connect: scan for Wi-Fi networks and connect to the strongest of the networks above.. } if (WiFi.status() == WL_CONNECTED) // Check connection { digitalWrite( linkOffLED, LOW); digitalWrite( linkOnLED, HIGH); udp.begin(localPort); } else { digitalWrite( linkOffLED, HIGH); digitalWrite( linkOnLED, LOW); } } void readRtcTime() { readDS3231time(&rtcSecond, &rtcMinute, &rtcHour, &rtcDay, &rtcDate, &rtcMonth, &rtcYear); getDayOfWeek(rtcDay); } void readDS3231time (byte *sec, byte *min, byte *hour, byte *day, byte *date, byte *month, byte *year) { Wire.beginTransmission(DS3231_Address); Wire.write(0); // set DS3231 register pointer to 00h Wire.endTransmission(); Wire.requestFrom(DS3231_Address, 7); // Request seven bytes of data from DS3231 starting from register 00h *sec = bcdToDec(Wire.read() & 0x7f); *min = bcdToDec(Wire.read()); *hour = bcdToDec(Wire.read() & 0x3f); *day = bcdToDec(Wire.read()); *date = bcdToDec(Wire.read()); *month = bcdToDec(Wire.read()); *year = bcdToDec(Wire.read()); } void setRtcTime( ) { setDS3231time(ntpSecond, ntpMinute, ntpHour, ntpDay, ntpDate, ntpMonth, ntpYear); } void setDS3231time(byte sec, byte min, byte hour, byte day, byte date, byte month, byte year) { Wire.beginTransmission(DS3231_Address); Wire.write(0); // Set next input to start at the seconds register Wire.write(decToBcd(sec)); Wire.write(decToBcd(min)); Wire.write(decToBcd(hour)); Wire.write(decToBcd(day)); Wire.write(decToBcd(date)); Wire.write(decToBcd(month)); Wire.write(decToBcd(year)); Wire.endTransmission(); } byte decToBcd(byte val) { return ( (val / 10 * 16) + (val % 10) ); } byte bcdToDec(byte val) { return ( (val / 16 * 10) + (val % 16) ); } void getDayOfWeek( byte dayNo) { switch (dayNo) { case 1 : strcpy ( dayString, "SUNDAY"); break; case 2 : strcpy ( dayString, "MONDAY"); break; case 3 : strcpy ( dayString, "TUESDAY"); break; case 4 : strcpy ( dayString, "WEDNESDAY"); break; case 5 : strcpy ( dayString, "THURSDAY"); break; case 6 : strcpy ( dayString, "FRIDAY"); break; case 7 : strcpy ( dayString, "SATURDAY"); break; default : break; } } void getMonth( byte monthNo) { switch (monthNo) { case 1 : strcpy ( monthString, "January"); break; case 2 : strcpy ( monthString, "February"); break; case 3 : strcpy ( monthString, "March"); break; case 4 : strcpy ( monthString, "April"); break; case 5 : strcpy ( monthString, "May"); break; case 6 : strcpy ( monthString, "June"); break; case 7 : strcpy ( monthString, "July"); break; case 8 : strcpy ( monthString, "August"); break; case 9 : strcpy ( monthString, "September"); break; case 10 : strcpy ( monthString, "October"); break; case 11 : strcpy ( monthString, "November"); break; case 12 : strcpy ( monthString, "December"); break; default : break; } } void getNtpDateTime () { dateTime = NTPch.getNTPtime(5.5, 0); if (dateTime.valid) { NTPch.printDateTime(dateTime); ntpHour = dateTime.hour; ntpMinute = dateTime.minute; ntpSecond = dateTime.second; ntpYear = dateTime.year - 2000; ntpMonth = dateTime.month; ntpDate = dateTime.day; ntpDay = dateTime.dayofWeek; setRtcTime(); rtcToday = rtcDate; // No need to check till tomorrow.. delay(2000); } } void updateWiFiStatus() { if ( WiFi.status() == WL_CONNECTED ) { digitalWrite(linkOnLED, HIGH); digitalWrite(linkOffLED, LOW); } else { digitalWrite(linkOnLED, LOW); digitalWrite(linkOffLED, HIGH); } } void updateGenie() { Display.txt_FontID(4); Display.txt_Width(4); Display.txt_Height(4); Display.txt_Xgap(10); Display.txt_FGcolour(AQUA); Display.gfx_MoveTo(250, 50); Display.putstr(dayString); Display.txt_FGcolour(YELLOW); Display.txt_Width(6); Display.txt_Height(6); Display.gfx_MoveTo(75, 190); Display.putstr(timeString); Display.txt_FGcolour(RED); Display.txt_Width(4); Display.txt_Height(4); Display.gfx_MoveTo(120, 370); Display.putstr(monthYearString); }
Comment