AC-dimmer with Blynk - cause ESP crash

Hi,I have big problems with an AC-dimming project using Blynk to dim.
Error is the ESP2866 crash and do not restart.
I have hardware working very well for about 15-20 minutes, then it crach.
I have made a very simple (cut & past from other projects), it seems working god.
My question is, why does the ESP crash. FYI, I do not change value for dimming, it’s fixed.
Is there a way to restart ESP after crach?

CODE BELOW


#include <BlynkSimpleEsp8266.h>

int dim = 128;
volatile int dimming = 128;                           // Dimming level (0-128)  0 = ON, 128 = OFF
volatile int dimTime;

char auth[] = "";        
char ssid[] = "";                            
char pass[] = "";                                   

void setup()
{
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass); 
  delay(10);
  pinMode(13, OUTPUT);                                   	 // Set AC Load pin as output
  attachInterrupt(12, zero_crosss_int, RISING);           // Choose the zero cross interrupt # from the table above
  ESP.wdtDisable();
  ESP.wdtEnable(WDTO_8S);
  Blynk.syncAll();
}

// *******************************************************************************************
BLYNK_WRITE(V1)                                          	 // button
{
  dim = param.asInt();
  dimming = dim;
}

// *******************************************************************************************
void zero_crosss_int()                                 		   //function to be fired at the zero crossing to dim the light
{
  dimTime = (75*dimming);                                	 // Value set for 50Hz    
  delayMicroseconds(dimTime);                              	// Wait till firing the TRIAC
  digitalWrite(13, HIGH);                                	  // Fire the TRIAC
  delayMicroseconds(10);                                	  // triac On propogation delay 
  digitalWrite(13, LOW);                                  	 // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
}

// *******************************************************************************************
void loop()  
{
  if(Blynk.connected())                                   	// Check if still connected
   {
     Blynk.run();
   }
 ESP.wdtFeed();
}

------------------------------------------------- ESP8266 - ERROR ----------------------------------------

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

ctx: sys 
sp: 3ffffc60 end: 3fffffb0 offset: 01a0

>>>stack>>>
3ffffe00:  40106b58 0002b9c4 0000a8c0 402265e4  
3ffffe10:  ffffffff 00000020 3ffed5c8 401024ec  
3ffffe20:  3fff0ab0 3fff0aac 00000080 00000022  
3ffffe30:  3fffc200 40106b20 3fffc258 4000050c  
3ffffe40:  4000437d 00000030 00000019 ffffffff  
3ffffe50:  60000200 00000008 00f8ffff 80000000  
3ffffe60:  20000000 3fff0f30 80000000 2007c020  
3ffffe70:  80000000 3fffc6fc 00000001 3fff0f34  
3ffffe80:  000002d4 0007c020 3ffed4d0 00000030  
3ffffe90:  3fff0aac 3fff0ab0 00000006 00000001  
3ffffea0:  00000000 cd1a0000 3fff0aac 3fff0d88  
3ffffeb0:  3fff0ab0 3fff0d2c 3fff0aac 40223f49  
3ffffec0:  40000f3d 00000023 00000000 fffffffc  
3ffffed0:  00000000 000048b7 3fff0aac 40223ffa  
3ffffee0:  000048b7 3fffc6fc 00000001 3fffdab0  
3ffffef0:  00000000 3fffdad0 3ffeebb0 00000004  
3fffff00:  402248c4 00000000 0000007d 401004d8  
3fffff10:  3ffeead0 00000015 00000015 401070d4  
3fffff20:  3fff00e4 3fff00e0 08d5ea09 40224825  
3fffff30:  00000000 400042db 08d5ea09 3ffed4d0  
3fffff40:  40004b31 3fff0f14 000002f4 0007c000  
3fffff50:  4010569e 00000000 3ffed3e0 40107118  
3fffff60:  40208961 3ffed3e0 00000000 3fffdc00  
3fffff70:  3fff0f14 00001000 40208df6 00000002  
3fffff80:  4021a5ca 3fffdab0 40209ff7 3fffdab0  
3fffff90:  00000000 3fffdab0 3ffeebb0 40203ff7  
3fffffa0:  40000f49 40000f49 3fffdab0 40000f49  
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(1,7)


 ets Jan  8 2013,rst cause:4, boot mode:(1,7)

