Hey guys and girls!
I have not much experience with programming.
I will explain my problem here and i hope that there is a bright mind that knows what is wrong with it.
First of all i want to explain what i want my programm to do and what i have.
I use Arduino Uno board
cheap chinese stepper motor driver HY DIV258N 5A
Nema 17 stepper motor. 1,8 degrees , up to 3A
I need that motor to rotate how much rotations i want, and so far everything has been fine, but then i had to change my driver settings so it splits signal. Instead of being 1:1 , i wanted it to go to 1:16.
Now this is where i found out my problem.
In the programm there is command for motor and it has X in it.
When my driver settings are set 1:1, my X number was set to 3800 and it was very good for me.
Once i set my driver to 1:2, X number settings have to double, so it would be 7600.
And so it goes till 1:16.
Now for me it makes sense that since its 1:16 all i have to do is multiply 3800x16 and result i enter for X
Unfortunately it doesnt work like that, once i enter 60800, motor spins like forever.
I have tried to enter different numbers and i found out that once i get over like 32000, it starts to behave strangely and just dont stop.
Atm i have driver set to 1:8 and my number is 30400 which seems to cover my distance perfectly.
(int x = 0; x < 60800 ; x++) this is where i have my problem
Here is the code that i am using ( I havent written it myself, i have read many others and kinda adapted it to what i need so dont judge me hard on that
)
// defines pins numbers
const int stepPin = 4;
const int dirPin = 3;
void setup() {
// Sets the three pins as Outputs
pinMode(stepPin,OUTPUT);
pinMode(dirPin,OUTPUT);
pinMode(7, OUTPUT);
}
void loop() {
delay(230000); // long Break at start
digitalWrite(7, HIGH);
delay(300);
digitalWrite(7, LOW);
delay(2000);
digitalWrite(dirPin,LOW); // Enables the motor to move in a particular direction
for(int x = 0; x < 30400 ; x++) { //3800 1:1, 30400 1:8, ??? 1:16
digitalWrite(stepPin,HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin,LOW);
delayMicroseconds(1000);
}
//delay(2000); // One second delay
delay(2000);
digitalWrite(7, HIGH);
delay(300);
digitalWrite(7, LOW);
delay(2000);
digitalWrite(dirPin,LOW); // Enables the motor to move in a particular direction
for(int x = 0; x < 30400 ; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin,LOW);
delayMicroseconds(1000);
}
delay(2000);
digitalWrite(7, HIGH);
delay(400);
digitalWrite(7, LOW);
delay(230000); //Long pause before direction change
delay(2000);
digitalWrite(7, HIGH);
delay(400);
digitalWrite(7, LOW);
delay(2000);
digitalWrite(dirPin,HIGH); //Changes the rotations direction
// Makes 400 pulses for making two full cycle rotation
for(int x = 0; x < 30400; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin,LOW);
delayMicroseconds(1000);
}
delay(2000);
digitalWrite(7, HIGH);
delay(300);
digitalWrite(7, LOW);
delay(2000);
digitalWrite(dirPin,HIGH); //Changes the rotations direction
// Makes 400 pulses for making two full cycle rotation
for(int x = 0; x < 30400 ; x++) {
digitalWrite(stepPin,HIGH);
delayMicroseconds(1000);
digitalWrite(stepPin,LOW);
delayMicroseconds(1000);
}
delay(2000);
digitalWrite(7, HIGH);
delay(300);
digitalWrite(7, LOW);
delay(2000);
}