Controlling Large Stepper Motor With Raspberry Pi

แชร์
ฝัง
  • เผยแพร่เมื่อ 15 ก.ย. 2023
  • In this video I will demonstrate the wiring and coding to control a Nema23 stepper motor with a Raspberry Pi.
    Links
    Stepper Motor Driver
    www.amazon.com/dp/B06Y5VPSFN?...
    Stepper Motor Mount
    www.amazon.com/dp/B00Q6GIO5K?...
    Nema 23 Stepper Motor
    www.amazon.com/dp/B00PNEPW4C?...
    Raspberry Pi Kit
    www.amazon.com/dp/B07BDRD3LP?...
    48 VDC Power Supply
    www.amazon.com/dp/B075ZT5TNF?...
    Python Code (Note some formatting may be lost)
    from time import sleep
    import RPi.GPIO as gpio
    direction_pin = 20
    pulse_pin = 21
    cw_direction = 0
    ccw_direction = 1
    gpio.setmode(gpio.BCM)
    gpio.setup(direction_pin, gpio.OUT)
    gpio.setup(pulse_pin, gpio.OUT)
    gpio.output(direction_pin,cw_direction)
    try:
    while True:
    print('Direction CW')
    sleep(.5)
    gpio.output(direction_pin,cw_direction)
    for x in range(200):
    gpio.output(pulse_pin,gpio.HIGH)
    sleep(.001)
    gpio.output(pulse_pin,gpio.LOW)
    sleep(.0005)
    print('Direction CCW')
    sleep(.5)
    gpio.output(direction_pin,ccw_direction)
    for x in range(200):
    gpio.output(pulse_pin,gpio.HIGH)
    sleep(.001)
    gpio.output(pulse_pin,gpio.LOW)
    sleep(.0005)
    except KeyboardInterrupt:
    gpio.cleanup()
  • แนวปฏิบัติและการใช้ชีวิต

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

  • @rexmyers991
    @rexmyers991 8 หลายเดือนก่อน +18

    Mr. Lee, I am 80:years old and that is the FIRST time I have understood computer code. THANK YOU SO MUCH. I am a self taught machinist (starting 15 years ago) and your videos have helped me to be a much better skilled machinist. CNC (and stepper motor logic) are way beyond my goals, but at least it’s not a mystery anymore.

  • @fredberry1342
    @fredberry1342 7 หลายเดือนก่อน +2

    It's nice to see you combine a little bit of programming with a little bit of rock and roll. Thanks for the videos sir.

  • @MCobra3050
    @MCobra3050 2 หลายเดือนก่อน +1

    Switch 4 for half current reduces the current when the stepper is not running. It helps keep the heat down when not stepping. It has no effect on operation. Excellent video.

  • @jamesbowenjr.3022
    @jamesbowenjr.3022 6 หลายเดือนก่อน +1

    So now this will eliminate the motor with the adjustable arm that you had on the surface grinder awhile back. This looks much better and easier I think. Thanks for all the detail.

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

    I'm an old programmer too, also setup a hobby machine shop. But i haven't retired yet, so I'm living a bit vicariously watching what kind of trouble you can get into. Lol😊

  • @teropiispala2576
    @teropiispala2576 8 หลายเดือนก่อน +4

    I've been using raspberry pi to drive my mill for few years. I use my own fast direct io library and c++ to drive the stepper. I run my control loop in 1us cycle time, which might sound overkill, but it's best to reserve one core for driving task anyway. There are lots of benefits, allowing smoother run and easier code structure.
    When using delay, excecution time of the code affects on loop speed. It's also difficult to drive several motors at the time using delays.
    My approach poll the timer and starts loop in a proper moment, no matter how long code excecution has taken. Cycle time is short enough to allow max 200khz pulse frequency for controller. It means fast speeds with high microstepping.
    I use 64 bit integer as a counter, and copy highest bit for motor pulse output after every cycle. I also have signed 64 bit number as a speed value. That number is added to counter in every cycle. In a start if the cycle, sign of that counter is copied into direction pin.
    With this approach, I can drive several motors with any speed and direction just changing the speed value, and pulses are as uniform and jitter free as possible. I can read encoders in same loop if I need to.
    If controller have timing requirements for direction, they must not violated. It can be done by adding required delay for direction change.

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

    This is phenomenal man! I’ve been looking for a good TH-cam coach for controls programming! Thanks so much!!!!

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

    Thanks a lot for your informatic video. Because of your video we have been able to build a mindblowing machine!!!!!!!

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

    Lee, your videos are incredibly informative. While some is foreign language to me I like to watch because I get to learn a bit. God bless you, If I only you could show me around your shop. I can dream! You are a hardworking fellow. I envy you! Have a great week buddy!!

  • @Mad-Duk_Machine_Werkes
    @Mad-Duk_Machine_Werkes 8 หลายเดือนก่อน +1

    EXCELLENT!!! Best video on this subject I've seen yet! cant wait for more!

  • @AmateurRedneckWorkshop
    @AmateurRedneckWorkshop 8 หลายเดือนก่อน +1

    You have made me very curious as to what you are going to do with that stepper motor. Of course I bet you meant to do just that. One of my viewers gave a a raspberry pi one time and I let if set around until I no longer know where it is. I was getting older then and did not want to learn another programming language. Getting old has the effect of making you not want to change how you do things. Thanks for the video keep on keeping on.

  • @chirots
    @chirots 6 หลายเดือนก่อน +1

    I have got experience on Pi pico. The way to define pins is a little different to Pi, Hence I couldn't fully understand GPIO on pi and how you generated the pulse.
    After a few reading on GPIO module on pi, I now fully understand you generate pulse via High/Low of pulse_pin. Really appreciate your effort to make this educational videos for everyone to learn

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

    Nicely paced tutorial. Thanks so much.

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

    Really good video. Code is very easy to follow and extremely well commented.

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

    Mr. Lee. Great stuff please do more.

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

    you made my day with this as want to add automation to my Eagle surface grinder excellent explanation on the coding thank you so much

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

    Thanks for the video. I always like micro processor programing. You did a great job.

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

    Thank you Sir. Finely someone who makes it a lot more easy to understand ,how this all works together. All my very best.

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

    Thanks Lee. That was very helpful and practical example 👍😎👍

  • @907jl
    @907jl 8 หลายเดือนก่อน

    Very interesting, thanks for sharing, Lee!

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

    That was excellent thank you I have some projects later on and I was going to see if I could do the same thing thanks for the video

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

    Mr Lee, Thank you . I'm working on a tracer unit for the cross slide on a lathe

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

    I found this to be very informative great demonstration

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

    Great video! I had hopes for a PM electronic lead screw (yes, I’ve seen Clough 42’s version for Grizzly) until you said “pulley” and “table” in the same sentence. 😂😂😂😂😂

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

    Great video 😁👌👍

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

    Very clear!

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

    Fun and interesting video.

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

    Very interesting to be exposed to computer code!! Thanks

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

    Very informative can you use this same setup to drive a weld positioner

  • @theundergroundesd
    @theundergroundesd 8 หลายเดือนก่อน +5

    Good job but I want to see how to hookup the pie to the computer and bring up the pie program on the computer screen. Keep up the good work.

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

      That was going to be my question. What interface is used between Pi and computer program...

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

      The Pi is the computer.

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

      The Pi is the computer

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

      Lee. I know the pie is a computer but how do you input programs into it to control other devices? I not really a computer guy so I have a hand time wrapping my head around it. Keep up the good work

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

    great explanation! i love your accent :)

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

    I would love to see a Mr. Pragmatic Lee Python Tutorial!

  • @duongthanhnhan1568
    @duongthanhnhan1568 2 หลายเดือนก่อน +1

    Sorry for my bad English, but why can I use a 5v driver with a 3.3v rasperry output?

  • @jimdean7335
    @jimdean7335 8 หลายเดือนก่อน +1

    Seems you are planning to apply a stepper motor to your surface grinder. I’ve considered doing the same so I’m interested to see if the step action has an impact on the surface finish.

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

    Heck yeah! Is the project a CNC surface grinder?

  • @aseeker2109
    @aseeker2109 7 หลายเดือนก่อน +1

    This is brilliant, just what I need, thank you. Are you planning to use a Touchscreen to select variable input values to the program you are using?

    • @MrPragmaticLee
      @MrPragmaticLee  7 หลายเดือนก่อน +1

      I’ll likely add a touch screen and onscreen keyboard later, but just using an old flat screen monitor for now - seems I’ve got several of them - I don’t seem to be able to throw anything away. 😀

    • @aseeker2109
      @aseeker2109 7 หลายเดือนก่อน +1

      @@MrPragmaticLee Thank you, I look forward to learning more from you.

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

    since pi does not have real time kernel, does skipping steps occur often ? i did a similiar program and measured with perf_counter each step, it occurs several time in one rotation.

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

    Darn that makes the Gcode I create seem way simpler. I guess this type of code is what makes the Gcode work kinda. I recently learned to set my Arduino settings in two of my CNC machines you type $$ to see the settings then change the lines by like on line 13 (Inches) you would type $13=1 ( I think that's right)

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

    can i drive to 600 rpm ? with raspberry pi ? i coudnt do that i tryed to everything my step driver dm860

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

    I got an instant error for missing a library it looks like. Any chance you installed additional support files to your stock OS image?

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

      What library is missing? If it’s the GPIO library, that’s only available on Raspberry Pi. I’ll take a look at the code a little later this morning and review the imports.

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

    Does the raspberry pi do the same thing an arduino does

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

    Hello MrPragmaticLee, was firmware loaded on the Raspberry Pi before booting?

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

      No, you have to load the OS on the SIMM card.

  • @jamesbowenjr.3022
    @jamesbowenjr.3022 5 หลายเดือนก่อน

    I see the RPi 3 B+ is unavailable. Can the RPi 4 be used instead? That seems to be available.

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

      Absolutely - i did all my development and testing in a 4.

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

    What hapens if I use two ground pins from raspberry for PUL- and ENA-?

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

      Should be okay if they are both connected to pins on the Raspberry Pi that are designated as a ground pin.

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

    I am intrigued by the following observation. When I wired my setup, I shared your approach, put DIR- and PUL- to ground, and sent PUL+ to a GPIO pin and DIR+ to a GPIO pin. This is consistent with how I understand GPIO pins work. I am worried about this because my motor stalls once per revolution and I suspect my wiring can be improved. I watched your video and you agreed with my approach. Next, I watched a video by Jeremy Fielding and he wired PUL+ and DIR+ to +5v while sending the DIR- and PUL- to two GPIO pins. I watched a video on the Dronebot Workshop and he did likewise, +5v to PUL+ and DIR+ while sending DIR- and PUL- to the GPIO pins. Do you have any thoughts on why these wiring diagrams differ so much? It is me with zero views and you with 4,800 views against Jeremy with 1.2 million views and the Dronebot Workshop with 1.1 million views. Have you seen the movie "300"? While we are the underdogs, are we Spartans?

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

    What interface is used between Pi and computer program...?

    • @MrPragmaticLee
      @MrPragmaticLee  7 หลายเดือนก่อน +1

      It’s a Python program with the GPIO library.

    • @briankelly3884
      @briankelly3884 7 หลายเดือนก่อน +1

      raspberry pi has several different base environments (if you choose the one with the recommended software from the main website, will have everything you need to duplicate this project) which you can download and write onto a SD card from your windows computer, you just put the card in the pi after its done and it has its own desktop and programs similar to windows. The device has usb ports and hdmi outs. It functions as a slower but still capable computer with easy access to multiple digital I/Os.

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

      @@briankelly3884 Thanks!

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

    Hi Sir
    Good day i can you share the code to us is a great try i want to learn from it ,
    Many Thanks,
    Tan Meow Soon

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

    🎯 Key Takeaways for quick navigation:
    00:18 📌 *In this video, MrPragmaticLee demonstrates how to control a Nema23 stepper motor with a Raspberry Pi.*
    01:01 📌 *MrPragmaticLee introduces himself as a retired programmer who runs a hobby machine shop and occasionally combines programming with machining in his videos.*
    02:08 📌 *He explains that he's using a Raspberry Pi 3B+ with GPIO pins to control the stepper motor.*
    03:28 📌 *MrPragmaticLee differentiates stepper motors from standard DC motors, emphasizing precise movement achieved through step pulses.*
    06:59 📌 *He shows the wiring of the stepper motor, Raspberry Pi, and stepper driver, including the connection of GPIO pins.*
    08:10 📌 *MrPragmaticLee mentions the importance of setting a switch on the stepper driver to the 5-volt position when using a Raspberry Pi.*
    09:23 📌 *He briefly goes over the overall wiring diagram of the setup.*
    13:16 📌 *MrPragmaticLee demonstrates the physical wiring of the Raspberry Pi GPIO pins to the stepper driver.*
    19:35 📌 *He starts explaining the Python program used to control the stepper motor.*
    25:33 📌 *MrPragmaticLee discusses the use of try-except blocks in Python for handling exceptions, specifically keyboard interrupts.*
    28:10 📌 *The video goes into detail about sending pulses to control the stepper motor, with sleep intervals for timing.*
    31:36 📌 *The video concludes with the cleanup of GPIO pins using gpio.cleanup to ensure proper shutdown.*
    31:48 🤖 *The program uses GPIO pins on the Raspberry Pi to control the direction and pulses sent to a stepper motor driver.*
    32:27 🧰 *A Python program demonstrates controlling a stepper motor. It can specify the direction and number of pulses, allowing precise control.*
    35:16 🔄 *The program allows for dynamic adjustments to the number of revolutions and speed of the stepper motor, making it suitable for various applications.*
    37:47 💡 *The demonstration provides a practical overview of hooking up a 48-volt power supply, stepper motor driver, and Raspberry Pi for motor control.*