I kindly asking for help to solve an issue when using AttachInterupt with Blynk.
I’m working with an AC dimmer which works fine until I add Blynk, to control by Android App.
The ESP8266 crach immediately after uploading the code.
I have tried compile, choos different ESP boards (NodeMCU, WeMos, Generic). same issue.
Following error occurs:
10:46:18.084 -> ets Jan 8 2013,rst cause:4, boot mode:(1,7)
10:46:18.084 ->
10:46:18.084 -> wdt reset
FYI, I have updated to latest Blynk lib. ver.0.5.4 and Arduino too.
I think the new Blynk version, has a timing issue.
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
// Pin 12 = INT
// Pin 13 = DIM
#define TCHPIN 14
#define LEDPIN 2
char auth[] = "xx";
char ssid[] = "yy";
char pass[] = "zz";
int dim;
volatile int dimming = 127; // Startup value for max dimming
volatile int dimTime;
void setup()
{
Serial.begin(115200);
pinMode(2, OUTPUT);
pinMode(13, OUTPUT); // Set AC Load pin as output
pinMode(14, INPUT);
attachInterrupt(digitalPinToInterrupt(12), zcint, RISING); // Zero cross interrupt
Blynk.begin(auth, ssid, pass);
}
// *******************************************************************************************
void zcint() //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()
{
Blynk.run();
}
// *******************************************************************************************
BLYNK_WRITE(V1) // slider
{
dim = param.asInt();
dimming = dim;
}
If I remove Blynk lines and use my button version code, it works perfect and very stable.
----------- CODE FOR BUTTON VERSION ---------
// This works fine !
// Pin 12 = INT
// Pin 13 = DIM
#define TCHPIN 14
#define LEDPIN 2
int tchState;
volatile int dimTime;
volatile int dimming = 127; // Startup value for max dimming
int count = 0;
int period = 200; // Time for debunch when touch
unsigned long time_now = 0;
void setup()
{
Serial.begin(115200);
pinMode(2, OUTPUT);
pinMode(13, OUTPUT); // Set AC Load pin as output
pinMode(14, INPUT);
attachInterrupt(12, zcint, RISING); // Zero cross interrupt
dimming = count;
ESP.wdtDisable();
ESP.wdtEnable(WDTO_8S);
}
// *******************************************************************************************
void zcint() //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()
{
time_now = millis(); // Initial timer
tchState = digitalRead(TCHPIN);
if (tchState == HIGH)
{
if(count == 120)
{
digitalWrite(2, LOW); // Turn LED on
}
else
{
digitalWrite(2, HIGH);
}
if (count < 100)
{
count = count + 15; // Dimmer is not liniar
}
else
{
count = count + 5;
}
if(count > 125) // Value 125 set max. dimming
{
count = 10; // Reset to full light
}
while(millis() < time_now + period) // Here is the delay for debunch
{
dimming = count;
}
}
ESP.wdtFeed();
}