Stepper motor control Board 36820 MS

Thread Starter

Pcarmour

Joined Jun 24, 2023
105
BTW, the A4988 is a translator IC, similar in function to the L297 I mentioned in post #32.
One important feature of both, is to maintain the stepper motor rated current throughout the RPM range when using a higher than a motor rated voltage..
Thank you Max,
I’m working my way through a big unknown world so I am taking on board what you say but I’ll try to understand once everything else is working.
Peter
 

Thread Starter

Pcarmour

Joined Jun 24, 2023
105
Great progress, next step, remove the LEDs and connect the H Bridge and the stepper motor!
Ok, so I’ve managed to get the motor doing a revolution of 8 steps by using the one step at a time (and I can speed up or slow down) but it doesn’t like the one revolution and reverse and just turns.
I’m now researching the programming language to try to understand what is happening.
Peter.
 
Ok, so I’ve managed to get the motor doing a revolution of 8 steps by using the one step at a time (and I can speed up or slow down) but it doesn’t like the one revolution and reverse and just turns.
I’m now researching the programming language to try to understand what is happening.
Peter.
That's a big step in the right direction! Maybe post your code? Should be okay to simply copy and paste it into your reply.
 

Thread Starter

Pcarmour

Joined Jun 24, 2023
105
That's a big step in the right direction! Maybe post your code? Should be okay to simply copy and paste it into your reply.
This is the code I copied, then slightly modified, and is working.
I can speed up by lowering the delay.
Changing the number of steps to either 8 or 200 doesn't seem to make any difference.
I have a button on pin 3 to start each 1/3 turn of 3 steps but haven't added the Hall effect sensor yet to reduce the last 1/3 to 2 steps.
While experimenting I am now aware that these tiny motors aren't man enough to even turn the number plate so I've bought some slightly larger motors, 8x9.3mm but rated at 3v, which is as large as I can go to fit in the bumper.


/*
Stepper Motor Control - one step at a time
This program drives a unipolar or bipolar stepper motor.
The motor is attached to digital pins 8 - 11 of the Arduino.
The motor will step one step at a time, very slowly. You can use this to
test that you've got the four wires of your stepper wired to the correct
pins. If wired correctly, all steps should be in the same direction.
Use this also to count the number of steps per revolution of your motor,
if you don't know it. Then plug that number into the oneRevolution
example to see if you got it right.
Created 30 Nov. 2009
by Tom Igoe
*/
#include <Stepper.h>
const int stepsPerRevolution = 8; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 5 through 8:
Stepper myStepper(stepsPerRevolution, 5,6,7,8);
int stepCount = 0; // number of steps the motor has taken
void setup() {
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
// step one step:
myStepper.step(1);
Serial.print("steps:");
Serial.println(stepCount);
stepCount++;
delay(100);
}

Thank you Jerry for all your help and comments.
Peter.
 
I've not used the stepper library, I've always just used digitalWrite() to manipulate the I/O lines, but looking at your code myStepper.step(1); will always simply do one step. Your code is in the "void.loop() { code here }" so it will keep going around this loop which is continuous rotation. Your delay(100); will just put a pause of 100ms between each loop.

For one revolution change myStepper.step(1); to myStepper.step(8); or myStepper.step(stepsPerRevolution); which you have defined with "const int stepsPerRevolution = 8;" Then change your delay(100); to delay(2000); so you see a two second delay between rotations.

When you incorporate the switch into the loop you need to put the stepper code inside an "if" statement so that it only turns the stepper if the switch is pressed. The code will keep going round the loop looking for the button press but it will only do the stepper rotation when it sees a button press.

Pity about the motor power. How about a worm drive - if you can find a small gear with 12 teeth (i.e. a factor of 3) you'll be able to do 4 revolutions of your motor to do one third of a revolution of the number plate. That gearing may be sufficient to work with your existing motor.
 

Thread Starter

Pcarmour

Joined Jun 24, 2023
105
I've not used the stepper library, I've always just used digitalWrite() to manipulate the I/O lines, but looking at your code myStepper.step(1); will always simply do one step. Your code is in the "void.loop() { code here }" so it will keep going around this loop which is continuous rotation. Your delay(100); will just put a pause of 100ms between each loop.

For one revolution change myStepper.step(1); to myStepper.step(8); or myStepper.step(stepsPerRevolution); which you have defined with "const int stepsPerRevolution = 8;" Then change your delay(100); to delay(2000); so you see a two second delay between rotations.

When you incorporate the switch into the loop you need to put the stepper code inside an "if" statement so that it only turns the stepper if the switch is pressed. The code will keep going round the loop looking for the button press but it will only do the stepper rotation when it sees a button press.

Pity about the motor power. How about a worm drive - if you can find a small gear with 12 teeth (i.e. a factor of 3) you'll be able to do 4 revolutions of your motor to do one third of a revolution of the number plate. That gearing may be sufficient to work with your existing motor.
Hi Jerry,
I've tried this code but it's not working, not really surprised as It is a bit of trial and a lot of error!
I did consider it but there's just here's no room for a worm drive, I think the new motors will do the job, fingers crossed.
Peter


/*
Stepper Motor Control - one step at a time

*/
#include <Stepper.h>
const int buttonPin = 3; // the number of the pushbutton pin
int buttonState = 0; // variable for reading the pushbutton status
const int stepsPerRevolution = 8; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 5 through 8:
Stepper myStepper(stepsPerRevolution, 5, 6, 7, 8);
int stepCount = 0; // number of steps the motor has taken
void setup() {
// initialize the serial port:
Serial.begin(9600);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop() {
// step one step:
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);

// check if the pushbutton is pressed. If it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// move 3 steps:
digitalWrite(buttonPin, HIGH);
myStepper.step(3);
} else {
// Stop:
digitalWrite(buttonPin, LOW);
//myStepper.step(8); //Turned off for now
Serial.print("steps:");
Serial.println(stepCount);
stepCount++;
delay(100);
}
}
 
You only need to test the condition of the buttonPin and step the motor if it's high. There is no need for the "else" and I'm concerned about writing the buttonPin LOW if it's pulled high by the button press - that may have damaged whichever I/O pin you used for the button, maybe try another pin. Every time the code goes round the loop, if the button pin is low it does nothing

