Stranger Things have happened
Now that I've really got to grips with the ESP8266 I can start to use it in various projects. This one has been on the cards for a very long time and there are already lots of projects doing something similar here's my effort. For anyone still not sure what it is, Stranger Things (season 1) is a tv series about a missing boy, who at one point, communicates with his mum through the medium of fairy lights. This is just a fun way to spell out messages for people but it's wifi controlled so any old phone can set up the messages to display.
These displays are now available in my store as kits or working items, should you want to build one for yourself or read on for further details.
The project is based around some 12mm WS2811 RGB led's. The 12mm lights have a lot of diffusion are easy to mount in holes and don't have to be spaced evenly apart making them ideal for quick installation in a back board like this. The board is 3mm birch ply with a mixture of engraving and line artwork to still give the appearance of fairy lights. (svg here)
The controller is the Wemos D1, I have run a capacitor between the 3V3 and Gnd to filter out any power supply noise to the ESP8266 (much more important when driving motors). The LEDs connect directly to pin D1 on the device and are driven using the FastLed library. The whole thing is powered from the USB connection, if you intend to crank the LED's up to full brightness you probably want to consider an appropriate external PSU that can handle the required current ~1.5A. In this demo the lights are set to <1% brightness and they're still perfectly visible.
The HTML input for this project is so simple I decided not to serve a whole web page from SPIFFS. It's actually just a few lines that can easily be served from a string. Below you can see that it's just a text box and a submit button. The text box is restricted to 49 characters so as not to overload the input buffer on the ESP but this limitation could be easily removed by keeping the data as a string.
The ESP code is also fairly straight forward, the device is configured to start it's own wifi network with a given SSID and password. It then sets up a webserver to supply the browser with the input page. Finally it responds to an incoming message by saving the data and replying back to the browser with the new message
Most of the interesting things happen in the main loop, firstly we use the fastled library function "EVERY_N_MILLISECONDS" to process our code once every 350 milliseconds, this is a non blocking function and leaves the controller free to deal with the webserver and dns for the rest of the time. Every 350 milliseconds we rebuild a string of colours to display to the lights. Firstly we decide if this is an even or an odd loop, the coloured lights should be on all the time but the displayed letter should flash on and off. I've used a simple list of 4 different colours, LED 1, 5, 9 etc will always be red and because the middle row of lights is reversed the pattern isn't blindingly obvious. Every other loop we simple increase the brightness of the letter we're trying to display. This leads to the first problem though, because the middle row of LED's is reversed it's not as simple as saying A=1, B=2.
The solution is to map letters to LED's, the code currently has 2 sets of mapping functions in 2 different methods. The first is to map the letters A,B,C to the numbers 1,2,3. In the ASCII standard A=65 so it's a simple subtraction but it allows us to map the lower case characters to the same place since a=97. After this first mapping process we end up with the numbers in a standard we're used to. The second is to map those numbers to specific LED's, we could do it with simple subtraction again (because it's only one row that is reversed) but this time I opted to create an array of 27 characters and assign each letter individually. This offers greater flexibility with wiring, with this method I could go up and down with the lights or any random order I chose.
Full Source code here
Improvements could definitely be made in the colouring of the lights, the main loop itself doesn't need to know what colour each pixel is so the colours could all be chosen in the setup function and each loop through the main code simply increasing the brightness of a pixel or decreasing it to turn them 'on/off'.