controlling servo
bluejay
Posts: 131
Whats the best way to control a 180 degrees servo to move to certain positions such as 0, 45, 90 and 180 degrees? Is it by using pwm, frequency-out, or pulse out command? Could someone please illustrate a simple project? Thanks
Comments
When you say 180-degree servo do you have a Parallax standard servo?
https://www.parallax.com/product/900-00005
https://www.parallax.com/downloads/standard-servo-product-documentation
http://learn.parallax.com/tutorials/language/propeller-c/propeller-c-simple-devices/standard-servo
If you look at the documentation you will see that the width of the repeating pulse controls the servo position, but there is a C function that takes in an angle and sends the needed width.
https://cdn.rawgit.com/parallaxinc/propsideworkspace/master/Learn/Simple Libraries/Motor/libservo/Documentation servo Library.html
The Propeller doesn't actually use the BlockyProp program.
BlockyProp blocks are turned into C code that runs on the Propeller.
Start with the link that Francis Bauer provided which is a simple BlockyProp program.
Instead of P0 use whatever pin you have your servo connected to.
The first angle is already 0 so change the 2nd from 90 to 45.
Change the 3rd angle from 180 to 90.
Now add a 4th 'set angle' block and use 180.
Also add a 4th 'wait' block.
The tutorial that was given by Francis Bauer, refers to BlocklyProp code that is specific to the Parallax S3 Robot. Unless you are running this code on an S3 Robot, just ignore the "Change these LEDs to these colors" blocks. Leave those out of the program and it should work!
dgately
Vdd source is from usb.
Try turning the servo by hand (unpowered), in case it jammed at one of the stops. You can also try changing 0 to 10 deg and 180 to 170 deg in case the servo is off slightly and jams at the stops. (That happened to me with an off brand servo).
Your code ran servos on my Activity Bot when I changed the pin to 12 or 13! There must be something about your hardware setup. 5 volts (and low current from USB) may be a little low for the servos. I used the VIN input from 2x3.7 volt lithium batteries to run the servos at 7.4 volts rather than the USB's 5 volts.
dgately
A picture of your setup would be a great help at this point.
I am also concerned that your 5V to the servo will not supply enough current if you are relying on the onboard FLIP supply voltage. That voltage comes directly from the USB port which may not be able to supply the 500mA that the specification states. Are you driving anything else from the FLIP 5V ? LED's, etc.
Does your servo vibrate, make noise, or get warm when you run your code?
Use the "Attach a File" at the bottom left in your new post. A .jpeg would be fine.
That's great news. Time to play.