Recently, I've had the pleasure of completing a small project with Nerves, an Elixir platform for developing embedded software.
I'd been looking for a fun project to get my feet wet with Nerves. I found the open-source SumoBot, and it felt like a good fit - and what's more fun than building a robot?
Getting the parts
For the electronics, The main components were:
- Raspberry Pi Zero W
- 2 Continous Rotation Servos
- 5V step-up-down voltage regulator
- 4 AA Battery Holder
Note that the original kit was created for an Arduino, but since I'm using Nerves, the Zero seemed like a good choice (cheap, with built-in wifi). In retrospect, I wish I modified the SumoBot design to better place holes to mount the Pi.
Putting it together
Putting the case together was straightforward, especially with the helpful video guide.
Since AA batteries can range in voltage from 1-1.5V, I needed the regulator to ensure the Pi receives the proper 5V input to avoid damaging it. Here's the circuit I wired up:
After testing the circuit in a breadboard, I attempted to solder it together. It took a lot of failed attempts before I got the hang of soldering, and I learned that hardware mistakes are a bit harder to fix than software ones. Lots of practice, and AdaFruit's perma-proto board ended up being helpful.
Controlling the hardware
GPIO pulses are required to drive the servos properly. These pulses have to be precise widths, and there wasn't built-in support for it with existing Nerves GPIO libraries like Elixir ALE.
Writing the wrapper was a simple port from Python, and was very illustrative of the power of Elixir. Locking code was eliminated by using processes, and binary pattern matching made sending and receiving messages simple.
The hardest part of this project was figuring out the hardware, in particular the power supply. Nerves was a joy to work with - setting up the base system was straightforward, and pushing firmware updates over ssh made iterating as quick as I could imagine it being (for working with hardware).
The Nerves ecosystem seems to still be evolving rapidly -even in the short time I worked on this project, core aspects of Nerves were changing out from under me. Luckily, the core team is super helpful in the #nerves channel on Slack.
If you're curious to explore hardware, I wholeheartedly recommend diving in!
Special thanks to Frank Hunleth for his ElixirBot repository, which was very helpful in this project