Це відео не доступне.
Перепрошуємо.

How To Control A Standard Servo With Raspberry Pi

Поділитися
Вставка
  • Опубліковано 18 сер 2024
  • Demonstrated here is the fast way to control either small 9-gram servos or a much more powerful 15KG servo using a GPIO Pin on a Raspberry Pi.
    Article with Code - core-electroni...
    Related Information
    16 Servo Adafruit HAT for Raspberry Pi - core-electroni...
    Controlling a Servo Motor with an Arduino - core-electroni...
    Control Your Raspberry Pi Remotely Using Your Phone (RaspController Guide) - core-electroni...
    Dual Monitors with Raspberry Pi (Excellent Beginner Guide to Connecting Everything Up) - core-electroni...
    Servos are an immensely useful way to turn electrical energy into a rotational or linear motion with high efficiency and with great precision. The ones in this guide are all Standard Rotary Actuator Servos that can rotate 180 degrees or 270 degrees. Precise control over the narrow range (degrees of movement) is achieved through position. Information on the desired position is sent through via a PWM (pulse-width modulation) signal. Each servo has unique specifications which you can find in the datasheet and often at the bottom of our product pages. The code wants the values in seconds and datasheets usually provide data in microseconds so you will need to divide those numbers by 100000. Bigger servos need more current than a GPIO Pin can send out so I demonstrate how to power it if that situation arises. Shown here are servos commonly seen by makers but there are exotic types of servos that can rotated 300 degrees and even have internal clutches built in. The code used here allows you to control the angle at which a servo will orientate too maximising your control over the system.
    If you have any questions about this content or want to share a project you're working on head over to our maker forum, we are full time makers and here to help - coreelec.io/forum
    Core Electronics is located in the heart of Newcastle, Australia. We're powered by makers, for makers. Drop by if you are looking for:
    DFRobot Metal Geared 15Kg Standard Servo 270° (used here): core-electroni...
    Makeblock 9g Micro Servo Pack (used here): core-electroni...
    Raspberry Pi 4 Model B (4GB) Ultimate Kit Bundle (AVALIABLE!) - core-electroni...
    Raspberry Pi 4 Model B 2GB: core-electroni...
    Raspberry Pi 16 Channel Servo HAT: core-electroni...
    2Kg 300° Clutch Servo: core-electroni...
    Primoroni Picade Pan-Tilt HAT: core-electroni...
    5V DC 4A Fixed 2.1mm Plugpack: core-electroni...
    0:00 Intro and Schematic
    0:10 Overview
    1:20 Small Servo What You Will Need
    1:47 Schematic and Build
    2:23 Coding the Raspberry Pi
    2:42 Its Working!
    2:47 Explaining the Code
    3:05 Pulse Width Modulation Explained
    3:45 Data Shown is for Large Servo
    3:50 End Explaining code
    4:15 Large Servo What You Will Need
    4:50 Schematic and Build 2
    5:40 Coding the Raspberry Pi 2
    5:58 Large Servo is Working!
    6:10 Explaining the Code 2
    6:47 How to use only one Power Supply
    7:08 Outro

