14 Commits

Author SHA1 Message Date
432fbb95d9 Updated README, fixed Arduino ESP8266FS tool link. 2017-12-12 13:36:45 -06:00
350feed191 Update README.md 2017-10-14 12:47:30 -05:00
410186e6a5 Update README.md 2017-06-22 15:33:28 -05:00
c17cea3426 Improved instructions. 2017-05-06 11:30:15 -05:00
407fd536c2 Fixed #25 (brightness not restored on startup) 2017-05-05 19:09:37 -05:00
020b0b0e43 Fixed autoplay compile error. 2017-02-23 19:22:51 -06:00
681c29a877 Added palette selector
* Added palette selector and supporting code.
* Switched several patterns to use the selected palette: Confetti,
Sinelon, BPM, Juggle
* Limit EEPROM writes in autoplay mode.
2017-02-18 13:24:05 -06:00
9bc7b7a5e7 Merge pull request #20 from seanspotatobusiness/master
Libraries part of readme
2017-02-18 11:40:20 -06:00
e28346a6ee Update README.md 2017-01-27 22:18:50 +00:00
95e5f27caf Update README.md 2017-01-27 22:13:38 +00:00
608a7827d2 Update README.md 2017-01-27 22:11:49 +00:00
f49ca2d1f9 Merge pull request #12 from seanspotatobusiness/master
Update to README?
2017-01-12 15:19:06 -06:00
1e9b486cfd Update README.md
Added Step to download files from GitHub (not obvious what to download or where if you're new to this)
2017-01-12 18:57:23 +00:00
f5702fe80f Update README.md
Added Arduino IDE preparations to Installing section.
2017-01-12 16:19:20 +00:00
4 changed files with 192 additions and 36 deletions

View File

@ -6,14 +6,38 @@ Control an addressable LED strip with an ESP8266 via a web browser or infrared r
Hardware
--------
An ESP8266 development board, such as the [Adafruit HUZZAH ESP8266 Breakout]:
##### ESP8266 development board
[![Wemos D1 Mini Pro & Headers](https://ae01.alicdn.com/kf/HTB1P1KVaMsSMeJjSsphq6xuJFXah/WEMOS-D1-mini-Pro-V1-1-0-16M-bytes-external-antenna-connector-ESP8266-WIFI-Internet-of.jpg_200x200.jpg)](https://www.aliexpress.com/item/WEMOS-D1-mini-Pro-16M-bytes-external-antenna-connector-ESP8266-WIFI-Internet-of-Things-development-board/32724692514.html)
[Wemos D1 Mini Pro & Headers](https://www.aliexpress.com/item/WEMOS-D1-mini-Pro-16M-bytes-external-antenna-connector-ESP8266-WIFI-Internet-of-Things-development-board/32724692514.html)
or
[![Adafruit HUZZAH ESP8266 Breakout](https://cdn-shop.adafruit.com/310x233/2471-10.jpg)](https://www.adafruit.com/products/2471)
Addressable LED strip, such as the [Adafruit NeoPixel Ring]:
[Adafruit HUZZAH ESP8266 Breakout](https://www.adafruit.com/products/2471)
##### Addressable LED strip
[![Adafruit NeoPixel Ring](https://www.adafruit.com/images/145x109/1586-00.jpg)](https://www.adafruit.com/product/1586)
[Adafruit NeoPixel Ring]
Other hardware:
* [3.3V to 5V Logic Level Shifter](http://www.digikey.com/product-detail/en/texas-instruments/SN74HCT245N/296-1612-5-ND/277258) (required if LEDs "glitch")
Recommended by [Adafruit NeoPixel "Best Practices"](https://learn.adafruit.com/adafruit-neopixel-uberguide/best-practices) to help protect LEDs from current onrush:
* [1000µF Capacitor](http://www.digikey.com/product-detail/en/panasonic-electronic-components/ECA-1EM102/P5156-ND/245015)
* [300 to 500 Ohm resistor](https://www.digikey.com/product-detail/en/stackpole-electronics-inc/CF14JT470R/CF14JT470RCT-ND/1830342)
Optional shield to make everything more tidy:
[![Wemos D1 Mini ESP8266 LED & Level Shifter Shield](https://d3s5r33r268y59.cloudfront.net/13194/products/thumbs/2017-05-06T15:02:37.208Z-IMG_20170506_100623.jpg.114x76_q85_pad_rcrop.jpg)](https://www.tindie.com/products/jasoncoon/wemos-d1-mini-esp8266-led-and-level-shifter-shield/)
[Wemos D1 Mini ESP8266 LED & Level Shifter Shield](https://www.tindie.com/products/jasoncoon/wemos-d1-mini-esp8266-led-and-level-shifter-shield)
Features
--------
* Turn the NeoPixel Ring on and off
@ -30,17 +54,27 @@ Patterns are requested by the app from the ESP8266, so as new patterns are added
The web app is stored in SPIFFS (on-board flash memory).
The web app is a single page app with separate files for js and css, using [jQuery](https://jquery.com) and [Bootstrap](http://getbootstrap.com). It has buttons for On/Off, a slider for brightness, a pattern selector, and a color picker (using [jQuery MiniColors](http://labs.abeautifulsite.net/jquery-minicolors)). Event handlers for the controls are wired up, so you don't have to click a 'Send' button after making changes. The brightness slider and the color picker use a delayed event handler, to prevent from flooding the ESP8266 web server with too many requests too quickly.
The only drawback to SPIFFS that I've found so far is uploading the files is extremely slow, requiring several minutes, regardless of how large the files are. It's so slow that I've been just developing the web app and debugging locally on my desktop (with a hard-coded IP for the ESP8266), before uploading to SPIFFS and testing on the ESP8266.
The web app is a single page app that uses [jQuery](https://jquery.com) and [Bootstrap](http://getbootstrap.com). It has buttons for On/Off, a slider for brightness, a pattern selector, and a color picker (using [jQuery MiniColors](http://labs.abeautifulsite.net/jquery-minicolors)). Event handlers for the controls are wired up, so you don't have to click a 'Send' button after making changes. The brightness slider and the color picker use a delayed event handler, to prevent from flooding the ESP8266 web server with too many requests too quickly.
The only drawback to SPIFFS that I've found so far is uploading the files can be extremely slow, requiring several minutes, sometimes regardless of how large the files are. It can be so slow that I've been just developing the web app and debugging locally on my desktop (with a hard-coded IP for the ESP8266), before uploading to SPIFFS and testing on the ESP8266.
Installing
-----------
The app is installed via the Arduino IDE which can be [downloaded here](https://www.arduino.cc/en/main/software). The ESP8266 boards will need to be added to the Arduino IDE which is achieved as follows. Click File > Preferences and copy and paste the URL "http://arduino.esp8266.com/stable/package_esp8266com_index.json" into the Additional Boards Manager URLs field. Click OK. Click Tools > Boards: ... > Boards Manager. Find and click on ESP8266 (using the Search function may expedite this). Click on Install. After installation, click on Close and then select your ESP8266 board from the Tools > Board: ... menu.
The web app needs to be uploaded to the ESP8266's SPIFFS. You can do this within the Arduino IDE after installing the [Arduino ESP8266FS tool](https://github.com/esp8266/Arduino/blob/master/doc/filesystem.md#uploading-files-to-file-system).
The app depends on the following libraries. They must either be downloaded from GitHub and placed in the Arduino 'libraries' folder, or installed as [described here](https://www.arduino.cc/en/Guide/Libraries) by using the Arduino library manager.
With ESP8266FS installed run the sketch and then upload the web app using `ESP8266 Sketch Data Upload` command in the Arduino Tools menu.
* [FastLED](https://github.com/FastLED/FastLED)
* [IRremoteESP8266](https://github.com/sebastienwarin/IRremoteESP8266)
* [Arduino WebSockets](https://github.com/Links2004/arduinoWebSockets)
Download the app code from GitHub using the green Clone or Download button from [the GitHub project main page](https://github.com/jasoncoon/esp8266-fastled-webserver) and click Download ZIP. Decompress the ZIP file in your Arduino sketch folder.
The web app needs to be uploaded to the ESP8266's SPIFFS. You can do this within the Arduino IDE after installing the [Arduino ESP8266FS tool](http://esp8266.github.io/Arduino/versions/2.3.0/doc/filesystem.html#uploading-files-to-file-system).
With ESP8266FS installed upload the web app using `ESP8266 Sketch Data Upload` command in the Arduino Tools menu.
Then enter your wi-fi network SSID and password in the .ino file, and upload the sketch using the Upload button.
Compression
-----------
@ -61,7 +95,7 @@ The firmware implements basic [RESTful web services](https://en.wikipedia.org/wi
Infrared Remote Control
-----------------------
Control via infrared remote control is also supported, via the [ESP8266 port of the IRremote library](https://github.com/markszabo/IRremoteESP8266).
Control via infrared remote control is also supported, via the [ESP8266 port of the IRremote library](https://github.com/sebastienwarin/IRremoteESP8266).
[Adafruit NeoPixel Ring]:https://www.adafruit.com/product/1586
[Adafruit HUZZAH ESP8266 Breakout]:https://www.adafruit.com/products/2471

View File

@ -52,9 +52,13 @@
<label for="inputPattern" class="col-sm-2 control-label">Pattern</label>
<div class="col-sm-6">
<select class="form-control" id="inputPattern">
<option>Rainbow</option>
<option>Sinelon</option>
<option>Juggle</option>
</select>
</div>
</div>
<div class="form-group">
<label for="inputPalette" class="col-sm-2 control-label">Palette</label>
<div class="col-sm-6">
<select class="form-control" id="inputPalette">
</select>
</div>
</div>

View File

@ -70,6 +70,10 @@ $("#inputPattern").change(function() {
setPattern($("#inputPattern option:selected").index());
});
$("#inputPalette").change(function() {
setPalette($("#inputPalette option:selected").index());
});
$("#inputColor").change(function() {
if(ignoreColorChange) return;
@ -105,15 +109,30 @@ function getAll() {
updatePowerButtons(data.power);
// clear pattern list
$("#inputPattern").find("option").remove();
// load pattern list
for(var i = 0; i < data.patterns.length; i++) {
var pattern = data.patterns[i];
$("#inputPattern").append("<option value='" + i + "'>" + pattern + "</option>");
}
// select the current pattern
$("#inputPattern").val(data.currentPattern.index);
// clear palette list
$("#inputPalette").find("option").remove();
// load palette list
for(var i = 0; i < data.palettes.length; i++) {
var palette = data.palettes[i];
$("#inputPalette").append("<option value='" + i + "'>" + palette + "</option>");
}
// select the current palette
$("#inputPalette").val(data.currentPalette.index);
$("#status").html("Ready");
});
}
@ -154,6 +173,12 @@ function setPattern(value) {
});
}
function setPalette(value) {
$.post(urlBase + "palette?value=" + value, function(data) {
$("#status").html("Set Palette: " + data.name);
});
}
function delaySetColor(value) {
clearTimeout(colorTimer);
colorTimer = setTimeout(function() {

View File

@ -1,20 +1,20 @@
/*
* ESP8266 + FastLED + IR Remote + MSGEQ7: https://github.com/jasoncoon/esp8266-fastled-webserver
* Copyright (C) 2015 Jason Coon
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
ESP8266 + FastLED + IR Remote + MSGEQ7: https://github.com/jasoncoon/esp8266-fastled-webserver
Copyright (C) 2015 Jason Coon
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "FastLED.h"
FASTLED_USING_NAMESPACE
@ -46,7 +46,7 @@ const char* password = "";
ESP8266WebServer server(80);
#define DATA_PIN 13 // for Huzzah: Pins w/o special function: #4, #5, #12, #13, #14; // #16 does not work :(
#define DATA_PIN D8 // for Huzzah: Pins w/o special function: #4, #5, #12, #13, #14; // #16 does not work :(
#define LED_TYPE WS2812
#define COLOR_ORDER GRB
#define NUM_LEDS 24
@ -89,6 +89,8 @@ bool autoplayEnabled = false;
uint8_t autoPlayDurationSeconds = 10;
unsigned int autoPlayTimeout = 0;
uint8_t currentPaletteIndex = 0;
uint8_t gHue = 0; // rotating "base color" used by many of the patterns
CRGB solidColor = CRGB::Blue;
@ -111,6 +113,8 @@ void setup(void) {
EEPROM.begin(512);
loadSettings();
FastLED.setBrightness(brightness);
irReceiver.enableIRIn(); // Start the receiver
Serial.println();
@ -245,6 +249,16 @@ void setup(void) {
sendBrightness();
});
server.on("/palette", HTTP_GET, []() {
sendPalette();
});
server.on("/palette", HTTP_POST, []() {
String value = server.arg("value");
setPalette(value.toInt());
sendPalette();
});
server.serveStatic("/index.htm", SPIFFS, "/index.htm");
server.serveStatic("/fonts", SPIFFS, "/fonts", "max-age=86400");
server.serveStatic("/js", SPIFFS, "/js");
@ -260,7 +274,6 @@ void setup(void) {
}
typedef void (*Pattern)();
typedef Pattern PatternList[];
typedef struct {
Pattern pattern;
String name;
@ -283,6 +296,36 @@ PatternAndNameList patterns = {
const uint8_t patternCount = ARRAY_SIZE(patterns);
typedef struct {
CRGBPalette16 palette;
String name;
} PaletteAndName;
typedef PaletteAndName PaletteAndNameList[];
const CRGBPalette16 palettes[] = {
RainbowColors_p,
RainbowStripeColors_p,
CloudColors_p,
LavaColors_p,
OceanColors_p,
ForestColors_p,
PartyColors_p,
HeatColors_p
};
const uint8_t paletteCount = ARRAY_SIZE(palettes);
const String paletteNames[paletteCount] = {
"Rainbow",
"Rainbow Stripe",
"Cloud",
"Lava",
"Ocean",
"Forest",
"Party",
"Heat",
};
void loop(void) {
// Add entropy to random number generator; we use a lot of it.
random16_add_entropy(random(65535));
@ -559,6 +602,12 @@ void loadSettings()
{
solidColor = CRGB(r, g, b);
}
currentPaletteIndex = EEPROM.read(5);
if (currentPaletteIndex < 0)
currentPaletteIndex = 0;
else if (currentPaletteIndex >= paletteCount)
currentPaletteIndex = paletteCount - 1;
}
void sendAll()
@ -572,6 +621,10 @@ void sendAll()
json += "\"index\":" + String(currentPatternIndex);
json += ",\"name\":\"" + patterns[currentPatternIndex].name + "\"}";
json += ",\"currentPalette\":{";
json += "\"index\":" + String(currentPaletteIndex);
json += ",\"name\":\"" + paletteNames[currentPaletteIndex] + "\"}";
json += ",\"solidColor\":{";
json += "\"r\":" + String(solidColor.r);
json += ",\"g\":" + String(solidColor.g);
@ -587,6 +640,15 @@ void sendAll()
}
json += "]";
json += ",\"palettes\":[";
for (uint8_t i = 0; i < paletteCount; i++)
{
json += "\"" + paletteNames[i] + "\"";
if (i < paletteCount - 1)
json += ",";
}
json += "]";
json += "}";
server.send(200, "text/json", json);
@ -610,6 +672,16 @@ void sendPattern()
json = String();
}
void sendPalette()
{
String json = "{";
json += "\"index\":" + String(currentPaletteIndex);
json += ",\"name\":\"" + paletteNames[currentPaletteIndex] + "\"";
json += "}";
server.send(200, "text/json", json);
json = String();
}
void sendBrightness()
{
String json = String(brightness);
@ -663,8 +735,10 @@ void adjustPattern(bool up)
if (currentPatternIndex >= patternCount)
currentPatternIndex = 0;
if (autoplayEnabled) {
EEPROM.write(1, currentPatternIndex);
EEPROM.commit();
}
}
void setPattern(int value)
@ -677,8 +751,24 @@ void setPattern(int value)
currentPatternIndex = value;
if (autoplayEnabled == 0) {
EEPROM.write(1, currentPatternIndex);
EEPROM.commit();
}
}
void setPalette(int value)
{
// don't wrap around at the ends
if (value < 0)
value = 0;
else if (value >= paletteCount)
value = paletteCount - 1;
currentPaletteIndex = value;
EEPROM.write(5, currentPaletteIndex);
EEPROM.commit();
}
// adjust the brightness, and wrap around at the ends
@ -748,7 +838,8 @@ void confetti()
// random colored speckles that blink in and fade smoothly
fadeToBlackBy( leds, NUM_LEDS, 10);
int pos = random16(NUM_LEDS);
leds[pos] += CHSV( gHue + random8(64), 200, 255);
// leds[pos] += CHSV( gHue + random8(64), 200, 255);
leds[pos] += ColorFromPalette(palettes[currentPaletteIndex], gHue + random8(64));
}
void sinelon()
@ -756,14 +847,15 @@ void sinelon()
// a colored dot sweeping back and forth, with fading trails
fadeToBlackBy( leds, NUM_LEDS, 20);
int pos = beatsin16(13, 0, NUM_LEDS - 1);
leds[pos] += CHSV( gHue, 255, 192);
// leds[pos] += CHSV( gHue, 255, 192);
leds[pos] += ColorFromPalette(palettes[currentPaletteIndex], gHue, 192);
}
void bpm()
{
// colored stripes pulsing at a defined Beats-Per-Minute (BPM)
uint8_t BeatsPerMinute = 62;
CRGBPalette16 palette = PartyColors_p;
CRGBPalette16 palette = palettes[currentPaletteIndex];
uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
for ( int i = 0; i < NUM_LEDS; i++) { //9948
leds[i] = ColorFromPalette(palette, gHue + (i * 2), beat - gHue + (i * 10));
@ -777,7 +869,8 @@ void juggle()
byte dothue = 0;
for ( int i = 0; i < 8; i++)
{
leds[beatsin16(i + 7, 0, NUM_LEDS)] |= CHSV(dothue, 200, 255);
// leds[beatsin16(i + 7, 0, NUM_LEDS)] |= CHSV(dothue, 200, 255);
leds[beatsin16(i + 7, 0, NUM_LEDS)] |= ColorFromPalette(palettes[currentPaletteIndex], dothue);
dothue += 32;
}
}