Jerry-Hat-Trick
- Joined Aug 31, 2022
- 829
With digitalWrite(LOW); to all four motor wires there is no current flowing. Somewhere in the stepper.h library there may be an option to leave the current in the coil(s) after each step or make it zero. A stepper motor will stay where it is with no current flowing but the holding torque, i.e. the torque to rotate it by hand will be lower. By leaving the current flowing the holding torque will be greater which is important for some applications. Frankly, I think the zero current option should be the default - another reason I don't like to use libraries. But a cheap motor is more likely to overheat if you are simply leaving 5V flowing through 12 Ohms - and when your number plate is in one of the three positions there is nothing to make it rotate.
This is code I wrote to rotate a 200 step motor once, wait for one second and repeat. I'm just turning the coils on and off one at a time. This doesn't get the maimum torque out of the motor and it's not very elegant, but it works.
This is code I wrote to rotate a 200 step motor once, wait for one second and repeat. I'm just turning the coils on and off one at a time. This doesn't get the maimum torque out of the motor and it's not very elegant, but it works.
Code:
//Simple Bipolar Stepper Example for XIAO and SN754410 H bridge
// One coil with D5 and D6, the other with D7 and D8
int step_delay = 6; // 6 mS between steps
int step_count = 50; //Loop does 4 steps, need to do this 50 times for one revolution
int n = 0;
int m = 0;
int coil_array[] = {5, 8, 6, 7};
void setup() {
// put your setup code here, to run once: Motor coil pins as outputs and made LOW
for(n=0;n<4;n++){
pinMode(coil_array[n], OUTPUT);
digitalWrite(coil_array[n],0);
}
}
void loop() {
// put your main code here, to run repeatedly:
for(n=0; n<step_count; n++){
for(m=0;m<4;m++){
digitalWrite(coil_array[m],1);
delay(step_delay);
digitalWrite(coil_array[m],0);
}
}
delay(1000);
}
Last edited by a moderator: