Тёмный

Controlling DC and Stepper Motors With A Raspberry Pi - How to use Adafruit DC & Stepper Motor HAT 

Core Electronics
Подписаться 121 тыс.
Просмотров 45 тыс.
50% 1

This will demonstrate exactly how to control Standard Stepper Motors and DC Motors with a Raspberry Pi Single-Board Computer. To do this as fast and seamlessly as possible we will utilise an Adafruit HAT and the Python Programming Language.
Full Article (with Terminal Commands) - core-electronics.com.au/guide...
Related Information
Set Up a Raspberry Pi as a Desktop Computer - core-electronics.com.au/guide...
Controlling a Solenoid With Raspberry Pi - core-electronics.com.au/guide...
Controlling Standard Servos With Raspberry Pi - core-electronics.com.au/guide...
Project Auto Tracking Camera System - core-electronics.com.au/proje...
How to use Raspberry Pi Imager - core-electronics.com.au/guide...
Use Your Phone to Control Your Raspberry Pi - core-electronics.com.au/tutor...
We want a fully customisable method of converting electrical energy into rotational energy (angular kinetic energy). This HAT is stackable up to 32 times. This means you can control independently up to 128 DC Motors or up to 64 Stepper Motors all through a single Raspberry Pi Single Board Computer
Depending on your needs either a DC motor or a Stepper Motor is going to be preferable. You might want a device that can rotate at a certain speed (RPM, revolutions per minute). In that case, a DC motor is what you would want to use. You might want a device that rotates to a precise angular position, at a very precise speed, or a set amount of rotations. In this case, a Stepper motor is what you would want to use.
DC motors are available in a huge range of sizes. You can get very tiny motors to very large industrial motors capable of many kilowatts, and everything in between. They are lightweight, reasonably efficient, and have good torque. They come in Brushless or Brushed variants. Stepper motors are DC motors that move in discrete steps. They have multiple coils that are organized in groups/phases. By energizing each phase in sequence, the stepper motor will rotate. Throw in some computer control and you can achieve very precise positioning and rotational speed control. For this reason, stepper motors are utilised in almost all precision motion control applications.
The motor controllers on this HAT are designed to run from 5V to 12V. Weird motor problems are often due to voltage mismatches so double-check your specification sheets first when it comes to troubleshooting. Most tiny 1.5V-3V Motors are not going to work or will slowly become damaged by 5V power. It is OK to run Stepper Motors at lower-than-rated voltage. They will simply carry less current and deliver less torque. Each Motor Driver on the HAT is capable of pushing out 2A.
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:
Adafruit DC and Stepper Motor HAT - core-electronics.com.au/catal...
Adafruit DC and Stepper Motor Bonnet (Solderless Solution) - core-electronics.com.au/catal...
Raspberry Pi 4 Model B (4GB) Ultimate Kit Bundle (AVALIABLE!) - core-electronics.com.au/raspb...
Standard 5V DC Motor - core-electronics.com.au/catal...
Standard 12V Stepper Motor - core-electronics.com.au/catal...
Raspberry Pi Single Board Computers and Gear: core-electronics.com.au/raspb...
Stackable Headers - core-electronics.com.au/catal...
0:00 Intro
0:18 HAT Overview
0:56 What You Need
3:11 Soldering Hardware
3:55 Hardware Assembly
6:12 Software Installation
6:56 DC Motor Control Script
7:33 Success 1!
7:57 DC Motor Script Explanation
9:32 Stepper Motor Control Script
10:02 Success 2!
10:19 Stepper Motor Script Explanation
11:55 Where to Now
12:35 Outro

Опубликовано:

 

