element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Raspberry Pi Forum How to control single servo with pwm
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
Raspberry Pi Wishlist
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 11 replies
  • Subscribers 667 subscribers
  • Views 1361 views
  • Users 0 members are here
  • raspberry_pi
Related

How to control single servo with pwm

tabarus12
tabarus12 over 11 years ago

Hi all,

 

Im looking for info on how to control a single servo with the Rpi PWM pin and all ive found is info on how to control the 16 channel adafruit breakout board and no info on a single servo.

Can anyone guide me on the right direction on how to set the correct duty cycle and frequency to control the servo with no wiggling on the servo.

Ive included a picture for what Im trying to control.

 

Please help.

Attachments:
image
You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image
  • Sign in to reply
  • Cancel
  • Former Member
    0 Former Member over 11 years ago

    Check out https://learn.adafruit.com/adafruits-raspberry-pi-lesson-8-using-a-servo-motor/software

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago

    Nice project.

    But I do not understand why you have the servo so far away from the first rotation point. Why did not remove one step and put the servo on the first finger joint?

    Usually servos are simple to program. just a pulse varying from one (1) millisecond to two (2) milliseconds with a repetition rate or 50 or 100 Hz.

     

    Jean-Paul

    AC9GH

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • tabarus12
    0 tabarus12 over 11 years ago in reply to Former Member

    Thanks for the info, the reason for the servo so far apart is because Im planning to separate the servo and build a complete hand (all five fingers) and the servo has to go on the forearm not the hand, bu its a good idea to have it on the joint, thought about it at first but its wasnt going to work for me

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago

    If I'm not mistaken the frequency or duty cycle determines the position of the servo motor. The timings just increase the speed of each turn.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 11 years ago in reply to Former Member

    Nope, it is the actual pulse width as correctly stated above, a nominal 1 - 2 mS with about 1.5 being the centre, of course some manufacturers deviate a bit from this to get more range etc., but for basic RC Servos, that's it

     

    the repetition rate is typically about 20mS and many receivers use this as a way to detect a disconnect and move the servos to a default "Safe" value perhaps to put a plane into a slow circle pattern hoping to pick up the transmitter again

     

    If the servo looses its signal, it will typically just sit where it was but stop powering the motor so other forces could move it externally

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 11 years ago

    the "Wiggling" will be due to the fact that the PI is a multi tasking OS (AKA Linux) and therefore you can not guarantee exact timing so from that perspective your kinda stuck with it, you could try sending the pulses long enough to get to position but then stop sending them, this may work but probably wont maintain the "Grip" as the drive system in the servo will probably stop. Adding more servos to the PI will just serve to make this worse.

     

    a better way to drive the servos would be to use an ATMega328 or an MSP430 micro controller which are very cheap but will maintain a very accurate timing thereby reducing the wiggling considerably. In my testing there was NO declarable wiggle

     

    the PI can send the commands for positioning to the controller and it will simply do all the work for you. The pi is then left with the higher level brain functions image

     

    you can test this out simply by using an Arduino UNO or something (With a PDIP 328) then once it is working it can be removed and placed into a smaller and dedicated pcb/circuit. you then have the ability to make multiple independent limbs and have the PI orchestrate them.  NICE.

     

     

    there is plenty of code in the forums and on the Arduino site regarding this. there is even a dedicated Servo library

    Regards

     

    peter

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • tabarus12
    0 tabarus12 over 11 years ago in reply to Robert Peter Oakes

    Thanks for the reply, that is exactly my plan but I needed to start by testing the servos one by one and then move to a more robust and multi servo platform.

    Thanks for the tip on the wiggling now I know the reason for it, thought the servo was faulty.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 11 years ago in reply to tabarus12

    well for testing, why not test with the platform your going to drive it with, AKA an Arduino UNO or similar. This will also confirm the servo is indeed not faulty

     

    Peter

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • rew
    0 rew over 11 years ago in reply to Robert Peter Oakes

    I'm not sure how the Raspberry pi "servo library" works. Or whatever Omar tried.... But from "pwm" I would think that the raspberry pi has a hardware PWM module (which I know it has) and that this is being used to send out the servo pulses. That should be "not wiggling" even if there is a multitasking OS driving the values for the servo position.

     

    On the other hand, if it's user-space GPIO implementation then things can indeed be bad.


    Searching for what you can/should be using, I found: http://pythonhosted.org/RPIO/pwm_py.html, which uses DMA to achieve hardware PWM even on pins that are not PWM according to broadcom....

     

    If you buy the super-cheap servos, yes, they sometimes wiggle. Hmm. IIRC the one that I had that on had a capacitor fall off the PCB inside the servo....  (damaged in transit).

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Robert Peter Oakes
    0 Robert Peter Oakes over 11 years ago in reply to rew

    interesting stuff to know, thanks

     

    Peter

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube