ptarpley
Posts: 3
Joined: Wed Feb 10, 2016 10:27 pm

Controlling Servos

Wed Feb 10, 2016 11:00 pm

I have seen ServoBlaster mentioned ( https://github.com/richardghirst/PiBits ... rvoBlaster ). Does this work without any additional hardware? I was under the impression that the PI could only accommodate one PWM channel. If it can do this w/o additional hardware, I'm guessing there are downsides (precision, jitter, etc?)

In addition, I've also seen references to hardware designed for servo function, such as: https://www.adafruit.com/products/815

I would like to tinker around and use some sensors and write a program to automate control of the servos using the PI based on sensor inputs.

I would appreciate any lessons learned about using multiple servos with the PI. FYI: I would be willing to spend some money to get an optimal setup if that meant higher precision/less servo jitter, or simply easier to work with.

Thanks :)

User avatar
mikronauts
Posts: 2783
Joined: Sat Jan 05, 2013 7:28 pm
Contact: Website

Re: Controlling Servos

Thu Feb 11, 2016 2:26 am

Take a look at joan's excellent pigpio library, I use it with my PiDroidAlpha controller.

On my RoboPi controller I added an eight core 32 bit risc chip just for hard real time I/O :-)

I have a couple of the Adafruit servo driver boards, but have not used them yet.

Links

pigpio: http://abyz.co.uk/rpi/pigpio/
PiDroidAlpha: http://www.mikronauts.com/raspberry-pi/pi-droid-alpha/
RoboPi: http://www.mikronauts.com/raspberry-pi/robopi/
ptarpley wrote:I have seen ServoBlaster mentioned ( https://github.com/richardghirst/PiBits ... rvoBlaster ). Does this work without any additional hardware? I was under the impression that the PI could only accommodate one PWM channel. If it can do this w/o additional hardware, I'm guessing there are downsides (precision, jitter, etc?)

In addition, I've also seen references to hardware designed for servo function, such as: https://www.adafruit.com/products/815

I would like to tinker around and use some sensors and write a program to automate control of the servos using the PI based on sensor inputs.

I would appreciate any lessons learned about using multiple servos with the PI. FYI: I would be willing to spend some money to get an optimal setup if that meant higher precision/less servo jitter, or simply easier to work with.

Thanks :)
http://Mikronauts.com - home of EZasPi, RoboPi, Pi Rtc Dio and Pi Jumper @Mikronauts on Twitter
Advanced Robotics, I/O expansion and prototyping boards for the Raspberry Pi

fsr
Posts: 88
Joined: Wed Jan 13, 2016 2:29 am

Re: Controlling Servos

Thu Feb 11, 2016 2:59 am

ptarpley wrote:I was under the impression that the PI could only accommodate one PWM channel.
Modern (40pin header) PI's support 2 out of the box. You can enable using the appropriate overlay (see /boot/overlays/README on your PI). The only gotya is you need to enable them & start up a PWM clock (which is also used for analogue audio) at each boot.

I use this script (called from rc.local). Note I have a group setup ('pwm') so I can use from pwm's from an unprivileged account.

Code: Select all

#!/bin/sh

#start the PWM clock by sending some audio :-/
speaker-test -Dhw:CARD=ALSA,DEV=0 -f300 -c1 -p100 -P2 -l1 > /dev/null 2>&1

#enable the PWM(s). Try both in leu of parsing config.txt.
echo "0" > /sys/class/pwm/pwmchip0/export
echo "1" > /sys/class/pwm/pwmchip0/export

#configure the PWM(s) so users can use them
chgrp pwm /sys/class/pwm/pwmchip0/pwm?/*
chmod 660 /sys/class/pwm/pwmchip0/pwm?/*

Return to “Beginners”