Components and supplies
rtc ds1302 module
Nokia 5110 LCD
Breadboard (generic)
esp8266 NodeMCU
Project description
Code
Updated Software
arduino
Flash the esp using the Arduino IDE
1 2#include <Arduino.h> 3#include <Ds1302.h> 4#include <Adafruit_PCD8544.h> // include adafruit PCD8544 (Nokia 5110) library 5 6 7// DS1302 RTC instance 8Ds1302 rtc(15,12,13); 9// Nokia 5110 LCD module connections CLK, DIN, D/C, CS, RST (opposite to the actual pin positions !!) 10Adafruit_PCD8544 display = Adafruit_PCD8544(14, 2, 0, 4, 5); 11const static char* WeekDays[] = 12{ 13 " Mon ", 14 " Tues ", 15 " Wed ", 16 " Thurs ", 17 " Fri ", 18 " Sat ", 19 " Sun " 20}; 21 22 23void setup() { 24 display.begin(); 25 // initialize the RTC 26 rtc.init(); 27 display.setContrast(60); 28 display.clearDisplay(); // clears the screen and buffer 29 display.drawRect(0, 0, 84, 30, BLACK); 30 display.drawRect(0, 29, 84, 12, BLACK); 31} 32 33 34void loop() 35{ 36 // get the current time 37 Ds1302::DateTime now; 38 rtc.getDateTime(&now); 39 static uint8_t last_second = 0; 40 if (last_second != now.second) 41 { 42 last_second = now.second; 43 44 display.setTextColor(BLACK); 45 display.setTextSize(2); 46 display.setCursor(6,10); 47 if (now.hour <= 9) { //If Hour is single figures, put a 0 in front 48 display.print("0"); 49 } 50 display.print(now.hour); 51 display.print(":"); 52 if (now.minute <= 9) { //If Minute is single figures, put a 0 in front 53 display.print("0"); 54 } 55 display.print(now.minute); 56 // display.print(":"); 57 display.setTextSize(1); 58 if (now.second <= 9) { //If Seconds is single figures, put a 0 in front 59 display.print("0"); 60 } 61 display.print(now.second); 62 63 64 display.setCursor(0,31); 65 display.print(WeekDays[now.dow -1]); 66 display.print(now.day); 67 display.print("/"); 68 display.print(now.month); 69 70 display.display(); 71 72 73 display.setTextColor(WHITE); 74 display.setCursor(0,31); 75 display.print(WeekDays[now.dow -1]); 76 display.print(now.day); 77 display.print("/"); 78 display.print(now.month); 79 80 81 82 display.setTextSize(2); 83 display.setCursor(6,10); 84 if (now.hour <= 9) { 85 display.print("0"); 86 } 87 display.print(now.hour); 88 display.print(":"); 89 if (now.minute <= 9) { 90 display.print("0"); 91 } 92 display.print(now.minute); 93 // display.print(":"); 94 display.setTextSize(1); 95 if (now.second <= 9) { 96 display.print("0"); 97 } 98 display.print(now.second); 99 100// No need to display the screen again 101 102 } 103 delay(100); 104} 105
Updated Software
arduino
Flash the esp using the Arduino IDE
1 2#include <Arduino.h> 3#include <Ds1302.h> 4#include <Adafruit_PCD8544.h> // include adafruit PCD8544 (Nokia 5110) library 5 6 7// DS1302 RTC instance 8Ds1302 rtc(15,12,13); 9// Nokia 5110 LCD module connections CLK, DIN, D/C, CS, RST (opposite to the actual pin positions !!) 10Adafruit_PCD8544 display = Adafruit_PCD8544(14, 2, 0, 4, 5); 11const static char* WeekDays[] = 12{ 13 " Mon ", 14 " Tues ", 15 " Wed ", 16 " Thurs ", 17 " Fri ", 18 " Sat ", 19 " Sun " 20}; 21 22 23void setup() { 24 display.begin(); 25 // initialize the RTC 26 rtc.init(); 27 display.setContrast(60); 28 display.clearDisplay(); // clears the screen and buffer 29 display.drawRect(0, 0, 84, 30, BLACK); 30 display.drawRect(0, 29, 84, 12, BLACK); 31} 32 33 34void loop() 35{ 36 // get the current time 37 Ds1302::DateTime now; 38 rtc.getDateTime(&now); 39 static uint8_t last_second = 0; 40 if (last_second != now.second) 41 { 42 last_second = now.second; 43 44 display.setTextColor(BLACK); 45 display.setTextSize(2); 46 display.setCursor(6,10); 47 if (now.hour <= 9) { //If Hour is single figures, put a 0 in front 48 display.print("0"); 49 } 50 display.print(now.hour); 51 display.print(":"); 52 if (now.minute <= 9) { //If Minute is single figures, put a 0 in front 53 display.print("0"); 54 } 55 display.print(now.minute); 56 // display.print(":"); 57 display.setTextSize(1); 58 if (now.second <= 9) { //If Seconds is single figures, put a 0 in front 59 display.print("0"); 60 } 61 display.print(now.second); 62 63 64 display.setCursor(0,31); 65 display.print(WeekDays[now.dow -1]); 66 display.print(now.day); 67 display.print("/"); 68 display.print(now.month); 69 70 display.display(); 71 72 73 display.setTextColor(WHITE); 74 display.setCursor(0,31); 75 display.print(WeekDays[now.dow -1]); 76 display.print(now.day); 77 display.print("/"); 78 display.print(now.month); 79 80 81 82 display.setTextSize(2); 83 display.setCursor(6,10); 84 if (now.hour <= 9) { 85 display.print("0"); 86 } 87 display.print(now.hour); 88 display.print(":"); 89 if (now.minute <= 9) { 90 display.print("0"); 91 } 92 display.print(now.minute); 93 // display.print(":"); 94 display.setTextSize(1); 95 if (now.second <= 9) { 96 display.print("0"); 97 } 98 display.print(now.second); 99 100// No need to display the screen again 101 102 } 103 delay(100); 104} 105
Downloadable files
Circuit pin diagram
Circuit pin diagram
Comments
Only logged in users can leave comments
stevie135s
6 Followers
•11 Projects
0
0