I was looking for a fun project to work on over the xmas break. I thought about building a new robot with my 5yo but the parts got delayed and aren’t going to show up till the following week when I’m back at work. So I managed to scrounge some parts together and put together a new project.
With a couple of servos, a raspberry pi and a Alexa I got for xmas I thought it would be fun to make a laser toy for the cat and dog that could be turned on by a voice command. This also makes it easy for the kids to interact with it via the Amazon Echo.
I started wiring the servos together and trying to get them to move from the Raspberry Pi. I found that ServoBlaster allowed multiple servos to be controlled by the GPIO pins on the Pi. To install it on the Pi you just use git to checkout the repo from GitHub and execute the servod program.
It should output something like this below:
Board model: 1 GPIO configuration: P1 (26 pins), P5 (8 pins) Using hardware: PWM Using DMA channel: 14 Idle timeout: Disabled Number of servos: 8 Servo cycle time: 20000us Pulse increment step size: 10us Minimum width value: 50 (500us) Maximum width value: 250 (2500us) Output levels: Normal
The really important part is the servo mapping which shows which GPIO pin is mapped to which servo.
Servo mapping: 0 on P1-7 GPIO-4 1 on P1-11 GPIO-17 2 on P1-12 GPIO-18 3 on P1-13 GPIO-27 4 on P1-15 GPIO-22 5 on P1-16 GPIO-23 6 on P1-18 GPIO-24 7 on P1-22 GPIO-25
The Pin number is important, you should wire up one servo to GPIO-4 and another to a different like GPIO-17. When you go to execute the commands to turn the servo you can do it by using echo like this.
$ echo 0=50% > /dev/servoblaster $ echo 1=50% > /dev/servoblaster
The next step is wiring up the battery pack and the motors into the breadboard. I usually just use bread boards for my projects when prototyping. Once you get everything working, you can solder it up to a board.
If you have never controlled a servo with a Raspberry Pi then try this tutorial first. I actually have the same parts as the guide except my other servo is much smaller.
Here is a wiring schematic that shows what wires go where. It’s very similar and even if you didn’t have two servos you could probably just use 1 servo to move in one direction.
I built a crude stand out of some metal parts I got in the hobby bin at Lowes. You can use whatever you want.
The last part is I built a Node API server called lastertoy. You can install the service on your pi by doing a git checkout of the repo.
$ git clone https://github.com/willywos/lastertoy $ cd lastertoy $ npm install $ npm start > firstname.lastname@example.org start /home/pi/lastertoy > node lib/server.js ▄ ▄ ▌▒█ ▄▀▒▌ ▌▒▒█ ▄▀▒▒▒▐ much api ▐▄▀▒▒▀▀▀▀▄▄▄▀▒▒▒▒▒▐ ▄▄▀▒░▒▒▒▒▒▒▒▒▒█▒▒▄█▒▐ ▄▀▒▒▒░░░▒▒▒░░░▒▒▒▀██▀▒▌ ▐▒▒▒▄▄▒▒▒▒░░░▒▒▒▒▒▒▒▀▄▒▒▌ ▌░░▌█▀▒▒▒▒▒▄▀█▄▒▒▒▒▒▒▒█▒▐ ▐░░░▒▒▒▒▒▒▒▒▌██▀▒▒░░░▒▒▒▀▄▌ ▌░▒▄██▄▒▒▒▒▒▒▒▒▒░░░░░░▒▒▒▒▌ ▀▒▀▐▄█▄█▌▄░▀▒▒░░░░░░░░░░▒▒▒▐ ▐▒▒▐▀▐▀▒░▄▄▒▄▒▒▒▒▒▒░▒░▒░▒▒▒▒▌ wow ▐▒▒▒▀▀▄▄▒▒▒▄▒▒▒▒▒▒▒▒░▒░▒░▒▒▐ ▌▒▒▒▒▒▒▀▀▀▒▒▒▒▒▒░▒░▒░▒░▒▒▒▌ ▐▒▒▒▒▒▒▒▒▒▒▒▒▒▒░▒░▒░▒▒▄▒▒▐ ▀▄▒▒▒▒▒▒▒▒▒▒▒░▒░▒░▒▄▒▒▒▒▌ ▀▄▒▒▒▒▒▒▒▒▒▒▄▄▄▀▒▒▒▒▄▀ ▀▄▄▄▄▄▄▀▀▀▒▒▒▒▒▄▄▀ ▒▒▒▒▒▒▒▒▒▒▀▀ Running on port 5150.
Once the service is running. You can hook up Amazon Echo to control it by running creating a new skill. You don’t have to worry about publishing it, you can leave it in test mode.
If you want to see the code I used, you can view it on GitHub
I won’t go through the whole process of setting up Echo to integrate but basically it runs a lambda function which makes a http request to the node service running on the raspberry pi. Then the node service tells the servo to move. There is a step by step tutorial on Amazon that I used to follow.
Here is a video of what it looks like. https://twitter.com/willywos/status/815943075243687936