Soft WDT reset on NodeMCU 1.0 LoLin V3 using delayMicroseconds()

33 views Asked by At

I am getting the following error on NodeMCU 1.0 LoLin V3. It comes to the serial console. For now, nothing is connected to the board so it is not a hardware issue.

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Soft WDT reset

Exception (4):
epc1=0x4000dd38 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

>>>stack>>>

ctx: cont
sp: 3ffffe30 end: 3fffffd0 offset: 0160
3fffff90:  402010dc 000003a5 000003e8 402010d4  
3fffffa0:  3fffdad0 00000000 3ffee54c 40201119  
3fffffb0:  feefeffe 00000000 3ffee54c 402019a4  
3fffffc0:  feefeffe feefeffe 3fffdab0 40100d89  
<<<stack<<<

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Here is the code that produces it. It is straightforward.

If I comment out the 2 lines containing delayMicroseconds(), the error goes.

It is trying to move a stepper motor.

// define the pins
#define EN_PIN    14 //enable 
#define STEP_PIN  5 //step
#define DIR_PIN   12 //direction

void setup() 
{
  pinMode(LED_BUILTIN, OUTPUT);  // Initialize the LED_BUILTIN pin as an output

  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);

  //set pin modes
  pinMode(EN_PIN, OUTPUT); // set the EN_PIN as an output
  digitalWrite(EN_PIN, HIGH); // deactivate driver (LOW active)
  pinMode(DIR_PIN, OUTPUT); // set the DIR_PIN as an output
  digitalWrite(DIR_PIN, LOW); // set the direction pin to low
  pinMode(STEP_PIN, OUTPUT); // set the STEP_PIN as an output
  digitalWrite(STEP_PIN, LOW); // set the step pin to low

  digitalWrite(EN_PIN, LOW); // activate driver

}

void loop()
{
  //make steps
  rotateMotor(1600,1,100); // full fast rotation clockwise
  delay(1000); // one second delay
  rotateMotor(1600,0,1000); // full slow rotation anticlockwise
  delay(1000); // one second delay
  rotateMotor(400,1,500); // quarter rotation clockwise
  delay(1000); // one second delay
  rotateMotor(400,0,500); // quarter rotation anticlockwise
  delay(1000); // one second delay
}

// This function sets the number of steps, the direction and the speed
// steps: a full rotation requires 1600 steps
// direction: 1 = clockwise, 0 = anticlockwise
// speed: number of microseconds between each step, min 100
void rotateMotor(int steps, bool direction, int speed) {
  digitalWrite(LED_BUILTIN, LOW);
  // Set the motor direction
  digitalWrite(DIR_PIN, direction);
  
  // Step the motor
  for (int i = 0; i < steps; i++) {
    digitalWrite(STEP_PIN, HIGH);
    delayMicroseconds(speed);
    digitalWrite(STEP_PIN, LOW);
    delayMicroseconds(speed);
  }

  digitalWrite(LED_BUILTIN, HIGH);
}

I tried different boards of the same kind and all gave me this error.

0

There are 0 answers