For fast transaction call 0916.457.0748
Wemos Clock with Dot Matrix Display

Wemos Clock with Dot Matrix Display

The D1 mini Pro is designed to allow Wemos compatible shields to be plugged into the board in a similar way to the Arduino development board platform which greatly expands its capabilities.  But this time we will be using it connect to a network and fetch the current time in a certain location. This tutorial covers Philippine time using NTP.

Things you'll need:

Schematic and Wiring:

Building the Code:

Before you can upload the code to your Wemos.
Download and include first the following library:

Instruction here how to install Wemos Board.
Please follow Installing with Boards Manager!

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Max72xxPanel.h>
#include <time.h>
#include <ESP8266WiFi.h>

int pinCS = D4;
int numberOfHorizontalDisplays = 4;
int numberOfVerticalDisplays = 1;
char time_value[20];

// LED Matrix Pin -> ESP8266 Pin
// Vcc -> 3v (3V on NodeMCU 3V3 on WEMOS)
// Gnd -> Gnd (G on NodeMCU)
// DIN -> D7 (Same Pin for WEMOS)
// CS -> D4 (Same Pin for WEMOS)
// CLK -> D5 (Same Pin for WEMOS)

Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays);

int wait = 150; // In milliseconds

int spacer = 1;
int width = 5 + spacer; // The font width is 5 pixels

void setup() {
Serial.begin(115200);
WiFi.begin("SSID", "Password"); // Initiate connection to the Wi-Fi network
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.println(".");
}
Serial.println("Connected!");
delay(1000);
configTime(28800, 0, "3.asia.pool.ntp.org", "time.nist.gov");
matrix.setIntensity(3); // Use a value between 0 and 15 for brightness
matrix.setRotation(0, 1); // The first display is position upside down
matrix.setRotation(1, 1); // The first display is position upside down
matrix.setRotation(2, 1); // The first display is position upside down
matrix.setRotation(3, 1); // The first display is position upside down
}

void loop() {
matrix.fillScreen(LOW);
time_t now = time(nullptr);
String time = String(ctime(&now));
time.trim();
time.substring(11, 19).toCharArray(time_value, 10);
matrix.drawChar(2, 0, time_value[0], HIGH, LOW, 1); // H
matrix.drawChar(8, 0, time_value[1], HIGH, LOW, 1); // HH
matrix.drawChar(14, 0, time_value[2], HIGH, LOW, 1); // HH:
matrix.drawChar(20, 0, time_value[3], HIGH, LOW, 1); // HH:M
matrix.drawChar(26, 0, time_value[4], HIGH, LOW, 1); // HH:MM
matrix.write(); // Send bitmap to display
delay(15000);
display_message(time); // Display time in format 'Wed, Mar 01 16:03:20 2017
}

void display_message(String message) {
for ( int i = 0 ; i < width * message.length() + matrix.width() - spacer; i++ ) {
//matrix.fillScreen(LOW);
int letter = i / width;
int x = (matrix.width() - 1) - i % width;
int y = (matrix.height() - 8) / 2; // center the text vertically
while ( x + width - spacer >= 0 && letter >= 0 ) {
if ( letter < message.length() ) {
matrix.drawChar(x, y, message[letter], HIGH, LOW, 1); // HIGH LOW means foreground ON, background off, reverse to invert the image
}
letter--;
x -= width;
}
matrix.write(); // Send bitmap to display
delay(wait / 2);
}
}

 

Copy code to your Arduino IDE.

Select Board: "Wemos D1 R2 & mini"

Please take note of the following details:

If ever the uploading process fail, disconnect first your Dot Matrix Module and try to upload again.

 

That's it, you already have your own WEMOS Clock!

Happy Coding!


0 comments

Leave a comment

Please note, comments must be approved before they are published

Payment Methods

Facebook Rewards Program