Chat freely about anything...

User avatar
By FEC
#79116 Hello, I am trying to use the ESP8266, MCP23008, Blynk and a step motor. The idea is to use these to open and close blinds. Everyone works until you push a button the Blynk App. At which point I get this:

V1 - Pressed

Soft WDT reset

ctx: cont
sp: 3ffffc50 end: 3fffffd0 offset: 01b0

>>>stack>>>
3ffffe00: 00007fff 01763d33 4010224e 00000001
3ffffe10: 3ffef2b0 0000000c 3ffef4c4 40205908
3ffffe20: 3ffef2b0 00000001 3ffef4c4 40205ad9
3ffffe30: 3ffe8b4b 3fffff13 00000000 40205ad9
3ffffe40: 3ffe8a00 00000000 00000007 40106561
3ffffe50: 3ffef2b0 00000001 00000000 402032b3
3ffffe60: 3ffef4a4 3ffef2a4 3ffe851c 402033aa
3ffffe70: 00000000 00000000 3fff049c 00000001
3ffffe80: 3ffef2b0 00000001 3fffff16 402037d4
3ffffe90: 00000000 00000000 4bc6a7f0 4020fbf9
3ffffea0: 3fffff15 00000001 00000001 3fffff10
3ffffeb0: 00000001 00000000 4bc6a7f0 3fffff15
3ffffec0: 3fffff16 3fff7776 401064ca b1a9fbe7
3ffffed0: 00000006 3fffff10 00000000 402019ef
3ffffee0: 00000000 3fffff10 3ffef2b0 3fffff10
3ffffef0: 00000000 3fffff10 3ffef2b0 40203b78
3fffff00: 3fffdad0 3ffef2d4 3ffef2b0 402038a0
3fffff10: 31007776 4b003100 00005fce 3ffef59c
3fffff20: 00000000 00000000 3ffe863c 3ffef2d4
3fffff30: 3fffdad0 06787b14 3ffe8600 3ffef2d4
3fffff40: 3fffdad0 3ffef59c 40206100 3fffefb0
3fffff50: 00000006 3ffef2d4 00000000 402019ef
3fffff60: 3fffdad0 3ffef2d4 3ffef2b0 3ffef59c
3fffff70: 3fffdad0 3ffef2d4 3ffef2b0 40203dde
3fffff80: 00000001 00000002 3ffef4c4 3ffef59c
3fffff90: 00000000 3ffef2ac 00000001 3ffef59c
3fffffa0: 3fffdad0 00000000 3ffef594 40204123
3fffffb0: 3fffdad0 00000000 3ffef594 4020618c
3fffffc0: feefeffe feefeffe 3ffe863c 40100739
<<<stack<<<


The ESP8266 then resets and it starts again fine, until a button is pushed!

From what I can tell, this is because the stepper code (below) is stopping the ESP Library doing its thing for too long. But I am not sure how to get around this. This is the stack decoded:

