A, I am not allowed to
B, what does the rest have to do with this loop?
I have reduced the code to this.
/*
*/
const char compile_date[] = __DATE__;
const char compile_time[] = __TIME__;
#include <AccelStepper.h>
#define motorInterfaceType 1
#define ENABLE 7
#define DIR 6
#define PUL 8
const int SENSOR5 = 11; // digital input
int lastPosition = 0;
// Define a stepper and the pins it will use
AccelStepper stepper = AccelStepper(motorInterfaceType, PUL, DIR);
#define stepsPerRevolution 6400
void setup()
{
Serial.begin(115200);
while (!Serial); //Wait for the serial port to come online
Serial.println("\n\n\n\n\n\n\n\n\n");
Serial.print("Compiled on: ");
Serial.print(compile_date);
Serial.print(" at ");
Serial.println(compile_time);
Serial.println("Starting... ");
// Motor controller
pinMode(PUL, OUTPUT); // sets the digital pin 13 as output
pinMode(DIR, OUTPUT); // sets the digital pin 13 as output
pinMode(ENABLE, OUTPUT); // sets the digital pin 13 as output
digitalWrite(ENABLE, LOW);
// Set the maximum speed and acceleration:
stepper.setMaxSpeed(5000);
stepper.setAcceleration(1000);
stepper.setSpeed(800);
digitalWrite(ENABLE, HIGH);
Serial.println("End init");
}
static bool homeFound = false;
void findHome()
{
int count = 0;
int loops = 0;
int value_D0 = 0;
long currentPosition = 0;
bool sensorFound = false;
Serial.print("Find Home ");
digitalWrite(ENABLE, LOW);
stepper.setAcceleration(300);
stepper.setSpeed(200);
static int toMove = 6400;
homeFound = false;
long position = stepper.currentPosition();
Serial.println(position);
sensorFound = false;
// Wait for the motor to reach its target position
currentPosition = stepper.currentPosition();
Serial.print(" Forward-1: "); Serial.print(toMove);
Serial.print(" : "); Serial.println(currentPosition);
stepper.moveTo(toMove + currentPosition);
while (stepper.distanceToGo() != 0) {
value_D0 = digitalRead(SENSOR5);// reads the digital input from the sensor2
if (value_D0 == LOW)
{
homeFound = true;
break;
}
stepper.run();
}
// delay(1000);
if (homeFound)
Serial.println("stop");
else
Serial.println("\t NO SENSOR5");
}
/****************************************************************************/
void loop()
{
if (Serial.available())
{
String line = Serial.readStringUntil('\n');
int blower = line.substring(1).toInt();
char command = line.charAt(0);
if (command == 'h')
{
Serial.println("Find Home");
findHome();
}
}
}
I am not able to provide a schematic as it all goes into a pcb that is proprietary. 12v 3a power supply to TB6000.
Here is a link to a video. Notice the end. Also notice the sound. https://youtu.be/_Nu_L05lknA