1

I have written the following script to set positions for a single servo.

import RPi.GPIO as GPIO
import time

#set up pin 11 as an output
GPIO.setmode (GPIO.BOARD)
GPIO.setup (11, GPIO.OUT)

frequencyHertz = 50
pwm = GPIO.PWM (11, frequencyHertz)

RPosition = 0.5
R1Position = 1.0
MPosition = 1.5
L1Position = 2.0
LPosition = 2.5

positionList = [LPosition]

msPerCycle = 1000/frequencyHertz

for position in positionList:
    dutyCyclePercentage = position * 100 / msPerCycle
    pwm.start(dutyCyclePercentage)
    time.sleep (0.5)

pwm.stop ()
GPIO.cleanup ()

I want to create a way in which I can do one of two things:

1) create a masterscript which runs 6 scripts (I have 6 servos) to set them to a specific position.

2) Use a keyboard input to set a static position of the set of servos. i.e: input 'a' will result in the 6 servos moving to a position of yaw left.

How can i do this? Ideally option 2 would be better, but option 1 is the base for this. Will i need this: http://www.ebay.co.uk/itm/Adafruit-16-Channel-12-Bit-Pwm-Servo-Driver-I2C-ControlLED-Raspberry-Pi-Arduino/191472547370?_trksid=p2054897.c100204.m3164&_trkparms=aid%3D222007%26algo%3DSIC.MBE%26ao%3D1%26asc%3D20140407115239%26meid%3D5fe9f0b606ea4774ac50b3d3d270ede4%26pid%3D100204%26rk%3D1%26rkt%3D26%26sd%3D191446913846

  • 1
    If your aim is to build a quadcopter or similar you are using the wrong tools for the job. What is your end goal? – joan Mar 16 '15 at 13:23
  • I am building a tilting nacelle bi copter. For the bench test, my aim is to use the 2 brushless motors for VTOL (vertical take off and landing). And then perform static movements of the 6 servos: ie: keyboard input = set positions of all servos for yaw left. – tanuj Jain Mar 16 '15 at 13:26
  • It might be worth looking through the magpi magazine for relevant articles. There is at least one on a quadcopter which will have similarities to your project. You will need accurate PWM. That means either a board like the Adafruit one or you will need to use a module like servolaster or my pigpio on the Pi. Software timed PWM such as provided by RPi.GPIO will not be stable enough for servos/ESCs. A quadcopter is a very challenging project. – joan Mar 16 '15 at 14:21
  • thank you, I have just ordered the Adafruit 16 channel pwm/servo hat. I will check out the things you have recommended, thank you so much for your help :D – tanuj Jain Mar 16 '15 at 14:56
  • yeah the project is very challenging, and as I have no experience in coding I am finding it very intimidating. – tanuj Jain Mar 16 '15 at 14:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.