Code I Write
I also contributed a bit of code to scripty2 — namely its UI library and its support for hardware‐accelerated animation.
I wrote Fluorescence, the code highlighting script that makes the code blocks on this blog look pretty. Before D3 existed, I wrote a thing called Krang for drawing SVG charts, but now that D3 exists you should really just use D3.
I started playing around with Ruby sometime in 2004 when Rails was a brand‐new thing. It’s still my preferred language for most scripting tasks.
For large projects, Rails is my go‐to web framework. For small projects, I use Sinatra and pull in ActiveRecord if I need to. For projects that don’t need a relational database, I use Redis enthusiastically.
I’ve written a few TextMate bundles, though most of them are for my own use to fit my weird brain.
I caught the Raspberry Pi bug a couple years ago. There are a half‐dozen or so around the house employed in various ways:
- A home automation server running Node‐RED and Homebridge.
- A combination print server and scanned‐document database using CUPS and Paperless.
- A camera pointed at our bird‐feeder so we can watch birds eat at our leisure.
- A bartop arcade cabinet running RetroPie and Daphne. There are roughly a hundred games installed. If you come to my house I will make you play Windjammers.
- An RPi is affixed to the back of my 3D printer. It runs OctoPrint and allows me to send prints to the machine without messing with SD cards.
- An RPi in my back yard is hooked up to an extension board and runs OpenSprinkler. This allows me to create and manage sprinkler schedules over a web interface, gives me an open API to use in fun and strange ways, and makes HomeKit integration possible through this Homebridge plugin.
Once you get over the initial learning curve, microcontrollers are great for single‐purpose tasks. I don’t know much about electrical hardware, but I can solder and follow directions.
I’ve got a couple Arduino Unos that I use for prototyping; when it’s time to finish, I flash my code onto an Arduino Nano knockoff — their size and low cost makes them easy to put just about anywhere.
The ESP8266 is a workhorse MCU from China that costs a few bucks and does Wi‐Fi. They are cheap enough that it’s feasible to buy them a dozen at a time — they’ll take a month to arrive, but when they do you’ll already have twelve projects in mind.
Thanks to work done by enthusiasts since late 2014, they can be programmed within the Arduino IDE, and most Arduino libraries will work as‐is on the ESP.
For only slightly more than the bare MCU, you can get an ESP with a built‐in voltage regulator and USB connector. My favorite is the Wemos D1 Mini, but NodeMCU hardware is far easier to find and nearly as good.
I’ve got a few microcontrollers around the house doing basic things:
- A Nano inside my bartop arcade cabinet is responsible for turning on the monitor and the marquee light when it senses that the Raspberry Pi has power. This lets me control all three with one switch.
- A Nano drives a pair of outlets on my desk. When I press a button on the box, the outlets turn on for ninety minutes. I made this after the tenth time I realized I had left my soldering iron plugged in all day.
- An ESP8266 lives on the wall in our laundry room. It connects to two accelerometers, one on our washer and one on our dryer, and monitors the acceleration values that they report. This lets it detect when one of the machines is vibrating. After some trial‐and‐error with force thresholds and waiting periods, the result is that we get a notification on our phones when a laundry cycle is done. (The ESP is only responsible for publishing the washer/dryer states to an MQTT topic; the RPi that runs Node‐RED reacts to that state to send notifications via Pushover.)
- If you’re a skinflint and willing to wait a few weeks for your order to arrive, you can do what I did and get a handful of Sonoff smart outlets for the same price as a single smart outlet from your local hardware store. These are driven by ESPs, which means that their firmware can be replaced. I use Tasmota. One of these switches powers the lamps above my girlfriend’s vanity.
- In fact, Tasmota is installed on a number of devices around my house. Some of them — mainly smart bulbs — are pre‐flashed with Tasmota, but others I’ve taken apart and flashed manually when I’ve had no alternative. For instance, I’ve managed to flash three different outdoor smart outlets that exist (or have existed) on this list (see the “Outdoor Plug” section); two of them control two strings of lights in my backyard. This allows them to be controllable through Node‐RED but still expose a HomeKit interface through Homebridge.