Learn Python for the #RaspberryPi with this series of articles

Words by David Briddock: Learn Python

David Briddock has been hard at work writing a series of blog posts about Python and how to use it. This series caters for beginners of all ages who want to learn how to program and don’t know where to start. There are 5 lessons so far and the series is growing at about 2 posts a week. So if you want to know more about Python and how to get started, head on over to David’s page on his blog.

Controlling servo motors on the #RaspberryPi

Better PWM on the Raspberry Pi

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:

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)

WebIOPi for the #RaspberryPi updated to 0.6

Eric, over at trouch.com, has released a new version of his Python libraries for the Pi. These give an Arduino-like feel to your Python code and provide a clarity that I’ve not seen in many similar projects.

There are quite a few chips and sensors that are built-in and dealt with natively and I’m definitely going to be using it for my next project that deals with the GPIO.

Read more details here