Hello. I am still on my way to make an XY-table for a microscope.
Last time I got this issue:
https://forum.arduino.cc/index.php?topic=625991.0
And the reason of the issue was the shield.
Now a stepper motor from a CD-ROM won't go backward, only forward.
I can control forward movement with a joystick, but regardless of the signal from the joystick, it only moves forward, then, when it reaches the end of the CD-ROM device, it goes backward. Here is my code.
#include <Stepper.h>
#include "AFMotor.h"
#define joystick A0
//int joystick = A0;
int sensorReading = 0;
int stepRev = 5;
const int stepsPerRevolution = 20;
const int motorSpeed = 255;
const int motorSpeed2 = 255;
// Stepper myStepper(stepsPerRevolution, 5,6);
AF_Stepper Stepper1(20,1);
void setup() {
Serial.begin(9600);
}
void loop() {
//Stepper1.setSpeed(255);
sensorReading = analogRead(joystick);
delay(50);
Serial.print(sensorReading);
Serial.print("\t");
if (sensorReading<500){
Serial.print("Hello world.") ;
Serial.print("\t");
Stepper1.step(stepRev,FORWARD,MICROSTEP);
Stepper1.setSpeed(motorSpeed);
delay(10);
// sensorReading = analogRead(joystick);
// delay(10);
}
if (sensorReading >600){
Stepper1.step(stepRev,BACKWARD,MICROSTEP);
Stepper1.setSpeed(motorSpeed2);
Serial.print("bye world.");
Serial.print("\t");
delay(10);
// sensorReading = analogRead(joystick);
// delay(10);
}
Stepper1.release();
}
I tried simple code, but it also did not go backward.
#include "AFMotor.h"
AF_Stepper Stepper1(20,1); // #2 M3,M4
void setup() {
Stepper1.setSpeed(255);
}
void loop()
{
Stepper1.step(200,BACKWARD, MICROSTEP);
delay(1000);
}