Hi,
I'm new to this forum and after having searched on the internet I come to ask an answer to my problem.
I found on this forum someone who had exactly the same needs as me but he had no answer .. This topic dating back to 2012 I opened a new one.
My project is a wheel that rotates 360 °. It is controlled by Ascom driver windows (VBA) that it is controlled by a video capture software.
So: Arduino Nano --> Ascom Driver VBA --> Windows software
I have a sketch (I did not create because I do not know much coding) that positions the wheel in 5 precise positions.
FILTER1
FILTER2
.....
#include <AccelStepper.h>
#define HALFSTEP 8 // Nécessaire au bon fonctionnement du moteur
#define LEDoccupe A3
#define LEDok A1
int CurrentFilter = 0;
int homepin = A2;
// Motor pin definitions
#define motorPin1 8 // IN1 on UL2003
#define motorPin2 9 // IN2 on UL2003
#define motorPin3 10 // IN3 on UL2003
#define motorPin4 11 // IN4 on UL2003
// Initialisation de la sequence des pins IN1-IN3-IN2-IN4
AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
void setup() {
stepper1.setAcceleration(3000.0);// Acceleration Max du moteur A PARAMETRER
stepper1.setMaxSpeed(5000.0); // Vitesse Max du moteur A PARAMETRER
stepper1.setCurrentPosition(0);
Serial.flush();
Serial.begin(9600); // Doit correspondre à votre driver ASCOM A PARAMETRER
pinMode(homepin, INPUT);
analogWrite(LEDok,1023);
analogWrite(LEDoccupe,1023);
delay(500);
analogWrite(LEDok,0);
analogWrite(LEDoccupe,0);
}
void loop() {
String cmd;
if (Serial.available() >0) {
cmd = Serial.readStringUntil('#');
if (cmd=="GETFILTER") {
Serial.print(CurrentFilter); Serial.println("#");
}
else if (cmd=="FILTER0") MoveFilter(0);
else if (cmd=="FILTER1") MoveFilter(1);
else if (cmd=="FILTER2") MoveFilter(2);
else if (cmd=="FILTER3") MoveFilter(3);
else if (cmd=="FILTER4") MoveFilter(4);
else if (cmd=="FILTER5") MoveFilter(5);
}
}
void MoteurOFF() {
digitalWrite(8,LOW);
digitalWrite(9,LOW);
digitalWrite(10,LOW);
digitalWrite(11,LOW);
}
void MoveFilter(int pos)
{
CurrentFilter = pos;
switch (CurrentFilter)
{
case 0: // DEPLACEMENT FILTER 1
analogWrite(LEDok,0);
analogWrite(LEDoccupe,1023);
stepper1.run();
stepper1.runToNewPosition(CurrentFilter * 6250); // 6250= Distance entre chaque FILTER en nbre pas 360°/5 A PARAMETRER
Serial.print(CurrentFilter); Serial.println("#");
MoteurOFF();
analogWrite(LEDoccupe,0);
delay(750);
analogWrite(LEDok,1023);
MoteurOFF();
break;
case 1: // DEPLACEMENT FILTER 2
analogWrite(LEDok,0);
analogWrite(LEDoccupe,1023);
stepper1.run();
stepper1.runToNewPosition(CurrentFilter * 6250); // 6250= Distance entre chaque FILTER en nbre pas 360°/5 A PARAMETRER
Serial.print(CurrentFilter); Serial.println("#");
MoteurOFF();
analogWrite(LEDoccupe,0);
delay(750);
analogWrite(LEDok,1023);
break;
case 2: // DEPLACEMENT FILTER 3
analogWrite(LEDok,0);
analogWrite(LEDoccupe,1023);
stepper1.run();
stepper1.runToNewPosition(CurrentFilter * 6250); // 6250= Distance entre chaque FILTER en nbre pas 360°/5 A PARAMETRER
Serial.print(CurrentFilter); Serial.println("#");
MoteurOFF();
analogWrite(LEDoccupe,0);
delay(750);
analogWrite(LEDok,1023);
break;
case 3: // // DEPLACEMENT FILTER 4
analogWrite(LEDok,0);
analogWrite(LEDoccupe,1023);
stepper1.run();
stepper1.runToNewPosition(CurrentFilter * 6250); // 6250= Distance entre chaque FILTER en nbre pas 360°/5 A PARAMETRER
Serial.print(CurrentFilter); Serial.println("#");
MoteurOFF();
analogWrite(LEDoccupe,0);
delay(750);
analogWrite(LEDok,1023);
break;
case 4: // DEPLACEMENT FILTER 5
analogWrite(LEDok,0);
analogWrite(LEDoccupe,1023);
stepper1.run();
stepper1.runToNewPosition(CurrentFilter * 6250); // 6250= Distance entre chaque FILTER en nbre pas 360°/5 A PARAMETRER
Serial.print(CurrentFilter); Serial.println("#");
MoteurOFF();
analogWrite(LEDoccupe,0);
delay(750);
analogWrite(LEDok,1023);
break;
}
}
}
With the serial monitor I can control the wheel as well that from my software when I icons that correspond to different positions.
I bought a Hall sensor to try to create a home point for the wheel but I can not control it in the sketch. I tried several things found here and there on the forums but nothing functional.
What I would like is to add a position in void MoveFilter(int pos) that rotates the wheel until detect the sensor and the magnet at this time, puts the original position.
I thought then add this position in the setup function by calling MoveFilter(5) for example.
you can find the change that I have tried to do in CASE 5 and who does not work. When I call GETFILTER5 wheel moves only one position. She does not go to the sensor
case 5: // DEPLACEMENT FILTER 5
pinMode(homepin, INPUT);
analogWrite(LEDok,0);
analogWrite(LEDoccupe,1023);
while(digitalRead(homepin) == HIGH){ // switch not yet triggered/home
stepper1.run();
// stepper1.runToNewPosition(CurrentFilter * 6250); // 6250= Distance entre chaque FILTER en nbre pas 360°/5 A PARAMETRER
Serial.print(CurrentFilter); Serial.println("#");
MoteurOFF();
analogWrite(LEDoccupe,0);
delay(750);
analogWrite(LEDok,1023);
break;
If anyone can give me a solution that would be great appreciated.
Here the guy from the video link that creates the code where it explains the operation.
thank you