As the moment youtube notified me about this new video, I was watching Explaning Computers: the Latte Panda Delta Review. Bought two of those myself. :)
Very interesting I very much appreciate your comments which add a real world perspective. For example, how the SG90 you used is the "most common type servo in the world" I just assumed it was a hobbyist piece of electronics. It really brings home how relevant what you are sharing is.. Thanks again
I’m building a little robotics platform for myself and had typed out a little Python Library for myself to handle the wheels but didn’t know for sure if the PWM methods could control more than one servo at a time. With this hindsight I realize it’d be a bit silly if it weren’t capable of doing so. Now I just have to remember where I saved the two libraries, test them out, and add in turning to the Wheel library. Thank you again for the awesome videos!
Not to argue with you, but, seemed more like 67,65 to me 😉. Thanks as always for charing your knowledge with us. Ordered a Rasp PI 4B for my 11 year old just today.
With just 2 PWM chanels but 4 outputs I had wondered if you can coltrol 4 servos independantly, turnd out you can. All working fine thanks, for the code really speeded things up for me, only used stepper motors before.
Thanks Chris, I think you just cured my MeArm's Parkinsons symptoms. It's driven by Arduino but got it with the intention to link up to the Pie instead. Never got around to it, thought the servo's were sketchy. Other commitments killed off any progression, that's all history 01/01/2020 😀
I find the Pi is much more interesting once you start interfacing it with the physical world. I already own four or five computers that are better than a Pi at everything else... but once you tinker with sensors, motors, hats, designing your own enclosures and so on, you find that there’s a real sense of achievement. Also, I am able to tell myself it doesn't matter if you nuke one... although I haven't lobotomised a single Raspberry Pi yet.
Reminds me of the days when I flew RC aircraft -- that was back in the late '80s and early '90s. We definitely didn't have anything like a Raspberry Pi to control them, however. :-) This looks like it would be a lot of fun to experiment with.
Fascinating to see this. There is a whole world of unused possibilities for the humble Pi. All explained impeccably. I reckon you could explain Einstein's special theory of relativity to a bunch of 8 year olds and they would all understand
I was planning to use something similar for my tv to pivot to the otherside of the room and vice versa and this solves the trickiest part of it actually. Now i have find some stronger servos...
Probably cheaper to use some limit switches and a normal geared motor... Heavy duty servos are expensive, plus servos tend to be designed to move rapidly to arbitrary precise positions, while it sounds like you just want 2 positions.
Been following your videos for some time. I like them all, but this one is by far my favorite. I now have a raspberry pi 4 B, partially due to some of the videos on raspberry pi that you have made. I would have purchased it from an Amazon affiliate link from your video if one existed. I'm not sure what that kind of thing entails but it might help to pay for future projects. I can't wait to see what you do with the servos in future videos. Would love to see you control the servos remotely through wifi. Thanks for the great videos. :D
lol. i am not that interested in computers but love learning and I love this video. well done and thank you. I do like rc cars and other rc stuff so this would something nice to incorporate into that. like have the pi control the lights so when you turn it puts on the directional. when you brake it but on the brake lights
@@ExplainingComputers It will be when I get that far. RIght now I'm having difficulty since eBay sellers are willing to sell but not to supply. If I was back in Swansea I could go to Tom Whitehouse in the market but I'm in South Carolina.
You are correct -- it is 0.02. There are time when I detest having a weekly schedule, which means I have to produce things so quickly that errors creep in and are not found. I will now have myself and this video for ages. :(
@@ExplainingComputers On the bright side, this is only your first mistake in 2020. But sadly, now you've used up your entire quota for the year, and it's only January.
That left me quite confused and I thought I had become stupid, thanks for the comment :) PS: does the Raspberry have enough resolution to impose a 20ms delay?
@@ExplainingComputers no worries better to make an erroe here and there and do exciting projects as these than neither!! Really loved this one! I am so excited to see more singleboard builds, possibly with item detection and some wheels under with various functionality, dare I say an arm that could fetch drinks? We are allowed to dream right? :)))
"That was one the most exciting things, ever." !! People may mock but you have to start somewhere if you want to build a self driving car. I started with a "blink" programme and it's still blinking..... Bob
if it's still blinking, that's better than when you do something more and it stops blinking... like how I find myself when I ignore pulldown resistors... or pullup?
03:10 Was that a "sponsored" comment? Just kidding. I'm sure we all rectified on our own. Nice video, really got me wanting to try my hands on basic robotics. 👍🏼
For some reason changing the duty cycle to 13.222 on SG90 will send the servo more than 180 degrees, maybe 320 degrees, but not to an angle, just adding to current angle, so if you change it to 13.222 twice it will go to 640 degrees counter-clockwise from the current position. Here is some code to make it spin continuously for 5 seconds import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) GPIO.setup(11,GPIO.OUT) servo1 = GPIO.PWM(11,50) servo1.start(0) count = 0 while (count < 10): print(count) servo1.ChangeDutyCycle(13.222222222222221) time.sleep(0.5) servo1.ChangeDutyCycle(0) count = count + 1 servo1.stop() GPIO.cleanup() print("Finished")
Nice work! Must say your video quality, camera work and editing are top notch! You make it look easy breezy but I sure there's heaps of production gone into every video. Chris rules!
This goes back a couple of decades for me, but it looks like the problem with driving servos directly from a microcontroller still exists. If you put an oscope on your pwm signal with the servo connected, you'll find a distortion on the waveform. This is happening because the servo controller is drawing more current than the MCU pin can supply. You can build or buy servo buffers that will fix this for you. The biggest issue with not fixing this is that with very high speed servos, the waveform can distort enough to "command" the servo into the stops on the gears. Since the motor still wants to spin, you get stripped gears.
Thanks for this, though I doubt that this is the case. The servo is not drawing significant current from the GPIO pin, and the signal on that pin is generated by software, not hardware. The software PWM signal will certainly vary, but not due to current draw. I think! :)
@@ExplainingComputers build yourself a simple buffer circuit and give it a try, I can't remember how many sets of gears I went through before learning this lesson. I did some quick web searching, and not finding something that was pretty easy to find back in about 1999. Some much garbage fills the search engines now. Some other info suggested that 5 volt signals may be to much for some servos, that 3.3 volts might work better and you could buffer this with a simple opto-isolator. I remember using some kind of common buffer chip, but not recollection of what it was.
I can only come back to my point that the PWM output from the Pi's GPIO pins is being generated by software code, not directly from any form of electronic circuitry. So it cannot be influenced by the current draw from the pin. Current draw could damage the pin, the Pi, or cause the Pi to reset perhaps. But unlike current drawn from a hardware PWM output, it cannot alter the pulse itself.
I can only confirm that controlling a servo with RPI was particularly exciting for me as an RPI enthusiast. This is the technology that inspires. Thanks again for an interesting Sunday.
2:12 "... in contrast a servo does not spin continuously, ..." That is not entirely accurate. Servo is a general term for a closed-loop system consisting of a motor, feedback, and, well, the control system. You can have speed servos that, as the name suggests, will maintain speed, given a reference. They do spin continuously at a set speed and (try to) maintain that speed as the load changes. What you describe in this video is a position servo, which spins to get to a position set by the reference.
I think you would really like using an arduino. Yeah, there are a lot of channels already doing stuff with arduino but I think you would like physical computing quite a bit.
Chris, that was a great explanation and very easy to follow....only thing i would like to see extra is how to control the speed. Could that be added sometime?
@13:30 Explained for my sanity. Duty cycles range from 2 to 12, which represent 0 to 180 degrees. So for our input variable "angle" you are using "angle/18" (to get 10 degree position steps out of 180 degrees). So for an input "angle" of 90 degrees, it would be 90/18=5 for the duty cycle. However if we gave 5 as a duty cycle in the range of 2 to 12, then this would effectively be a 3 and not 90 degrees, because 5 is not the midway point between 5 and 12, 7 is. So this is why we add 2 for the duty cycle position (5+2).
I am struggling with the concept of duty cycle to explain Pulse Width Modulation in the Raspberry Pi. To start with the wikipedia article and others about PWM for controlling RC servos says that a 1msec pulse turns the servo one way and a 2msec pulse turns it the other way, and therefore a 1.5msec pulse centers the servo. en.wikipedia.org/wiki/Servo_control . This is of course independent of the frequency of the pulses, whether they be one every 20msec or one a minute. This 1msec/2msec are generally the minimum/maximum values. Duty cycle usually should have a fixed frequency, but this is not mandatory. This is the width of the pulse relative to the period of the pulses. Within the Raspberry Pi software we are specifying a frequency of 50 Hertz, which gives a period of 20msec. A 20 msec pulse is 100% duty cycle, and a 10msec one is 50%. For a servo to get a pulse width of 1 msec, this is a duty cycle (50Hertz) of 5% and a 2msec pulse is 10%. The leap of faith that you have to have here is that in the software the value that you use to specify the pulse width is the duty cycle percentage. This is never stated explicitly. Testing with a couple of servos that I have in my collection, and guessing the angle as I don't have a protractor handy, and starting from a central position (1.5msec pulse specified as a 7.5% duty cycle) one servo arm moves +/- 45 degrees and the other moves just less than +/- 90 degrees. So whichever servo you use, testing is required. Good information about Servos www.pololu.com/blog/12/introduction-to-servos Deatil about using PWM for RC servo control: en.wikipedia.org/wiki/Servo_control Python PWM. To my mind uses the term 'duty cycle' rather than 'pulse width'. sourceforge.net/p/raspberry-gpio-python/wiki/PWM/
After a long daunting wait, I took the plunge into Windows 10 at the weekend. Not that I wanted to but it was the end of the road really and now I'll be feeding Microsoft a regular diet of my likes, dislikes, data, loads of encrypted data (hahaha), silly noises into microphones, random searches for 'strong XXXXL adult diapers' (to mess with the system) and the content of this fine channel. Take that Microsoft, and now I'm unpausing to watch a fine vid about servos.
Great explanation and code works 1st time Christopher, most excellent! I am brand new to raspberry pi and python. Q: Is there a code example that would repeat (or loop) the code 50 times? (Without copy and pasting code 50 times… lol) thanks again you are a great teacher. John
You could add something like this: count = 0 while count < 50 [SERVO CODE] count = count + 1 Note that here the code inside the while loop is indented with a tab. I have a Python intro video here: ua-cam.com/video/Crsp_He70no/v-deo.html
The straightforward precision with which you explain, diagram, apply and demonstrate is a refreshing and very QUICK way to learn! I've never been anywhere near a Rasberry Pi yet. But I can't wait to meet "familiar friends" when I finally get some! I find your dry humor a SCREAM! Thank you for making this topic interesting.
Interesting, though a bit difficult for amateurs like me... I extrapolate: we will be able to use this new knowledge soon, in particularly exciting fields! Can't wait! Thank you very much!
Servos... I don't think its your concern to conrol... you're computer, programming specialist so.... but if you want to enter in electronics control then go more deeper to work more like with microcontrollers, fpgas, PLCs, motors, Sensors to explain deeply...
4 роки тому+1
Micro servo motors are fine for learning, but they're too fragile for most real world applications. Personally I'm a fan stepper motors, they are robust, precise and you can literally find them in a trash area of any larger office building (you can find really lovely stepper motors in higher end commercial printers from brands like OKI or Kyocera). I have buit a reliable drive for a camera slider (with timelapse function) pretty much for free (I already had arduino, motor controller and some old li-po drone batteries)
Kinda time senstive but no rush obv. With the servo motor, what wire would fit in the holes along the servo? and how would you go about attaching said wire? do you just make a tiny knot so it doens't thread back through or is their an actual component you can buy?? THanks in advance!!!
Please setup one using NRF24L01 modules to wirelessly control servos on the pi. I've done it on arduino for a pan-tilt ESP32 camera mounting. I have uploaded my sketch on github and a youtube video on it using arduino. I would like to know how to do bi-directional communication as well.
How to set the initial position of servo motor, and all angles with relation to it? It always starts of at 45 degrees. Whenever I input 0 degrees for example it's at a 45 degrees angle. And when I input 45 degrees it's at a 90 degrees angle.
What kid wouldn't like to learn to code so he can control servos? The Raspberry Pi may be the greatest invention of the age -- it encourages young people to do something other than watch TV and play videogames. It encourages them to use their minds. And Chris is doing an excellent job of showing people what is possible with a Pi. Good job!
Chris, in many of your videos you're seen having a nice cuppa tea. I'm a tea drinker myself and would love to know what brand(s) you find go best with computer projects. I myself like Yorkshire Gold, P&G and Typhoo! Thanks and best regards from the Windy City!
Would you be interested in making a experimental video of jury rigging SBCs into gaming machines through hardware adapters? I would be interested into seeing how well that would turn out. For example some SBCs have 8gb of RAM and a PCI-e mobile port, a adapter could be used to house a PCI-e x16 v3 graphics card and the same with a Lenovo L440 and you could quite possibly compare it with a Asus gaming laptop. To make it all happen, you might need to collab with another youtuber computer enthusiast if you want fresh results.
This is the link for information on the Pi's GPIO pinout and GPIO functionality. There is nothing on servos or how to code for GPIO, which is the subject of this video. :)
@@ExplainingComputers You're right about that. So let me correct the sentence as follows. You must first go to the address I mentioned above and get preliminary information, then go to the address I will specify now and get more detailed information. Address: tutorials-raspberrypi.com/raspberry-pi-servo-motor-control/
RPI has two hardware PWM pins. Also you can try different lib (pigpio) which supports PWM by hardware timer. Maybe this could help to reduce jitter I have never used RPI with servo personally :)
As is my custom, I went to church this morning and then thought about Explaining Computers to watch this afternoon. I thought, "Wish he'd do another technical how-to type soon". In fact, that's how I found the channel a few years ago. I had a Raspberry Pi Model 1 B and wanted to learn about it and stumbled on to this channel and have been watching ever since. Much to my delight, this was the video waiting for me! Good deal. Thank you. I do like them all, but interested in this type of controller logic from time to time.
Honestly, automated window treatments sound inconsequential, but many a year ago, I worked in retail selling flooring...so naturally, I was required to sell window treatments too...(?). The amount of money they (the relatively few companies that offer custom window treatments) want just to mill custom window treatments is ridiculous (even more so when you see the margins they pull); but add "motorized" to any order & it would add more to the price of custom window treatments than any other option available. There were times, to motorize a standard sized shade, it would easily double/triple+ the price (& this was always assuming self-installation…). There are very few window treatments that are more complex than a single rotating metal rod. As a general public service, if you cannot find a UA-cam video to help...then out of a sense of moral/ethical duty to act, I would think EC would be compelled to take on the Custom Window Treatments cabal and their insatiable appetite for profit with just a single UA-cam video. Motorized aside, Window Treatments are one of the New Home Buyer's 1st or 2nd surprise dropkicks to the pants/trousers. It's definitely common in the States...not so sure about the UK....(?)
I modified the Go_to_Angle example and came up with this: # Script originally from Christopher Barnatt over at www.explainingcomputers.com. # Modified by Alex Landherr. Python Version: 3.7.3. # Import libraries import RPi.GPIO as GPIO import time # Set GPIO numbering mode GPIO.setmode(GPIO.BOARD) # Set pin 11 as an output, and define as servo1 as PWM pin GPIO.setup(11,GPIO.OUT) servo1 = GPIO.PWM(11,50) # pin 11 for servo1, pulse 50Hz # Start PWM running, with value of 0 (pulse off) servo1.start(0) # Loop to allow user to set servo angle. Exit command allows exit # with execution of servo.stop and GPIO cleanup :) while True: # Ask user for angle and turn servo to it angle = input('Enter angle between 0 & 180, type ''exit'' to exit program: ') if angle == 'exit': servo1.stop() GPIO.cleanup() print("Goodbye!") break int_angle = float(angle) servo1.ChangeDutyCycle(2+(int_angle/18)) time.sleep(0.5) servo1.ChangeDutyCycle(0)
Again, explaining computers makes a video I find interesting even though I never knew I had any interest in servos. 👏👍
One of the clearest explanations/demonstrations of using servos on the RPi. Also a good demonstration of using thonny.
Thank you for taking the extra effort to explain the python code. Also thank you for explaining the power supply requirements.
As the moment youtube notified me about this new video, I was watching Explaning Computers: the Latte Panda Delta Review. Bought two of those myself. :)
Thanks for watching! :)
Very interesting
I very much appreciate your comments which add a real world perspective.
For example, how the SG90 you used is the "most common type servo in the world" I just assumed it was a hobbyist piece of electronics. It really brings home how relevant what you are sharing is..
Thanks again
I’m building a little robotics platform for myself and had typed out a little Python Library for myself to handle the wheels but didn’t know for sure if the PWM methods could control more than one servo at a time. With this hindsight I realize it’d be a bit silly if it weren’t capable of doing so. Now I just have to remember where I saved the two libraries, test them out, and add in turning to the Wheel library. Thank you again for the awesome videos!
Good luck with your platform. :)
@@ExplainingComputers Thank you!
This is the most well documented piece of well put practical code I have ever seen, since witnessing Linus's kernel 1.0.
Thanks.
Not to argue with you, but, seemed more like 67,65 to me 😉.
Thanks as always for charing your knowledge with us.
Ordered a Rasp PI 4B for my 11 year old just today.
With just 2 PWM chanels but 4 outputs I had wondered if you can coltrol 4 servos independantly, turnd out you can. All working fine thanks, for the code really speeded things up for me, only used stepper motors before.
Glad you have moved on to SBC implementation.... Thanks for another interesting video....
Thanks Chris, I think you just cured my MeArm's Parkinsons symptoms. It's driven by Arduino but got it with the intention to link up to the Pie instead. Never got around to it, thought the servo's were sketchy. Other commitments killed off any progression, that's all history 01/01/2020 😀
Nice little tutorial better than most out there, hope u continue them and show us how to combine them into other codes and with other sensors.
finally after long time real projects
Glad you appreciated. More soon!
I find the Pi is much more interesting once you start interfacing it with the physical world. I already own four or five computers that are better than a Pi at everything else... but once you tinker with sensors, motors, hats, designing your own enclosures and so on, you find that there’s a real sense of achievement. Also, I am able to tell myself it doesn't matter if you nuke one... although I haven't lobotomised a single Raspberry Pi yet.
Why have I not subscribed to your channel already? You sir are one of awesomest dude around here! This is what I was looking for!
Welcome aboard!
Thankyou Sir ...it was a crystal clear content for a beginner working on servo with Raspberry Pi ....No words to say 😁
Reminds me of the days when I flew RC aircraft -- that was back in the late '80s and early '90s. We definitely didn't have anything like a Raspberry Pi to control them, however. :-) This looks like it would be a lot of fun to experiment with.
Love the Raspberry Pi content. Please keep it coming!
Fascinating to see this. There is a whole world of unused possibilities for the humble Pi. All explained impeccably. I reckon you could explain Einstein's special theory of relativity to a bunch of 8 year olds and they would all understand
I was planning to use something similar for my tv to pivot to the otherside of the room and vice versa and this solves the trickiest part of it actually. Now i have find some stronger servos...
There are some very big, heavy duty servos available! I had not thought of mounting a TV on one. You have now got me contemplating something!
Probably cheaper to use some limit switches and a normal geared motor... Heavy duty servos are expensive, plus servos tend to be designed to move rapidly to arbitrary precise positions, while it sounds like you just want 2 positions.
Been following your videos for some time. I like them all, but this one is by far my favorite.
I now have a raspberry pi 4 B, partially due to some of the videos on raspberry pi that you have made.
I would have purchased it from an Amazon affiliate link from your video if one existed. I'm not sure what that kind of thing entails but it might help to pay for future projects.
I can't wait to see what you do with the servos in future videos. Would love to see you control the servos remotely through wifi. Thanks for the great videos. :D
Excellent video and explanations. Thumbs up. Just on the side note - you could use a piece of something like Scotch tape to anchor the servos.
Thank you very much! I learned a lot from the no jitter
Thank you Professor! Fascinating, as always.
lol. i am not that interested in computers but love learning and I love this video. well done and thank you. I do like rc cars and other rc stuff so this would something nice to incorporate into that. like have the pi control the lights so when you turn it puts on the directional. when you brake it but on the brake lights
Excellent presentation. I'm going to have a fun time working out how to control two servoes on a Delta V-wing drone.
Sounds like a cool project.
@@ExplainingComputers It will be when I get that far. RIght now I'm having difficulty since eBay sellers are willing to sell but not to supply. If I was back in Swansea I could go to Tom Whitehouse in the market but I'm in South Carolina.
Just a heads up: at 3:19 you said that a pulse is expected every 0.2 seconds, whereas it should be 0.02 seconds.
You are correct -- it is 0.02. There are time when I detest having a weekly schedule, which means I have to produce things so quickly that errors creep in and are not found. I will now have myself and this video for ages. :(
@@ExplainingComputers On the bright side, this is only your first mistake in 2020. But sadly, now you've used up your entire quota for the year, and it's only January.
@@AnttiNannimus1 First and second mistake, he said PMW instead of PWM at 3:09 :)
That left me quite confused and I thought I had become stupid, thanks for the comment :)
PS: does the Raspberry have enough resolution to impose a 20ms delay?
@@ExplainingComputers no worries better to make an erroe here and there and do exciting projects as these than neither!! Really loved this one! I am so excited to see more singleboard builds, possibly with item detection and some wheels under with various functionality, dare I say an arm that could fetch drinks? We are allowed to dream right? :)))
Very helpfull. I like your Raspberry Pi projects. I always learn something new. Thank you.
Excellent servo motor tutorial, I really enjoy these resources. Thanks!
Nice demo thanks. I have a RPi but haven't used it with servos yet.
Thank you profesör. I from Turkey. 🙋♀️
"That was one the most exciting things, ever." !! People may mock but you have to start somewhere if you want to build a self driving car. I started with a "blink" programme and it's still blinking..... Bob
if it's still blinking, that's better than when you do something more and it stops blinking... like how I find myself when I ignore pulldown resistors... or pullup?
Brilliant explanation of the code Chris ......nice Vlog learned something today thank you 😀😀😀Kim😀😀😀
Very interresting video!
Please make more of this practical video's, where you can learn what fun stuff you can do with SBC'S.
alone in the kitchen figuring out servos and i couldnt help myself but to get embarrasingly jiggy with that intro beat . lmao
03:10 Was that a "sponsored" comment? Just kidding. I'm sure we all rectified on our own. Nice video, really got me wanting to try my hands on basic robotics. 👍🏼
I love any video you make. Always professional and always FULL of valuable information. It's like tech eye candy.
Instructions crystal clear
Thanks.
bloody awesome content as always mate, thanks a bunch!
Awesome!!! You explain very well, thank you!!!
Awesome channel. Simply love it 👍
Thanks.
I guess a rover making video is on the way....sir BTW very informative video.. :)
You can see where this is going . . .
@@ExplainingComputers 😀
Mr. & Mrs. Servo Motor...
Agreed: the most exciting thing ever!!! Thank you for the video.
For some reason changing the duty cycle to 13.222 on SG90 will send the servo more than 180 degrees, maybe 320 degrees, but not to an angle, just adding to current angle, so if you change it to 13.222 twice it will go to 640 degrees counter-clockwise from the current position.
Here is some code to make it spin continuously for 5 seconds
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(11,GPIO.OUT)
servo1 = GPIO.PWM(11,50)
servo1.start(0)
count = 0
while (count < 10):
print(count)
servo1.ChangeDutyCycle(13.222222222222221)
time.sleep(0.5)
servo1.ChangeDutyCycle(0)
count = count + 1
servo1.stop()
GPIO.cleanup()
print("Finished")
Nice work! Must say your video quality, camera work and editing are top notch! You make it look easy breezy but I sure there's heaps of production gone into every video. Chris rules!
Thanks for the Explaining, beautiful Presentation.
👍👍👍👍👍
Awesome video! Nicely paced and concise explanations. Thank you.
Thanks for your kind feedback, it is much appreciated.
This goes back a couple of decades for me, but it looks like the problem with driving servos directly from a microcontroller still exists. If you put an oscope on your pwm signal with the servo connected, you'll find a distortion on the waveform. This is happening because the servo controller is drawing more current than the MCU pin can supply. You can build or buy servo buffers that will fix this for you. The biggest issue with not fixing this is that with very high speed servos, the waveform can distort enough to "command" the servo into the stops on the gears. Since the motor still wants to spin, you get stripped gears.
Sorry for the editing, lots of failures with my typing today.
Thanks for this, though I doubt that this is the case. The servo is not drawing significant current from the GPIO pin, and the signal on that pin is generated by software, not hardware. The software PWM signal will certainly vary, but not due to current draw. I think! :)
@@ExplainingComputers build yourself a simple buffer circuit and give it a try, I can't remember how many sets of gears I went through before learning this lesson. I did some quick web searching, and not finding something that was pretty easy to find back in about 1999. Some much garbage fills the search engines now.
Some other info suggested that 5 volt signals may be to much for some servos, that 3.3 volts might work better and you could buffer this with a simple opto-isolator. I remember using some kind of common buffer chip, but not recollection of what it was.
I can only come back to my point that the PWM output from the Pi's GPIO pins is being generated by software code, not directly from any form of electronic circuitry. So it cannot be influenced by the current draw from the pin. Current draw could damage the pin, the Pi, or cause the Pi to reset perhaps. But unlike current drawn from a hardware PWM output, it cannot alter the pulse itself.
This is great, and very well explained!
thank you Mr.Chris
I was told running motors directly from the Pi was not recommended. Utilizing servos is a marvelous way to cicumvent this peccadillo.
This is true, as the servo includes its own motor controller.
@@ExplainingComputers That is good for us Pi noobs
I can only confirm that controlling a servo with RPI was particularly exciting for me as an RPI enthusiast. This is the technology that inspires. Thanks again for an interesting Sunday.
I think that there must be a Py2C which will produce machine code that can be compiled using gcc-arm.so to produce reasonably efficient machine code.
That was an amazingly detailed video!!
Thanks very much. On the contrary, very interesting and helpful.
2:12 "... in contrast a servo does not spin continuously, ..."
That is not entirely accurate. Servo is a general term for a closed-loop system consisting of a motor, feedback, and, well, the control system.
You can have speed servos that, as the name suggests, will maintain speed, given a reference. They do spin continuously at a set speed and (try to) maintain that speed as the load changes.
What you describe in this video is a position servo, which spins to get to a position set by the reference.
Thankyou for this, its just what I needed. Definitely earned a subscribe!
Excellent -- welcome aboard!
I enjoyed the video. Maybe i'll get a Pi and servos and program my own analogue clock with it.
You're the best, mil gracias inge.
Thanks.
I think you would really like using an arduino. Yeah, there are a lot of channels already doing stuff with arduino but I think you would like physical computing quite a bit.
Chris, that was a great explanation and very easy to follow....only thing i would like to see extra is how to control the speed. Could that be added sometime?
For speed control generally you would use a stepper motor.
@13:30 Explained for my sanity.
Duty cycles range from 2 to 12, which represent 0 to 180 degrees. So for our input variable "angle" you are using "angle/18" (to get 10 degree position steps out of 180 degrees). So for an input "angle" of 90 degrees, it would be 90/18=5 for the duty cycle. However if we gave 5 as a duty cycle in the range of 2 to 12, then this would effectively be a 3 and not 90 degrees, because 5 is not the midway point between 5 and 12, 7 is. So this is why we add 2 for the duty cycle position (5+2).
A great way to start the week!
Thanks Leslie! :)
I am struggling with the concept of duty cycle to explain Pulse Width Modulation in the Raspberry Pi. To start with the wikipedia article and others about PWM for controlling RC servos says that a 1msec pulse turns the servo one way and a 2msec pulse turns it the other way, and therefore a 1.5msec pulse centers the servo. en.wikipedia.org/wiki/Servo_control . This is of course independent of the frequency of the pulses, whether they be one every 20msec or one a minute. This 1msec/2msec are generally the minimum/maximum values.
Duty cycle usually should have a fixed frequency, but this is not mandatory. This is the width of the pulse relative to the period of the pulses. Within the Raspberry Pi software we are specifying a frequency of 50 Hertz, which gives a period of 20msec. A 20 msec pulse is 100% duty cycle, and a 10msec one is 50%. For a servo to get a pulse width of 1 msec, this is a duty cycle (50Hertz) of 5% and a 2msec pulse is 10%.
The leap of faith that you have to have here is that in the software the value that you use to specify the pulse width is the duty cycle percentage. This is never stated explicitly.
Testing with a couple of servos that I have in my collection, and guessing the angle as I don't have a protractor handy, and starting from a central position (1.5msec pulse specified as a 7.5% duty cycle) one servo arm moves +/- 45 degrees and the other moves just less than +/- 90 degrees. So whichever servo you use, testing is required.
Good information about Servos
www.pololu.com/blog/12/introduction-to-servos
Deatil about using PWM for RC servo control:
en.wikipedia.org/wiki/Servo_control
Python PWM. To my mind uses the term 'duty cycle' rather than 'pulse width'.
sourceforge.net/p/raspberry-gpio-python/wiki/PWM/
After a long daunting wait, I took the plunge into Windows 10 at the weekend.
Not that I wanted to but it was the end of the road really and now I'll be feeding Microsoft a regular diet of my likes, dislikes, data, loads of encrypted data (hahaha), silly noises into microphones, random searches for 'strong XXXXL adult diapers' (to mess with the system) and the content of this fine channel.
Take that Microsoft, and now I'm unpausing to watch a fine vid about servos.
Great explanation and code works 1st time Christopher, most excellent! I am brand new to raspberry pi and python. Q: Is there a code example that would repeat (or loop) the code 50 times? (Without copy and pasting code 50 times… lol) thanks again you are a great teacher. John
You could add something like this:
count = 0
while count < 50
[SERVO CODE]
count = count + 1
Note that here the code inside the while loop is indented with a tab.
I have a Python intro video here:
ua-cam.com/video/Crsp_He70no/v-deo.html
or you can use for loop:
for i in range(50):
servo code
The straightforward precision with which you explain, diagram, apply and demonstrate is a refreshing and very QUICK way to learn! I've never been anywhere near a Rasberry Pi yet. But I can't wait to meet "familiar friends" when I finally get some! I find your dry humor a SCREAM! Thank you for making this topic interesting.
Interesting, though a bit difficult for amateurs like me... I extrapolate: we will be able to use this new knowledge soon, in particularly exciting fields! Can't wait! Thank you very much!
Thanks for this -- keep watching! :)
Servos... I don't think its your concern to conrol... you're computer, programming specialist so.... but if you want to enter in electronics control then go more deeper to work more like with microcontrollers, fpgas, PLCs, motors, Sensors to explain deeply...
Micro servo motors are fine for learning, but they're too fragile for most real world applications. Personally I'm a fan stepper motors, they are robust, precise and you can literally find them in a trash area of any larger office building (you can find really lovely stepper motors in higher end commercial printers from brands like OKI or Kyocera). I have buit a reliable drive for a camera slider (with timelapse function) pretty much for free (I already had arduino, motor controller and some old li-po drone batteries)
Kinda time senstive but no rush obv. With the servo motor, what wire would fit in the holes along the servo? and how would you go about attaching said wire? do you just make a tiny knot so it doens't thread back through or is their an actual component you can buy?? THanks in advance!!!
Please setup one using NRF24L01 modules to wirelessly control servos on the pi. I've done it on arduino for a pan-tilt ESP32 camera mounting. I have uploaded my sketch on github and a youtube video on it using arduino. I would like to know how to do bi-directional communication as well.
This is really interesting and I look forward to seeing what projects you have in store! Thank you.
Thanks! I am going to use this to teach kids how to make a cat feeder.
Excellent! :) You may be interested in the video I did making a hamster feeder with servos . . . ua-cam.com/video/lT4AZAJdtAs/v-deo.html
How to set the initial position of servo motor, and all angles with relation to it? It always starts of at 45 degrees. Whenever I input 0 degrees for example it's at a 45 degrees angle. And when I input 45 degrees it's at a 90 degrees angle.
I'm surprised hardware PWM has not need added to latest boards for sure I noticed that PWM control on LEDs is glitcchy.
What kid wouldn't like to learn to code so he can control servos? The Raspberry Pi may be the greatest invention of the age -- it encourages young people to do something other than watch TV and play videogames. It encourages them to use their minds. And Chris is doing an excellent job of showing people what is possible with a Pi. Good job!
Thanks.
Another wonderful video! Love from Johannesburg, South Africa ❤️
Absolutely riveting 🧐
Me > Watches video.
> ...
> Adds a dozen servos to wishlist.
Thank you for another enjoyable video. Cheers.
Chris, in many of your videos you're seen having a nice cuppa tea. I'm a tea drinker myself and would love to know what brand(s) you find go best with computer projects. I myself like Yorkshire Gold, P&G and Typhoo! Thanks and best regards from the Windy City!
I usually drinkg Tetley or Typhoo. :)
RP has build in PWM. Running this as bit-bang PWM is unnecessary and inaccurate, and takes the entire CPU
Would you be interested in making a experimental video of jury rigging SBCs into gaming machines through hardware adapters? I would be interested into seeing how well that would turn out.
For example some SBCs have 8gb of RAM and a PCI-e mobile port, a adapter could be used to house a PCI-e x16 v3 graphics card and the same with a Lenovo L440 and you could quite possibly compare it with a Asus gaming laptop.
To make it all happen, you might need to collab with another youtuber computer enthusiast if you want fresh results.
For detailed information, you can look this address: www.raspberrypi.org/documentation/usage/gpio/
This is the link for information on the Pi's GPIO pinout and GPIO functionality. There is nothing on servos or how to code for GPIO, which is the subject of this video. :)
@@ExplainingComputers
You're right about that. So let me correct the sentence as follows. You must first go to the address I mentioned above and get preliminary information, then go to the address I will specify now and get more detailed information.
Address: tutorials-raspberrypi.com/raspberry-pi-servo-motor-control/
RPI has two hardware PWM pins. Also you can try different lib (pigpio) which supports PWM by hardware timer. Maybe this could help to reduce jitter I have never used RPI with servo personally :)
Could you please make a video for controlling the servo using raspberry pi keyboard and mouse
A motor can only spin. A Servo can holds the torqur or the position of the arm.
I have an extra pi 3, so yeah, I need to learn this stuff.
He’s giving a pi 🕵️♂️ a serve!
very helpful, thank you
As is my custom, I went to church this morning and then thought about Explaining Computers to watch this afternoon. I thought, "Wish he'd do another technical how-to type soon". In fact, that's how I found the channel a few years ago. I had a Raspberry Pi Model 1 B and wanted to learn about it and stumbled on to this channel and have been watching ever since. Much to my delight, this was the video waiting for me! Good deal. Thank you. I do like them all, but interested in this type of controller logic from time to time.
@3.16 Question, 50 Hz is 50 cycles per second, so how come you say a pulse is expected every 0.2 seconds? Isn't it every 0.02 seconds?
I would love to see a build guide for a home automation unit with these motors for raising and lowering window blinds.
stepper motors would be better, they have continuous rotation, search for
"home automation blinds" on youtube : the hookup and drzzs
Honestly, automated window treatments sound inconsequential, but many a year ago, I worked in retail selling flooring...so naturally, I was required to sell window treatments too...(?).
The amount of money they (the relatively few companies that offer custom window treatments) want just to mill custom window treatments is ridiculous (even more so when you see the margins they pull); but add "motorized" to any order & it would add more to the price of custom window treatments than any other option available. There were times, to motorize a standard sized shade, it would easily double/triple+ the price (& this was always assuming self-installation…).
There are very few window treatments that are more complex than a single rotating metal rod. As a general public service, if you cannot find a UA-cam video to help...then out of a sense of moral/ethical duty to act, I would think EC would be compelled to take on the Custom Window Treatments cabal and their insatiable appetite for profit with just a single UA-cam video.
Motorized aside, Window Treatments are one of the New Home Buyer's 1st or 2nd surprise dropkicks to the pants/trousers. It's definitely common in the States...not so sure about the UK....(?)
@@jyvben1520 Thanks my man! Will definitely look that up
when someone shows their code on youtube does anyone else try to scroll the screen down so you can see the rest of it?
I am always trying to scroll (or click on) computer screens shown in videos! :)
Yep, me too....
I watch Tim Pool's videos about news events, and I'm constantly trying to scroll the pages or un-pause the videos he has open.
It's worse to try an rotate a .jpeg image as if it were a 3D CAD file
3:40 for the famous sg90 the correcrt duty cycle is 5%-10%
In the video, it is claimed that the code is available. Where is it?
As indicated with the link in the second line of the video description it is here :) www.explainingcomputers.com/pi_servos_video.html
I like his accent it make the video intresting
do not mind my typos
I modified the Go_to_Angle example and came up with this:
# Script originally from Christopher Barnatt over at www.explainingcomputers.com.
# Modified by Alex Landherr. Python Version: 3.7.3.
# Import libraries
import RPi.GPIO as GPIO
import time
# Set GPIO numbering mode
GPIO.setmode(GPIO.BOARD)
# Set pin 11 as an output, and define as servo1 as PWM pin
GPIO.setup(11,GPIO.OUT)
servo1 = GPIO.PWM(11,50) # pin 11 for servo1, pulse 50Hz
# Start PWM running, with value of 0 (pulse off)
servo1.start(0)
# Loop to allow user to set servo angle. Exit command allows exit
# with execution of servo.stop and GPIO cleanup :)
while True:
# Ask user for angle and turn servo to it
angle = input('Enter angle between 0 & 180, type ''exit'' to exit program: ')
if angle == 'exit':
servo1.stop()
GPIO.cleanup()
print("Goodbye!")
break
int_angle = float(angle)
servo1.ChangeDutyCycle(2+(int_angle/18))
time.sleep(0.5)
servo1.ChangeDutyCycle(0)
Thank you for the informative video. Best wishes.