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

  Переглядів 39,436

Core Electronics

Core Electronics

День тому

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

КОМЕНТАРІ: 75
@awensman25
@awensman25 Місяць тому
I've done nothing with rasberry Pi, but your explanations make it so easy to understand. Keep it up!
@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!
@fosterdexing5673
@fosterdexing5673 7 місяців тому
Great Video! Very informative and useful links too. Thanks!!
@zechenwei1139
@zechenwei1139 Рік тому
Thank you for the video! Exactly what I needed
@Core-Electronics
@Core-Electronics Рік тому
Sweeet 😊!
@minhtruong9408
@minhtruong9408 17 днів тому
Thank you so much to show how to working with i2c stepper motor control. have a nice day.
@YINGAI1995
@YINGAI1995 Рік тому
Just stumbled upon your channel, great production quality and steps!! Subscribed
@Core-Electronics
@Core-Electronics Рік тому
Welcome aboard!
@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!
@barrythelad7793
@barrythelad7793 Рік тому
incredible video, thank you so much
@Core-Electronics
@Core-Electronics Рік тому
Thanks for your kind words 😊😊❤️❤️
@richardliu6163
@richardliu6163 Рік тому
Good tutorial.
@flickmew99
@flickmew99 11 місяців тому
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 😊
@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.
@Wizardnil
@Wizardnil Рік тому
Can you use this on top of the servo hat?
@user-cf4rw6bt4h
@user-cf4rw6bt4h 20 днів тому
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?
@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 - ukposts.info/have/v-deo/iKacYZxtqGlepJc.html Then all you need to do is write up a Python script to turn it into a Edge/Limit Switch
@HairyHitman
@HairyHitman 6 місяців тому
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 6 місяців тому
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 UKposts support.
@shubhamkale7420
@shubhamkale7420 Місяць тому
Have the same setup as you but motor is not giving the required output. Any suggesttions?
@anneother6224
@anneother6224 2 місяці тому
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?
@brasportt4667
@brasportt4667 3 місяці тому
Top 😊
@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.
@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
@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/
@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/
@vincentma6792
@vincentma6792 5 місяців тому
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?
@leftmindmedia
@leftmindmedia 5 місяців тому
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 5 місяців тому
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!
@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.
@petrasvestartas4359
@petrasvestartas4359 9 місяців тому
Is it normal that the stepper motor moves and vibrates a lot and in microsteps the sound is like breaking glass?
@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
@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
@hghlndr2
@hghlndr2 Рік тому
i tried installing the dependencies and now the module board has no attribute I2C
@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 😊
@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
@abu8422
@abu8422 9 місяців тому
how many dc motors raspberry pi can move
@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 😊.
@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 - ukposts.info/have/v-deo/apKYlaSNm4KYloU.html I hope that helps you\ - Tim
@bridgetclinch3678
@bridgetclinch3678 Рік тому
Ah my first pi hat
@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 11 місяців тому
but the hat hides camera slot! Further, we wont be able to add any other device to be controlled1
@Core-Electronics
@Core-Electronics 11 місяців тому
"There are not solutions... only tradeoffs!" Perhaps you can work around this constraint by extending the Pi's headers
@codiegagne7055
@codiegagne7055 6 місяців тому
does this guy only wear one shirt....?
How Stepper Motors Work - Electric motor
14:01
The Engineering Mindset
Переглядів 1 млн
The Ultimate Guide to using Motors in Robotics (including ROS, Raspberry Pi)
25:56
Articulated Robotics
Переглядів 286 тис.
I Can Save You Money! - Raspberry Pi Alternatives
15:04
Linus Tech Tips
Переглядів 3,2 млн
Microstepping steppers, and driving steppers with Raspberry Pi
7:18
Matthias random stuff
Переглядів 94 тис.
Control ANY COMPUTER with these Pi KVMs!
17:46
Jeff Geerling
Переглядів 784 тис.
How to control a DC motor with an encoder
9:30
Curio Res
Переглядів 401 тис.
Big Stepper Motors with Arduino
29:43
DroneBot Workshop
Переглядів 1,1 млн
Beginners Guide To Using Large Stepper Motors: #087
19:49
Jeremy Fielding
Переглядів 275 тис.
The Cheapest Microcontroller? Getting started with the 10 cent Puya PY32.
21:36
Zach of All Trades
Переглядів 24 тис.
Raspberry Pi Stepper Motor Tutorial
27:32
rdagger68
Переглядів 478 тис.