Fun with microcontrollers

Today it’s something about actual hardware, not just software. For Christmas I took a long LED-strip and hooked it up to an Arduino One to create some animations. But not having WiFi was a bit of a shame, because this meant you couldn’t control it from a smartphone. So I dug around and found this: Atom Lite ESP32 which is a nice little controller including WiFi, USB-C, a 4-pin cable with +5V, GND, and two data pins, as well as 6 other pin-IOs. It’s based on the ESP32 controller and you can program it from the Arduino IDE. It also has bluetooth and Infrared, but I didn’t try this out.

It took me some time to get all the libraries correctly loaded, and then finding the good examples. Of course I spent 1h with nothing working, only to discover that

  • If you connect to Data Out of the LED-strip to send your commands through, it fails – use Data In
  • One of the cables was badly soldered and didn’t make contact

But after that the libraries allow you to create a nice REST interface using callbacks, in C, nonetheless.

// Setting up WiFi
  WiFi.begin(ssid, password);
// Handling requests
  server.on("/", handleRoot);
  server.on(UriBraces("/led/{}"), handleLed);

This is all for the setup. The handleRoot is sending out just a static website, while the handleLED takes part of the path as an argument:

void handleLed() {
  String led = server.pathArg(0);

So really easy. Just for the demonstration I made a small animations of the 8 leds in the stripe, and using the web-interface you can add a green or a red led to it:

Now for next Christmas I can take the rest of the 5m stripe and add a WiFi interface…

— Linus