Running a stepper in both directions from analogue input - AccelStepper

Hi,
Having some troubles in running the motor in reverse, theres probably an easy solution that im missing. Hope its quite straight forward to see what Im doing. The 499 value is center for my pot.

Also trying to get a higher rpm by using SBright's code / library but having difficulty calling out some of his functions (mainly 12V 35rpm) stuff.

Motor is the ubiquitous 28BY J-48

Thanks for any help

#include <AccelStepper.h>

AccelStepper stepper;
AccelStepper stepper2;

#define HORIZ_IN A0
#define VERT_IN A1

const int Xdeadzone = 3, Ydeadzone = 3; 

void setup()
{
  Serial.begin(9600);
  stepper.setMaxSpeed(1000);
  stepper2.setMaxSpeed(1000);
  stepper.setSpeed(700);
  stepper2.setSpeed(700);
}
  

void loop()
{
  int X = analogRead(HORIZ_IN);
  int Y = analogRead(VERT_IN);
  Serial.println(X);
  
if (X >= (499 + Xdeadzone))//Right
  stepper.runSpeed(); 
  
else if (X < (499 - Xdeadzone))//Left
  -stepper.runSpeed();
   
  
  }

I guess setSpeed() must be fed a new parameter within loop()
The minus-sign I believe is irrelevant.

Putting a minus sign before "stepper" makes no sense. "stepper" is an instance of the Class "AccelStepper". It's like putting a minus before your own name.

I'm not familiar with AccelStepper but I presume there is a method to set the direction of rotation such as "stepper.direction"

...R

In the Accel Stepper library there is a value for clockwise and anti cw but they seem to be more reference rather than executable.

"Direction indicator Symbolic names for the direction the motor is turning.

Enumerator:
DIRECTION_CCW
Clockwise.

DIRECTION_CW
Counter-Clockwise."

I will try putting a while (do) statement into the loop instead. I am quite happy with the motors just turning for now, they do not need to reach a specific analogue-relevant position.

Still would like to know more about running at 12v for higher rpm

I've had a quick look at the AccelStepper website (I strongly recommend reading!) and it seems that you use negative values to go backwards - such as move(10) or move(-10).

I think I will stick with my own code and not bother with the library.

You haven't said what stepper driver board you are using - that will determine the max voltage you can use. H-bridge boards can't limit the current in the way that "proper" stepper driver boards can.

...R

Hi GreyE30,

I,m also playing with the "ubiquitous 28BY J-48"

The max RPM of the motor at 5v is only 14 rpm

I tried using a value of 1000 as" Max Speed", or "set-speed" , or what ever your sketch calls it.

Didn't work!!

A value of 750 gets the motor running at about 14 RPM.

Hope it helps

Mick