6 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 81   
@fredwupkensoppel8949
@fredwupkensoppel8949 18 дней назад
Clear instructions, simple language, safety advice where necessary - that's a good tutorial, great even!
@Roxomus
@Roxomus 3 месяца назад
You have a really good way of explaining things. Clear, at a good pace, and in the right amount. Thanks for this video!
@awensman25
@awensman25 4 месяца назад
I've done nothing with rasberry Pi, but your explanations make it so easy to understand. Keep it up!
@fosterdexing5673
@fosterdexing5673 10 месяцев назад
Great Video! Very informative and useful links too. Thanks!!
@minhtruong9408
@minhtruong9408 3 месяца назад
Thank you so much to show how to working with i2c stepper motor control. have a nice day.
@marlonsamaniego7884
@marlonsamaniego7884 Год назад
Excellent video. I am trying to get a very similar setup to work so this was very helpful.
@Core-Electronics
@Core-Electronics Год назад
Cheers mate 😊 Glad to of helped!
@zechenwei1139
@zechenwei1139 Год назад
Thank you for the video! Exactly what I needed
@Core-Electronics
@Core-Electronics Год назад
Sweeet 😊!
@richardliu6163
@richardliu6163 Год назад
Good tutorial.
@YINGAI1995
@YINGAI1995 Год назад
Just stumbled upon your channel, great production quality and steps!! Subscribed
@Core-Electronics
@Core-Electronics Год назад
Welcome aboard!
@barrythelad7793
@barrythelad7793 Год назад
incredible video, thank you so much
@Core-Electronics
@Core-Electronics Год назад
Thanks for your kind words 😊😊❤️❤️
@KSp33dlin
@KSp33dlin Год назад
Hi @core electronics! Thanks for the very informative video. I’ve learned to control step motors using a DRV8825 driver with which one usually tunes the step motor current using a potentiometer. Could you explain to me why this board does not require this kind of tuning? Also, what happens if I connect, say, a 1.5A motor to the board? Will the motor try to draw too much power from the board? Sorry if these questions have obvious answers - I’m just getting into electronics. Thanks again and best wishes!
@brasportt4667
@brasportt4667 7 месяцев назад
Top 😊
@flickmew99
@flickmew99 Год назад
If I don't have those hat for running my stepper motor, could I directly connect my raspberry pi directly to the regular stepper driver? I heard that you should convert the logic level from the stepper driver first (because most of the pinout using 5v logic), so it would not damage your Pi. But I have seen people directly connect the driver to Pi and had no issued with it. I'm confused
@DanielGeri
@DanielGeri Год назад
This is great! Any chance you have advice on how to add a "homing" mechanism to the stepper?
@Core-Electronics
@Core-Electronics Год назад
The Free and unused GPIO pins are shown in this forum post - forums.adafruit.com/viewtopic.php?f=8&t=115770 With that knowledge you can then add limit switches coming from those previously free GPIO pins. Then you just got to program in what you need 😊
@Wizardnil
@Wizardnil Год назад
Can you use this on top of the servo hat?
@lukalovric4872
@lukalovric4872 Год назад
Great video! Can you show us how to control more than 4 stepper motors with this HAT?
@Core-Electronics
@Core-Electronics Год назад
The full written up article explains how to stack multiple HATs 😊 the trickiest part is assigning I2C Addresses in the script which requires only one line to be altered in the demo Python scripts.
@X-Ray76
@X-Ray76 Год назад
Does this hat also work with an Arduino Mega 2560 board? (With loose wire connections)
@gilles4332
@gilles4332 Год назад
Hello and thank you for your work, could you show the hall effect sensor connection for the direction limits and the home return with this configuration and the stepper motors, no information on this subject, thank you.
@Core-Electronics
@Core-Electronics Год назад
Love your idea! That is something I'm definitely interested in pursuing. Until I get to it here is a fellow using hall effect sensors with a Raspberry Pi - ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-Pvk-f6q3-Cc.html Then all you need to do is write up a Python script to turn it into a Edge/Limit Switch
@user-cf4rw6bt4h
@user-cf4rw6bt4h 4 месяца назад
In your video, you used separate power sources for the motor controller and the Raspberry Pi, totaling two power sources. Instead of doing that, isn't there a Raspberry Pi component, similar to a computer supply unit, that automatically supplies the necessary power to each module?
@HairyHitman
@HairyHitman 9 месяцев назад
Hi @core celectronics Awesome video which I'm using as a base to build a dog treat dispenser with a stepper motor. I've bought the none- soldering version and have set it all up but I'm getting an error on the stepper motor script saying it can't find the i2c devices. I've googled and ran i2cdetect which isn't bring back anything. I've double checked I've enabled i2c, is there a step I've missed? The bonnet does seem loose but I don't know if I'm meant to use too much force putting it on. Any help would be appreciated, thanks!
@Core-Electronics
@Core-Electronics 9 месяцев назад
Hey Hitman, flick us the question over on our forums: coreelec.io/forum Our staff check there several times a day during work hours and someone can help you out with that (and if anyone is having the same issue its easier for them to find), we aren't as frequently on RU-vid support.
@shubhamkale7420
@shubhamkale7420 4 месяца назад
Have the same setup as you but motor is not giving the required output. Any suggesttions?
@petrasvestartas4359
@petrasvestartas4359 Год назад
Is it normal that the stepper motor moves and vibrates a lot and in microsteps the sound is like breaking glass?
@ownage3523
@ownage3523 Год назад
When soldering the piece at 3:37, is it ok if the solders on different pins end up connecting? Will this mess up anything electronically?
@Core-Electronics
@Core-Electronics Год назад
Definitely could cause issues (including the dreaded puff of magic smoke)! For instance if you accidentally electrically connected a 5V Pin to the 3.3V Pin that will break your Raspberry Pi. pinout.xyz/ Removing solder can best be done with a lot of flux and solder wick - core-electronics.com.au/solder-wick-desolder-braid-0-8mm-5ft-8015.html You can flick off solder by heating it up and whipping the soldering pencil away from you but it is no where near as elegant or as easy to do.
@vincentma6792
@vincentma6792 9 месяцев назад
I am receiving an error when running the installation package for the adafruit circuit python motorkit. It is saying that it is an "externally-managed-environment". What could be causing this issue?
@gilles4332
@gilles4332 Год назад
as I told you issac uses an arduino and I want to replace it with an rpi with the hat that you present, I have already printed and assembled all the parts, and modify for the rpi, I also have the stepper motor and my two cameras (an rpi hq and a usb), the one in usb to serve me as a pointer, I think to use open cv, and have an automatic mode and a manual mode, if you can help me it would be great otherwise thank you anyway
@Core-Electronics
@Core-Electronics Год назад
Sounds like a formidable project 😊 the best place to get help for big project knowledge is our Core Electronics Forum, definitely come write up a post there if you need - forum.core-electronics.com.au/
@ownage3523
@ownage3523 Год назад
I have a power supply that delivers 12V at 2A. If I have a stepper motor rated for 12V at 1.68A, will the extra 0.32A from the power supply damage the motor?
@Core-Electronics
@Core-Electronics Год назад
You are totally safe. The system will only pull the amps that it requires. Come check here if you want to know my Golden Rules when it comes to Power supply selection 😊 core-electronics.com.au/guides/prototyping/power-supply-which-to-choose/
@wamtm
@wamtm Год назад
could I stack another board on top of the ada that gives me access to the underlying gpio pins so i can run some solonoids in addition to the stepper motor? Thanks
@Core-Electronics
@Core-Electronics Год назад
I've added a comment to the bottom of the Article that Address just this 😊. The HAT has pads that break out the unused GPIO pins. That means you won't need to add anything extra to gain access to the GPIO for your Solenoids/Relay Control. Check here for more information - forum.core-electronics.com.au/t/guide-by-tim-how-to-use-stepper-motors-and-dc-motors-with-a-raspberry-pi-adafruit-dc-stepper-motor-hat/15071
@wamtm
@wamtm Год назад
@@Core-Electronics thank you so much for your fast reply and resource . Really helpful
@hghlndr2
@hghlndr2 Год назад
i tried installing the dependencies and now the module board has no attribute I2C
@danachristie3862
@danachristie3862 Год назад
is there a way to run a python script using gcode, such as the ending script gcode of a 3d printer?
@Core-Electronics
@Core-Electronics Год назад
Sweet question and there is indeed come check out these two resources - www.reddit.com/r/klippers/comments/nlxx59/run_python_script_with_gcode/ and github.com/th33xitus/kiauh/blob/master/docs/gcode_shell_command.md
@gilles4332
@gilles4332 Год назад
Thank you the problem is that I do not speak English, the subtitles are not available and therefore the translation either, despite everything I can understand the principle, is if you could make a video on the subject using the dc stepper hat would be great, my current project is to take the turret from isaac879 and replace the Arduino with the rpi and make it a stellar observation turret, thank you.
@Core-Electronics
@Core-Electronics Год назад
Subtitles should be available now, sometimes it takes a couple of days. Hopefully that will help. And I would love to see that project completed! Pointing Pan-Tilt systems are the Stars are the best possible use case (in my opinion). Come check out project which does a very similar thing as to what you want - core-electronics.com.au/projects/auto-camera-tracking-system/
@gilles4332
@gilles4332 Год назад
@@Core-Electronics Yes thank you, looking on my side I was stumbling on this project, unfortunately it uses an arduino for engine control, and on my side I do not know programmed in python, it would help me a lot to know how can self-control the engine step by step with video detection (either motioneye or opencv) via the hat, Is there a code that I could import, in any case thank you anyway.
@abu8422
@abu8422 Год назад
how many dc motors raspberry pi can move
@leftmindmedia
@leftmindmedia 8 месяцев назад
Is it possible to connect other things with the hat on? I'd like to control both a motor and a light.
@Core-Electronics
@Core-Electronics 8 месяцев назад
That depends on what light you are trying to control and how you are setting it up. You can think of the M terminals as a controllable voltage. You can increase and decrease or swap the polarity of the voltage. So if your light is suitable, you can happily run it off another motor channel, and you could even change the brightness of it the same way you would control motor speed, but it all depends on the light. If you want some more help, chuck us a post on our forums, we have a lot more eyes on there. Just give us some more details of the light you are using and the setup: forum.core-electronics.com.au Cheers!
@anneother6224
@anneother6224 6 месяцев назад
I kind of imagined that I'd be able to buy some kit which would allow the pi to control a stepper with very high level commands such as " rotate clockwise at rate n" But I'm not finding it. Looks like I need something like a pico or arduino. But hasn't someone bundled all that stuff and the driver for me?
@fredwupkensoppel8949
@fredwupkensoppel8949 18 дней назад
Well, you can basically do that yourself - write a function that converts mm/s into steps/s (clockwise can be found in the example code shown in the video), then you can pass "rotate clockwise at 10 mm/s" to that function.
@PickYourPoisons
@PickYourPoisons Год назад
can u add other sensors/inputs with the hat?
@Core-Electronics
@Core-Electronics Год назад
Absolutely, that protoboard section is ready to be utilised on the HAT and a number of GPIO pins are not being used by the HAT and are free to power/control other hardware - pinout.xyz/pinout/adafruit_dc_stepper_motor_hat
@zakariatamzarti8034
@zakariatamzarti8034 Год назад
what is the maximum speed of the stepper motot
@Core-Electronics
@Core-Electronics Год назад
This 12V stepper motor hums along nicely at 50 RPM with the Adafruit Arduino Motor HAT. The Adafruit Arduino Motor HAT has the exact same Driving IC's as the Raspberry Pi Motor HAT so that's your answer 😊.
@bridgetclinch3678
@bridgetclinch3678 Год назад
Ah my first pi hat
@fonz7697
@fonz7697 Год назад
Where can I find the wires used at 5:39
@Core-Electronics
@Core-Electronics Год назад
I used these Jumper wires here and cut/stripped off one end with my clippers - core-electronics.com.au/catalog/product/view/sku/ADA1954
@carloscabrera6683
@carloscabrera6683 Год назад
Can I use a Dc encoder with this motor hat?
@Core-Electronics
@Core-Electronics Год назад
This simple questions is an excellent one. The libraries made for this HAT won't know what to do with the encoded data from the DC Motor. You can just hook up a DC Motor (which has an encoder) and not use the encoder part just fine with this HAT. There are empty/free pins on the Raspberry Pi. You could write your own script that runs along side the Adafruit scripts that would analyse the encoding for you. You could also use a board more designed for DC Encoded Motors like this one here - ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-2bganVdLg5Q.html I hope that helps you\ - Tim
@ownage3523
@ownage3523 Год назад
If I instead wanted to use a stepper motor and a servo motor, would the setup be similar? What if the servo motor needs to be connected to the same pins as the stepper? Is it ok to connect wires from the servo and the stepper to the same pins?
@Core-Electronics
@Core-Electronics Год назад
Heyya champ 😊 come check it out here as it is exactly what your interested in - learn.adafruit.com/adafruit-motor-shield-v2-for-arduino/using-rc-servos
@ownage3523
@ownage3523 Год назад
@@Core-Electronics Thank you! This looks like it will allow me to easily control a servo and stepper at the same time! Unfortunately, however, it looks like the shield is out of stock.
@ownage3523
@ownage3523 Год назад
Is this compatible with the Raspberry Pi 3 Model B V1.2?
@ownage3523
@ownage3523 Год назад
If not, would you have any similar recommendations that would work for that model of Raspberry Pi?
@Core-Electronics
@Core-Electronics Год назад
Both shields are compatible with that model of Raspberry Pi and much like how that Motor shield has GND, 5V and Data pins right next to each other so does the DC and Stepper Motor HAT (from above video). You'll be able to set up servo control with the exact same connection set up for both of them 😊
@demetriuscurry2697
@demetriuscurry2697 Год назад
What if someone is using a unipolar stepper motor?
@Core-Electronics
@Core-Electronics Год назад
You will need to identify which wire is the Centre Tap and connect that one to the Center GND Screw-Down Terminal. The remaining 4 wires make up Two Coil Loops. You can Identify a Coil Pair by checking the end of two wires for continuity with a Multimeter. If the Multimeter beeps (confirming continuity) you have identified coil pair. Come check the full written up article for more help if you need 😊 core-electronics.com.au/guides/raspberry-pi/raspberry-pi-dc-stepper-motor-guide/
@bhandarkarvivekvasanta8464
@bhandarkarvivekvasanta8464 Год назад
but the hat hides camera slot! Further, we wont be able to add any other device to be controlled1
@Core-Electronics
@Core-Electronics Год назад
"There are not solutions... only tradeoffs!" Perhaps you can work around this constraint by extending the Pi's headers
@That_droper
@That_droper 28 дней назад
Hello I am new to ras pi but u have an 80 dollar gift card for micro center and I want to know what raspberry pi and what stepper motor to get and how to connect them and power it. thanks guys and is there a way to connect more than on stepper motor to only one ras pi thanks again
@Core-Electronics
@Core-Electronics 28 дней назад
This depends on what the project you are using it for. Raspberry Pis come in their main series boards, the Pi4 is the last Gen, and the Pi 5 is the newer generation which is a tad more expensive but worth the upgrade. They also come in different RAM sizes, for general day to day tasks I've had no issus on 2 or 4gb. The Pis also come in a much cheaper Rsapberry Pi Zero form factor, which is a fair bit slower, but great for simple tasks that don't need the power. As for what stepper you need, it also depends on the project. We have a comprehensive guide here on different motors that has a lot of good information: core-electronics.com.au/guides/digital-electronics/servos-steppers-or-solenoids-choosing-an-actuator-to-move-your-project/ Happy making!
@That_droper
@That_droper 28 дней назад
@@Core-Electronics thanks would you know where to find a power cable for the raspberry pi 4 and a 12 volt stepper motor
@codiegagne7055
@codiegagne7055 9 месяцев назад
does this guy only wear one shirt....?
Далее
Beginners Guide To Using Large Stepper Motors: #087
19:49
How Stepper Motors Work - Electric motor
14:01
Просмотров 1 млн
Raspberry Pi Stepper Motor Tutorial
27:32
Просмотров 488 тыс.
Big Stepper Motors with Arduino
29:43
Просмотров 1,2 млн
The Clever Way to Count Tanks - Numberphile
16:45
Просмотров 754 тыс.