ESP8266 Wall Clock 2.0

by martinhui in Circuits > Electronics

2387 Views, 12 Favorites, 0 Comments

ESP8266 Wall Clock 2.0

ESP8266 Wall Clock 2.0
F66KCDGJ0486NM3.jpeg

After the publish of https://www.instructables.com/id/ESP8266-Wall-Cloc... , which may be called the 1.0 version, I found some problem, though it still working, it seemed overloading my wifi router, and stop it from working, so I changed the SSID to some free source and saved my router. I cannot investigate the root cause but the display was designed multiplexing at high speed which mean it sent request to fetch the NTP clock at same speed that may overloaded the router.

I start look for some display doesn't need multiplexing and found MAX7219 with 8 x 8 dot matrix display could worked, because I have several pieces to try on.

Schematic

IMG_2798.JPG
IMG_2800.JPG

Compared with version 1.0, this is the most simplest version ever, I like to show you the schematic, I'm not sure if any instructabler had simillar connection, but I have tried and it worked. The led matrix are connected in daisy chain, be noted that new add led matrix extends to the left, connect the rightmost led matrix to the esp8266, I need five pieces but I have only 4 now, a minor change in the code can accommodate it.

Code 1

I will not post all the code as usual, because the code is not written by me, I even didn't know who are the first one wrote the code, I just modify it to suit my need, I'm pleased to show you the modified parts.

1. header files

#include <ESP8266WiFi.h>

#include <WifiUDP.h>
#include <MaxMatrix.h>

#include <NTPClient.h>

2. character map

This map can be found from MAX7912 instructable code, I included some parts herebelow:

const unsigned char CH[ ] PROGMEM = {
3, 8, B00000000, B00000000, B00000000, B00000000, B00000000, // space

1, 8, B01011111, B00000000, B00000000, B00000000, B00000000, // !

3, 8, B00000011, B00000000, B00000011, B00000000, B00000000, // "

5, 8, B00010100, B00111110, B00010100, B00111110, B00010100, // #

4, 8, B00100100, B01101010, B00101011, B00010010, B00000000, //........};

Code 2

3. Define NTP properties

#define NTP_OFFSET 60 * 60 // In seconds
#define NTP_INTERVAL 60 * 1000 // In miliseconds

#define NTP_ADDRESS "....." // change this to whatever pool is closest (see ntp.org)

4. Setup the NTP UDP client

WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, NTP_ADDRESS, NTP_OFFSET, NTP_INTERVAL);

int data = 0;// DIN pin of MAX7219 module

int load = 1;// CS pin of MAX7219 module

int clk = 2;// CLK pin of MAX7219 module

int maxInUse = 4; //change this variable to set how many MAX7219's you'll use

MaxMatrix m(data, load, clk, maxInUse); // define module

byte buffer[10];

const char* ssid = " "; // insert your own ssid

const char* password = " "; // and password

byte ten, th;

int hours, minutes, seconds;

Code 3

5 void setup() {

timeClient.begin(); // Start the NTP UDP client
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {

delay(500);

}

delay(1000);

}

6. void loop() {

hours=minutes=seconds=0;

if (WiFi.status() == WL_CONNECTED) //Check WiFi connection status {

// update the NTP client and get the UNIX UTC timestamp

timeClient.update();

unsigned long epochTime = timeClient.getEpochTime(); // get the hour, minute and second:

hours = (epochTime % 86400L) / 3600 + 7; // (GMT+8 time zone)

if (hours >= 24) //if you find 25, 26, 27....... hours shown

hours-=24;

minutes = (epochTime % 3600 / 60);

seconds = (epochTime % 60);

} else { // attempt to connect to wifi again if disconnected

WiFi.begin(ssid, password);

delay(1000);

}

displayTime(hours,minutes,seconds); //display routine

delay(10000); //Send a request to update every 10 sec (= 10,000 ms)

}

Code 4

7. void displayTime(int hrs, int mins, int secs) { //this is my modified parts

m.init();
th = byte(hrs%10+48); //extract byte by byte of hour, minute and second

ten = byte(hrs/10+48); //convert int to byte must add 48 to correct display

printCharWithShift(ten, 100); //display routine

printCharWithShift(th, 100);

printStringWithShift(":", 100); // print " : " between hour, minute and second

if (mins < 0) {

printStringWithShift("0", 100); //add leading zero

th = byte(mins%10+48);

printCharWithShift(th, 100);

} else {

th = byte(mins%10+48);

ten = byte(mins/10+48);

printCharWithShift(ten, 100);

printCharWithShift(th, 100);

}

printStringWithShift(":", 100); //this " : " has been modified in the character map

if (secs < 10) {

printStringWithShift("0", 100); //add leading zero

//th = byte(secs%10+48); //uncomment for five led matrix

//printCharWithShift(th, 100); //uncomment for five led matrix

} else {

th = byte(secs%10+48);

ten = byte(secs/10+48);

printCharWithShift(ten, 100);

// printCharWithShift(th, 100); //uncomment for five led matrix

}

}

Code 5

8. Display routines (these routines can be found in MAX7219 instructable code)

void printCharWithShift(char c, int shift_speed) {
if (c < 32) return;

c -= 32;

memcpy_P(buffer, CH + 7*c, 7);

m.writeSprite(maxInUse*8, 0, buffer);

m.setColumn(maxInUse*8 + buffer[0], 0);

for (int i=0; i<buffer[0]+1; i++) {

delay(shift_speed);
m.shiftLeft(false, false);

}

}

void printStringWithShift(char* s, int shift_speed) {

while (*s != 0) {

printCharWithShift(*s, shift_speed);

s++;

}

}

Waiting for the Fifth Piece

IMG_2797.JPG

As shown in the video, the time scroll to the left every 10 second, I hope it may not overloading the router.