Skip to content

Instantly share code, notes, and snippets.

@probonopd
Last active December 11, 2017 18:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save probonopd/8a85e7643e01bd2b238c901cdb6d651a to your computer and use it in GitHub Desktop.
Save probonopd/8a85e7643e01bd2b238c901cdb6d651a to your computer and use it in GitHub Desktop.
Getting Melvanimate to fly :-)

Getting Melvanimate to fly :-)

What is Melvanimate?

Melvanimate is a library for ESP8266 that lets you control your Neopixels over WLAN easily. It supports everything imaginable besides toasting your toast, e.g.,:

  • Animate Neopixels (hence the name!) or set them to solid colors
  • Control LEDs via a web interface (for casually setting a certain color of effect)
  • Control LEDs via MQTT or DMX/E131 (for automation)
  • Adalight DIY ambient monitor lighting similar to Ambilight
  • PixelController
  • Timer to switch lights on/off or select a preset after a certain time
  • Super awesome easy configuration web interface and over-the-air updateability

(Insert cool photos/videos here!)

Hardware setup

  • 1 ESP8266 board, e.g., a NodeMCU 1.0 board (around USD 3 from China shipped) or, if it should fit a small enclosure, a bare ESP12E module (around USD 2 from China shipped; in this case need a matching programming jig too in order to flash it initially, and you need to use the usual minimal circuit to pull up CH_PD and pull down GPIO15 as well as a voltage regulator)
  • WS2812 strip or matrix

The NodeMCU 1.0 board has an integrated power regulator so I can hook up the light strip and the ESP directly to 5V and it works with 0 external components. The data line of the neopixels strip is connected to the RX of the NodeMCU 1.0 board.

Compiling and uploading the sketch

These are very concise instructions on how to build and run using Ubuntu 16.04 (other versions should also work).

First, install known working versions of the dependency libraries.

which git || sudo apt-get install -y git
# rm -rf $HOME/Arduino/ # Uncomment this only if you are sure what you are doing
mkdir -p $HOME/Arduino/libraries/
cd $HOME/Arduino/libraries/
git clone -o dc40877 https://github.com/adafruit/Adafruit-GFX-Library.git
git clone -o 6cfe2a5 https://github.com/bblanchon/ArduinoJson.git
git clone -o b4e453c https://github.com/sticilface/ESPmanager.git
git clone -o f1b4576 https://github.com/marvinroger/async-mqtt-client.git
git clone -o 2cc9846 https://github.com/me-no-dev/ESPAsyncTCP.git
git clone -o 5159d8b https://github.com/me-no-dev/ESPAsyncWebServer.git
git clone -o 94f5ad3 https://github.com/Makuna/NeoPixelBus.git
git clone -o 58138fe https://github.com/sticilface/Melvanimate.git
cd -

By the way, this list was made with

DIRS=$(find ~/Arduino/libraries -mindepth 1 -maxdepth 1 -type d )
echo "cd ~/Arduino/libraries"
for DIR in $DIRS ; do
  cd $DIR
  unset URL
  unset REV
  URL=$(git config --get remote.origin.url 2>/dev/null)
  REV=$(git log --pretty=format:'%h' -n 1 2>/dev/null)
  if [ ! -z $REV ] ; then echo git clone -o $REV $URL ; fi
  cd - >/dev/null
done
echo "cd -"

Download and run Arduino AppImage that contains the IDE, the esp8266 core, and the SPIFFS upload tool.

If you are not running Linux or do not want to use the AppImage, you have to download and install those parts manually.

AI="Arduino-1.6.11.esp2.3.0-x86_64.AppImage"
wget -c "https://bintray.com/probono/AppImages/download_file?file_path=$AI" -O "$AI"
chmod a+x "$AI"
./"$AI" &

Now that we have everything in place, configure, compile, and upload.

  • File -> Examples -> Melvaimate-withESPManager
  • Tools -> Board -> Your board type
  • Tools -> CPU Frequency -> 160 MHz
  • Tools -> Upload Speed -> 921600
  • Tools -> Port -> Your port (can also use OTA)
  • Sketch -> Upload
  • Tools -> ESP8266 Sketch Data Upload (otherwise we see only white HTML pages)

Configuriation

Melvanimate has a super cool web interface that can do real magic, including over-the-air updates.

GUI and upgrade mechanism

  • You should see a new WLAN access point. Connect to it
  • Open the IP of this access point (you need to find it out somehow)
  • In the GUI, connect to your WLAN using your credentials. Save and reboot
  • From thereon, you should be able to use the GUI from within your network

