Servos take more power than the Raspberry Pi can deliver without causing errors, so I run a battery to power it separately. In the pictures you will see an inland battery from micro center, but in my diagrams I used adafruit parts… because they are available in the diagram software. Score one for the supplier who knows their makers and makes diagram software models!
This diagram is -close- to what I used, instead it has common and available adafruit parts like the LiPo Controller, Pi Cobbler, and the Servo because that’s what I found in the diagram program “Fritzring” – the standard in these things. I use servo #0 – which according to the documentation at servo blaster is the same as GPIO #4 which is pin #7 on the Pi Header / Cobbler.
Here is the code :
#!/usr/bin/python #import libraries import os import time # Start the servo motors os.system('sudo /home/pi/PiBits/ServoBlaster/user/servod') # turn servo 0 to 10% position os.system("echo 0=10% > /dev/servoblaster") time.sleep(0.5) # turn servo 0 to 60% position os.system("echo 0=60% > /dev/servoblaster") time.sleep(2) os.system("echo 0=10% > /dev/servoblaster") time.sleep(0.5) # turn servo 0 to 10% position # Stop the servo motors os.system('sudo killall servod')
This script has been tested only on a Raspberry Pi 3 computer.
Please report any tests or improvements in the comments box at the bottom of this page.
This is a part of the 2017 Rock, Paper, Lasers Science Project.
Here’s a quick video of it in action :
2017 Rock Paper Laser, Part 1 of 5