stevie135s
Published © CC BY-NC-SA

RTC1302 Clock using Nokia5110 Display and esp8266 NodeMCU

A simple program to display RTC information on the Nokia5110 lcd using an esp8266 NodeMCU

BeginnerWork in progress2,862
RTC1302 Clock using Nokia5110 Display and esp8266 NodeMCU

Things used in this project

Hardware components

esp8266 NodeMCU
×1
Nokia 5110 LCD
×1
rtc ds1302 module
×1
Breadboard (generic)
Breadboard (generic)
×1

Story

Read more

Schematics

Circuit pin diagram

Code

Updated Software

Arduino
Flash the esp using the Arduino IDE
#include <Arduino.h>
#include <Ds1302.h>
#include <Adafruit_PCD8544.h>  // include adafruit PCD8544 (Nokia 5110) library


// DS1302 RTC instance
Ds1302 rtc(15,12,13);
// Nokia 5110 LCD module connections CLK, DIN, D/C, CS, RST (opposite to the actual pin positions !!)
Adafruit_PCD8544 display = Adafruit_PCD8544(14, 2, 0, 4, 5);
const static char* WeekDays[] =
{
    "  Mon   ",
    " Tues   ",
    "  Wed   ",
    " Thurs  ",
    "  Fri   ",
    "  Sat   ",
    "  Sun   "
};


void setup() {
    display.begin();
    // initialize the RTC
    rtc.init();
    display.setContrast(60);
    display.clearDisplay();   // clears the screen and buffer
    display.drawRect(0, 0, 84, 30, BLACK);
    display.drawRect(0, 29, 84, 12, BLACK);
}


void loop()
{
    // get the current time
    Ds1302::DateTime now;
    rtc.getDateTime(&now);
    static uint8_t last_second = 0;
    if (last_second != now.second)
    {
        last_second = now.second;

        display.setTextColor(BLACK);
        display.setTextSize(2);
        display.setCursor(6,10);
        if (now.hour <= 9) { //If Hour is single figures, put a 0 in front
        display.print("0");
        }
        display.print(now.hour);
        display.print(":");
     if (now.minute <= 9) {  //If Minute is single figures, put a 0 in front
        display.print("0");
     }
        display.print(now.minute);
  //      display.print(":");
        display.setTextSize(1); 
        if (now.second <= 9) {  //If Seconds is single figures, put a 0 in front
        display.print("0");
     } 
        display.print(now.second);

        
        display.setCursor(0,31);
        display.print(WeekDays[now.dow -1]);
        display.print(now.day);
        display.print("/");
        display.print(now.month);
        
        display.display();

        
        display.setTextColor(WHITE);
        display.setCursor(0,31);
        display.print(WeekDays[now.dow -1]);
        display.print(now.day);
        display.print("/");
        display.print(now.month);           
        
                
        
        display.setTextSize(2);
        display.setCursor(6,10);
     if (now.hour <= 9) {
        display.print("0");
    }
       display.print(now.hour);
       display.print(":");
     if (now.minute <= 9) {
       display.print("0");
  }
       display.print(now.minute);
  //     display.print(":");
       display.setTextSize(1);
     if (now.second <= 9) {
       display.print("0");
  } 
      display.print(now.second);
 
// No need to display the screen again
 
    }
    delay(100);
}

Credits

stevie135s

stevie135s

25 projects • 11 followers

Comments