Run a Single Servo on an Arduino with MyRobotLab

 

 

SpenMarsden's picture

some code

Heres some code Ive edited so I can speed up firing up arduino and servos- I've annotated it for where you put your own settings in. Hopefully helpful:)


#this will turn on arduino and servo services for diagnostics
 
from org.myrobotlab.service import Arduino
from org.myrobotlab.service import Servo
from org.myrobotlab.service import Runtime
 
from time import sleep
 
# create the services
 
#/set up your services-arduino and here are 3 services-delete or add as applicable
arduino = Runtime.createAndStart("arduino","Arduino")
pan = Runtime.createAndStart("pan","Servo")
tilt = Runtime.createAndStart("tilt","Servo")
yournamehere = Runtime.createAndStart("yournamehere","Servo")
 
# initialize arduino- change the value in "" for the computers name for the USB port
#your arduino is attached to
arduino.connect("/dev/ttyACM0", 57600, 8, 1, 0)
 
#/have a few beats rest to help the attaching process-not 100 percent if this is needed
sleep(2)
 
# attach servos to pins on the Arduino - this method will actually attach em
pan.attach(arduino.getName(), 9)
tilt.attach(arduino.getName(), 10)
yournamehere.attach(arduino.getName(), 12)
 
# set safety limits - servos
# will not go beyond these limits-change for your own best results
pan.setMinMax(50,170)
tilt.setMinMax(50,170)
yournamehere.setMinMax(10,175)
 
#/starting position - un comment this when you have the
#settings you want your servos to be at when this script starts
#pan.moveTo(90)
#tilt.moveTo(90)
#yournamehere.moveTo(67)