wdt reset

Blynk - FTFC

2 Likes

AC-dimming problem solved.
I have done some tests, using different boards ex. NodeMCU, Generic ESP boards.
If use a Generic ESP-07 module and select NodeMCU board in compiler, then a rst cause:2, boot mode:(1,7) error occures.
“cause 2”, means instruction error.
If I select Board type as Generic ESP8266 and compile, no error at all.

AC dimming problem solved for me using ESP-07 module and select Generic ESP in Arduino Boards.

So problem solved by using proper board setting. Marking topic solved and fixing your code formatting. Thanks for playing :stuck_out_tongue_winking_eye:

EDIT - Then I merged your 2nd topic about same issue, and reopened this topic. One topic at a time on same issue please…

Hi, again.
I still aim for a stable AC-dimmer using Blynk, but it seems a difficult way.
First I created a code as below, just for testing my hardware:

#include <ESP8266WiFi.h>
#include <Ticker.h>

 // Interupt PIN = 12
 // Dim PIN      = 13
 
Ticker blinker;

volatile int dimTime;
int LED = 2;
volatile int dimVal = 20;

void ICACHE_RAM_ATTR onTimerISR()
{
  digitalWrite(LED,!(digitalRead(LED)));  //Toggle LED Pin
  timer1_write(12800000);
  dimVal = dimVal + 10;
  if(dimVal > 130)
  {
    dimVal = 20;
  }
}

// *******************************************************************************************
void setup()
{
  Serial.begin(115200);
  delay(10);
  pinMode(13, OUTPUT);                                    // Set AC Load pin as output
  pinMode(2,OUTPUT);
  timer1_attachInterrupt(onTimerISR);
  timer1_enable(TIM_DIV16, TIM_EDGE, TIM_SINGLE);
  timer1_write(12800000); //60000 = 120000 us
  attachInterrupt(12, zero_crosss_int, RISING);           // Choose the zero cross interrupt # from the table above
  ESP.wdtDisable();
  ESP.wdtEnable(WDTO_8S);
 }

// *******************************************************************************************
void zero_crosss_int()                                    //function to be fired at the zero crossing to dim the light
{
  dimTime = (75*dimVal);                                  // Value set for 50Hz    
  delayMicroseconds(dimTime);                             // Wait till firing the TRIAC
  digitalWrite(13, HIGH);                                 // Fire the TRIAC
  delayMicroseconds(10);                                  // triac On propogation delay 
  digitalWrite(13, LOW);                                  // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
}

// *******************************************************************************************
void loop()  
{
  ESP.wdtFeed();
}

This code works stable for over two days.

Then I add BLYNK to control dimming in a new code as below:

#include <BlynkSimpleEsp8266.h>

char auth[] = " ";        			 //  
char ssid[] = " ";                           		 //
char pass[] = " ";                               	 // 

int dimS;
volatile int dimVal = 20;
volatile int dimTime;

// *******************************************************************************************
void setup() 
{
  Serial.begin(115200);
  delay(10);
  pinMode(13, OUTPUT);                                    // Set AC Load pin as output
  Blynk.begin(auth, ssid, pass); 
  attachInterrupt(12, zero_crosss_int, RISING);           // Choose the zero cross interrupt # from the table above
  ESP.wdtDisable();
  ESP.wdtEnable(WDTO_8S);
}