Code: Select allDecoding stack results
0x40205904: HardwareSerial::write(unsigned char const*, unsigned int) at /Users/Andrew/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.2/cores/esp8266/HardwareSerial.h line 159
0x40205ad5: Print::write(char const*) at /Users/Andrew/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.2/cores/esp8266/Print.h line 60
0x40205ad5: Print::write(char const*) at /Users/Andrew/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.2/cores/esp8266/Print.h line 60
0x40106561: __digitalWrite at /Users/Andrew/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.2/cores/esp8266/core_esp8266_wiring_digital.c line 82
0x402032b3: stepper(int) at /Users/Andrew/Documents/Arduino/ESP8266_MCP23008_BLYNK__BLIND-EXAMPLE/ESP8266_MCP23008_BLYNK__BLIND-EXAMPLE.ino line 167
0x4020330e: BlynkWidgetWrite0(BlynkReq&, BlynkParam const&) at /Users/Andrew/Documents/Arduino/ESP8266_MCP23008_BLYNK__BLIND-EXAMPLE/ESP8266_MCP23008_BLYNK__BLIND-EXAMPLE.ino line 63
0x402037d0: BlynkApi    > >::processCmd(void const*, unsigned int) at /Users/Andrew/Documents/Arduino/libraries/Blynk/src/BlynkApiArduino.h line 188
0x4020fbf9: pbuf_free_LWIP2 at core/pbuf.c line 777
0x401064ca: millis at /Users/Andrew/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.2/cores/esp8266/core_esp8266_wiring.c line 183
0x402019ef: delay at /Users/Andrew/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.2/cores/esp8266/core_esp8266_wiring.c line 51
0x40203b74: BlynkProtocol   >::processInput() at /Users/Andrew/Documents/Arduino/libraries/Blynk/src/Blynk/BlynkProtocol.h line 344
0x4020389c: BlynkProtocol   >::processInput() at /Users/Andrew/Documents/Arduino/libraries/Blynk/src/Blynk/BlynkProtocol.h line 392
0x402060fc: esp_yield() at /Users/Andrew/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.2/cores/esp8266/core_esp8266_main.cpp line 91
0x402019ef: delay at /Users/Andrew/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.2/cores/esp8266/core_esp8266_wiring.c line 51
0x40203dda: BlynkProtocol   >::run(bool) at /Users/Andrew/Documents/Arduino/libraries/Blynk/src/Blynk/BlynkProtocol.h line 150
0x4020411f: loop() at /Users/Andrew/Documents/Arduino/ESP8266_MCP23008_BLYNK__BLIND-EXAMPLE/ESP8266_MCP23008_BLYNK__BLIND-EXAMPLE.ino line 163
0x40206188: loop_wrapper() at /Users/Andrew/Library/Arduino15/packages/esp8266/hardware/esp8266/2.4.2/cores/esp8266/core_esp8266_main.cpp line 125


This line seems to be 63:
Code: Select all    currentMillis = micros();


Line 167 which it also quotes in the decode stack seems to be:

Code: Select all        break; 


This is the full code I am using:

Code: Select all#define BLYNK_PRINT Serial
#define IN1  4
#define IN2  5
#define IN3  6
#define IN4  7
#include <Wire.h>
#include "Adafruit_MCP23008.h"
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
Adafruit_MCP23008 mcp;
int Steps = 0;
boolean Direction = true;// gre
unsigned long last_time;
unsigned long currentMillis ;
int steps_left = 16380; // 50cm
long ttime;
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "e09ed8cee21041708588514d3fc9cc91";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "Andrew's mini iPad";
char pass[] = "12345678";
int status = WL_IDLE_STATUS;
BlynkTimer _timer;
BLYNK_WRITE(V0) {
  Serial.println("V0 - Pressed");
  while (steps_left > 0) {
    currentMillis = micros();
    if (currentMillis - last_time >= 1000) {
      stepper(1);
      ttime = ttime + micros() - last_time;
      last_time = micros();
      steps_left--;
    }
  }

  delay(12000);
  Direction = !Direction;
  steps_left = 16380; //50cm 4095 = one revolution;
}
BLYNK_WRITE(V1) {
  Serial.println("V1 - Pressed");
  while (steps_left > 0) {
    currentMillis = micros();
    if (currentMillis - last_time >= 1000) {
      stepper(1);
      ttime = ttime + micros() - last_time;
      last_time = micros();
      steps_left--;
    }
  }
  Direction = true;
  steps_left = 16380; // 50cm 4095 = one revolution;
}

void TimerEvent() {
  Serial.println("V2 - WiFiCheck");
  Serial.println(WiFi.status());
  mcp.digitalWrite(2, HIGH);
  if (WiFi.status() != WL_CONNECTED) {
    mcp.digitalWrite(2, LOW);
  }
  Serial.println("V6 - BLYNK Server Check");
  bool result = Blynk.connected();
  if (result == true) {
    mcp.digitalWrite(3, HIGH);
  } else {
    mcp.digitalWrite(3, LOW);
  }

}

