Controlling stepper motors

Hi. I have been enjoying Blynk for a while, and I have used it a few times with fun with my high school students.
Now I have a problem that I do not understand: I am using Arduino UNO over USB, Arduino stepper library, nema 17 stepper motor. I am trying to make the motor move as long as I keep a virtual button pressed on the app. (of course I verified that the same code works without blynk)

BLYNK_WRITE(V2){
if (param.asInt())
{
myStepperA.step(100);
} else
{
myStepperA.step(0);
}
}
I was expecting the same result i get with a led (if I keep the button pressed on the app, the lights is on), but in this case the motor makes a single rotation of 100 steps and then stops. i need to press the button again to move 100 more steps…
It is possible to get a continuous rotation?
Thanks for your help (and for Blynk!!!)
V

Instead of this use
myStepperA.step(param.asInt());
And in app use button as switch .
& Give maximum value for ON
For continuous rotation.
I think there should be some syntax for continuous rotation.

Thanks for your reply (very quick!!)
unfortunately it doesn’t work, beacause the argument for
myStepperA.step(…);
is the number of steps the motor should move.
It seems that the loop runs only once, the motor moves for the first block of steps, but then, when the loop should be repeated, the program does not feel that the virtual pin is already pressed (but with a simple LED it works…)
strange

Button will send value ones on pressing it .& Loop will runs onces.
BLYNK_WRITE(V2){ int steps = param.asInt(); if (steps >0) { myStepperA.step(steps); } else { myStepperA.step(0); } }
Define like this.

I would like to keep the motor in movement as long as i press the button, I also tried the while function with no success…I tried with a counter i++…always the same response from the motor

I think you should use this instead of
myStepperA.step(steps);
myStepperA.setSpeed(4); // set the motor speed to 4 RPM
Instead 4RPM you can use required RPM.

Same results
it rotates far a very small angle and then stops (with button and switch)
setSpeed()
is just a setting for the speed, but to make it move
myStepperA.step ()
is required
the same code with a real digital button works in the loop

thanks for your help!!!

1 Like

You need to use a loop to make it happen.

do
{
stepper.step(i);
i++;
}while param.asInt == 1;

Something like that should do it I thiink. Set button to Push for this, not for switch :slight_smile:

Hi, thanks a lot for your help, really
I have already tried that (and i did it again 3 minutes ago); the problem is that when i press the button the motor start rotating continuously and it keeps moving even if I release the button (in push mode!!!)

That is weird, the while statement should prevent that. Maybe add an if-statement in the loop;

do
{
if(param.asInt == 0)
{
  return();
}
// stepper stuff here
} while param.asInt() == 0;

I’m not sure about the “==” part. could be = to indicate a condition for comparison. The if statement should break the function and exit it. Also, of course, the condition should be 0, not 1.

HI again. i appreciate so much your help (i did not remember what return was…)
I used your last code but it works the same as while with i++

i press the button, the motor spins forever, even if i release the button (and i need to cut the power off to stop it)

very weird!!!

That is not my understanding of how Blynk buttons work (with Android) i.e. holding a button down does not repeat the signal sent to the server and then on to the hardware.

What I would do is use the button in switch mode, set a global flag for the on and off states, use a timer to read the flag states. If the state is on keep the servo spinning and stop it when the state is off. You would have to work out the number of milliseconds it takes for myStepperA.step(100) to complete and then just keep repeating it.

1 Like

Thanks a lot for your reply, i did not write before as i could not try a new code
YOU ARE RIGHT!!!
i followed your advices ad it works perfectly
Thank you sooooo much
and thank everybody who helped me these days
v

1 Like

Hi there. I want to do the same thing as you did but having troubles as well. Could you please send me the final code you used to accomplish your task?

Thanks
Rodrigo

@loviesbolies Please take note of the TimeDate stamps before posting… this topic is over a year old, so probably no code snippets for you :stuck_out_tongue:

But you could try creating your own topic and posting the code you have written and are working on :wink: