├── ESP-MAX7219-LED-4x8x8-Matrix-Clock_WiFiManager.ino ├── ESP8266_MAX7219_Time.ino ├── ESP_MAX7219_Specific_Format_Time.ino ├── Licence.txt └── README.md /ESP-MAX7219-LED-4x8x8-Matrix-Clock_WiFiManager.ino: -------------------------------------------------------------------------------- 1 | #ifdef ESP32 2 | #include 3 | #include 4 | #include 5 | #else 6 | #include 7 | #include 8 | #include 9 | #endif 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | int pinCS = D4; // Attach CS to this pin, DIN to MOSI and CLK to SCK (cf http://arduino.cc/en/Reference/SPI ) 17 | int numberOfHorizontalDisplays = 4; 18 | int numberOfVerticalDisplays = 1; 19 | char time_value[20]; 20 | 21 | // LED Matrix Pin -> ESP8266 Pin 22 | // Vcc -> 3v (3V on NodeMCU 3V3 on WEMOS) 23 | // Gnd -> Gnd (G on NodeMCU) 24 | // DIN -> D7 (Same Pin for WEMOS) 25 | // CS -> D4 (Same Pin for WEMOS) 26 | // CLK -> D5 (Same Pin for WEMOS) 27 | 28 | Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays); 29 | 30 | int wait = 70; // In milliseconds 31 | 32 | int spacer = 1; 33 | int width = 5 + spacer; // The font width is 5 pixels 34 | 35 | void setup() { 36 | Serial.begin(115200); 37 | WiFi_Setup(); 38 | configTime(0 * 3600, 0, "pool.ntp.org", "time.nist.gov"); 39 | setenv("TZ", "GMT0BST,M3.5.0/01,M10.5.0/02",1); 40 | matrix.setIntensity(0); // Use a value between 0 and 15 for brightness 41 | matrix.setRotation(0, 1); // The first display is position upside down 42 | matrix.setRotation(1, 1); // The first display is position upside down 43 | matrix.setRotation(2, 1); // The first display is position upside down 44 | matrix.setRotation(3, 1); // The first display is position upside down 45 | } 46 | 47 | void loop() { 48 | matrix.fillScreen(LOW); 49 | time_t now = time(nullptr); 50 | String time = String(ctime(&now)); 51 | time.trim(); 52 | Serial.println(time); 53 | time.substring(11,19).toCharArray(time_value, 10); 54 | matrix.drawChar(2,0, time_value[0], HIGH,LOW,1); // H 55 | matrix.drawChar(8,0, time_value[1], HIGH,LOW,1); // HH 56 | matrix.drawChar(14,0,time_value[2], HIGH,LOW,1); // HH: 57 | matrix.drawChar(20,0,time_value[3], HIGH,LOW,1); // HH:M 58 | matrix.drawChar(26,0,time_value[4], HIGH,LOW,1); // HH:MM 59 | matrix.write(); // Send bitmap to display 60 | delay(2000); 61 | display_message(time); // Display time in format 'Wed, Mar 01 16:03:20 2017 62 | } 63 | 64 | void display_message(String message){ 65 | for ( int i = 0 ; i < width * message.length() + matrix.width() - spacer; i++ ) { 66 | //matrix.fillScreen(LOW); 67 | int letter = i / width; 68 | int x = (matrix.width() - 1) - i % width; 69 | int y = (matrix.height() - 8) / 2; // center the text vertically 70 | while ( x + width - spacer >= 0 && letter >= 0 ) { 71 | if ( letter < message.length() ) { 72 | matrix.drawChar(x, y, message[letter], HIGH, LOW, 1); // HIGH LOW means foreground ON, background off, reverse to invert the image 73 | } 74 | letter--; 75 | x -= width; 76 | } 77 | matrix.write(); // Send bitmap to display 78 | delay(wait/2); 79 | } 80 | } 81 | 82 | void WiFi_Setup(){ 83 | WiFiManager wifiManager; // Connect to Wi-Fi 84 | // A new OOB ESP has no Wi-Fi credentials so will connect and not need the next command to be uncommented and compiled in, a used one with incorrect credentials will 85 | // so restart the ESP and connect your PC to the wireless access point called 'ESP_AP' or whatever you call it below in "" 86 | // wifiManager.resetSettings(); // Command to be included if needed, then connect to http://192.168.4.1/ and follow instructions to make the WiFi connection 87 | // Set a timeout until configuration is turned off, useful to retry or go to sleep in n-seconds 88 | wifiManager.setTimeout(180); 89 | //fetches ssid and password and tries to connect, if connections succeeds it starts an access point with the name called "ESP8266_AP" and waits in a blocking loop for configuration 90 | if(!wifiManager.autoConnect("ESP_AP")) { 91 | Serial.println(F("failed to connect and timeout occurred")); 92 | delay(6000); 93 | ESP.restart(); //reset and try again 94 | } 95 | // At this stage the WiFi manager will have successfully connected to a network, or if not will try again in 180-seconds 96 | Serial.println(F("WiFi connected...")); 97 | //---------------------------------------------------------------------- 98 | Serial.println(F("Use this URL to connect: http://")); Serial.println(WiFi.localIP().toString()+"/");// Print the IP address 99 | } 100 | 101 | -------------------------------------------------------------------------------- /ESP8266_MAX7219_Time.ino: -------------------------------------------------------------------------------- 1 | #ifdef ESP32 2 | #include 3 | #else 4 | #include 5 | #endif 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | int pinCS = D4; // Attach CS to this pin, DIN to MOSI and CLK to SCK (cf http://arduino.cc/en/Reference/SPI ) 12 | int numberOfHorizontalDisplays = 4; 13 | int numberOfVerticalDisplays = 1; 14 | char time_value[20]; 15 | 16 | // LED Matrix Pin -> ESP8266 Pin 17 | // Vcc -> 3v (3V on NodeMCU 3V3 on WEMOS) 18 | // Gnd -> Gnd (G on NodeMCU) 19 | // DIN -> D7 (Same Pin for WEMOS) 20 | // CS -> D4 (Same Pin for WEMOS) 21 | // CLK -> D5 (Same Pin for WEMOS) 22 | 23 | Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays); 24 | 25 | int wait = 70; // In milliseconds 26 | 27 | int spacer = 1; 28 | int width = 5 + spacer; // The font width is 5 pixels 29 | 30 | void setup() { 31 | Serial.begin(115200); 32 | WiFi.begin(ssid,password); 33 | configTime(0 * 3600, 0, "pool.ntp.org", "time.nist.gov"); 34 | setenv("TZ", "GMT0BST,M3.5.0/01,M10.5.0/02",1); 35 | matrix.setIntensity(0); // Use a value between 0 and 15 for brightness 36 | matrix.setRotation(0, 1); // The first display is position upside down 37 | matrix.setRotation(1, 1); // The first display is position upside down 38 | matrix.setRotation(2, 1); // The first display is position upside down 39 | matrix.setRotation(3, 1); // The first display is position upside down 40 | } 41 | 42 | void loop() { 43 | matrix.fillScreen(LOW); 44 | time_t now = time(nullptr); 45 | String time = String(ctime(&now)); 46 | time.trim(); 47 | Serial.println(time); 48 | time.substring(11,19).toCharArray(time_value, 10); 49 | matrix.drawChar(2,0, time_value[0], HIGH,LOW,1); // H 50 | matrix.drawChar(8,0, time_value[1], HIGH,LOW,1); // HH 51 | matrix.drawChar(14,0,time_value[2], HIGH,LOW,1); // HH: 52 | matrix.drawChar(20,0,time_value[3], HIGH,LOW,1); // HH:M 53 | matrix.drawChar(26,0,time_value[4], HIGH,LOW,1); // HH:MM 54 | matrix.write(); // Send bitmap to display 55 | delay(2000); 56 | display_message(time); // Display time in format 'Wed, Mar 01 16:03:20 2017 57 | } 58 | 59 | void display_message(String message){ 60 | for ( int i = 0 ; i < width * message.length() + matrix.width() - spacer; i++ ) { 61 | //matrix.fillScreen(LOW); 62 | int letter = i / width; 63 | int x = (matrix.width() - 1) - i % width; 64 | int y = (matrix.height() - 8) / 2; // center the text vertically 65 | while ( x + width - spacer >= 0 && letter >= 0 ) { 66 | if ( letter < message.length() ) { 67 | matrix.drawChar(x, y, message[letter], HIGH, LOW, 1); // HIGH LOW means foreground ON, background off, reverse to invert the image 68 | } 69 | letter--; 70 | x -= width; 71 | } 72 | matrix.write(); // Send bitmap to display 73 | delay(wait/2); 74 | } 75 | } 76 | 77 | -------------------------------------------------------------------------------- /ESP_MAX7219_Specific_Format_Time.ino: -------------------------------------------------------------------------------- 1 | #ifdef ESP32 2 | #include 3 | #else 4 | #include 5 | #endif 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | int pinCS = D4; // Attach CS to this pin, DIN to MOSI and CLK to SCK (cf http://arduino.cc/en/Reference/SPI ) 12 | int numberOfHorizontalDisplays = 4; 13 | int numberOfVerticalDisplays = 1; 14 | const byte buffer_size = 45; 15 | char time_value[buffer_size]; 16 | 17 | // LED Matrix Pin -> ESP8266 Pin 18 | // Vcc -> 3v (3V on NodeMCU 3V3 on WEMOS) 19 | // Gnd -> Gnd (G on NodeMCU) 20 | // DIN -> D7 (Same Pin for WEMOS) 21 | // CS -> D4 (Same Pin for WEMOS) 22 | // CLK -> D5 (Same Pin for WEMOS) 23 | 24 | Max72xxPanel matrix = Max72xxPanel(pinCS, numberOfHorizontalDisplays, numberOfVerticalDisplays); 25 | 26 | int wait = 70; // In milliseconds 27 | 28 | int spacer = 1; 29 | int width = 5 + spacer; // The font width is 5 pixels 30 | const char *ssid = "your_SSID"; 31 | const char *password = "your_PASSWORD"; 32 | 33 | void setup() { 34 | Serial.begin(115200); 35 | WiFi.begin(ssid,password); 36 | configTime(0 * 3600, 0, "pool.ntp.org", "time.nist.gov"); 37 | // See https://github.com/nayarsystems/posix_tz_db/blob/master/zones.csv for Timezone codes for your region 38 | setenv("TZ", "GMT0BST,M3.5.0/01,M10.5.0/02",1); 39 | matrix.setIntensity(0); // Use a value between 0 and 15 for brightness 40 | matrix.setRotation(0, 1); // The first display is position upside down 41 | matrix.setRotation(1, 1); // The first display is position upside down 42 | matrix.setRotation(2, 1); // The first display is position upside down 43 | matrix.setRotation(3, 1); // The first display is position upside down 44 | } 45 | 46 | void loop() { 47 | matrix.fillScreen(LOW); 48 | String time = get_time(); 49 | time.trim(); 50 | Serial.println(time); 51 | time.substring(23,28).toCharArray(time_value, 10); 52 | Serial.println("HH:MM"); 53 | Serial.println(time_value); 54 | //( Sun 21-07-19 ) ( PM 12:52:12 ) 55 | matrix.drawChar(2,0, time_value[0], HIGH,LOW,1); // H 56 | matrix.drawChar(8,0, time_value[1], HIGH,LOW,1); // HH 57 | matrix.drawChar(14,0,time_value[2], HIGH,LOW,1); // HH: 58 | matrix.drawChar(20,0,time_value[3], HIGH,LOW,1); // HH:M 59 | matrix.drawChar(26,0,time_value[4], HIGH,LOW,1); // HH:MM 60 | matrix.write(); // Send bitmap to display 61 | delay(2000); 62 | display_message(time); // Display time in format 'Wed, Mar 01 16:03:20 2017 63 | } 64 | 65 | void display_message(String message){ 66 | for ( int i = 0 ; i < width * message.length() + matrix.width() - spacer; i++ ) { 67 | //matrix.fillScreen(LOW); 68 | int letter = i / width; 69 | int x = (matrix.width() - 1) - i % width; 70 | int y = (matrix.height() - 8) / 2; // center the text vertically 71 | while ( x + width - spacer >= 0 && letter >= 0 ) { 72 | if ( letter < message.length() ) { 73 | matrix.drawChar(x, y, message[letter], HIGH, LOW, 1); // HIGH LOW means foreground ON, background off, reverse to invert the image 74 | } 75 | letter--; 76 | x -= width; 77 | } 78 | matrix.write(); // Send bitmap to display 79 | delay(wait/2); 80 | } 81 | } 82 | 83 | String get_time(){ 84 | time_t now; 85 | time(&now); 86 | char time_output[buffer_size]; 87 | // See http://www.cplusplus.com/reference/ctime/strftime/ for strftime functions 88 | // Desired format: ( Sun ,Jul 21 2019 ) ( AM 10:03:20 ) 89 | strftime(time_output, buffer_size, "( %a %d-%m-%y ) ( %p %T )", localtime(&now)); 90 | return String(time_output); // returns ( Sat 20-Apr-19) ( AM 12:31:45 ) 91 | } 92 | -------------------------------------------------------------------------------- /Licence.txt: -------------------------------------------------------------------------------- 1 | This software, the ideas and concepts is Copyright (c) David Bird 2014 and beyond. 2 | 3 | All rights to this software are reserved. 4 | 5 | It is prohibited to redistribute or reproduce of any part or all of the software contents in any form other than the following: 6 | 7 | 1. You may print or download to a local hard disk extracts for your personal and non-commercial use only. 8 | 9 | 2. You may copy the content to individual third parties for their personal use, but only if you acknowledge the author David Bird as the source of the material. 10 | 11 | 3. You may not, except with my express written permission, distribute or commercially exploit the content. 12 | 13 | 4. You may not transmit it or store it in any other website or other form of electronic retrieval system for commercial purposes. 14 | 15 | 5. You MUST include all of this copyright and permission notice ('as annotated') and this shall be included in all copies or substantial portions of the software and where the software use is visible to an end-user. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS" FOR PRIVATE USE ONLY, IT IS NOT FOR COMMERCIAL USE IN WHOLE OR PART OR CONCEPT. 18 | 19 | FOR PERSONAL USE IT IS SUPPLIED WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | 21 | IN NO EVENT SHALL THE AUTHOR OR COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ESP8266-MAX7219-LED-4x8x8-Matrix-Clock --------------------------------------------------------------------------------