// *******************************************************************************************
void zero_crosss_int()                                    //function to be fired at the zero crossing to dim the light
{
  dimTime = (75*dimVal);                                  // Value set for 50Hz    
  delayMicroseconds(dimTime);                             // Wait till firing the TRIAC
  digitalWrite(13, HIGH);                                 // Fire the TRIAC
  delayMicroseconds(10);                                  // triac On propogation delay 
  digitalWrite(13, LOW);                                  // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
}

// *******************************************************************************************
void loop()  
{
  Blynk.run();
  ESP.wdtFeed();
}

// *******************************************************************************************
BLYNK_WRITE(V1)                                           // Slider
{
  dimS = param.asInt();
  dimVal = dimS;
}

Then troubles starts. ESP crash after 10-30 min. with error message as below:


// ---------------------------------------------------------  ESP ERROR  -------------------------------------------------------------

14:33:54.877 -> Exception (0):
14:33:54.877 -> epc1=0x4020210c epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000
14:33:54.877 -> 
14:33:54.877 -> ctx: sys 
14:33:54.877 -> sp: 3ffffc30 end: 3fffffb0 offset: 01a0
14:33:54.877 -> 
14:33:54.877 -> >>>stack>>>
14:33:54.877 -> 3ffffdd0:  40106b58 00000000 3ffeb986 000000f7  
14:33:54.877 -> 3ffffde0:  ffffffff 00000020 00000001 00000000  
14:33:54.877 -> 3ffffdf0:  00000000 40100fab 00000000 00000022  
14:33:54.877 -> 3ffffe00:  3fffc200 40106b20 3fffc258 4000050c  
14:33:54.877 -> 3ffffe10:  4000437d 00000030 00000019 ffffffff  
14:33:54.924 -> 3ffffe20:  60000200 00000008 ffffffff 80000000  
14:33:54.924 -> 3ffffe30:  20000000 3fff1630 80000000 2007c100  
14:33:54.924 -> 3ffffe40:  80000000 3fffc6fc 3ffee308 3fff1634  
14:33:54.924 -> 3ffffe50:  000001f4 0007c100 60000600 00000030  
14:33:54.924 -> 3ffffe60:  00000128 40103891 00040000 40202148  
14:33:54.924 -> 3ffffe70:  40106bbc 00080000 00000000 40106ba6  
14:33:54.924 -> 3ffffe80:  ffffffff 00000020 00000000 4000050c  
14:33:54.971 -> 3ffffe90:  00000000 00000000 0000001f 40105139  
14:33:54.971 -> 3ffffea0:  4000050c 40106b20 3fffc258 4000050c  
14:33:54.971 -> 3ffffeb0:  40000f68 00000030 0000001a ffffffff  
14:33:54.971 -> 3ffffec0:  40000f58 00000000 00000020 00000000  
14:33:54.971 -> 3ffffed0:  3fff04dc 40208f24 00000000 00000000  
14:33:54.971 -> 3ffffee0:  ffffffff 3ffe8f64 3ffee308 3fffdab0  
14:33:54.971 -> 3ffffef0:  00000000 3fffdcb0 3ffee348 00000030  
14:33:55.018 -> 3fffff00:  00000000 400042db 00000064 60000600  
14:33:55.018 -> 3fffff10:  40004b31 3fff1534 000002f4 0007c000  
14:33:55.018 -> 3fffff20:  4010569e 3ffee330 3ffed3d0 40107118  
14:33:55.018 -> 3fffff30:  402089f5 3ffed3d0 3ffee330 1dfbe4e0  
14:33:55.018 -> 3fffff40:  3fff1534 00001000 40208e8a 00000008  
14:33:55.018 -> 3fffff50:  40105e5c 00000000 40208f37 3ffed484  
14:33:55.018 -> 3fffff60:  3ffee330 08ea9ad5 3ffee330 60000600  
14:33:55.065 -> 3fffff70:  4021a619 3ffed484 3ffee330 1dfbe24e  
14:33:55.065 -> 3fffff80:  4021a65e 3fffdab0 00000000 3fffdcb0  
14:33:55.065 -> 3fffff90:  3ffee350 00000000 40000f65 3fffdab0  
14:33:55.065 -> 3fffffa0:  40000f49 0002f684 3fffdab0 40000f49  
14:33:55.065 -> <<<stack<<<

