As I mentioned last week, I got an Amazon Echo for Christmas. The first time I heard about it I thought “Meh, I already have a phone that does that”. Then I heard people raving about it on Podcasts and thought “hmm..” Then I heard the thing that really got me excited: The Echo has a developer kit you can work with.
Project update: I’ve put the code for this project up on Github for anyone interested.
So after having played with my Echo for a day, I started to wonder what kinds of things I could do with it. I pointed out previously that you could accomplish a lot with an Echo simply by utilizing IFTTT. There’s a lot of flexibility there, but if you really want to do something unique and cool, you have the opportunity to write it yourself.
Originally, I wanted to control the Christmas lights still up on the house. A few years ago I was at home depot and bought a set of wireless remote outlets. They plug into the wall outlet and you press a button on a remote and it switches the load on. They run relatively cheap and I figured at some point I would hack the remote to control it with a computer. I found that a lot of people have done that sort of thing, and actually a number of people have written code to control these outlets simply using a 315Mhz or 433Mhz radio with an Arduino. Due to Amazon’s busy holiday schedule, the very soonest I was going to get one of these radios was early January, and I was impatient.
I had purchased a strand of WS2811 LEDs a few weeks back for Christmas, but never got to doing anything with them. I thought: “These will work!” And dived in.
My first goal was to actually just get my Echo to send and receive messages from a web service. The Alexa Skills Kit is Amazon’s mechanism for extending the Echo. Basically, you setup a “skill” where you define a bunch of potential phrases someone can use and the data to send with them. Then you setup a web site that’ll receive the information, do something with it, and send a response back to the Echo.
It took me a few hours and a couple of websites worth of help to figure out how to put it together. I leaned on this site mostly for direction. The Alexa Skills Kit documentation is excellent and the Echo team clearly made an awesome tool. I was amazed at how easy it was to work with.
The only real hangup I had was with the SSL cert. I just recently posted about how awesome LetsEncrypt is, and how finally we can all have secure communications. It’s possible I’ve got it configured wrong, but I wasn’t able to get my cert to work with Amazon. The ASK requires SSL (and that’s a good thing) but it was a pain in the neck for me. I finally just gave them the certificate as though it were self signed. That got me far enough for a demo.
Once I got Echo responding to commands I started working on getting the LEDs to do what I wanted. There was a small hitch – the WS2811 chip is pretty demanding in terms of clocking. It uses a single wire so clocking is part of the data stream. As a result, it’s difficult to do this in a higher level language, and I was writing my web service in NodeJS.
Per usual, the Internet had some suggestions:
- A NodeJS binding written in C to control it from a Raspberry Pi (and only a Raspberry Pi)
- Use an intermediary – like an Arduino.
I went with the latter, mostly because I wanted to build it first on my laptop and I couldn’t do that with option #1. Additionally, I can easily transition an Arduino program to a program that runs on an ESP8266 – a microcontroller with wifi On-board. That means a central computer.
For an older project, I bought an
Arduino Pro Micro. Arduino doesn’t make a “Pro Micro”. It’s actually a Sparkfun product based on a nicer chip. The one I bought was a Chinese knockoff of said Sparkfun product It mostly does the same stuff as an Arduino Leonardo. I didn’t use it for that project and had it laying around, so I figured it’d be a good fit here.
For this portion of the project, I borrowed the code listed on this website. It was a simple construction for the LED data needing to go in. I decided to not to initially support individual colors on the LEDs initially, because I just wanted to prove out changing the color via the Echo.
I had to make a few modifications to the code on the Arduino and work the NodeJS side into my server and the Alexa service. I ran a couple of tests and then gave a demo to Hykel. I’m very happy with how it turned out, and I’m looking forward to doing more with the Echo. Here’s a video to see the demo: