Servo Control with the Raspberry Pi
HTML-код
- Опубликовано: 9 сен 2024
- This video outlines both how a servo work, and how to control one using the Raspberry Pi using pulse-width modulation.
Learn more about programming, electronics, and the Raspberry Pi at:
cutequbit.zapto...
Thank you. Very clear explanation. Short, to the point. This is perfect.
How to control servo using PIR SENSOR TO OPEN AND CLOSE THE SERVO MOTOR
Clear concise explanation with straightforward code examples. I like this. I also liked how you clarified that the time to each position is independent of the current position
This video introduced me to Linux, and changed my life.
This helped me so much - thank you. Your teaching style is very easy to follow.
you got me going in less than 5mins. Thanks for this nice video.
yep after hooking up diodes to restrict the backflow of current I have successfully got the servo to work without zapping and rebooting the rpi. Try connecting some diodes to the stop that.
fantastic video! great explanation while being short and concise
Brilliant, worked great as soon as I figured out that I had been an idiot copying the code xD
Thank you so much. I was really trying hard to make a servo work on a RPi and this really helped!!
Bro, your explanation was simple and clear ... Thank you for sharing with the world ... :thumbup:
Sounds like you have an older version of RPi.GPIO . You should be able to fix this by simply doing a 'sudo apt-get update' followed by a 'sudo apt-get upgrade' . Let me know if you still have problems after trying that.
How would you control multiple servos? Anyone? Btw great video very clear and concise explaination. Well done!
You have gotta nice teaching skills.
Thanks, this video is a great starting point!
I got this to work on my Raspberry Pi3 by connecting the 5volt negative pin as described in the video to a GND pin
Awesome, worked like a charm. Thanks!
Thank you so much man ! You helped me a lot ;)
First of all, your video ABSOLUTELY helped me understand and grasped the concept of this. THANK YOU SO MUCH FOR THIS VIDEO. I have one question, I am now experimenting with continous servo motor. I'm not exactly sure how to control it to make it spin for certain amount of time? Like I'm working on a blind and I want it to keep spinning for amount of time. What's the proper coding for this?
Hi, have you already find the solution? I am attempting to do same thing
Solution to spinning? I just actually found out you have to have a special servo motor that enables 360 degree rotation. Does this help?
You should probably use a stepper motor, not a servo motor. With a stepper motor, you send a command to make a single step ( a step is some fix angle, say, 1.8 degree, ... that depends on how the motor is built), again and again. You don't care much where it the motor "is pointing to" (in terms of angle), you just want it to turn "n steps". It is a kind of fire and forget thing. With a servo, you care where the motor is pointing to, and you send a signal telling it where you want its position to be (or to keep, even under a load).
As example, for a car, the wheel with traction could use a stepper motor, since you don't care really if the wheel has make a quarter of turn. or half that... what is important is the position of the car itself. But with a robotic arm, you may want to know where the arm is, at which angle it is, so a servo is required, not a stepper.
There are many videos out here, on youtube, showing how to control a stepper motor with the Raspberry Pi... Just be sure to use a stepper motor.
Great video, super helpful!
Great video
Great video, thank you
Are you running Raspbian? You can try installing the RPi.GPIO module with the following command:
sudo apt-get -y install python-rpi.gpio
If that doesn't work, let me know.
What would the hardware implementation look like?
For example a servo controller like the Polulu Micro Maestro.. I guess you can communicate to it over USB or on TX/RX
Supply your own 5 volts or what ever to your servo not from the Rpi board and just use the Signal wire.
Gaven,
Is there anything I could add to terminate the script right after the servo finishes one cycle of neutral, 0, and 180?
thanks for this video
Thanks great video
I have been having the same issue. What I think is happening is when the servo moves it creates a backflow of electricity and is causing the rpi to reboot. Can anyone clarify this? I have tried to stop this from occurring by putting diodes to stop the backflow but still no success.
Can you expand on hardware implimentation thankyou.
Thanks!
for those getting the attribute error on the p = GPIO.PWM(7,50) command, try "sudo easy_install RPi.gpio"
You mentioned hardware for generating PWM that wasn't under software control. Do you have a link or reference to such a thing?
Is it safe to power the servo directly from the RPi? AFAIK you are not supposed to power a DC motor directly from the pi, both because it maybe power hungry, drawing more amps than the pi's pins can handle or because motors can generate current. Also wouldn't it be safer to place a 1kohm resistor to the signal pin?
+Alande Amorim Everywhere else i've read says that you shouldn't use the raspberry pi to power this servo. It can pull too much current and cause your pi to crash.
Servo works in python interpretter , but doesnt work in python script even if i run it in sudo
I cannot get this to work. I connect the servo to a 6v power supply (both battery and regulated) and I see a short switch of the servo.
Once i send commands to the pin connected to the servo's control wire, nothing happens. Tried with both power supplys and also with two different servos. Only difference is I have a diode to prevent back EMF
Welp, figured it out. Works perfeclty now. Was a dumb error on my part. Didnt realize the longer breadboards' positive and negative power rails are split in the middle of the breadboard and need a jumper wire to bridge the two. I wasn't getting the final ground to the raspberry pi.
I love you!!
What servo motor would you suggest which would be powerful enough to press a button ? How much torque should I look for ?
Hey Gaven, really great video but I am really struggling with the whole servo controlling. I have two servos both with the three brown, red, orange pins like yours but I see you use a divider or something - firstly what is it? Also is there no other way to directly connect and control the servo from the GPIO without having to divide it onto different pins? I just have one more question, for my project I plan on having 9 servos eventually hooked up to the raspberry pi, I'm confident I will need something else, but I'm really not sure what - do you have any idea what device that is cheap that would do this for me and also I really don't want to get any external power supplies (w/ batteries). Would really appreciate your reply if you can :) Thank you!!
I have a 360° servo can i plug a regular battery strait into the servo with negetive to negetive and postive to postive without the 3rd wire and the servo will start spining
Very clear, but the DMA option for this library makes my servo try to go past it's limiter. Do you have anything for the precision option (i.e. RC)? Thanks
I'm considering setting up a motor to raise and lower my blinds. Would you recommend this be accomplished with a full-rotation servo or a dc motor?
Shouldn't it first rotate right at 3:34? As it was programmed to turn NEUTRAL, 180, 0. But what actually it does is NEUTRAL, 0, 180
How could you make the servo spin faster? Love your video!
Pætur Magnussen I got mine to spin faster by applying sufficient voltage.
Thanks, did me!
I want it to simulate the opening of a door, to make just 90 degree. then the opposite in another script. is it possible?
Same issue here... ran update and upgrade as you suggested but get the same error... any ideas?
I saw that GPIO PIN 18 is an hardware PWM output on the rpi, wouldn't it be rather good than using the software implementation ?
I am looking for solder free connection options - like yourself .. what connector kit would you recommend?
Can i use this for a helpcopter?
Got your code working with a HiTec HS-422 servo. It swings all the way through 0 - 180 and to neutral using your timing. Should I worry about double checking (aka trying to interpret) the 422 specs or with PWM will it be fine it it works anyway?
I tested your code with a XQ Power Digital Servo, but my motor doesn't do anything...could you help me why the motor doesn't do anything? I have an external Power Supply
I'm using the exact same code as your pwm example yet my servo goes from neutral to 180, to neutral, then stutters and repeats?
thanks
I'm wondering, if i want a really fast servo (like way faster then 0.10s/60 degrees) where can i find such?
sorry, i need your help, when the servo start to move the black screen freezes up and I have to reset raspberry in order to run again. what can i do? please
I found that if you recude the hertz to 20 the strange spatsic move dissapears
good example. but I have yet to have it working...
Hi, congratulations very good their application, I am experimenting with a PCDUINO plate and I do the same with your installed IDE does not work and I SERVO.h library could ised the same with a script?? you help?? Thank you. regards
Thanks for the reply... I am running Wheezy Raspbian - when I installed the python-rpi.gpio it said it was already the newest version.
every time i run this in the terminal it gives "AttributeError: 'module' object has no attribute 'PWM' " which says its relating to p = GPIO.PWM(7,50). Is there a PWM module i have to import first or something?
im new to this, how do i run the script? and i don not have highlighted blue words like yours?
my mouse and keyboard get unresponsive whenever the servo motor runs, may i know if servo motor has anything to do with this and if there is any solution??
Fuck man this video is literally perfect. Thanks.
So why doesn't the program stop once it has gone through all 3 cycles? Is there a way to make it do so?
I want to ask a question
what do try and except mean in his code?
I search for the answer in RPi website but I didn't understand !!!
if the code at Try fails because of an error, code will jump to Except :)
+Shahad Alrawi The answer is: try and except are python commands, and not RPi :) And what they do, said Dave.
can you command servo to a 90dgree angle?
Gaven, Thanks to you I wrote my first Python program yesterday and pulsed an LED (very exciting (and not that's not sarcasm)).
One suggestion is to explain many (if not most) servos will need a separate power supply.
I see many "the program" didn't type comments when the problem wasn't the program but the power supply.
IMO, This would be worth adding in or adding to the description or having a commenter point it out.
When you say "a hardware" solution, do you mean an external microcontroller?
QuickStartControlling32Servos120129.AVI
(If you don't want me to link to my own stuff let me know and I'll edit the link (or other content) out.) Please don't delete my comments like the kid who calls himself "The Raspberry Pi Guy".
I have followed your example exactly, however, when I run the .py file to move the servo it will cause my RPi to restart. Is the only way to fix this problem to use an external power supply?
Why does yours not need an external power supply?
Did you use the same servo? If it's a more power hungry servo, I could see it needing it's own power supply. If that isn't the case, it could be an issue with the Pi's power supply being unable to handle the additional current.
The one I am using is slightly different than the one you are using, it's operating range is 4.8v-6v.
If I were to connect a battery pack to the servos pos/gnd wires I would have only one wire going back to my GPIO pin of choice?
@Doogles With all modules, you will have to share the ground wire between pi (gnd), external battery (neg) and servo (neg). So yea there is another wire
Your servo is damaged dude like my servo
So it cause the Raspberry Pi Restart
I try my damaged servo with Arduino but it can't move it
I don't get why this works, because the only pin with capability of PWM is pin number 18 right?
Please enlighten
+Hendo Lim According to some pages on StackExchange, Pin 18 is PCM Clock, not PWM. In the code he sets his signal pin (Pin7) to use Pulse Width Modulation (PWM).
With software PWM, you should be to use all of the GPIO pins.
which r pi have you used ??
According to raspian it is version 0.5.3a
So I have it working just fine but the KeyboardInterrupt command isn't working. I have to shutdown the raspberry pi for it to end the program. What am I doing wrong?
codes punkrock The KEyboardinterrupt works with ctrl + c , not woith any key ;)
When i plug my servo to the raspberry, my raspberry reboot. I have a 2A power suplly. Any idea for me?
Alexandre ALB I had the same problem. For me its solved when the servo is powered from external 5V.
my servo got really really hot and didn't work and all the pin layout and code are the same
What can I use to make it do it once and then stop
+2starsinthemaking One move? I'm starting with the Raspberry Pi, Linux and Python. But i know other programming languages.. So if i understand it right, you only have to delete the while-loop.
I just get an error message:
Traceback (most recent call last):
File '/home/pi/Python_Projects/Servo/servo3.py", Line 9, in
p = GPIO(7,50)
AttributeError: 'module' object has no attribute 'PWM'
i think that you must replace 7,50 with 7,1 or 7,0!!!!! :-)
Ευθύμης Κρητικός
I did manage to find out what the problem was eventually, I hadn't updated the RPi.
While trying to do this, we got an error message of [Errno 13] Permission denied: '/home/pl/servo1.py'
sudo
Every time I try to compile the code, the raspberry pi just reboot after the servo motor worked.
Hi guys I am trying to do a Raspberry Door Lock Using 4×4 Keypad and Servo Motor anyone know how I would code this in python?
I am working on this, and seemed to have some trouble connecting the Pin 6, Pin 7, and basically the whole circuit to the Raspberry Pi. I am more of the Arduino guy:) Please clarify...anyone.
can u help me i wanna control the servo using raspberry pi 3 but with g-code
any help please
I can confirm that this little project doesn't work. I am using the same components. When I connect the positive and negative of the servo into the pins, the raspberry reboot itself.
Hmm, if the Raspberry Pi is rebooting there may be a power issue. The only thing I can think of is to check that your power supply can handle enough current (the one I used is rated to 1A), and make sure the ground and 5V wires are connected to the correct pins on the servo. Hope that helps.
hi Gaven, thanks for you reply. I am using a Motorola power supply. DC4050US0301 5.1V 850mA 0.85A Power supply AC Adapter SPN5504A. is it not enough? regards
Gaven MacDonald Solved. The power supply was too weak! I am using a IPad power supply and it works as well! Thanks Gaven!
Great to hear!
Hi Gaven, this day I have spent my sparetime to create a simple Web Based Servo Controller, here a screenshot: i2.minus.com/iQQ4Cgmogxj9n.jpg and here the code: snipet.co.uk/zd
is there a way to control a servo using the degrees?
Thanks for your video!
Dont know what any of this means exept hes using the raspberry pi to cod a...hmmm... Ah ive got it... A helicopter!!!!!
Great work.