Control a Servo over the Internet


Note: If you are using Chrome and cannot see a live image here, hard refresh (shift plus refresh). Consider switching to Firefox if you're still having issues, Chrome has limited support of MJPEG.

Command: set [0-180]. (Example: set 20)

The servo is controlled via a Raspbery Pi. The Pi is running a python script that controls H|Bot. H|Bot takes input from IRC and relays that information to the Servo using pySerial.


Raspberry Pi, Python Servo Control

The following python code, along with Adafruit PWM and Servo Kernel allows you to control a servo with the following syntax:

python [degree] [degree] [degree]...

Example rotation to 180 and back to 0 twice:

python 0 180 0 180 0

# Servo Control
import time  
import sys  
def set(property, value):  
                f = open("/sys/class/rpi-pwm/pwm0/" + property, 'w')
                print("Error writing to: " + property + " value: " + value)

def setServo(angle):  
        set("servo", str(angle))

set("delayed", "0")  
set("mode", "servo")  
set("servo_max", "180")

point = 1  
while point < len(sys.argv):  
    time.sleep(0.5) #may need to change depending on speed of servo to allow full range of movement
    point = point + 1

If you want to build in a non-standard time delay we simply change:
time.sleep(0.5) to time.sleep(float(sys.argv[1])) and now we can use the syntax like such:

python [delay] [degree] [degree] [degree]...

On top of this if you want to program your own delays as arguments you could with sys.argv.