14:33:55.111 ->  ets Jan  8 2013,rst cause:2, boot mode:(1,7)
14:33:55.111 -> 

14:34:02.939 ->  ets Jan  8 2013,rst cause:4, boot mode:(1,7)
14:34:02.939 -> 
14:34:02.939 -> wdt reset

I’m using an ESP-07 module.
Newest Arduino version.
Latest Blynk lib.
Hardware works 100%

Can anyone tell me what’s wrong when adding Blynk?

So… what is your question?

Hi,
Please go to Blynk issues & Errors area. I have open a new topic, re. AC-Dimmer. I think Blynk has an error in lib.
My Test code still working.

There is only one forum and we see all at the same time, even if differing topic category. I merged both of your topics here already.

Since you haven’t backed that up with any form of qualifiable or quantifiable evidence… or for that matter even a clearly defined description of the issue :stuck_out_tongue_winking_eye: no one will take your issue seriously

My question is: What cause ESP module crash, when adding Blynk lib.?
Test code works great, without Blynk.

Bad code? bad power? bad wiring? bad day? Too may variables, not enough info.

You may look at the code. One without Blynk (works great) and one with Blynk, (cause ESP error).

Not my job to look at (in depth) or fix your code, only to advise and suggest (and actually that is just volunteer, not a job :stuck_out_tongue_winking_eye: )

Blynk is not just a drop in magic pill… it needs to be integrated and has it’s own coding/timing rules… I recommend you learn how those rules work on smaller, simpler projects before attempting on larger, more complicated code.

PS, I had to edit your posted code to show the separate sketches & comments… if you are unable to grasp the correct syntax on formatting code (Backticks, NOT commas), then perhaps you also need more coding practice to integrate Blynk?

Perhaps timing conflict?? I have not used ESP.wdtFeed() (part of Ticker?) so I do not know. Blynk works well with the SimpleTimer based BlynkTimer for all timing purposes.

What do the errors translate out to? Google for ways to translate ESP errors

ESP.wdtFeed() is just to keep ESP WatchDog alive. I have also removed ESP WatchDog line in Blynk code.
Same issue. It works OK for 10-30 minutes. Code without Blynk works for days.

I think it’s fair to say that your two pieces of code are very different. You haven’t just added-in a few lines of Blynk code. You’ve removed some timers, that appear to be using the Ticker library, but haven’t replaced them with anything else.

I’ve not taken the time to delve too deeply into your code, one because I don’t have the time or inclination, but two because I don’t have your hardware to test-out any changes.

What I would say is that any code that has this as a void loop:

has some issues with timeouts. Blynk has very strict rules around timeouts and ensuring that the Blynk background processes receive plenty of processor time.
As A result, I’d start by looking again at your original code and what you’ve changes, and possibly add-in some Blynk.run(); commands into your void zero_crosss_int() function to feed Blynk, as well as feeding the watchdog.

Pete.

Well, as I said… Blynk is not just some simple drop-in… it is rather complex library. Many others have Blynkified code running for weeks, months, years without issue (not including partial update conflicts), so you will have to learn over time how to integrate it with other timing sensitive code. This is a common issue when merging libraries that tend to compete for system resources.

1 Like

The only Timing I use is delayMicroseconds in the ISR.
The only Library I add is #include <BlynkSimpleEsp8266.h>.
I don’t see how I need other timers and Libraries. It works, but only for 10 minutes.

FYI, I have also done some test using MCU AT328, it was very stable (without using Blynk).

At the end Hardware seems stable.

Have you tried searching this forum. There is an example of some working code for an AC dimmer using Zero-Cross detection. Although I personally have not tried this project.