BLYNK_APP_CONNECTED()
{
  //Blynk.virtualWrite(V0, mcp.digitalRead(0));
  //Blynk.virtualWrite(V1, mcp.digitalRead(1));
}

void setup()
{
  // Debug console
  Serial.begin(9600);
  Serial.println("ready");
  Wire.begin(0, 2);
  Blynk.begin(auth, ssid, pass);

  mcp.begin();      // use default address 0
  mcp.pinMode(0, OUTPUT); // Blind Up
  mcp.pinMode(1, OUTPUT); // Blind Down
  //mcp.pinMode(2, OUTPUT);
  //mcp.pinMode(3, OUTPUT);
  mcp.pinMode(IN1, OUTPUT); // motor IN1
  mcp.pinMode(IN2, OUTPUT); // motor IN2
  mcp.pinMode(IN3, OUTPUT); // motor IN3
  mcp.pinMode(IN4, OUTPUT); // motor IN4

  _timer.setInterval(5000L, TimerEvent);
}

void loop()
{
  Blynk.run();
  _timer.run();
}

void stepper(int xw) {
  for (int x = 0; x < xw; x++) {
    switch (Steps) {
      case 0:
        digitalWrite(IN1, LOW);
        digitalWrite(IN2, LOW);
        digitalWrite(IN3, LOW);
        digitalWrite(IN4, HIGH);
        break;
      case 1:
        digitalWrite(IN1, LOW);
        digitalWrite(IN2, LOW);
        digitalWrite(IN3, HIGH);
        digitalWrite(IN4, HIGH);
        break;
      case 2:
        digitalWrite(IN1, LOW);
        digitalWrite(IN2, LOW);
        digitalWrite(IN3, HIGH);
        digitalWrite(IN4, LOW);
        break;
      case 3:
        digitalWrite(IN1, LOW);
        digitalWrite(IN2, HIGH);
        digitalWrite(IN3, HIGH);
        digitalWrite(IN4, LOW);
        break;
      case 4:
        digitalWrite(IN1, LOW);
        digitalWrite(IN2, HIGH);
        digitalWrite(IN3, LOW);
        digitalWrite(IN4, LOW);
        break;
      case 5:
        digitalWrite(IN1, HIGH);
        digitalWrite(IN2, HIGH);
        digitalWrite(IN3, LOW);
        digitalWrite(IN4, LOW);
        break;
      case 6:
        digitalWrite(IN1, HIGH);
        digitalWrite(IN2, LOW);
        digitalWrite(IN3, LOW);
        digitalWrite(IN4, LOW);
        break;
      case 7:
        digitalWrite(IN1, HIGH);
        digitalWrite(IN2, LOW);
        digitalWrite(IN3, LOW);
        digitalWrite(IN4, HIGH);
        break;
      default:
        digitalWrite(IN1, LOW);
        digitalWrite(IN2, LOW);
        digitalWrite(IN3, LOW);
        digitalWrite(IN4, LOW);
        break;
    }
    SetDirection();
  }
}
void SetDirection() {
  if (Direction == 1) {
    Steps++;
  }
  if (Direction == 0) {
    Steps--;
  }
  if (Steps > 7) {
    Steps = 0;
  }
  if (Steps < 0) {
    Steps = 7;
  }
}



Can anyone assist with this please ?

Thanks

Andrew
User avatar
By QuickFix
#79122 Above WDT occurs because of the stepper loop inside BLYNK_WRITE(V1).
Just insert a yield() somewhere in the block after the while-loop (for instance between currentMillis = micros(); and if (currentMillis - last_time >= 1000) and that part will be fixed. :idea:

You probably have to do the same somewhere inside the stepper() method.
User avatar
By RichardS
#79125 It is exactly the same thing! If you dig in the code....

RichardS