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...

Комментарии • 114

  • @fpapleux
    @fpapleux 10 лет назад +19

    Thank you. Very clear explanation. Short, to the point. This is perfect.

    • @jarnelramiscal3443
      @jarnelramiscal3443 6 лет назад

      How to control servo using PIR SENSOR TO OPEN AND CLOSE THE SERVO MOTOR

  • @cwash08
    @cwash08 9 лет назад +2

    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

  • @seanlebeck
    @seanlebeck Год назад

    This video introduced me to Linux, and changed my life.

  • @AverageManvsPi
    @AverageManvsPi 9 лет назад +1

    This helped me so much - thank you. Your teaching style is very easy to follow.

  • @pierig56
    @pierig56 8 лет назад +1

    you got me going in less than 5mins. Thanks for this nice video.

  • @AkaSoggyBunz
    @AkaSoggyBunz 11 лет назад +3

    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.

  • @wfpnknw32
    @wfpnknw32 7 лет назад

    fantastic video! great explanation while being short and concise

  • @kowetas
    @kowetas 10 лет назад +1

    Brilliant, worked great as soon as I figured out that I had been an idiot copying the code xD

  • @anubhavbhattacharya6216
    @anubhavbhattacharya6216 5 лет назад

    Thank you so much. I was really trying hard to make a servo work on a RPi and this really helped!!

  • @diditdwianto8034
    @diditdwianto8034 11 лет назад

    Bro, your explanation was simple and clear ... Thank you for sharing with the world ... :thumbup:

  • @updowndown
    @updowndown  11 лет назад +1

    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.

  • @michaelwood7355
    @michaelwood7355 6 лет назад

    How would you control multiple servos? Anyone? Btw great video very clear and concise explaination. Well done!

  • @vaibhavsawant801
    @vaibhavsawant801 8 лет назад

    You have gotta nice teaching skills.

  • @KarimNiazi
    @KarimNiazi 10 лет назад

    Thanks, this video is a great starting point!

  • @StephenJames2027
    @StephenJames2027 8 лет назад

    I got this to work on my Raspberry Pi3 by connecting the 5volt negative pin as described in the video to a GND pin

  • @peyte
    @peyte 10 лет назад

    Awesome, worked like a charm. Thanks!

  • @M4gicT0
    @M4gicT0 10 лет назад +2

    Thank you so much man ! You helped me a lot ;)

  • @michaelmcallister711
    @michaelmcallister711 8 лет назад +1

    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?

    • @sandalf-the-grey
      @sandalf-the-grey 8 лет назад

      Hi, have you already find the solution? I am attempting to do same thing

    • @michaelmcallister711
      @michaelmcallister711 8 лет назад

      Solution to spinning? I just actually found out you have to have a special servo motor that enables 360 degree rotation. Does this help?

    • @snnwstt
      @snnwstt 7 лет назад

      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.

  • @AvgAm
    @AvgAm 6 лет назад +1

    Great video, super helpful!

  • @Oli420X
    @Oli420X 5 лет назад

    Great video

  • @DoGaNKaRaHaN
    @DoGaNKaRaHaN 5 лет назад

    Great video, thank you

  • @updowndown
    @updowndown  11 лет назад +1

    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.

  • @irvinsanchez4516
    @irvinsanchez4516 8 лет назад +10

    What would the hardware implementation look like?

    • @ProtoMan137
      @ProtoMan137 7 лет назад +1

      For example a servo controller like the Polulu Micro Maestro.. I guess you can communicate to it over USB or on TX/RX

  • @damiendiablo3935
    @damiendiablo3935 10 лет назад +6

    Supply your own 5 volts or what ever to your servo not from the Rpi board and just use the Signal wire.

  • @joejenkins0
    @joejenkins0 10 лет назад +3

    Gaven,
    Is there anything I could add to terminate the script right after the servo finishes one cycle of neutral, 0, and 180?

  • @fungoro
    @fungoro 11 лет назад

    thanks for this video

  • @ConsultingjoeOnline
    @ConsultingjoeOnline 6 лет назад

    Thanks great video

  • @AkaSoggyBunz
    @AkaSoggyBunz 11 лет назад +1

    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.

  • @robn2497
    @robn2497 4 месяца назад

    Can you expand on hardware implimentation thankyou.

  • @cirofusco4459
    @cirofusco4459 4 года назад

    Thanks!

  • @andrewmaurer4313
    @andrewmaurer4313 10 лет назад +1

    for those getting the attribute error on the p = GPIO.PWM(7,50) command, try "sudo easy_install RPi.gpio"

  • @kolban1
    @kolban1 9 лет назад

    You mentioned hardware for generating PWM that wasn't under software control. Do you have a link or reference to such a thing?

  • @AAmorim1989
    @AAmorim1989 8 лет назад +1

    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?

    • @rsBrad
      @rsBrad 8 лет назад +2

      +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.

  • @ApplySkills
    @ApplySkills 6 лет назад +2

    Servo works in python interpretter , but doesnt work in python script even if i run it in sudo

  • @needsmoorecowbell
    @needsmoorecowbell 10 лет назад +4

    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

    • @needsmoorecowbell
      @needsmoorecowbell 10 лет назад +2

      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.

    • @GiuMagnani
      @GiuMagnani 7 лет назад +1

      I love you!!

  • @sanvedlop
    @sanvedlop 6 лет назад

    What servo motor would you suggest which would be powerful enough to press a button ? How much torque should I look for ?

  • @jongrant6385
    @jongrant6385 8 лет назад

    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!!

  • @ittailevani2535
    @ittailevani2535 9 лет назад

    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

  • @alexellis2
    @alexellis2 10 лет назад

    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

  • @gwemlins
    @gwemlins 11 лет назад

    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?

  • @TBadalov
    @TBadalov 6 лет назад

    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

  • @magnussenpaetur
    @magnussenpaetur 7 лет назад

    How could you make the servo spin faster? Love your video!

    • @chevycamaro-rp6tr
      @chevycamaro-rp6tr 7 лет назад

      Pætur Magnussen I got mine to spin faster by applying sufficient voltage.

  • @DieMasterMonkey
    @DieMasterMonkey 8 лет назад

    Thanks, did me!

  • @lamskev4602
    @lamskev4602 6 лет назад

    I want it to simulate the opening of a door, to make just 90 degree. then the opposite in another script. is it possible?

  • @ryanglenjames
    @ryanglenjames 11 лет назад

    Same issue here... ran update and upgrade as you suggested but get the same error... any ideas?

  • @tonio123energetics
    @tonio123energetics 6 лет назад

    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 ?

  • @uprajsingh
    @uprajsingh 5 лет назад

    I am looking for solder free connection options - like yourself .. what connector kit would you recommend?

  • @surod10
    @surod10 4 года назад

    Can i use this for a helpcopter?

  • @RickHenderson
    @RickHenderson 9 лет назад

    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?

  • @turgaybelek6188
    @turgaybelek6188 10 лет назад

    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

  • @cougargriff
    @cougargriff 9 лет назад

    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?

  • @mohibullahkhan3869
    @mohibullahkhan3869 4 года назад

    thanks

  • @denberghvanmartijn
    @denberghvanmartijn 11 лет назад

    I'm wondering, if i want a really fast servo (like way faster then 0.10s/60 degrees) where can i find such?

  • @theoneXXcristhianXX
    @theoneXXcristhianXX 10 лет назад

    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

  • @MikeLiteros
    @MikeLiteros 5 лет назад

    I found that if you recude the hertz to 20 the strange spatsic move dissapears

  • @adrenaline1
    @adrenaline1 8 лет назад

    good example. but I have yet to have it working...

  • @sergiocapillera9270
    @sergiocapillera9270 10 лет назад

    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

  • @ryanglenjames
    @ryanglenjames 11 лет назад

    Thanks for the reply... I am running Wheezy Raspbian - when I installed the python-rpi.gpio it said it was already the newest version.

  • @rorytyrrell
    @rorytyrrell 11 лет назад

    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?

  • @BrisbaneStomp
    @BrisbaneStomp 6 лет назад

    im new to this, how do i run the script? and i don not have highlighted blue words like yours?

  • @cahau8393
    @cahau8393 9 лет назад

    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??

  • @meowludo
    @meowludo 6 лет назад

    Fuck man this video is literally perfect. Thanks.

  • @neovictorius
    @neovictorius 7 лет назад

    So why doesn't the program stop once it has gone through all 3 cycles? Is there a way to make it do so?

  • @shahadalrawi6744
    @shahadalrawi6744 9 лет назад +1

    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 !!!

    • @davegriffiths8170
      @davegriffiths8170 9 лет назад +1

      if the code at Try fails because of an error, code will jump to Except :)

    • @TheMordano
      @TheMordano 9 лет назад

      +Shahad Alrawi The answer is: try and except are python commands, and not RPi :) And what they do, said Dave.

  • @TheKillerZmile
    @TheKillerZmile 5 лет назад

    can you command servo to a 90dgree angle?

  • @ddegn
    @ddegn 10 лет назад

    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".

  • @Ehrnsmersh
    @Ehrnsmersh 10 лет назад +1

    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?

    • @updowndown
      @updowndown  10 лет назад

      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.

    • @Ehrnsmersh
      @Ehrnsmersh 10 лет назад

      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?

    • @stylesoftware
      @stylesoftware 8 лет назад

      @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

    • @ekaadit7892
      @ekaadit7892 6 лет назад

      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

  • @hendolim9980
    @hendolim9980 9 лет назад +1

    I don't get why this works, because the only pin with capability of PWM is pin number 18 right?
    Please enlighten

    • @RickHenderson
      @RickHenderson 9 лет назад

      +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).

    • @ChrisD__
      @ChrisD__ 6 лет назад +1

      With software PWM, you should be to use all of the GPIO pins.

  • @atharvasaney3376
    @atharvasaney3376 5 лет назад

    which r pi have you used ??

  • @ryanglenjames
    @ryanglenjames 11 лет назад

    According to raspian it is version 0.5.3a

  • @codespunkrock
    @codespunkrock 9 лет назад

    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?

    • @konradpeter9547
      @konradpeter9547 9 лет назад +1

      codes punkrock The KEyboardinterrupt works with ctrl + c , not woith any key ;)

  • @AleAle-hj6db
    @AleAle-hj6db 9 лет назад

    When i plug my servo to the raspberry, my raspberry reboot. I have a 2A power suplly. Any idea for me?

    • @konradpeter9547
      @konradpeter9547 9 лет назад

      Alexandre ALB I had the same problem. For me its solved when the servo is powered from external 5V.

  • @elijus9889
    @elijus9889 6 лет назад

    my servo got really really hot and didn't work and all the pin layout and code are the same

  • @2starsinthemaking
    @2starsinthemaking 9 лет назад

    What can I use to make it do it once and then stop

    • @TheMordano
      @TheMordano 9 лет назад

      +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.

  • @steve_ancell
    @steve_ancell 10 лет назад

    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'

    • @someguy3032
      @someguy3032 10 лет назад

      i think that you must replace 7,50 with 7,1 or 7,0!!!!! :-)

    • @steve_ancell
      @steve_ancell 10 лет назад

      Ευθύμης Κρητικός
      I did manage to find out what the problem was eventually, I hadn't updated the RPi.

  • @TheBlankImagination
    @TheBlankImagination 9 лет назад

    While trying to do this, we got an error message of [Errno 13] Permission denied: '/home/pl/servo1.py'

  • @InluxBDX
    @InluxBDX 11 лет назад

    Every time I try to compile the code, the raspberry pi just reboot after the servo motor worked.

  • @maireainewallace7196
    @maireainewallace7196 7 лет назад

    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?

  • @samarthghodke8867
    @samarthghodke8867 6 лет назад

    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.

  • @alaa14781
    @alaa14781 5 лет назад

    can u help me i wanna control the servo using raspberry pi 3 but with g-code
    any help please

  • @MichelangeloTurillo
    @MichelangeloTurillo 10 лет назад

    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.

    • @updowndown
      @updowndown  10 лет назад +2

      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.

    • @MichelangeloTurillo
      @MichelangeloTurillo 10 лет назад

      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

    • @MichelangeloTurillo
      @MichelangeloTurillo 10 лет назад

      Gaven MacDonald Solved. The power supply was too weak! I am using a IPad power supply and it works as well! Thanks Gaven!

    • @updowndown
      @updowndown  10 лет назад

      Great to hear!

    • @MichelangeloTurillo
      @MichelangeloTurillo 10 лет назад +3

      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!

  • @theilikecatskid
    @theilikecatskid 10 лет назад

    Dont know what any of this means exept hes using the raspberry pi to cod a...hmmm... Ah ive got it... A helicopter!!!!!

  • @johncgibson4720
    @johncgibson4720 7 лет назад

    Great work.