Multiply the fun

If you have multiple installations of Melvanimate in the same network, they will automatically discover each other and talk to each other. From the web interface, you can select the different devices in the upper right-hand corner.

Hacking

Let's say I want my LEDs to come up as blue, whenever I attach them to a power plug, whether there is WLAN or not. To do this, we create a preset in the GUI called "Default" and change the following section like so:

  SPIFFS.begin();
  lights.Load("Default"); // Add this line
  manager.begin();

//  Add effects to the manager.
  lights.Add("Off",          new SwitchEffect( offFn)); // Remove "true" here
  lights.Add("SimpleColor",  new SimpleEffect(SimpleColorFn), true); // Add "true" here

Done! Now, whenever I power on, the lights go blue.

Feature ideas

Who is going to implement them?

  • A GUI setting so that a given preset is automatically loaded when the device is powered on
  • Scenarios, e.g., set LED strip on ESP #1 to blue and LED strip on ESP #2 to orange
  • A setting to limit the milliamps
  • Kelvin based on daytime and location (see code below)
  • Bus is coming
  • Weather info
  • Hue mode (e.g., using code from ESP8266HueEmulator)
  • Use dithering so that you can't see the individual steps e.g., in RainbowChase
  • Investigate MIDI or OSC for professional stage lighting control (e.g., using https://github.com/OSSIA/i-score which can do things like https://vimeo.com/113089469, or http://www.duration.cc/)
// https://github.com/kayno/arduinolifx
#include <math.h>
struct rgb {
double r; // percent
double g; // percent
double b; // percent
};
rgb kelvinToRGB(long kelvin) {
rgb kelvin_rgb;
long temperature = kelvin / 100;
if(temperature <= 66) {
kelvin_rgb.r = 255;
}
else {
kelvin_rgb.r = temperature - 60;
kelvin_rgb.r = 329.698727446 * pow(kelvin_rgb.r, -0.1332047592);
if(kelvin_rgb.r < 0) kelvin_rgb.r = 0;
if(kelvin_rgb.r > 255) kelvin_rgb.r = 255;
}
if(temperature <= 66) {
kelvin_rgb.g = temperature;
kelvin_rgb.g = 99.4708025861 * log(kelvin_rgb.g) - 161.1195681661;
if(kelvin_rgb.g < 0) kelvin_rgb.g = 0;
if(kelvin_rgb.g > 255) kelvin_rgb.g = 255;
}
else {
kelvin_rgb.g = temperature - 60;
kelvin_rgb.g = 288.1221695283 * pow(kelvin_rgb.g, -0.0755148492);
if(kelvin_rgb.g < 0) kelvin_rgb.g = 0;
if(kelvin_rgb.g > 255) kelvin_rgb.g = 255;
}
if(temperature >= 66) {
kelvin_rgb.b = 255;
}
else {
if(temperature <= 19) {
kelvin_rgb.b = 0;
}
else {
kelvin_rgb.b = temperature - 10;
kelvin_rgb.b = 138.5177312231 * log(kelvin_rgb.b) - 305.0447927307;
if(kelvin_rgb.b < 0) kelvin_rgb.b = 0;
if(kelvin_rgb.b > 255) kelvin_rgb.b = 255;
}
}
return kelvin_rgb;
}
Additional notes
===
Erase chip completely (might not be necessary but I wanted to be extra cautious)
#include <FS.h>
#include <ESP8266WiFi.h>
void setup() {
Serial.begin(115200);
Serial.println("ERASING: ");
ESP.eraseConfig();
SPIFFS.format();
Serial.print("done");
}
void loop() {
}
Upload and wait for "done"
===
Install SPIFFS uploader tool manually
mkdir $HOME/Arduino/tools
cd $HOME/Arduino/tools
wget -c "https://github.com/esp8266/arduino-esp8266fs-plugin/releases/download/0.2.0/ESP8266FS-0.2.0.zip"
unzip ESP8266FS-0.2.0.zip
rm ESP*.zip
cd -
===
For documenting the precise versions used, see
https://github.com/sticilface/Melvanimate/issues/20#issuecomment-241207754
===
For verbosity, uncomment
#define Debug_ESPManager
in espmanager.h
to get debug output you also need to select the debug port in the arudino IDE
Just use generic module, and set reset method to nodemcu, make sure CPU speed is 160, SPIFFS is 4m
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment