Stepper motor control Board 36820 MS

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.

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:

Thread Starter

Pcarmour

Joined Jun 24, 2023
105
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.

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);
}
Thank you Jerry, Initially the code didn’t work, the motor was stationary but vibrated if I tried to move it. That got me thinking so I checked the coils and both were 12.8 ohms. Then I checked my pinout wiring and all ok. I then tried different combination of connections to the motor as I know which are the coils but they aren’t clearly marked as A or B and BINGO!! The motor revolved paused and then turned again. Simple errors are the easiest! Although the motor was previously turning it was probably fighting with itself!
Stopping now but tomorrow I’ll go back to my code with the button.
Thank you. Peter.
 

Thread Starter

Pcarmour

Joined Jun 24, 2023
105
Thank you Jerry, Initially the code didn’t work, the motor was stationary but vibrated if I tried to move it. That got me thinking so I checked the coils and both were 12.8 ohms. Then I checked my pinout wiring and all ok. I then tried different combination of connections to the motor as I know which are the coils but they aren’t clearly marked as A or B and BINGO!! The motor revolved paused and then turned again. Simple errors are the easiest! Although the motor was previously turning it was probably fighting with itself!
Stopping now but tomorrow I’ll go back to my code with the button.
Thank you. Peter.
I just spotted in your code the int coil_array[] = {5, 8, 6, 7};
Where as mine has always been 5,6,7,8. So is that why my motor worked with different connections?
Peter
 

Thread Starter

Pcarmour

Joined Jun 24, 2023
105
[/QUOTE]
Further investigations have shown the following observations:
My connections are:
1st motor coil is connected with a blue and yellow wire
2nd motor coil is connected with a green and orange wire
Output from the H Bridge pins are:
3 Blue
6 yellow
11 green
14 orange
Using the one revolution back and forward programme:
Connecting just the Blue to Blue and Yellow to Yellow the motor steps clockwise
Connecting just the Blue to yellow and Yellow to Blue the motor still steps clockwise
Connecting just the Blue to Green and Yellow to Orange the motor steps anti-clockwise
Connecting just the Blue to Orange and Yellow to Green the motor still steps anti-clockwise
The motor never reverses
Connecting the Green and yellow from the H Bridge to any wire only gets a judder!
Same results on a second motor.
To confirm XIAO to H Bridge connections:
8 - 2
9 - 7
10 - 10
11 - 15
All very confusing.
Peter.
 
Last edited:
I just spotted in your code the int coil_array[] = {5, 8, 6, 7};
Where as mine has always been 5,6,7,8. So is that why my motor worked with different connections?
When stepping the motor the sequence of coil activation is:
1. the first coil
2. the other coil (the polarity will determine the direction - try swapping pins 11 and 14)
3, the first coil but with the opposite polarity
4. the second coil but with the opposite polarity.
And start the sequence again.
My code had to include this coil_array[] sequence to keep the hardware layout simple - pins 5 and 6 to one side of the H Bridge, 7 and 8 to the other side.

I'm really not familiar with how the stepper.h library works, but it is amazing how stepper motors seem to cope with incorrect wiring. You might want to consider just driving the coils in the above sequence?
 

Thread Starter

Pcarmour

Joined Jun 24, 2023
105
When stepping the motor the sequence of coil activation is:
1. the first coil
2. the other coil (the polarity will determine the direction - try swapping pins 11 and 14)
3, the first coil but with the opposite polarity
4. the second coil but with the opposite polarity.
And start the sequence again.
My code had to include this coil_array[] sequence to keep the hardware layout simple - pins 5 and 6 to one side of the H Bridge, 7 and 8 to the other side.

I'm really not familiar with how the stepper.h library works, but it is amazing how stepper motors seem to cope with incorrect wiring. You might want to consider just driving the coils in the above sequence?
Well I think I've swapped about everything,
swapped pins 11 and 14
and all these around
8 - 2
9 - 7
10 - 10
11 - 15
and used the one step at a time prog.
funny enough results do not change!
Now I have no idea what's going on.
Mystified!
 
The problem with switching things around without understanding the consequences is that you may have damaged the XIAO, the H bridge or the motor! I'd suggest going back to the LEDs (with resistors in series), with the H Bridge IC removed, digitalWrite() pins 5.6.7 and 8 low, then write each one high for a second, then low for a second - in sequence in a repeating loop. This will check the XIAO outputs are still working.

Then remove the LEDs and connect:
pin 5 of the XIAO to pin 2 of the H Bridge
pin 6 of the XIAO to pin 15 of the H Bridge
pin 7 of the XIAO to pin 7 of the H Bridge
pin 8 of the XIAO to pin 10 of the H Bridge

And one coil of the motor between pins 3 and 6, and the other between 11 and 15 of the H bridge. Pins 1,9,8 and 16 of the H bridge still connected to 5V.

Run the same code. The motor should rotate. Swap the connections to 11 and 15 of the H Bridge - the motor should go in the opposite direction.

Personally, I'd forget about using the stepper.h library, it's confusing. If the following sequence goes wrong at any stage, best stop there and post the result!
 

Thread Starter

Pcarmour

Joined Jun 24, 2023
105
The problem with switching things around without understanding the consequences is that you may have damaged the XIAO, the H bridge or the motor! I'd suggest going back to the LEDs (with resistors in series), with the H Bridge IC removed, digitalWrite() pins 5.6.7 and 8 low, then write each one high for a second, then low for a second - in sequence in a repeating loop. This will check the XIAO outputs are still working.

Then remove the LEDs and connect:
pin 5 of the XIAO to pin 2 of the H Bridge
pin 6 of the XIAO to pin 15 of the H Bridge
pin 7 of the XIAO to pin 7 of the H Bridge
pin 8 of the XIAO to pin 10 of the H Bridge

And one coil of the motor between pins 3 and 6, and the other between 11 and 15 of the H bridge. Pins 1,9,8 and 16 of the H bridge still connected to 5V.

Run the same code. The motor should rotate. Swap the connections to 11 and 15 of the H Bridge - the motor should go in the opposite direction.

Personally, I'd forget about using the stepper.h library, it's confusing. If the following sequence goes wrong at any stage, best stop there and post the result!
I still can’t understand why when I connect the blue and yellow, either way round, one coil always goes clockwise and the other coil always goes anti clockwise.
I’m sorry but I’ve spent enough time with this and really getting nowhere, so at the moment I feel I’m going back to the original controller. Once I have the new motors I might consider returning if they behave differently. As there are only 8 steps pressing a button to just jump the number plate round will find the required position anyway.
Thank you Jerry and Max for your help and comments and I’m sorry that at the moment I’m giving up.
best wishes.
Peter
 
Top