NodeMCU ESP8266 - How to use stepper motors from Old printers with L298N







#include <Stepper.h>

const int stepsPerRevolution = 200;  // change this to fit the number of steps per revolution
// for your motor

// initialize the stepper library on pins 5 through 8:
Stepper myStepper(stepsPerRevolution, 5, 6, 7, 8);

int stepCount = 0;         // number of steps the motor has taken
int dirStep = 1;
void setup() {
  // initialize the serial port:
  Serial.begin(9600);
}

void loop() {
  // step one step:
  myStepper.step(dirStep);
  Serial.print("steps:");
  Serial.println(stepCount);
  stepCount++;

  if( stepCount > 500){
      stepCount = 0;
      if( dirStep == 1) dirStep = -1;
      else dirStep = 1;
  }


  delayMicroseconds(50);
}

ความคิดเห็น

  1. This code works for me on an Arduino UNO - ( using pins 8,9,10,11).
    I cannot get it to work on a ESP8266 with 5,6,7,8 .
    The motor does not turn. The ESP8266 crashes.

    Should I used delay(1); ?
    or
    Yield();

    ตอบลบ

แสดงความคิดเห็น