No video

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

  Рет қаралды 44,970

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-electroni...
Related Information
Set Up a Raspberry Pi as a Desktop Computer - core-electroni...
Controlling a Solenoid With Raspberry Pi - core-electroni...
Controlling Standard Servos With Raspberry Pi - core-electroni...
Project Auto Tracking Camera System - core-electroni...
How to use Raspberry Pi Imager - core-electroni...
Use Your Phone to Control Your Raspberry Pi - core-electroni...
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-electroni...
Adafruit DC and Stepper Motor Bonnet (Solderless Solution) - core-electroni...
Raspberry Pi 4 Model B (4GB) Ultimate Kit Bundle (AVALIABLE!) - core-electroni...
Standard 5V DC Motor - core-electroni...
Standard 12V Stepper Motor - core-electroni...
Raspberry Pi Single Board Computers and Gear: core-electroni...
Stackable Headers - core-electroni...
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

Пікірлер: 85
@awensman25
@awensman25 5 ай бұрын
I've done nothing with rasberry Pi, but your explanations make it so easy to understand. Keep it up!
@fredwupkensoppel8949
@fredwupkensoppel8949 28 күн бұрын
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!
@minhtruong9408
@minhtruong9408 4 ай бұрын
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 😊!
@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?
@barrythelad7793
@barrythelad7793 Жыл бұрын
incredible video, thank you so much
@Core-Electronics
@Core-Electronics Жыл бұрын
Thanks for your kind words 😊😊❤️❤️
@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.
@YINGAI1995
@YINGAI1995 Жыл бұрын
Just stumbled upon your channel, great production quality and steps!! Subscribed
@Core-Electronics
@Core-Electronics Жыл бұрын
Welcome aboard!
@fosterdexing5673
@fosterdexing5673 10 ай бұрын
Great Video! Very informative and useful links too. Thanks!!
@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.
@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 - kzfaq.info/get/bejne/htybYMln1pmRc5c.html Then all you need to do is write up a Python script to turn it into a Edge/Limit Switch
@shubhamkale7420
@shubhamkale7420 4 ай бұрын
Have the same setup as you but motor is not giving the required output. Any suggesttions?
@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 😊
@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 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?
@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/
@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
@mickzexe3086
@mickzexe3086 2 күн бұрын
Hey there, can i also stack the Adafruit 16-Channel PWM + Servo HAT on top of this?
@Core-Electronics
@Core-Electronics Күн бұрын
These use I2C which can have (theoretically) dozens of them stacked on top of each other. As long as you solder the right pin headers to stack them, it should work!
@richardliu6163
@richardliu6163 Жыл бұрын
Good tutorial.
@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.
@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
@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!
@petrasvestartas4359
@petrasvestartas4359 Жыл бұрын
Is it normal that the stepper motor moves and vibrates a lot and in microsteps the sound is like breaking glass?
@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
@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!
@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
@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 28 күн бұрын
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
@X-Ray76
@X-Ray76 Жыл бұрын
Does this hat also work with an Arduino Mega 2560 board? (With loose wire connections)
@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 😊.
@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 😊
@Wizardnil
@Wizardnil Жыл бұрын
Can you use this on top of the servo hat?
@HairyHitman
@HairyHitman 10 ай бұрын
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 10 ай бұрын
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 KZfaq support.
@chrisoology6932
@chrisoology6932 4 күн бұрын
How would I install motor kit on the pi 5 ... it does not install?
@Core-Electronics
@Core-Electronics 3 күн бұрын
The Pi 5 has the same 40 GPIO pinout as the previous Pi's so the installation should be the same!
@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 - kzfaq.info/get/bejne/aMiXlNGHybLLZYU.html I hope that helps you\ - Tim
@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
@abu8422
@abu8422 Жыл бұрын
how many dc motors raspberry pi can move
@brasportt4667
@brasportt4667 7 ай бұрын
Top 😊
@bridgetclinch3678
@bridgetclinch3678 2 жыл бұрын
Ah my first pi hat
@That_droper
@That_droper Ай бұрын
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 Ай бұрын
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 Ай бұрын
@@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 10 ай бұрын
does this guy only wear one shirt....?
The Ultimate Guide to using Motors in Robotics (including ROS, Raspberry Pi)
25:56
Jumping off balcony pulls her tooth! 🫣🦷
01:00
Justin Flom
Рет қаралды 35 МЛН
Schoolboy - Часть 2
00:12
⚡️КАН АНДРЕЙ⚡️
Рет қаралды 17 МЛН
A teacher captured the cutest moment at the nursery #shorts
00:33
Fabiosa Stories
Рет қаралды 62 МЛН
路飞太过分了,自己游泳。#海贼王#路飞
00:28
路飞与唐舞桐
Рет қаралды 43 МЛН
How Stepper Motors Work - Electric motor
14:01
The Engineering Mindset
Рет қаралды 1 МЛН
Electronic Basics #24: Stepper Motors and how to use them
6:47
GreatScott!
Рет қаралды 2,2 МЛН
Beginners Guide To Using Large Stepper Motors: #087
19:49
Jeremy Fielding
Рет қаралды 287 М.
I tried OVERPOWERING my Vacuum! (Homemade Turbine)
11:42
GreatScott!
Рет қаралды 1,8 МЛН
Big Stepper Motors with Arduino
29:43
DroneBot Workshop
Рет қаралды 1,2 МЛН
Stepper Motors with Arduino - Controlling Bipolar & Unipolar stepper motors
50:22
Raspberry Pi Pico 2 | Everything You Need To Know
7:04
Core Electronics
Рет қаралды 27 М.
Jumping off balcony pulls her tooth! 🫣🦷
01:00
Justin Flom
Рет қаралды 35 МЛН