Sasa!
Recently, I’ve been busy moving stuff from one house to another, changing jobs and once again re-organizing my life. Plus, I decided to go freelance! New starts always get me thrilled, although the problem is my timing: I tend to do many things at once! One of the first things I setup was my maker’s corner, a magic place filled with 3D printers, a soldering station and all sorts of electronic utilities. Originally I was thinking about getting a couch, but I wouldn’t have been half as fun as curating a geek’s corner 😬.
As I was unboxing all the stuff I’d carefully packed, I stumbled across some old projects I had been making back then. Because I had no real use for them, they were left collecting dust in a dark corner. One of the projects had been a series of of hexagon-shaped frames glued together, with a bunch of WS2812b on each frame, controlled by a Wemos D1 mini.
The idea was to build something similar to some posh hexagonal lamps I’ve seen around. Of course my expectations were more functional than aesthetic (after all form follows function according to Louis Sullivan): I needed a light source for my workspace. Since the Wemos has WiFi capabilities, I even built a simple API to change color and intensity of the LEDs! Everything worked but after a while Alexa came into my life and, with her, a smart bulb. That was that, and the lamp was partially dismantled and put into a box.
Fast forward to today: I found the lamp and I started looking for ways to interface it with Alexa. Long story short, I wanted a nice glowing light for my bedroom. Well, the search was pretty quick! Without reinventing the wheel and by writing something to interface with Amazon’s baby, I found a project that led me on the right track. Many thanks to Davide Gatti of Survival Hacking! So, after a bit of research, I drifted away a bit from Davide’s project. Instead of emulating a Wemo Belkin, like he does, I preferred using a different library, called FauxmoESP. In this way I do not have to create an account of any sort, allowing me to add new devices in a more straight-forward way.
The functioning is pretty easy. Basically you connect to the WiFi, do a couple of magic tricks and by using the function addDevice(‘YourDeviceName’) you can execute any callback of your liking. This opens doors to even more complex projects and gadgets… but one step at a time.
For now, let’s build these glowing hexagons, conveniently named…
Gloxes!
This project is very easy to replicate. It only needs very basics skills, equipment and components:
- 1x Wemos D1 mini;
- WS2812b, quantum satis;
- Frames, of any shape and dimensions. Alternatively, you can download my .stl here;
- Jumper wires, quantum satis;
- (optional) 1x 330Ω resistor;
Gloxes schematics:
The schematics are pretty eloquent, but let me stress the warning on more time: if you are using more than 30 leds (or less, in full brightness which is the RGB color 255, 255, 255), you should use an external power supply for the strip, and NOT draw the power from the Wemos, as it might malfunction. Simply put, this little rascal can’t withstand such a power draw. Instead of using 2 usb power adapters, you could achieve that by creating a Y cable, with one micro usb termination, and another one ready to be connected to the 5V and the GND of the led strip. Or if you are lucky like me, and you have a dual usb power adapter laying in your lab, this is the right time to use it.
Once the connections are sorted, you can start fidgeting with the software. I left some comments in the code, so you can follow what I am doing. Although, to get started, you might want to customize the following lines:
#define WIFI_SSID "your ssid"
#define WIFI_PASS "your password"
Here you just need to put the name and password of your WiFi connection. Then you can define the constant of the control pin (or the pins, if you would like to use more than one strip) here:
#define RGBCTL D4 //control pin
Do not forget to specify the number of leds here:
int numPixels = 39;
On line 106, you can add all the devices you want, by passing the name to each an every call of the addDevice(“Device”) function. For example:
fauxmo.addDevice("Gloxes");
Create a device called Gloxes, which you should speak aloud when asking Alexa. In case of multiple devices or a more complex logic, just add as many if blocks as you need, triggering all your desired actions:
if ( (strcmp(device_name, "Gloxes") == 0) ) {
Serial.println("You said Gloxes");
if (state) {
i = 1;
brightness = value;
Serial.println("Brightness:");
Serial.println(brightness);
}
else {
allOff();
i = 0;
}
}
In this specific case (which might be the most common), my if will assign an integer to the variable called i. Later on in the loop(), this variable is evaluated in startShow, a wrapper for a switch/case block, which calls colorWipe() passing to it the proper color value:
void startShow(int i)
{
switch (i)
{
case 0: colorWipe(strip.Color(0, 0, 0), 50); // off
Serial.println("I'm off");
break;
case 1: colorWipe(strip.Color(250, 220, 50), 50); // on
Serial.println("I'm on");
break;
}
}
If you want to have a strip with some color changing capabilities, just define multiple devices with fauxmo.addDevice(“colorOneLamp”), fauxmo.addDevice(“colorTwoLamp”), fauxmo.addDevice(“colorThreeLamp”), etc. and add the correspondent if block, assigning values to i and defining new colors.
Before flashing the board, do not forget to import the extra library /deps into your IDE of choice!
Once everything is set, you might see some debugging messages in the serial monitor. As soon as the board is connected to your WiFi, you can manually add the device/devices via the Alexa app on your phone: open it, go to the Devices tab, tap on the plus symbol in the top right corner, choose Add Device, the scroll to the bottom till you see Other, let Alexa do its thing aaaaand BOOM 💣!
If all went right, you should be able to do what I’m doing here:
This is just the first version of the project, I intend to make some more changes in the near future. Also, don’t be shy and give me your feedback!
For today, that’s all! Happy building âš’