Most common servos will have three wires and a three pin connector, as follows:
Black/Brown |
Red |
Orange/White/Yellow/Blue |
Ground |
Positive supply (typically 5V for small servos) |
Signal |
While it is usually possible to power the servos directly from the Raspberry Pi 5V pins on the GPIO header, they can draw a significant amount of current when moving. Unless you have a very good power supply, this can cause the Raspberry Pi to reset unexpectedly, risking corrupting the SD card. Therefore, it is recommended that you power them separately; for example, with an additional USB power supply and cable connected to the ground and positive supply.
By default, the servos can be wired as follows:
Servo |
0 |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
All GND |
All Power |
Raspberry Pi GPIO Pin |
|
|
||||||||
7 |
11 |
12 |
13 |
15 |
16 |
19 |
22 |
6 |
No Connect |
|
5V Power Supply |
|
GND |
+5V |
We will assume that we are controlling four servos (0, 1, 2, and 3) that will be fitted to the MeArm or a similar device later:
To install ServoBlaster, start by downloading the source files from the Git repository:
cd ~ wget https://github.com/richardghirst/PiBits/archive/master.zip
Unzip and open the matplotlib-master folder, as follows:
unzip master.zip rm master.zip cd PiBits-master/ServoBlaster/user
We will use the user space daemon (which is located in the user directory) that is called servod. Before we can use it, we should compile it with this command:
make servod
There should be no errors, showing the following text:
gcc -Wall -g -O2 -o servod servod.c mailbox.c -lm
For usage information, use the following command:
./servod --help
Now we can test a servo; first, start the servod daemon (with a timeout of 2,000 ms to switch the servo off after it has moved):
sudo servod --idle-timeout=2000
You can move the servo's position to 0% of the servo's range:
echo 0=0% > /dev/servoblaster
Now, update the servo to 50%, causing the servo to rotate to 90 degrees (servo mid-point):
echo 0=50% > /dev/servoblaster
As recommended by the MeArm build instructions, the servos should be connected and calibrated before building the arm, to ensure that each servo is able to move the arm in its correct range. This is done by ensuring that each servo is powered up and commanded to its mid-point position (50%/90 degrees), and the servo-arm is fitted at the expected orientation:
You can now set each of the MeArm servos (0, 1, 2, and 3) to their mid-points (by commanding each, in turn, to 50%) before building and fitting them to a completed arm.
The servos could be used to control a wide range of alternative devices other than the MeArm, but your servos will probably need to be calibrated in a similar manner: