Hello,
I am trying to integrate a 28byj-48 stepper motor and ULN2003 Driver Board into this existing program i have. I got it to work using a blocking code but i need it to be none blocking. I tried to make the calculation for steps required and then just implement 1 step through each pass of the code but the motor doesn't seem to move. A and B Lights are on on the board and C flickers like its maybe doing 1 step and my serial monitor shows it knows how many steps it want to take but just no steps from the motor. I started to look into the accelstepper library and some other ones but i have struggled in implementing them.
Im just learning as I go but any help would be greatly appreciated
Here is my main loop
void loop()
{
//***********************
//time to toggle the heartbeatLED ?
if(millis() - heartbeatMillis >= 500);
{
//restart the TIMER
heartbeatMillis = millis();
//toggle the LED
digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
}
//***********************
//time to check the wheel sensor ?
if (millis() - wheelMillis >= 10)
{
//restart the TIMER
wheelMillis = millis();
checkWheelSensor();
}
//***********************
//if we are timing, have we reached the upper timing limit ?
if (timerRunningFlag == weAreTiming && millis() - timerMillis >= 400)
{
//disable the timing
timerRunningFlag = weAreNotTiming;
duration = 400;
printDigitalPot();
}
//***********************
//Other non-blocking code goes here
//***********************
brake_value = analogRead(BRAKE_IN_PIN);
clutch_value = analogRead(CLUTCH_IN_PIN);
if (stepstaken < tension);
{tensionstep.step (1);
stepstaken = stepstaken+1;
}
if (stepstaken > tension);
{tensionstep.step (-1);
stepstaken = stepstaken-1;
}
while (brake_value < 920) {
ds3502.setWiper(127);
Serial.print("Brake on ");
Serial.println(brake_value);
brake_value = analogRead(BRAKE_IN_PIN);
}
while (clutch_value < 900 && brake_value > 920) {
clutch_temp = map(clutch_value, 800, 80, digitalPot, 127);
clutch_temp = constrain(clutch_temp, 0, 127);
ds3502.setWiper(clutch_temp);
Serial.print("Clutch on ");
Serial.print(clutch_value);
Serial.print(" Digitalpot value: ");
Serial.println(clutch_temp);
brake_value = analogRead(BRAKE_IN_PIN);
clutch_value = analogRead(CLUTCH_IN_PIN);
while (digitalRead(reset) == LOW)
{
stepsLeft = 0;
Serial.println("reset");
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalRead(reset);
}
And this is where the step count is calculated
void printDigitalPot()
{
lowValue = 250; //lowspeed value
highspeed = analogRead(POTH); //0 to 1023
highValue = map(highspeed, 0, 1000, highLow, highHigh);
int temp = map( duration, highValue, lowValue, 0, 127);
temp = constrain(temp, 0, 127); //stay within the 0-127 range
digitalPot = temp;
ds3502.setWiper(digitalPot);
force = analogRead(PRESSURE);
force = map(force,0,1023,0,6000); //6000 may need to change, total steps for 3 full rotations
stepmath = map(digitalPot,0,127,force,0);
if (temp > 0); //less than full throttle
{
fullthrottle = notfull;
tension = stepmath-stepstaken;
}
if (fullthrottle = full);
{
fullsqueeze = stepmath/300; //300 may need to change depending on required full throttle pressure
tension = fullsqueeze;
}
if (fullthrottle = notfull && temp == 0);
{fullthrottle = full;
tension = stepmath-stepstaken;
}
Serial.print("Brake : ");
Serial.print(brake_value);
Serial.print(" Clutch : ");
Serial.print(clutch_value);
Serial.print(" ");
Serial.print(lowValue);
Serial.print(" ");
Serial.print("Timer spread ");
Serial.print(highValue);
Serial.print (" Time in millis = ");
Serial.print (duration);
Serial.print(" Digital pot set to: ");
Serial.print(digitalPot);
Serial.print("\t");
Serial.print(" ");
Serial.print(stepmath);
Serial.print(" -Stepmath Stepstaken- ");
Serial.print(stepstaken);
Serial.print(" Needed tension: ");
Serial.println(tension);
Serial.println("");
} //END of printDigitalPot()