More ESP8266 Hacking - LOHAS LED
Yes, I have hacked another ESP8266-based device. This time it's the LOHAS WiFi Smart LED lightbulb.
These are really quite nice bulbs, and available on Amazon pretty cheaply. Internally there is your typical power supply, and a ring of LEDs. In the center is the main control circuit consisting of an ESP8266, 25Q80 1MB flash chip, and a pair of MY9231 3-channel LED drivers. The LEDs themselves are arranged as a channel of red, a channel of green, a channel of blue, and two channels of white. I have had one of these bulbs lighting my bedroom for some time now. While they're not super bright they're fine for that sort of environment - and I think they do brighter versions now as well.
Opening the bulbs is both easy and tricky. There are small clips holding the top cover on, but the plastic is so brittle you will break them. But the clips aren't really what holds it together - it's glued in with silicone. So it just sort of tears away. You'll want to glue it back together after you are finished. I used a couple of small blobs of superglue and it seems to have done the trick.
Those guys at LOHAS have even provided nice little test pads for us to connect wires to for programming - and they have even gone as far as to label them! Nice people! Except one: the pad labelled as 3V3 isn't. As far as I can tell it's not actually connected to anything. So you will have to connect your 3.3V power to somewhere else if you need it. I chose one end of the output capacitor from the power supply.
If you want to test the LEDs without plugging it in to the mains you'll want to provide about 12V to the power input. The simplest way is to connect a 12V power supply across the input capacitor to the power supply.
Be careful soldering the ground of the power input - it's right next to where the power enters the board from the outer ring. If you short the +12V with that you won't have much fun.
The hardest wire to solder has to be the reset pin. It's right in the middle of a bunch of components.
I took that picture before I realised the 3.3V pad didn't go anywhere, so the red wire is wrong. I wired the whole thing up to a 4x2 header in the same layout as the ESP-01, so that I could plug it into an ESP-01 programming dongle. That way I don't have to worry about resets and GPIO0 wangling - it does it for me.
As far as programming goes, that was much easier than I was expecting. I found a library that works perfectly with the MY9231 chips at https://github.com/xoseperez/my92xx and it only took me a few moments to get the LEDs lighting up with my own code. The GPIO pins 15 and 13 are used for the Clock and Data signals respectively.
#include <my92xx.h> #define CLOCK 15 #define DATA 13 my92xx leds(MY92XX_MODEL_MY9231, 2, DATA, CLOCK, MY92XX_COMMAND_DEFAULT);
The LEds to channel mapping is as follows:
When programming I would suggest, to make your life so much easier, the first thing you do is upload a simple sketch that enables OTA programming. Since there is only 1MB flash you can't have SPIFFS enabled at all. OTA programming on a device like this is so much easier than trying to use the bodge wires. It also means you can glue it back together and plug it in properly while experimenting with it. Of course, if you need SPIFFS, you could always upgrade the flash chip.
The IDE settings for this device are pretty straight forward:
- Flash size: 1MB (No SPIFFS)
- Flash Mode: DOUT
- Crystal: 26MHz
- Flash frequency: 40MHz
Setting an LED channel is as simple as:
leds.setChannel(1, 128); // Set green to 50% leds.update();
Don't forget to turn the system on first:
Now couple that with a smattering of MQTT and I have full control over my bedroom light from my favourite MQTT app MQTT Dash, as well as control through Google Assistant using IFTTT and a little PHP script to connect Webhooks to Mosquitto.
Finally I have complete control over my light colour. Each individual channel is now at my mercy. Plus some much nicer presets.