Running two Nema 17 with two DRV8825, Arduino, and Blynk

Hi everyone,

I have managed to make two Nema 17 accelerate, spin 5 times, and decelerate at the same time when I press a button once. Now I’m trying to do the same with a Blynk button, but I’m not sure how to incorporate my code with Blynk’s code and make it work.

I have managed to turn on and off an LED with Blynk with the setup bellow but nothing else. Online I haven’t found a clear example that shows me how to incorporate the functions I want to make within Blynks code.

Is there anyone that can help me with the matter? Thanks

Here is my setup:

  1. Nema 17 x2
  2. DRV8828 drivers x2
  3. Arduino Uno
  4. HM-10 Bluetooth board
  5. Push button x2
  6. IPhone 7

The code to run the stepper motors without Blynk is:

#include <Stepper.h>;

#include <AccelStepper.h>

const int buttonPin1 = 2;
const int REDledPin = 4;

const int buttonPin2 = 3;     // the number of the pushbutton pin
const int GREENledPin = 5;      // the number of the LED pin

int buttonState1 = 0;
int buttonState2 = 0;

AccelStepper stepper1(1, 9, 8); // pin 3 = step, pin 6 = direction
AccelStepper stepper2(1, 7, 6); // pin 4 = step, pin 7 = direction

void setup() {
 pinMode(REDledPin, OUTPUT);
 pinMode(GREENledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
 pinMode(buttonPin1, INPUT);
 pinMode(buttonPin2, INPUT);

 
}

void loop() {  

    // read the state of the pushbutton value:
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);

  
   // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState1 == HIGH) {
   //Trun LED on:
   digitalWrite(REDledPin, HIGH);
    } else {
     //Tun Off LED
     digitalWrite(REDledPin, LOW);
    }
    

      // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState2 == HIGH) {
   //Trun LED on:
   digitalWrite(GREENledPin, HIGH);
    } else {
     //Tun Off LED
     digitalWrite(GREENledPin, LOW);
    }

          // check if the pushbutton is pressed. If it is, the buttonState is HIGH:


  
  if (buttonState1 == HIGH) {
  stepper1.setMaxSpeed(2000.0);
   stepper1.setAcceleration(500.0);
  stepper1.moveTo(1000);
   
   
  stepper2.setMaxSpeed(2000.0);
  stepper2.setAcceleration(500.0);
  stepper2.moveTo(1000);

   
  }  if (buttonState2 == HIGH) {
    stepper1.setMaxSpeed(2000.0);
   stepper1.setAcceleration(500.0);
   stepper1.moveTo(-1000);
   
   
  stepper2.setMaxSpeed(2000.0);
  stepper2.setAcceleration(500.0);
  stepper2.moveTo(-1000);
  } 
  
 stepper1.run();
 stepper2.run();

}

First, you need to move all that code OUT of the void loop() and into timed functions so as not to bog down the Blynk communications link and cause disconnections.

http://docs.blynk.cc/#blynk-firmware-blynktimer

Steppers do require some precise timing of their own, so this can be challenging programming task.

Also this code is really good example for @ManiYr07 i guess