Hello everyone. I am attempting to control a stepper motors speed and direction, using a joystick, driven with a Geckodrive G213V.
The Geckodrive is driven simply by 2 pins. STEP and DIRECTION. I think I have that down.
But it won't respond quite like it should. I have direction control but I can't vary the speed. I have looked into changing the pwm frequency, but
everything I did resulted in no change. When I reach the upper/lower value of the joystick the motor stops turning.
I have modified the code from an earlier project, but when I take values from a multimeter on the pins, it appears to work just like it should.
I must be overlooking something.
The code:
//motor pins and reverse
const int XMPin = 11 ;
const int XPin = 3 ;
const int YMPin = 9 ;
const int YPin = 10 ;
// pointometers/joystick
int joyx = A0 ;
int joyy = A1 ;
// variables
int Xval = 0 ;
int Yval = 0 ;
/////////////////////////////////////////////////////////////////////////////////////
void setup() {
Serial.begin(9600);
pinMode (XMPin, OUTPUT);
pinMode (XPin, OUTPUT);
pinMode (YMPin, OUTPUT);
pinMode (YPin, OUTPUT);
}
/////////////////////////////////////////////////////////////////////////////////////
void loop()
{
Xval = analogRead(joyx);
if(Xval < 480)
{
Xval = map(Xval, 480, 1, 0, 255);
analogWrite (XPin, constrain (Xval, 0, 255));
digitalWrite (XMPin, HIGH);
}
if(Xval > 542)
{
Xval = map(Xval, 542, 1023, 0, 255);
analogWrite(XPin, constrain (Xval, 0, 255));
digitalWrite (XMPin, LOW);
}
{
Yval = analogRead(joyy);
if(Yval < 480)
{
Yval = map(Yval, 480, 1, 0, 255);
analogWrite (YPin, constrain (Yval, 0, 255));
digitalWrite (YMPin, LOW);
}
if(Yval > 542)
{
Yval = map(Yval, 542, 1023, 0, 255);
analogWrite(YPin, constrain (Yval, 0, 255));
digitalWrite (YMPin, HIGH);
}
}
}
Here is a video of what is happening.
Any help is appreciated
Thanks
Nick B.