if (digitalRead(buttonPin == HIGH) {
myStepper.step(3);
delay(500); //made this half a second to avoid chance of contact bounce
}

I've taken out your serial.print lines for clarity. You can put it back in the above loop and it will only print if the button is pressed.

If you are trying to turn the motor too fast the speed you can turn is limited by the torque, so maybe try slowing it down - single step three times in the above loop with a 500mS delay between each step. Also, although the motor rated at 5V, maybe use a 9V PP3 battery connected to pin 8 of the H bridge to see if that works. You are not turning continuously so it may be okay with a brief spurt at 9V. The H Bridge is designed to have a supply voltage to pin 16 and the motor voltage to pin 8 which can be significantly higher.
 

Thread Starter

Pcarmour

Joined Jun 24, 2023
105
Hi Max,
Thank you or your help and comments.
As you said I need to consider the rated motor current through the rpm range and, although mine is only stepping slowly, I'm trying to understand how to control either the voltage or current as one tiny motor has now failed and another is getting very hot, this is while connected to my PC. Also I decided to go for a slightly bigger motor with a bit more power but these are only rated at 3v.
Can I control the VA from the coding?
Peter.
 

Thread Starter

Pcarmour

Joined Jun 24, 2023
105
You only need to test the condition of the buttonPin and step the motor if it's high. There is no need for the "else" and I'm concerned about writing the buttonPin LOW if it's pulled high by the button press - that may have damaged whichever I/O pin you used for the button, maybe try another pin. Every time the code goes round the loop, if the button pin is low it does nothing

if (digitalRead(buttonPin == HIGH) {
myStepper.step(3);
delay(500); //made this half a second to avoid chance of contact bounce
}

I've taken out your serial.print lines for clarity. You can put it back in the above loop and it will only print if the button is pressed.

If you are trying to turn the motor too fast the speed you can turn is limited by the torque, so maybe try slowing it down - single step three times in the above loop with a 500mS delay between each step. Also, although the motor rated at 5V, maybe use a 9V PP3 battery connected to pin 8 of the H bridge to see if that works. You are not turning continuously so it may be okay with a brief spurt at 9V. The H Bridge is designed to have a supply voltage to pin 16 and the motor voltage to pin 8 which can be significantly higher.
Thank you again Jerry,
I’ll come back to all this in a while as I’m also having a problem with the motor overheating. Maybe worth waiting for the new ones.
Sorry but a lot to take in.
Peter
 
That shouldn't happen if the stepper code is grounding all the stepper lines when it's not being turned. You could try driving all the stepper coil pins 5,6,7 and 8 low at the end of the code within the loop. It depends on what the stepper library does with the coil lines when it's finished doing a step
 

MaxHeadRoom

Joined Jul 18, 2013
30,686
As you said I need to consider the rated motor current through the rpm range and, although mine is only stepping slowly, I'm trying to understand how to control either the voltage or current as one tiny motor has now failed and another is getting very hot, this is while connected to my PC. Also I decided to go for a slightly bigger motor with a bit more power but these are only rated at 3v.
Can I control the VA from the coding?
Peter.
If only using a very low RPM, the exact motor rated voltage can be used, if the motors are overheating when using an higher-than-rated voltage, you do not have the motor current set correctly in what ever translator or means of doing so you have.
When no 'translator' method is used then it can be done with the code/controller itself, but can get a bit messy.
 

Thread Starter

Pcarmour

Joined Jun 24, 2023
105
That shouldn't happen if the stepper code is grounding all the stepper lines when it's not being turned. You could try driving all the stepper coil pins 5,6,7 and 8 low at the end of the code within the loop. It depends on what the stepper library does with the coil lines when it's finished doing a step
If only using a very low RPM, the exact motor rated voltage can be used, if the motors are overheating when using an higher-than-rated voltage, you do not have the motor current set correctly in what ever translator or means of doing so you have.
When no 'translator' method is used then it can be done with the code/controller itself, but can get a bit messy.
Thank you.
Jerry has suggested coding the motor pins low at the end of the loop which I can understand as a solution to the overheating. These motors were rated at 5v so should have been ok.
Peter
 

MaxHeadRoom

Joined Jul 18, 2013
30,686
If running steppers at the rated voltage, the current should be correct and not require any attention.
It is only when running at higher voltage in order to get high end RPM (maintaining rated current) that the current has to be monitored.
Steppers will see an increase in inductive reactance very quickly as the RPM rises, so some means of maintaining the rated current has to be carried out when using higher supply voltage.
This is one of the functions of the translator IC.
 

Thread Starter

Pcarmour

Joined Jun 24, 2023
105
If running steppers at the rated voltage, the current should be correct and not require any attention.
It is only when running at higher voltage in order to get high end RPM (maintaining rated current) that the current has to be monitored.
Steppers will see an increase in inductive reactance very quickly as the RPM rises, so some means of maintaining the rated current has to be carried out when using higher supply voltage.
This is one of the functions of the translator IC.
So I shouldn’t have that kind of problem running at just 3 steps per button press and no question of increased RPM.
Peter
 

MaxHeadRoom

Joined Jul 18, 2013
30,686
Not as far as I know but that’s possibly why the motor is overheating.
Stepper motors are designed to operate at the plate rated current at all times, unless stationary where this current is optional, depending if you need to hold position.
This is what sets them apart from other common motor types where current is constantly being varied throughout the RPM range and according to load.
 
Top