Stepper Motor Control with the Raspberry Pi

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 มิ.ย. 2024
  • This video outlines both how stepper motors work, and how to control one using the Raspberry Pi.
    Learn more about programming, electronics, and the Raspberry Pi at:
    cutequbit.zapto.org

ความคิดเห็น • 146

  • @wolfman5555
    @wolfman5555 9 ปีที่แล้ว +17

    I happened by chance onto this video. I have to say that your explanation of how Stepper Motors function Is the best and most understandable one I have ever seen. I eagerly look further to viewing your other videos. Thanks

  • @Vokietas
    @Vokietas 7 หลายเดือนก่อน

    I just wish I had seen this video 10 years or anything in between ago... Great video- explains not even how the control works, but the physics behind it too. Thank you!

  • @LawrenceKesteloot
    @LawrenceKesteloot 10 ปีที่แล้ว

    Thank you for spending so much time making these videos! They're extremely well done.

  • @dandlmorrish
    @dandlmorrish 8 ปีที่แล้ว +1

    What a wonderfully explained tutorial. As someone who likes to know WHY not just HOW things work in the way that they do I can't thank you enough.
    My colleagues and I are attempting to construct an automated visual inspection rig using the Raspberry Pi as the PLC and operating the camera module in conjunction with a 12V RGB LED strip.
    The motor control will drive a turntable and is more or less the last piece of the jigsaw puzzle and I think you have just helped us solve it. Thank you very much.

  • @nirgalZG
    @nirgalZG 8 ปีที่แล้ว +50

    Before I watched the video I didn't believe that stepper motor control could be explained thoroughly in less than 10 minutes.
    Apparently it can :-)

  • @JeremieFrancois
    @JeremieFrancois 10 ปีที่แล้ว +8

    Outstanding! So clear and still, you manage to go into details. Really good tutorial, thanks. Really well done :)

  • @travisbenge1912
    @travisbenge1912 7 ปีที่แล้ว

    Really enjoy the explanation and breakdown of components. Great work!

  • @MrMr999Mr
    @MrMr999Mr 10 ปีที่แล้ว

    Excellent video! This is the best video I have seen on stepper motors. Thank-you for making and sharing it.

  • @timnixon2889
    @timnixon2889 7 ปีที่แล้ว +12

    IMHO this is very well though out and wonderfully explained

  • @michaelhawthorne8696
    @michaelhawthorne8696 8 ปีที่แล้ว +3

    That has to be the best explanation I have heard on how stepper motors work... thanks for that....sub'd

  • @BubuHaque
    @BubuHaque 5 ปีที่แล้ว

    thank you! Your explanation was super detailed, clear and easy to understand!

  • @siavashnoorb9604
    @siavashnoorb9604 3 ปีที่แล้ว

    Brilliant explanation! Answered heaps of my questions. Thank you so much!

  • @Pigcogames
    @Pigcogames 4 ปีที่แล้ว

    You are a godsend, this has been so helpful in creating a stepper motor face. Which sounds weird, but it'll be great thanks to this tutorial

  • @Ruben-cs6we
    @Ruben-cs6we 3 ปีที่แล้ว

    Finally, I cannot thank you enough. Great video even after al these years.

  • @lemkil76
    @lemkil76 3 ปีที่แล้ว

    Liked this video a lot. Seen several stepper motor videos but your's is the best. Keep it up man!

  • @NilsBelde
    @NilsBelde 6 ปีที่แล้ว

    Gaven, excellent explanation of a difficult issue. One of the best like/dislike ratio I have ever seen.

  • @ChipHirn
    @ChipHirn 10 ปีที่แล้ว +2

    Excellent video and great tutoring!! To everyone who is interested: If you type the motor's name into the amazon search bar, you will find the exact same board and motor used in this video, as well as a board without the leds. The single uln2003a ic is also available everywhere for less than two bucks. I will use my hereby aquired knowledge to build a tiny desktop plotter and a picamera control! ;)

  • @JonneyGee
    @JonneyGee 8 ปีที่แล้ว +2

    Great tutorial! Thanks for posting!

  • @abibubbly
    @abibubbly 5 ปีที่แล้ว

    The info provided is rich, helpful and complete!

  • @matthiasgehrmann1573
    @matthiasgehrmann1573 6 ปีที่แล้ว

    thank you very much for this in-depth tutorial... really awesome !

  • @jimmygore8214
    @jimmygore8214 ปีที่แล้ว

    Still works almost ten years later!! 😃

  • @SuperAn0nymus
    @SuperAn0nymus 8 ปีที่แล้ว +2

    WoWWW!!! What an explanation! 💪🏻🙏🏻😊 Love it!

  • @KaletheQuick
    @KaletheQuick 6 ปีที่แล้ว

    Great video, very concise. Especially the end. I just skipped there because I knew how the motor worked already.

  • @choahjinhuay
    @choahjinhuay ปีที่แล้ว

    Thank you so much for this tutorial!! It’s been so helpful

  • @omarherrera1786
    @omarherrera1786 10 ปีที่แล้ว

    Thank you very much for your videos, your videos are very clear. I really like your videos.

  • @andenandenia
    @andenandenia 5 ปีที่แล้ว +25

    import RPi.GPIO as GPIO
    import time
    GPIO.setmode (GPIO.BOARD)
    ControlPin = [7,11,13,15]
    for pin in ControlPin:
    GPIO.setup (pin, GPIO.OUT)
    GPIO.output (pin, 0)
    seg = [ [1,0,0,0],
    [1,1,0,0],
    [0,1,0,0],
    [0,1,1,0],
    [0,0,1,0],
    [0,0,1,1],
    [0,0,0,1],
    [1,0,0,1] ]
    for i in range (512):
    for halfstep in range (8):
    for pin in range (4):
    GPIO.output (ControlPin[pin], seg[halfstep][pin])
    time.sleep (0.001)
    GPIO.cleanup()

    • @windows10person30
      @windows10person30 5 ปีที่แล้ว

      how to fix "Non-ASCII character /d3f in line 27?

    • @CrystalDataMusic
      @CrystalDataMusic 4 ปีที่แล้ว

      @@windows10person30 Probably a problem with the copy/paste using a special format for a comma or something, try rewriting the line.

    • @windows10person30
      @windows10person30 4 ปีที่แล้ว

      @@CrystalDataMusic Thaks, I just typed it ad it worked, thanks!

    • @CrystalDataMusic
      @CrystalDataMusic 4 ปีที่แล้ว

      @@windows10person30 Happy to help!

  • @ammoniumhydroxide9739
    @ammoniumhydroxide9739 3 ปีที่แล้ว

    This is a great video. Very instructive.

  • @dexterwouters4949
    @dexterwouters4949 6 ปีที่แล้ว

    this is very well explained. Thanks

  • @BStateham
    @BStateham 8 ปีที่แล้ว +7

    Awesome video.

  • @citojaya1904
    @citojaya1904 7 ปีที่แล้ว

    Excellent job, keep up the good work

  • @splortz
    @splortz 9 ปีที่แล้ว

    A great explanation of a process that seems complex. Stepper motors are used in so many applications, knowing how they work and are controlled is very useful. Thanks!

    • @user-mb1xu8wk5h
      @user-mb1xu8wk5h 9 ปีที่แล้ว

      splortz I was use GPIO direct drive 8 digital 7 segment and LCD1602*1 and 12 stepper motors

  • @ConsertandoTudo
    @ConsertandoTudo 6 ปีที่แล้ว

    Great tutorial! Amazing!

  • @TheRsalinas21
    @TheRsalinas21 10 ปีที่แล้ว

    Awesome tutorial!

  • @updowndown
    @updowndown  10 ปีที่แล้ว +4

    The control board I used came with the stepper motor. Aside from the debugging LEDs (with resistors) it only has an ULN2003AN chip.
    With regards to the pins, 4 GPIO pins attach to 4 pins on the board (labeled IN1, IN2, etc...) and ground and 5V attach to a second 2 pin header. Hope that helps.

    • @edatoloch4938
      @edatoloch4938 2 ปีที่แล้ว

      Would it work without it?

  • @gghsusa
    @gghsusa 9 ปีที่แล้ว

    I really appreciate your excellent explanation of stepper motors and using Python on the Pi. I just happen to have this exact same motor so I used the same seq config in my script. I'm using the Pi to automatically control my wood stove by using a thermocouple as input. Thanks!

  • @fungoro
    @fungoro 11 ปีที่แล้ว

    thank you for this video, needed

  • @CyberAwed
    @CyberAwed 8 ปีที่แล้ว

    Excellent job!

  • @ulrichjudmayr-konrad6467
    @ulrichjudmayr-konrad6467 10 ปีที่แล้ว

    great tut! i have read several times that rpi gpio is sensitive to overvoltage since its only 3.3v internally, and that motor(-driver)s on top of this may bleed back spikes when the magnets stop... how do you address this in your setup?

  • @Bianchi77
    @Bianchi77 2 ปีที่แล้ว

    Nice info, thanks for sharing it:)

  • @brutesque
    @brutesque 10 ปีที่แล้ว

    great video!

  • @virendersingh9377
    @virendersingh9377 7 ปีที่แล้ว

    Brilliant explanation. I could now write my own program. However, I could see that using c# on windows iot and Raspberry pi3. The same time delay makes my motor much slower then yours. What could the reason be?

  • @subhashchalapati
    @subhashchalapati 7 ปีที่แล้ว

    nice explanation .I like it

  • @virtualan
    @virtualan 9 ปีที่แล้ว

    Good stuff! Thanks!

  • @neovictorius
    @neovictorius 7 ปีที่แล้ว +2

    What if you wanted the stepper motor to turn the other way round? Would you just reverse the array elements?

  • @jshriverOH
    @jshriverOH 10 ปีที่แล้ว

    Also curious how many of these motors and control boards can you use with a single pi? A project I'm thinking of would required 3-4.

  • @updowndown
    @updowndown  10 ปีที่แล้ว

    The Pi has 17 GPIO, which means you could run 4 stepper motors directly from the Pi (as each requires 4 GPIO pins), though some of those pins may need to be reconfigured, such as the UART pins. If you need more GPIO pins, check out the MCP23017 I2C port expander.

  • @sandy-se7ky
    @sandy-se7ky 3 ปีที่แล้ว

    Very informative video.
    Bro please let me know how to reverse the direction?

  • @SmashAnimations
    @SmashAnimations 10 ปีที่แล้ว

    would love to know if you need the stepper motor control board... The stepper motor i have is from a printer and has its own separate power cable. Could i go straight from the GPIO into the stepper then? considering the stepper motor isn't getting the power from the Raspberry pi?

  • @patricklim8258
    @patricklim8258 2 ปีที่แล้ว

    Thank for your clear TH-cam Stepper Motor Control with the RPi,
    As a beginner wish to test around my pi with the stepper Motor Control , as shown, how can I obtain the sample py code. Do you leave the demo code online? Thank you.

  • @SriniRRSrini7
    @SriniRRSrini7 9 ปีที่แล้ว

    Excellent. Is it "ULN2003 Stepper Motor Driver" used ?

  • @chiragvaghmare5648
    @chiragvaghmare5648 4 ปีที่แล้ว

    Very very very good job !

  • @alyssahillton895
    @alyssahillton895 2 ปีที่แล้ว

    Great video thank you so much for the help!!! One question, how would i make this go counter clockwise? :)

  • @westonbrierley2087
    @westonbrierley2087 5 ปีที่แล้ว +2

    So what aplacatoin do I run the code in? And in the python 3 application it says ControlPin is an invalad syntax.

  • @pvinis
    @pvinis 11 ปีที่แล้ว

    great video indeed

  • @YourMJK
    @YourMJK 9 ปีที่แล้ว

    So in order to spin it the other direction I just have to read the array (first dimension) from behind (index 7, 6, 5, 4, 3, 2, 1, 0)
    Right?

  • @jshriverOH
    @jshriverOH 10 ปีที่แล้ว +1

    This mentions the motor model # but not the control board and which pins specifically on the pi needs to go to which pins on the controller board.

  • @sarson29
    @sarson29 10 ปีที่แล้ว

    very well done

  • @TheJupiter732
    @TheJupiter732 10 ปีที่แล้ว

    Excellent!

  • @pu7iss
    @pu7iss 8 ปีที่แล้ว

    Hello Gaven !!
    I have a doubt, I raspberry pi 2 and I'm not getting set to run 120 degrees ie it go back and forth automatically, you can explain to me please?
    Thank You
    Adalberto / Brazil

  • @moheebtariq2499
    @moheebtariq2499 7 ปีที่แล้ว

    this is nice thank you very much

  • @SonyLonySony
    @SonyLonySony 9 ปีที่แล้ว

    Hi, it is also possible to connect several RaspberryPiB + by the number of training with each other / and to be able to constantly expand inputs? Which then of course be controlled with a Python script?

  • @gamedude1861
    @gamedude1861 4 ปีที่แล้ว

    I have bought the motor and the programme also worked. There was also something moving in the motor but this metal part that should move didn't. I opened it and saw that the gear from the magnets did move but it couldn't move the next gear and only scratched it. Does anyone know how to fix this? Thank you in advance.

  • @hortenseperruchio1508
    @hortenseperruchio1508 4 หลายเดือนก่อน

    Do you know how to plug on a simple raspberry p pico ?

  • @sahanakulkarni4795
    @sahanakulkarni4795 3 ปีที่แล้ว

    How can I make stepper motor stop at particular angle for some time and move again?

  • @AtaZ0tH
    @AtaZ0tH 3 ปีที่แล้ว

    Thanks, really nice explanation, very educational. On a closer look I see that at 1:39 the gears inside are not in the right order and the motor won't work as shown. I guess after you initially tore the motor down, when you reassembled it for the video you accidentally flipped the gear next to the blue one upside down.

  • @updowndown
    @updowndown  10 ปีที่แล้ว

    I'd first try searching the web for a datasheet. If one can't be found, I'd still worry about connecting a GPIO pin directly to a wire which I'm unsure of its function. I'd definitely use protection, at the very least a transistor. The stepper motor is this video uses a darlington array (uln2003).

  • @magnussenpaetur
    @magnussenpaetur 7 ปีที่แล้ว

    How would you make it spin faster? Is there a way to make it spin faster without adjust the milliseconds? I'm rewriting this code in JavaScript and can't seem to make the timer take a value less than 1 millisecond

  • @exonax4188
    @exonax4188 3 ปีที่แล้ว

    Can this motor be use with a controller like a b10k?

  • @TheNikolaschoulakis
    @TheNikolaschoulakis 6 ปีที่แล้ว +2

    Can u post the code pls?

  • @LargeGreenMan11
    @LargeGreenMan11 10 ปีที่แล้ว

    This may sound a stupid question, but I don't want the motor to run a prewritten program, I would like to type commands in to move the motor in a certain direction by a certain amount. Is this possible using python.

  • @zynthos9
    @zynthos9 9 ปีที่แล้ว +1

    Where did you come up with 1ms value for the delay?
    Arbitrary?

    • @idjles
      @idjles 7 ปีที่แล้ว +1

      yes, because it gave him the speed he wanted! you can speed up or slow it down. too fast makes the motor shake and not turn.

  • @cyclessaga8234
    @cyclessaga8234 10 ปีที่แล้ว

    great tutorial! Could you please share a diagram?

  • @searchthescripturessts6707
    @searchthescripturessts6707 2 ปีที่แล้ว

    I get this error please set pin numbering mode using GPIO.setmode(GPIO.BOARD) or GPIO.setmode(GPIO.BCM). How do I fix it?

  • @freemanfreed1581
    @freemanfreed1581 4 ปีที่แล้ว

    Can you make a stepper motor rotate 52.24 degrees only using raspberry pi or Arduino? how? what about a DC motor?

  • @georgegardner1165
    @georgegardner1165 7 ปีที่แล้ว

    how this be wired up using a raspberry pi 3 and jumper wires

  • @MaxMuelller
    @MaxMuelller 8 ปีที่แล้ว

    Hervorragendes Video! Hut ab, vor jemanden, der sich soviel Mühe gibt.
    Leider sieht es so aus, als muesste man das Listing abschreiben. Dennoch: TOLL

    • @TheDudeSvU
      @TheDudeSvU 7 ปีที่แล้ว

      I like the way you assume he speaks german lol

  • @mrcake4525
    @mrcake4525 7 ปีที่แล้ว

    thanks m8!

  • @shukhratdad9891
    @shukhratdad9891 3 ปีที่แล้ว

    Hello.Can you show how to solve gpio get permission, add group ...etc. ? Pi4

  • @Zueli87
    @Zueli87 3 ปีที่แล้ว +1

    Hey, is it possible to spin the motor faster with a simillar or different code? And how you would do this?

    • @oliverlee582
      @oliverlee582 3 ปีที่แล้ว +1

      One way would be to reduce the time delay, but eventually, the motor won't be able to respond because it's so fast. Maybe you could look into a faster sequence of coils? I'm not sure

  • @nehasankhe664
    @nehasankhe664 3 ปีที่แล้ว

    Which driver is used here!?

  • @clearly_blurry3416
    @clearly_blurry3416 6 ปีที่แล้ว

    Are the lights on the stepper motor supposed to come on as soon as power is applied or only when the code runs?

  • @cdef4321
    @cdef4321 2 ปีที่แล้ว

    Where do you put wires though????

  • @michaelsoares8160
    @michaelsoares8160 3 หลายเดือนก่อน

    What is this daughter board control board?

  • @stefanRastocky
    @stefanRastocky 9 ปีที่แล้ว

    What did you use the lan cable for? Connection to a laptop?

    • @JonneyGee
      @JonneyGee 8 ปีที่แล้ว

      +Štefan Restock Probably to SSH into the Pi from another computer.

  • @dmitryponyatov2158
    @dmitryponyatov2158 9 ปีที่แล้ว

    And tadam you can easily connect MCU to any computer, x86 desktop, or Pi using USB (use old cellphone serial cable or brew it yourself with FT232/CP21xx chip)

  • @zynthos9
    @zynthos9 9 ปีที่แล้ว

    Also, why do you (seemingly) not consider how much current the motor will be drawing from the RPi 5v pin?

    • @sergioaiello7135
      @sergioaiello7135 4 ปีที่แล้ว

      0,5mA for every pin set to 1 - just measured

  • @arieagustino9906
    @arieagustino9906 5 ปีที่แล้ว

    I try the code but it keep send me error "attribute error : 'int' object has no attribute 'seq')

  • @paulpatterson6090
    @paulpatterson6090 5 ปีที่แล้ว +1

    Most people struggle with controlling the speed of the stepper motor, more than controlling the location and step control.

  • @NicolajTopp
    @NicolajTopp 10 ปีที่แล้ว +1

    Since I need 4 GPIOs for one stepper motor, how can I address let's say 4 different motors? Or 4 motors and 3 servos? Or a bunch of motors and some GPIOs for other sensors?

    • @henk6172
      @henk6172 9 ปีที่แล้ว

      You have to buy multiple pi's.

    • @Ziplock9000
      @Ziplock9000 8 ปีที่แล้ว

      +Harm Prins I bet there's controller boards out there that can run several stepper motors.

    • @henk6172
      @henk6172 8 ปีที่แล้ว +3

      John Michael Stock yeah looking at my comment one year later makes me realise it was kinda dumb. using i2c would be the best solution in my opinion, because you could, if you really wanted, control 32 steppers using only the two i2c pins. and of course, there are microcontrollers designed to run stepper motors which would work too.

    • @shimuk8
      @shimuk8 6 ปีที่แล้ว

      and reading your comment after 2 years saved me !! I was so worried about this as well hahaha... btw can you please tell me which i2c chip you used... i am kind a new to this actually... I was looking at L298N chip... not sure if that's the right one :3

  • @AnarchisticCookie
    @AnarchisticCookie 10 ปีที่แล้ว

    you could write a function that moves the motor by a given amount, and get this amount from the user using raw_input. I'm no expert, but I think that would work.

  • @electrosnerd
    @electrosnerd 9 ปีที่แล้ว

    Not that I'm an expert here, in fact very far from it, but I think your last time.sleep(0.001) line should be indented in one more tab so it starts under the last GPIO.output line. Spent quite a while trying to get this to work and for me found it was the problem. All OK now though.

  • @digital_soldier4768
    @digital_soldier4768 หลายเดือนก่อน

    what about a pin sheet though

  • @FeliciaKrismanta
    @FeliciaKrismanta 6 ปีที่แล้ว

    How to change the code to make it rotate counterclockwise?

    • @CrystalDataMusic
      @CrystalDataMusic 4 ปีที่แล้ว

      GPIO.output(ControlPin[pin], seg[-1 * halfstep][pin]) #just multiply halfstep by -1

  • @suvambasak9313
    @suvambasak9313 6 ปีที่แล้ว

    Is it safe to supply stepper motor directly from PI ?

    • @sergioaiello7135
      @sergioaiello7135 4 ปีที่แล้ว

      160 mA for every pin set yo 1 - NOT recommended

  • @rlrsk8r1
    @rlrsk8r1 8 ปีที่แล้ว +7

    I go to aviation mechanic school, and most of my classmates can't even figure out how to flush a toilet. I think it's important for everyone to know.

  • @nathanarmstrong5620
    @nathanarmstrong5620 8 ปีที่แล้ว

    How do you reset the stepper motor to a fixed spot if for whatever reason you don't make a complete revolution.

    • @JamesChapmanSK
      @JamesChapmanSK 8 ปีที่แล้ว

      Maybe keep a counter that gets incremented for every (half) step you take, and then if you want to go back to the fixed spot, reverse the 2D array he has in the video and go up to the amount of steps you took in the first direction.

  • @himanshusingh623
    @himanshusingh623 6 ปีที่แล้ว

    Can anyone, please, tell me if I can use ControlPin=[7,11,13,15] in Raspberry Pi 3 also?

    • @DobraEspacial
      @DobraEspacial 6 ปีที่แล้ว

      Yes, you can, they are all GPIO.

  • @NoahSG05
    @NoahSG05 7 ปีที่แล้ว

    the link doesnt work

  • @chuc2rk
    @chuc2rk 10 ปีที่แล้ว

    good python program!

  • @coding4me440
    @coding4me440 6 ปีที่แล้ว

    luckily i had the motor and shield