├── LICENSE ├── README.md └── esp8266-LEDMatrix.ino /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Ben Schattinger 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # esp8266-LEDMatrix 2 | A simple program for displaying an animated message with an ESP8266 and a WS2812 (neopixel) matrix 3 | 4 | ## Using the program 5 | This program depends on the following items: 6 | 1. An ESP8266. In this case, I used a NodeMCU board. 7 | 2. A WS2812B (neopixel) 32 x 8 LED Matrix plugged into pin D6 on the NodeMCU pinout 8 | 3. The Arduino IDE setup for programming an ESP8266 9 | 4. Either an SSID to connect to, or the board will create a network named `LED Matrix` with a password of `12345678`. 10 | 11 | After uploading the program, the board will start scrolling its IP Address across the screen. 12 | -------------------------------------------------------------------------------- /esp8266-LEDMatrix.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #define PIN D6 11 | Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(32, 8, PIN, 12 | NEO_MATRIX_TOP + NEO_MATRIX_LEFT + 13 | NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG, 14 | NEO_GRB + NEO_KHZ800); 15 | const char *ssid = "WifiSSID"; 16 | const char *password = "WifiPassword"; 17 | String color = "00FFFF"; 18 | String jscolor = ""; 19 | int r = 0; 20 | int g = 255; 21 | int b = 255; 22 | int brightness = 90; 23 | bool brightnessChanged = false; 24 | 25 | ESP8266WebServer server ( 80 ); 26 | 27 | const int led = 13; 28 | String message = ""; 29 | bool messageChanged = true; 30 | 31 | void getData() { 32 | for ( uint8_t i = 0; i < server.args(); i++ ) { 33 | if (server.argName ( i ) == "name") { 34 | message = server.arg ( i ); 35 | messageChanged = true; 36 | } else if (server.argName ( i ) == "color") { 37 | color = server.arg ( i ); 38 | Serial.println(color); 39 | if (color.charAt(0) == '#') { 40 | color = color.substring(1); 41 | } 42 | Serial.println(color); 43 | Serial.println(color.length()); 44 | if (color.length() != 6) continue; 45 | long number = (long) strtol(color.c_str(), NULL, 16); 46 | r = number >> 16; 47 | g = number >> 8 & 0xFF; 48 | b = number & 0xFF; 49 | } else if (server.argName ( i ) == "brightness") { 50 | int br = server.arg(i).toInt(); 51 | if (br >= 0 && br <= 255) brightness = br; 52 | brightnessChanged = true; 53 | } 54 | } 55 | Serial.println(message); 56 | handleRoot(); 57 | } 58 | void handleRoot() { 59 | String messageSafe; 60 | messageSafe.reserve(message.length()); 61 | for (size_t pos = 0; pos != message.length(); ++pos) { 62 | switch (message[pos]) { 63 | case '&': messageSafe += "&"; break; 64 | case '\"': messageSafe += """; break; 65 | case '\'': messageSafe += "'"; break; 66 | case '<': messageSafe += "<"; break; 67 | case '>': messageSafe += ">"; break; 68 | default: messageSafe += message[pos]; break; 69 | } 70 | } 71 | String toSend = "ESP8266 Demo

Hello from ESP8266!




"; 72 | server.send ( 200, "text/html", toSend ); 73 | } 74 | 75 | void handleNotFound() { 76 | digitalWrite ( led, 1 ); 77 | String message = "File Not Found\n\n"; 78 | message += "URI: "; 79 | message += server.uri(); 80 | message += "\nMethod: "; 81 | message += ( server.method() == HTTP_GET ) ? "GET" : "POST"; 82 | message += "\nArguments: "; 83 | message += server.args(); 84 | message += "\n"; 85 | 86 | for ( uint8_t i = 0; i < server.args(); i++ ) { 87 | message += " " + server.argName ( i ) + ": " + server.arg ( i ) + "\n"; 88 | } 89 | 90 | server.send ( 404, "text/plain", message ); 91 | digitalWrite ( led, 0 ); 92 | } 93 | 94 | void setup ( void ) { 95 | pinMode ( led, OUTPUT ); 96 | digitalWrite ( led, 0 ); 97 | Serial.begin ( 115200 ); 98 | WiFi.begin ( ssid, password ); 99 | Serial.println ( "" ); 100 | 101 | // Wait for connection 102 | while ( WiFi.status() != WL_CONNECTED ) { 103 | delay ( 500 ); 104 | Serial.print ( "." ); 105 | } 106 | 107 | Serial.println ( "" ); 108 | Serial.print ( "Connected to " ); 109 | Serial.println ( ssid ); 110 | WiFi.softAP("LED Matrix", "12345678"); 111 | Serial.print ( "IP address: " ); 112 | Serial.println ( WiFi.localIP() ); 113 | message = "IP Address: "; 114 | message += WiFi.localIP().toString(); 115 | 116 | if ( MDNS.begin ( "esp8266" ) ) { 117 | Serial.println ( "MDNS responder started" ); 118 | } 119 | SPIFFS.begin(); 120 | File file = SPIFFS.open("/jscolor.min.js", "r"); 121 | jscolor = file.readString(); 122 | file.close(); 123 | server.on ( "/", HTTP_GET, handleRoot ); 124 | server.on ( "/", HTTP_POST, getData ); 125 | server.on ( "/jscolor.min.js", HTTP_GET, []() { 126 | server.send ( 200, "application/javascript", jscolor ); 127 | }); 128 | server.onNotFound ( handleNotFound ); 129 | server.begin(); 130 | Serial.println ( "HTTP server started" ); 131 | randomSeed(analogRead(0)); 132 | matrix.begin(); 133 | matrix.setTextWrap(false); 134 | matrix.setBrightness(brightness); 135 | } 136 | int x = matrix.width(); 137 | int xy = 0; 138 | void loop ( void ) { 139 | server.handleClient(); 140 | if (messageChanged) { 141 | x = matrix.width(); 142 | xy = 0; 143 | messageChanged = false; 144 | Serial.println(message); 145 | } 146 | yield(); 147 | if (brightnessChanged) matrix.setBrightness(brightness); 148 | matrix.fillScreen(0); 149 | matrix.setCursor(x, 0); 150 | matrix.setTextColor(matrix.Color(r, g, b)); 151 | matrix.print(message); 152 | if (x < ((int)message.length()) * -6) { 153 | Serial.print(x); 154 | Serial.print(' '); 155 | Serial.println(((int)message.length()) * -6); 156 | x = matrix.width(); 157 | } 158 | matrix.show(); 159 | delay(50); 160 | } 161 | --------------------------------------------------------------------------------