Stepper Motor: Modified 28BYJ-48
Ext. Power Supply: 6V
UC: Uno
Hbridge: SN754410
The motor works fine with the current code with significantly high torque.
The issue I'm having is that I cant calibrate a revolution without monitoring the steps over serial.
The thing is once I add the code "Serial.begin(9600);" the motor loses torque and dramatically slows down no matter how much I decrease the delay between each step.
I'm not sure what to do and how to set up the thing now...
Code:
int A = 5;//1
int B = 7;//3
int C = 4;//0
int D = 6;//2
long del = 1500;
int stepCount = 0;
bool fs[]={1,0,0,1,
1,1,0,0,
0,1,1,0,
0,0,1,1};
bool hs[]={1,0,0,1,
1,0,0,0,
1,1,0,0,
0,1,0,0,
0,1,1,0,
0,0,1,0,
0,0,1,1,
0,0,0,1};
#define L LOW
#define H HIGH
void setup() {
pinMode(A, OUTPUT);
pinMode(B, OUTPUT);
pinMode(C, OUTPUT);
pinMode(D, OUTPUT);
Serial.begin(9600); <<<<<<<<<
}
void fullStep(int step){
int stepNum = 4;
int trueStep = step-stepNum*round((step/stepNum)-0.4);
switch(trueStep){
case 0:
digitalWrite(A, fs[0]);
digitalWrite(B, fs[1]);
digitalWrite(C, fs[2]);
digitalWrite(D, fs[3]);
break;
case 1:
digitalWrite(A, fs[4]);
digitalWrite(B, fs[5]);
digitalWrite(C, fs[6]);
digitalWrite(D, fs[7]);
break;
case 2:
digitalWrite(A, fs[8]);
digitalWrite(B, fs[9]);
digitalWrite(C, fs[10]);
digitalWrite(D, fs[11]);
break;
case 3:
digitalWrite(A, fs[12]);
digitalWrite(B, fs[13]);
digitalWrite(C, fs[14]);
digitalWrite(D, fs[15]);
break;
default:
break;
}
}
void halfStep(int step){
int stepNum = 8;
int trueStep = step-stepNum*round((step/stepNum)-0.4);
switch(trueStep){
case 0:
digitalWrite(A, hs[0]);
digitalWrite(B, hs[1]);
digitalWrite(C, hs[2]);
digitalWrite(D, hs[3]);
break;
case 1:
digitalWrite(A, hs[4]);
digitalWrite(B, hs[5]);
digitalWrite(C, hs[6]);
digitalWrite(D, hs[7]);
break;
case 2:
digitalWrite(A, hs[8]);
digitalWrite(B, hs[9]);
digitalWrite(C, hs[10]);
digitalWrite(D, hs[11]);
break;
case 3:
digitalWrite(A, hs[12]);
digitalWrite(B, hs[13]);
digitalWrite(C, hs[14]);
digitalWrite(D, hs[15]);
break;
case 4:
digitalWrite(A, hs[16]);
digitalWrite(B, hs[17]);
digitalWrite(C, hs[18]);
digitalWrite(D, hs[19]);
break;
case 5:
digitalWrite(A, hs[20]);
digitalWrite(B, hs[21]);
digitalWrite(C, hs[22]);
digitalWrite(D, hs[23]);
break;
case 6:
digitalWrite(A, hs[24]);
digitalWrite(B, hs[25]);
digitalWrite(C, hs[26]);
digitalWrite(D, hs[27]);
break;
case 7:
digitalWrite(A, hs[28]);
digitalWrite(B, hs[29]);
digitalWrite(C, hs[30]);
digitalWrite(D, hs[31]);
break;
default:
break;
}
}
void loop(){
Serial.println(stepCount);
// fullStep(a);
halfStep(stepCount);
stepCount++;
delayMicroseconds(del);
// delay(del);
}