0

I am using Blynk to try and control a 28byj-48 stepper motor using the ULN2003 driver and an Arduino UNO from my iphone via USB withe the iOS Blynk App.

Without using Blynk, my stepper is smooth and works fine:

  #include <Servo.h>
  #include <Stepper.h>

  const int stepsPerMotorRevolution = 32;  //No of steps per internal revolution of motor,                                    
  const int stepsPerOutputRevolution = 32*64; //no of steps per revolution of the output shaft
  const int motorpin1 = 8;                    //Assign motor  pins to Arduino pins
  const int motorpin2 = 9;                    //
  const int motorpin3 = 10;                   //
  const int motorpin4 = 11;                   //

  // initialize the stepper library on pins 8 through 11, Motor rev steps, initialise firing sequence 1-3-2-4 
  Stepper myStepper(stepsPerMotorRevolution, motorpin1,motorpin3,motorpin2,motorpin4);    

  int pos = 0;    // variable to store the servo position

  void setup() {
    myStepper.setSpeed(600); 
  }

  void loop(){
     myStepper.step(-500); 
  }

But when I use Blynk, the stepper is so jerky and stutters terribly:

  #include <SoftwareSerial.h>
  SoftwareSerial SwSerial(10, 11);
  #define BLYNK_PRINT SwSerial
  #include <BlynkSimpleSerial.h>
  #include <Stepper.h>

  const int stepsPerMotorRevolution = 32;  //No of steps per internal revolution of motor,4-step mode                                     
  const int stepsPerOutputRevolution = 32*64; //no of steps per revolution of the output shaft
  const int motorpin1 = 8;                    //Assign motor pins to board pins
  const int motorpin2 = 9;                    //
  const int motorpin3 = 10;                   //
  const int motorpin4 = 11;                   //

  // initialize the stepper library on pins 8 through 11, Motor rev steps, initialise firing sequence 1-3-2-4 blah blah
  Stepper myStepper(stepsPerMotorRevolution, motorpin1,motorpin3,motorpin2,motorpin4);  
  char auth[] = "my auth key here";

  void setup(){
    SwSerial.begin(9600);
    Blynk.begin(auth);
    myStepper.setSpeed(600); 
  }

  BLYNK_WRITE(1){
    myStepper.step(param.asInt());
  }

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

I am using a slider on the app to control the stepper by the way. I am not sure what I am doing wrong, any suggestions?

2 Answers 2

1

Blynk runs over a network and therefore cannot respond in real-time nor consistently. You could have the Blynk slider control set a local variable which the motor controller would use for motor speed, but the basic motor-drive timing needs to be locally controlled and independent of network operations. The SimpleTimer library is one way; a timer interrupt would be another.

1
  • Ah I see, I'll look into the library and try come up with a solution! Thank you so much.
    – user20551
    Commented May 12, 2016 at 13:38
0

My guess would be you are suffering from a comms latency issue.

  1. Are you using a local server or the cloud?
  2. Is you iOS device connected over WIFI or 2G, 3G or 4G?

  3. Is you device on the same subnet as you iOS device and local server?

I've never used blynk (I might do this weekend though), my best thought as to how to fix it would be to revise your approach. When you are controlling devices over an unpredictable connection (Ethernet) you can't rely of messages to arrive in a certain order or at certain times. You need to tell the device to do something and keep doing it until its done or its told to stop.
So in this case tell the device to rotate clockwise at a certain rate until it travels n degrees or it is told to stop. Now you can't just tell the motor to make 20 turns, because that will make your app unresponsive. What you need to do it tell it to turn 50 steps and then return to the control loop, if no new order has come in it should then go and do another 50 steps, if there is a new order then off it goes with the new task.

Hope that makes sense and helps.

1
  • 1
    Great! I have a better understanding of the cons when it comes to my current setup now. I am using the cloud and my iOS connection is independant of my PC's internet connection (connected to Arduino). My servo motors however work almost instantaneously and without any issues! I might have to consider swapping out my stepper for a servo which in my case would also work fine. I hadn't thought about using control loops, i'll definitely give it a go! I just started using Blynk yesterday and it seems absolutely awesome so far. Thanks for the help!
    – user20551
    Commented May 12, 2016 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.