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 & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • 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
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • 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 677 subscribers
  • Views 1608 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
Parents
  • 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
Reply
  • 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
Children
  • 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