arduino-libraries / Stepper

Stepper Library for Arduino
http://arduino.cc/
107 stars 114 forks source link

ESP8266 Software reset #17

Open BenjaminZimbal opened 4 years ago

BenjaminZimbal commented 4 years ago

Hey there!

I am currently using a WEMOS D1 mini together with a 4-Pin stepper motor. It works correctly but after turning it, the esp runs through a software reset.

The Exception Decoder says the following:

0x402016a4: Stepper::stepMotor(int) at D:\Arduino\libraries\Stepper\src\Stepper.cpp line 356
0x402016df: Stepper::step(int) at D:\Arduino\libraries\Stepper\src\Stepper.cpp line 198

My code looks like this:

#include <NTPClient.h>
#include <Stepper.h>
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

// wifi settings
const char *ssid     = "Martin Router King";
const char *password = "<secret password here>";

// ntp settings
const long utcOffsetInSeconds = 3600;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

// Define NTP Client to get time
WiFiUDP ntpUDP;
NTPClient timeClient(ntpUDP, "pool.ntp.org", utcOffsetInSeconds);

// stepper settings
Stepper Motor(2048, D1, D3, D2, D4);

void setup(){
  Serial.begin(115200);

  // wifi
  WiFi.begin(ssid, password);
  while ( WiFi.status() != WL_CONNECTED ) {
    delay ( 500 );
    Serial.print ( "." );
  }
  Serial.println("Connected!");

  // ntp
  timeClient.begin();

  // stepper
  Motor.setSpeed(10);
}

void loop() {
  timeClient.update();

  int currentHour = timeClient.getHours();

  if(currentHour % 12 == 0 && timeClient.getMinutes() == 6 && timeClient.getSeconds() == 0){
    Serial.println("Liftoff!");
    Motor.step(2048);
  }
  delay(1000);
}

The stepper motor is connected as follows: IN1 -> D4 IN2 -> D3 IN3 -> D2 IN4 -> D1

As I said, it works and rotates but after its done my esp resets :/

Also I couldn't find any issue in the Stepper.cpp/Stepper.h (for my low experience level with C++).

EDIT: I tried using only the stepper motor without any NTP or anything else, it keeps resetting.

WhiteLionATX commented 2 years ago

I ve the same issu. I am using a Nema 17 stepper motor with L298N driver board and a WeMos D1. I think it has to do with the delays you are using. (lag of yield();) But I am unsure about that. My code is far more complex but this code does work for me. Try it:

// Include the Arduino Stepper Library
#include <Stepper.h>

// Number of steps per output rotation
const int stepsPerRevolution = 400;

// Create Instance of Stepper library
Stepper myStepper(stepsPerRevolution, 15, 13, 12, 14);

void setup()
{
  // set the speed at 60 rpm:
  myStepper.setSpeed(60);
  Serial.begin(9600); 
}

void loop() 
{
  Serial.println("clockwise");
  myStepper.step(stepsPerRevolution);
}
Hello1024 commented 1 year ago

This has been fixed by #13