Output devices¶
For my final project I decided to use stepper motors, to rotate guitar tuning pegs.
I found small stepper motor in DVD drive, it moves laser module that reads disc information.
As you can see, it has 4 pins, which means that it is 2 phase stepper motor.
2 of 4 pins are one coil called A, and ther others are for coil B. So pins are called A+,A-,B+,B-
The logic of the stepper motor movement is shown on this picture
But, the voltage value for “1” state is over 9V for this motor, So I can’t give it direct from microcontroller.
Microcontroller pins has Voltage and Current limits. Typically it is 3,3V or 5V for voltage and 10-20mA for current. So the output pins are mostly used for logic pins, or connected to very low power devices, such as LEDs.
To control stepper motor I must use Motor Driver.
I choosed DRV8825 stepper motor driver
Wiring¶
So, started by soldering breadboard friendly wires to stepper motor.
Then I checked my motor driver datasheet
to connect stepper motor with driver there is no need in giving 4 different phase signals to each motor pin from microcontroller. The driver is controling by only 2 pins. STEP and DIR (Direction). The state of DIR pin sets direction of movement, and every pulse on STEP pin moves motor by one step. The angle of one step is typically 1.8°, there are 3 control types - full step, half step and micro step. To set the mode that you need, there is 3 pins on stepper motor driver called M0,M1,M2.
Step Mode | MODE0 | MODE1 | MODE2 |
---|---|---|---|
Full Step | Low | Low | Low |
Half Step | High | Low | Low |
1/4 Step | Low | High | Low |
1/8 Step | High | High | Low |
1/16 Step | High | Low | High |
1/32 Step | High | High | High |
NOTE! The more precision you want, the less torque you get.
So I am using full step control to have maximum torque to hold strings on guitar.
I connected everything to bread board
Programming¶
I started to write program in CubeIDE.
Firstly I defined 2 GPIO pins as Step pin and Dir pin.
And then wrote 3 basic functions, that are moving motor by ine step, and seting direction Clockwise or Counter Clockwise
in my main loop i have only two commands CW(); or CCW(); to set direction, and then moving by one step. (The speed of rotation depends on HAL_Delay() duration in Stepper_Step function)
Experiment and troubleshooting¶
After that I powered driver from power power source with 10V and ..... nothing happens. It was not moving.
I took osciloscope and checked driver pins.
It is signal on STEP_Pin. everything is good.
and then I found that I accidently connected Enable pin of driver to 3.3V pin of STM32, instead of GND. (Most of drivers work when enable is in state (0))
After everything is done, I runned program and…
video1,
Everything works well and I tried to change delay value on program and move it with different speed
video2,
video3,
video4
Conclusion¶
Working with stepper motors is very interesting. They are used in many devises to get presisious movement and high torque.
Their control is really not hard))