КОМЕНТАРІ • 92

  • @sleef3334
    @sleef3334 10 місяців тому +10

    More tutorials need to be like this, short and straight to the point, too many channels add a bunch of unnecessary info

  • @ydocld05
    @ydocld05 Рік тому +3

    This helped me finish a project I had been working with for a while. Just wanted to say, Thank you!

  • @ima9969
    @ima9969 2 роки тому +6

    You clearly deserve 10k likes man

  • @SirTrollingham
    @SirTrollingham 3 роки тому +11

    Great video, I especially liked the code walkthrough.

  • @ianbertenshaw4350
    @ianbertenshaw4350 3 роки тому +11

    Cool video ! Straight to the point ,Clearly explained and easy to understand - I like that !

    • @maxuabo
      @maxuabo 2 роки тому

      I second this! Editing and prevention is more important than the information itself, I guess that’s subjective but this video format was very well done!

  • @jmac2543
    @jmac2543 2 роки тому +3

    exactly what i was looking for

  • @jonsnow3513
    @jonsnow3513 13 годин тому

    a king not wearing the crown

  • @Keeping_IT_Simple
    @Keeping_IT_Simple 3 роки тому +2

    Long time Subscribed , bell icon clicked but this video does not appear at all in my feed ! Thanks UA-cam!!!
    A good , easy to understand guide !

    • @ianbertenshaw4350
      @ianbertenshaw4350 3 роки тому

      Same here , I only spotted it because it came up on my home section , probably appear in a few days time .

  • @mithunchandra8221
    @mithunchandra8221 Рік тому +1

    Your Explanation is very very nice.Thank you so so much sir.

  • @rml0226
    @rml0226 Рік тому

    Thank you for this very helpful walkthrough with servo motors, I have a question if it is necessary to add the gpio.cleanup for this kind of coding.

  • @tischregal9678
    @tischregal9678 Рік тому +1

    nice short totorial. Is there also a way to adjust how fast the servo spins?

    • @Core-Electronics
      @Core-Electronics  Рік тому

      If you are using Continuous Servos you can. Otherwise if you are using a Normal Servo you can get it to step multiple times, with delays between each subsequent movement, instead of a single snap to direction request, which would mimic a slower rotation.

    • @tischregal9678
      @tischregal9678 Рік тому

      @@Core-Electronics alright ty that works, do you know if it is bad for a servo to change the spin directionn very frequently like every 0.1 seconds or does it not harm it?

  • @_nick.07
    @_nick.07 Рік тому

    Cool Video, really helps me! But which DC power jack did you use?

  • @robertoguerra5375
    @robertoguerra5375 Рік тому

    Thank you for making this video :)
    Does anybody know how many servos I can control at the same time?

  • @3dprintsiebarth978
    @3dprintsiebarth978 10 місяців тому

    what would interest me is how do i get rotary movement slower say from 90 to -90 in 1 min . Great video :)

    • @Core-Electronics
      @Core-Electronics  10 місяців тому +3

      Hey Siebarth!
      This is a very common code often called a "servo sweep". You could use a loop to steadily increase the position of the servo a little bit at a time. If you want the servo to rotate 180 degrees in 60 seconds, every second it would need to rotate 3 degrees.
      So you could create a loop that starts at 90 degrees, then every second decreases that number by 3 degrees till you get to -90 degrees in 60 seconds. You can make it even more smoother by decreasing the update time (changing the angle to 1 degree every 1/3 of a second).
      Here is a link to some example code: core-electronics.com.au/guides/getting-started-with-servos-examples-with-raspberry-pi-pico/#example-1
      This does use 0 to 180 degrees though, but the logic is the same.
      If you have any other questions or need any more help, feel free to ask us on our forums: coreelec.io/forum
      Cheers mate!

    • @TheChupacabra
      @TheChupacabra 9 місяців тому

      Great to see a content creator that gives in depth, helpful replies!

  • @TheVBounce
    @TheVBounce 9 місяців тому

    Do you need a special servo to make this a closed loop?

  • @mitkosokolov9382
    @mitkosokolov9382 8 місяців тому

    how can we control servos from Bluetooth (on rpi), and make it execute set of voice commands?

  • @actuallyganta6044
    @actuallyganta6044 2 роки тому +2

    Great video! I was just wondering, would it be possible to use a 5V DC 3A power supply instead of 4A? I'm struggling to find one in any European shops.

  • @GordonTam-zj7zy
    @GordonTam-zj7zy Рік тому +1

    Hi, this was a great video and I've used the same wiring except for a Micro Servo SG90 from tower pro. It didn't even move unlike the other problems in the comment section, is this kind of servo not compatible? Thanks! (also it's a stepper servo)

    • @Core-Electronics
      @Core-Electronics  Рік тому

      It should still be compatible. Perhaps adjusting the | min_pulse_width | and | max_pulse_width | to max it work. Determine a servos limits carefully by experiment, so adjust those default settings by small increments.

    • @GordonTam-zj7zy
      @GordonTam-zj7zy Рік тому +1

      Alright thanks for the quick response! I'll try it today

  • @serceband
    @serceband Рік тому +1

    If the servo I want to use requires higher voltage to operate and I need to power it via a 8.4V power supply, is it safe to connect it's ground to the Pi? or is it going to fry it?

    • @Core-Electronics
      @Core-Electronics  Рік тому +1

      Don't power the raspberry pi with the 8.4V but you can totally connect up the ground pins 😊 It is important that they share the same grounds

  • @GavinMiller2633
    @GavinMiller2633 Рік тому +2

    Where do I get the library for the code?

    • @Core-Electronics
      @Core-Electronics  Рік тому +1

      Check the bottom of the full written up article for any scripts I have utilised in this guide 😊 core-electronics.com.au/guides/control-servo-raspberry-pi/#Down
      No extra packages or external Python libraries are required to get this system running.

    • @GavinMiller2633
      @GavinMiller2633 Рік тому +1

      Thank you

  • @aadigupta4252
    @aadigupta4252 Рік тому +1

    Hi it was a really good video but I am facing a problem that my servo jitters very violently due to which it is not able to go full 90 degrees. I hope you can help me solve it.

    • @Core-Electronics
      @Core-Electronics  Рік тому

      Heyya mate 😊 thanks for your kinds words. If you do not get full rotation out of your 180 Degree Servo adjust the min pulse width and max pulse width values by 0.0001 increments until you do. Adjusting these numbers till they are good will also calm down the servo jittering as well.

    • @aadigupta4252
      @aadigupta4252 Рік тому +1

      @@Core-Electronics Thanks a lot

  • @antitialaman7301
    @antitialaman7301 Рік тому +1

    Can you tell me if I can connect directly Emax ES08MA II to raspberry pi zero? Ty

  • @oktayakdede9865
    @oktayakdede9865 Рік тому

    thanks a lot for the explanation. how can we control also the speed of the servo?

    • @fadsmfawopefaw
      @fadsmfawopefaw 5 місяців тому

      Based on the video, it sounds like the black and red wires just give power, and the yellow wire determines angle because it's connected to the GPIO on the Raspberry Pi. Since the yellow wire controls the angle, the speed of the servo would be controlled from the code-side by changing the angle at slower or faster rates. I'm new to this, but that's my understanding of it.

  • @HoangNguyen-fd7te
    @HoangNguyen-fd7te Рік тому

    Why not get 5V power from Raspberry Pi but have to power the servo separately?

  • @andreinarita5156
    @andreinarita5156 Рік тому +1

    Hello! I tried your code with a MG90S but my servo isn't moving. Any clue?

    • @Core-Electronics
      @Core-Electronics  Рік тому +1

      I am surprised that it doesn't work at all! The specifications for MG90S that you likely need to update into the script are the Pulse Cycle: 20 ms and the Pulse Width: 400-2400 µs.
      Update the script with that information and your servo should jump to life 😊

  • @kuross6605
    @kuross6605 Рік тому +1

    Can i connect 2 large servos in a raspberrypi 4 model b?

  • @AyakaPeak
    @AyakaPeak 10 місяців тому

    Do you have any tutorial recommendations for if I am wanting to use a button to switch a servo between to positions? Kinda of like in an iron man helmet!!

    • @Core-Electronics
      @Core-Electronics  10 місяців тому

      Hey Ayaka, Whilst we don't have a tutorial on that specifically it is not too hard to of a task. You would need to have a variable to count the state, here is what the psuedo code would look like.
      (in the set up)
      state = 0
      (in the main loop section)
      if button pressed
      if state = 0
      (set the first servo position you want)
      state = 1
      if state = 1
      (set the other servo position you want)
      state = 0
      And with a single button the state will change between these 2 variables. If you need any more help feel free to ask on our forums: coreelec.io/forum
      Good Luck!

  • @khaledkamelbouabdallah9716
    @khaledkamelbouabdallah9716 2 роки тому +1

    Hi love your videos, if you don't mind, which program are you using for your schematic circuit??

    • @Core-Electronics
      @Core-Electronics  2 роки тому +1

      I have been using this online Photoshop like program for all my image editing/schematic creations - pixlr.com/x/
      However there are totally programs made for the job, I just found it easier and more fun creating my own assets.

    • @khaledkamelbouabdallah9716
      @khaledkamelbouabdallah9716 2 роки тому +1

      @@Core-Electronics Thank you so much

  • @juniorberard9611
    @juniorberard9611 5 місяців тому

    can we run a 40kg servo motor with this technique sir ?

    • @Core-Electronics
      @Core-Electronics  5 місяців тому

      Yes, as long as you use the correct power supply that can provide enough current, you should be able to!

  • @bra1nsen
    @bra1nsen 2 роки тому +1

    5V and GND at the Pinout can handle currents of 1000mA?

    • @Core-Electronics
      @Core-Electronics  2 роки тому +1

      This is all for a Raspberry Pi 4 Model B -
      For the Power rails:
      - The 5 V rail appears to passed straight through from the USB and the current is therefore limited to whatever the USB port can supply minus the current being drawn by the board.
      - The 3.3 V rail can supply a maximum of 50 mA
      For the GPIO:
      - The max current you should draw from a single pin is 16mA
      - The max current you should draw from all the pins collectively should be below 50mA
      Hope that answers all your questions 😊

    • @bra1nsen
      @bra1nsen 2 роки тому +1

      @@Core-Electronics The 5V Pins at the GPIO bar are called Power rails? I use the Raspberry PoE+ HAT (802.3at). So I have ~ 5V and 4A available. Lets say I connect a 3Ohm resistor, so that a current of 1.6A would flow. Will it damage the Pi?

    • @bra1nsen
      @bra1nsen 2 роки тому +1

      3 Ohm connected to GND and 5V (Pin number 2 and 6)

  • @FourTweny
    @FourTweny 9 місяців тому

    Can you link the code for controlling a 360 degree servo?

  • @nictendonice2988
    @nictendonice2988 Рік тому

    I am working on a projekt where i need 7 servos in total but there are always a maximum of 2 working on the same time (most of the time just 1), do i need an external power supply?

    • @savanladva1197
      @savanladva1197 9 місяців тому

      yes Rpi board 5V pin is not able to give sufficient current to servo motor

  • @TheLinessCompany
    @TheLinessCompany Рік тому

    Anyway I can do this in c?

  • @kuross6605
    @kuross6605 Рік тому +1

    Hello! I am getting this error when doing the large servo
    "PWMSoftwareFallback: To reduce servo jitter, use pigpio pin factory." with a link to the gpiozero docs is there a fix? thanks!

    • @Core-Electronics
      @Core-Electronics  Рік тому

      That is just the system telling you a method to lower Servo Jitter. Is the servo moving at all when you run the script? Feel free to open up a forum post as well best be able to help you there - forum.core-electronics.com.au/

    • @whatdoyoudo1482
      @whatdoyoudo1482 Рік тому +1

      @@Core-Electronics I have the same error code. Im using python idle, I am going to try running it as a shell. Nope, Same error, thonny has the same error as well.

    • @Core-Electronics
      @Core-Electronics  Рік тому

      Does the error impact the correct function of the Servo? If not don't stress. If it is causing a very jittery response the solution to not seeing the message any more and a smoother servo can be found here - forums.raspberrypi.com/viewtopic.php?t=313651

  • @Videogame9559
    @Videogame9559 Рік тому

    Hi could you do a video on Auduino and raspiberry pi zero and flysky controller and reciver to contol 2 servos.

    • @Core-Electronics
      @Core-Electronics  Рік тому

      Heyya mate, this guide here will give you the run down on controlling hardware attached to a Raspberry Pi using an RC Controller - github.com/samfok/remote_receiver_tutorial
      I reckon that will be a proper help 😊

  • @vicked_vicky8908
    @vicked_vicky8908 2 роки тому +1

    How can I connect a 6- 8,4V Servo with a Rasberry or PWM?
    Please help

    • @Core-Electronics
      @Core-Electronics  2 роки тому

      For higher voltages than 5V you will need to use a I2C Motor/Servo Driver Board. Just be careful when you are hooking up power as you do not want to fry the Raspberry Pi. The Raspberry Pi will break if more than 5 Volts are sent through it.
      This would do the job well -
      core-electronics.com.au/catalog/product/view/sku/SS105020093

    • @vicked_vicky8908
      @vicked_vicky8908 2 роки тому +1

      @@Core-Electronics perfekt I would try it.
      Could you make a video how to code a "Flight simulator Joystick" Trustmaster
      For steering servos?
      Does I need to code every 0-1 ° for low sensitivity or is there any programs?

    • @Core-Electronics
      @Core-Electronics  2 роки тому

      I can see you have a very focused problem, hit this fellow up as he seems to be working right in your alley - ua-cam.com/video/TNUACvk1sto/v-deo.html

  • @icab0225
    @icab0225 Рік тому

    Can you do a tutorial on a 16 servo hat with external power tutorial

    • @Core-Electronics
      @Core-Electronics  Рік тому +1

      We already did 😀 core-electronics.com.au/guides/raspberry-pi/servo-hat-raspberry-pi/

    • @icab0225
      @icab0225 Рік тому

      @@Core-Electronics y'all are the best

  • @ChrisBullock1978
    @ChrisBullock1978 11 місяців тому

    how are stepper motors different than servos?

    • @WalkingBlock
      @WalkingBlock 4 місяці тому

      Stepper motors you control with “steps” so for example; move 10 steps to the left

  • @barzabelbehemothe1939
    @barzabelbehemothe1939 2 роки тому +1

    if we use PI 3

  • @user-iw7ii4lu6h
    @user-iw7ii4lu6h 2 роки тому +1

    how can i stop the jitter of the servo?

    • @Core-Electronics
      @Core-Electronics  2 роки тому

      That's a function of the RPi's soft-PWM. To completely remove the jitter, the RPi needs a hardware servo driver, like this one: ua-cam.com/video/bB-xymRI8BY/v-deo.html

    • @Core-Electronics
      @Core-Electronics  2 роки тому

      (If sticking with the same set-up, finding the perfect | min_pulse_width | and | max_pulse_width | should also prevent much of the jitter.)

    • @ShellDude01
      @ShellDude01 2 роки тому

      With the direct connection examples you can alleviate jitter by using a different library (rpi_hardware_pwm). Coupled with a one line config.txt change this library enables direct hardware timed communication for (up to) two servos when plugged into the right gpio pins.
      While pin factories like pigpio definitely help reduce jitter, they do not alleviate it 100%. Playing with pulse widths / etc do nothing to solve it. I'm guessing someone is experiencing a placebo effect.

  • @dingdong1813
    @dingdong1813 6 місяців тому +2

    Code worked the first time now it doesn’t 👍

  • @tze-ven
    @tze-ven 2 місяці тому

    GPIOs do not supply power to the servo motors, they only supply signal. I believe you mean Power pins, but they are not GPIOs.

  • @JohnSmith-kz3dy
    @JohnSmith-kz3dy 6 місяців тому

    could i use a seperate power supply to power a high power servo, 7.4 volts, and the rpi4 but still send signals from the rpi4 to control the servo? i want to use my body power to power the servo, i got this human vein to usb attachment on amazon, i think my body puts out about 12 volts

  • @aneraxxmusic2343
    @aneraxxmusic2343 7 місяців тому

    Tells me to use pigpio 😢

  • @jyvben1520
    @jyvben1520 3 роки тому +2

    gpiozero, nice

  • @rudyishortsy7020
    @rudyishortsy7020 Рік тому

    4 amps bruh i have 2 max

    • @Core-Electronics
      @Core-Electronics  Рік тому

      4 amps is kind of conservative. If the servo isn't holding high torque or stalling you're probably fine. If you use a micro servo then 1amp is sufficient.