Blynk interfere stepper motor

Hi,

I have two stepper motors that I control by Blynk and buttons. One motor "small_stepperB" works ok. The small_stepperF get interfered by Blyck code.
Running with the code below two leds is lit (and stays on) on the control board ULN2003 from power up and with no commands sent. The motor jerks around when command is sent to move.

I have removed all blynk code, the leds are off and the motor moves as it should.

The leds are lit when connecting pin 11. Tried other free pins but lit anyhow.

Any ideas why this happens and what to do?

Regards,
Mats

#include <SPI.h>
#include <Stepper.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>

int pos;
int  Steps2Take;

char auth[] = "xxxxxxxxxxxxxxxxxxxxxxxxx";

// Stepper
#define STEPS_PER_MOTOR_REVOLUTION 32
#define STEPS_PER_OUTPUT_REVOLUTION 32 * 64 
Stepper small_stepperF(STEPS_PER_MOTOR_REVOLUTION, 7, 9, 8, 11);
Stepper small_stepperB(STEPS_PER_MOTOR_REVOLUTION, 2, 5, 3, 6);

// Blynk
#define BLYNK_PRINT Serial 
// Ethernet
#define W5100_CS  10


BLYNK_WRITE(V1)
{int  stepp1 = param.asInt(); pos = pos + stepp1;  Steps2Take = stepp1; small_stepperF.step(Steps2Take); Steps2Take = 0; digitalWrite(7,LOW); digitalWrite(8,LOW); digitalWrite(9,LOW); digitalWrite(11,LOW); }

BLYNK_WRITE(V0)
{int  stepp5 = param.asInt(); pos = pos + stepp5;  Steps2Take = stepp5; small_stepperF.step(Steps2Take); Steps2Take = 0; digitalWrite(7,LOW); digitalWrite(8,LOW); digitalWrite(9,LOW); digitalWrite(11,LOW); }

BLYNK_WRITE(V3)
{int  stepp10 = param.asInt(); pos = pos + stepp10;  Steps2Take = stepp10; small_stepperF.step(Steps2Take); Steps2Take = 0; digitalWrite(7,LOW); digitalWrite(8,LOW); digitalWrite(9,LOW); digitalWrite(11,LOW); }

BLYNK_WRITE(V10) // Bathinov
{if (param.asInt() == 1) { small_stepperB.step(1024); digitalWrite(2,LOW); digitalWrite(3,LOW); digitalWrite(5,LOW); digitalWrite(6,LOW);}}

BlynkTimer timer;


void setup() {
  // Debug console
  Serial.begin(9600);

pinMode(0, INPUT); // Button Focuser -
pinMode(1, INPUT); // Button Bathinov
pinMode(12, INPUT); // Button Focuser + 

pinMode(2, OUTPUT); // Stepper B
pinMode(3, OUTPUT); // Stepper B
pinMode(5, OUTPUT); // Stepper B
pinMode(6, OUTPUT); // Stepper B
pinMode(7, OUTPUT); // Stepper F
pinMode(8, OUTPUT); // Stepper F
pinMode(9, OUTPUT); // Stepper B
pinMode(11, OUTPUT); // Stepper B


small_stepperB.setSpeed(500);
small_stepperF.setSpeed(100);

Blynk.begin(auth);

timer.setInterval(1007L, updateblynk);
timer.setInterval(200L, read_button_bath);
timer.setInterval(200L, read_button_focusplus);
timer.setInterval(200L, read_button_focusminus);
}


void read_button_bath() {
if (digitalRead(1) == LOW) {
delay(150);
  while (digitalRead(1) == LOW);
  small_stepperB.step(1024); digitalWrite(2,LOW); digitalWrite(3,LOW); digitalWrite(5,LOW); digitalWrite(6,LOW);}
}

void read_button_focusplus() {
if (digitalRead(12) == LOW) {
delay(150);
  while (digitalRead(12) == LOW);
  int  stepp10 = 100; pos = pos + stepp10;  Steps2Take = stepp10; small_stepperF.step(Steps2Take); Steps2Take = 0; digitalWrite(7,LOW); digitalWrite(8,LOW); digitalWrite(9,LOW); digitalWrite(11,LOW);}
}

void read_button_focusminus() {
if (digitalRead(0) == LOW) {
delay(150);
  while (digitalRead(0) == LOW);
  int  stepp10 = -100; pos = pos + stepp10;  Steps2Take = stepp10; small_stepperF.step(Steps2Take); Steps2Take = 0; digitalWrite(7,LOW); digitalWrite(8,LOW); digitalWrite(9,LOW); digitalWrite(11,LOW);}
}

void updateblynk() {
Blynk.virtualWrite(2, pos);
}


void loop() {
Blynk.run(); 
timer.run();
}
    int  stepp10 = -100; pos = pos + stepp10;  Steps2Take = stepp10; small_stepperF.step(Steps2Take); Steps2Take = 0; digitalWrite(7, LOW); digitalWrite(8, LOW); digitalWrite(9, LOW); digitalWrite(11, LOW);

Look carefully at your keyboard. One of the keys is big and long. There's only one of them. The next-largest key may even have two of them on the keyboard.

Use it.

The small_stepperF get interfered by Blyck code.

That is a useless statement. First, you misspelled Blynk. Second, what the hell does "get interfered" even mean?

Facts are good thing. They are in extremely short supply in your post.

I suspect it would be more accurate to say that your use of the standard Stepper library is interfering with your BLYNK code.

The standard Stepper library is rather primitive as it blocks the Arduino until it finishes a move. My wild guess is that Blynk is interrupting that process. If so then either write your own code to move the motor one step at a time so as to allow for Blynk to be checked between steps or maybe use the AccelStepper library which is non-blocking by default.

If my wild guess is all wrong then please explain what is really happening.

...R
Stepper Motor Basics
Simple Stepper Code

Thank you Robin2 :slight_smile:

I have checked the AccelStepper library and that was great!
Much more functions to use.

I have sorted out the issue. It looks like the Ethernet use pin 10,11,12 and 13.
Had only read that it should be pin 10.
I did not help though just to not use those pins.

The new pinout on the UNO that works are:
Stepper stepperF(STEPS_PER_MOTOR_REVOLUTION, 4, 6, 5, 7);
Stepper stepperB(STEPS_PER_MOTOR_REVOLUTION, 8, 2, 9, 3);

Regards,
Mats