Servo control with a Yún and a Pi

Making It All Work Together

At this point, you can power up the Yún with its servos properly connected. It should connect to your LAN. I ran it in infrastructure mode, meaning that when it boots up, it grabs an IP address from my LAN. This approach worked very well because I had the Pi hooked up via a wired connection to my router. For a standalone, portable application, switching to access point mode on the Yún might make sense [5].

Next, move over to the Pi and see that Processing is running, and load the slider Processing code that you copied from the notebook. You shouldn't have to change anything, such as the Yún IP address, if your Pi, Yún, and Linux notebook were all on the same LAN.

Click the Run arrow button to start the slider program. After a little while, a new window should appear with the sliders. Position the mouse on one of the sliders and click the left mouse button to change the setting. You can also hold the left mouse button down and move the sliders to change a value. The vertical slider should make the tilt servo move up and down, and the horizontal slider should move the pan servo left and right. Just swap the data pins on the servos if the controls are swapped on the Rasp Pi screen.

You might notice that the vertical slider's numbers stay on the screen and, as you move the slider, overwrite each other. This results in a "number line" next to the slider. Weird. The library probably needs some tweaking. If you make the x and y sizes for the tilt slider the same as for the pan slider, they'll both be displayed horizontally and the funny number behavior will disappear.

Next, I'll look at a few reasons why this setup might not work. First, the Pi and the Yún need to be connected to the same LAN. It's also possible that the Yún is in "access point" mode, which is its mode out of the box. See the Yún pages to configure it to work with your LAN in "infrastructure" mode.

Practical Considerations

Building systems with hardware components that communicate over WiFi connections, employ screen-driven controls, and command physical actuators gets complicated pretty quickly. And, I'm just talking one-way data flow here: sending position data from the Pi to the Yún. Additionally, it can be time consuming and sometimes frustrating to troubleshoot bugs, particularly if you're building all the parts from scratch.

Enhancements might include larger servos to move heavy loads. The Steampunk Eye mechanics were easy to actuate with tiny RC hobby servos. Larger servos might be needed for controlling an animatronic head or a robot. Remember that larger servos will need their own dedicated power supply.

So, now you have the basics for a wireless control system. Remember to start with a "minimum viable" project and develop from there. It always makes sense to document your project in a notebook or some kind of note application. As a project gets more complex, such as two-way data flow, organization is key, and documentation goes a long way to making that happen.

Multidevice systems are evolving quickly, so get the basics working first, and have fun.

Buy this article as PDF

Express-Checkout as PDF

Pages: 6

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content