As part of my “SpacePi” Raspberry Pi astronomy project, I want to be able to control the orientation of the camera module remotely. I want to be able to sit away from the camera rig and control where it is pointing using a web interface and (optionally, and because I damn well can) via a Wii remote.
So, I’m currently doing research into how best to do this.
I’ve got the actual mechanism sorted by buying one of these: Dagu Pan/Tilt which comes with two of these motors. I’m planning on building some kind of LEGO base for it as I don’t fancy trying to balance it on the bottom of the servo! 🙂
The motors operate at a known rate at around 4.8v, which is perfect because that’s what comes off the Pi. Except I don’t think it’s safe to do this. I know the 3.3v rails have a max power draw of 50ma, but I think that the amps available on the 5V is just whatever is left after the Pi takes it’s ~700ma. That might mean I have enough amps left, but I don’t fancy trying this out on one of my beloved Pis! So that means an extra power supply for the servo motors. Okay, I can live with that. I’d rather not, you understand, so if anyone knows that it is safe to power from the Pi, please let me know!
Control of the servos is via PWM, aka Pulse Width Modulation. This is something that the Arduino does very well, but that the Raspberry Pi does less well. This is because the Arduino is what is known as a “real time system”, meaning that when it is running it’s program loop nothing else can use up the CPU. Literally, the only thing running is what you’ve told it to run. The Raspberry Pi, on the other hand, is not a real time system as Linux itself is always beavering away in the background taking up CPU cycles. However, I have come across some ways of getting the Pi to give the impression that it is a real time system and to do PWM ‘properly’.
So, some web pages to look at:
- Better PWM on the Raspberry Pi – an article on hackaday.com about the ServoBlaster project which is a good implementation of software PWM.
- Gordon Henderson has written about an improvement to the WiringPi library to allow threaded PWM on every GPIO pin taking up 0.1% of the CPU each.
- Rahul Kar has blogged about using the WiringPi library and PWM.
- Benjamin van der Veen’s blog was useful in understanding PWM in the first place.
- Petervis.com has a little bit about the single PWM hardware pin on the Pi.
- Great question on StackExchange about using PWM to control servos.
- JRonald’s fork of ServoBlaster that doesn’t use up all the pins for PWM.
- Thread on the Foundation form dealing with ServoBlaster.
- A video showing the Pi driving 5 servos – I think using PigPio.
- Another video this time with link to download PigPio.
- Video showing Python PWM with a link to download. The GitHub is here.
After looking at all these, I would have tried out the Python version first. I like Python, it’s my sort of language. But the author of PyZiPi has said that it’s not suitable for servo control.
If Python fails me, I’ll move onto C/C++ with PigPio first as it seems the simplest, but will probably end up using ServoBlaster and jumping through the required hoops to get it working. (There are all kinds of things mentioned like ‘userland’ which I’ve heard of and frightens me!).
The other thing to try, of course, is to try the WiringPi-Python library which means you can use the WiringPi library from within Python. Certainly seems as though it might work, as Gordon Henderson has hinted in the comments section of this blog page.
More soon! (Once I’ve got the pan/tilt servo rig in my hands)
[…] recantha As part of my “SpacePi” Raspberry Pi astronomy project, I want to be able to control the […]
You’ve missed my blog from today Mike. The Guzunty could be perfect for what you’re after. I’m using it for a project involving servos. (Only 90 degree movement at the moment, but that will be sorted I think).
Don’t even think about running a servo directly from the Pi’s 5 Volt line. It won’t cope with it – not to mention the idea of running an inductive load from the Pi. Someone thought I was doing that with my direct servo control the other week (I was using a separate 5V supply) and shot me a disparaging message. 😉
Will have a read of your blog. 🙂 Got a bit behind in my RSS feeds!
[…] ในตอนแรกก็หาชิ้นส่วนก่อน […]