Arduino yun Stepper Joystick

I realized this project, to drive a stepper motor back and forth varying the speed, my problem and it can not go fast, it seems limited, tips.

#include <SPI.h>
#include <Bridge.h>
#include <BlynkSimpleYun.h>
#include <AccelStepper.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>


Adafruit_MotorShield AFMS = Adafruit_MotorShield(); 
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 1);
// you can change these to SINGLE, DOUBLE or INTERLEAVE or MICROSTEP!

void forwardstep2() {  
  myMotor->onestep(BACKWARD, DOUBLE);
}
void backwardstep2() {  
  myMotor->onestep(FORWARD, DOUBLE);
}
AccelStepper stepper2(forwardstep2, backwardstep2);
char auth[] = "317e64a1f161476fa8b748042bd8ca55"; 
char ssid[] = "saibai";
char pass[] = "";

void setup() {
  Serial.begin(9600); 
  Blynk.begin(auth);
  AFMS.begin(); 
  stepper2.setMaxSpeed(4800);
  stepper2.setAcceleration(4800);
 
}
float speed; 
int direction;


// Joystick speed
BLYNK_WRITE(V5) { 
   speed = param.asFloat();
   control(direction, speed);
   myMotor->release();
}

// ON OFF
BLYNK_WRITE(V1) { 
  direction = param.asInt();
  control(direction, speed);
  myMotor->release();
}

 void loop()
{
  Blynk.run();
  stepper2.runSpeed(); 
}

void control(int direction, float speed){

if (direction == 0)
   stepper2.runSpeed();
   else
   stepper2.setSpeed(speed * direction);

}

One thing to try, does it work correctly without Blynk? That is the first step (little pun intended :wink: ) to try. That way you know it’s a hardware or software problem.

1 Like

Thanks, I tried, but everything works.
// Torna a 0
BLYNK_WRITE(V3) {
speed = param.asInt();
stepper2.runToNewPosition(speed);
stepper2.setMaxSpeed(1000.0);
stepper2.setAcceleration(3000.0);
control(direction, speed,acceleration );
myMotor->release();

with this function the stepper motor turns faster.