So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By Bilz
#75268 Hi all.

I bought an AC dimmer module from aliexpress ( ... 0.0.aPh4fV ) and I am able to get it working just fine with an arduino uno. However, with my nodemcu, it either doesn't work at all or it flickers (after I've played around with it). Here's the code I am using: ... 65c9c5993b

I've played with using different pins on the node mcu but no joy. As in the code above, the light doesn't turn on at all. If I increase the delay in delayMicroseconds(10) to delayMicroseconds(20) it flickers. When I print out millis() in the interrupt function, the time between consecutive millis() appears to be ~ 20, which seems right (I'm in the UK, and AC mains is 50 Hz => 20 ms wave length). Note, I've tried it without the Serial.println(..) statements as well, and just stuck them in there now for debugging purposes.

Any ideas or experiences yourselves?
User avatar
By trackerj
#75302 Doing MAINS related Phase detection, ZCD, etc functions on ESP8266 might become very tricky and for more than one MAINS channel even more complicated.

The best solution that I found after playing a lot with ESP8266 and AC MAINS dimming was to design a AC Dimmer board that has onboard integrated Phase detection and ZCD functions and free ESP8266 resources for running the high level of application layer. In this case for AC Light Dimming ESP8266 need to provide only a simple VCNT (Voltage Control) signal to the AC Dimmer board, the MPDMv4 board itself will take care of the AC MAINS phase detection and zero crossing syncronisation. The VCNT signal can be a simple GPIO PWM or a external DAC output or even a simple variable resistor!

For more details about AC Dimmers please read articles below:
Triac command and Phase detection circuits explained
MPDMv4 - MAINS Dimmer / Switch - General Overview

For MPDMv4 AC Dimmer you will find a lot of tutorials and working examples for Arduino, LUA, ESPBasic, ESPEasy + Domoticz, etc: MPDMv4 AC Dimmer project.
User avatar
By btidey
#75307 On the esp8266 interrupt service routines should have the ICACHE_RAM_ATTR attribute to ensure they are run out of ram cache and not the flash. Like void ICACHE_RAM_ATTR zero_crosss_int()

You should also not have the Serial.println in the interrupt service routine. If you want to log the interrupt then just set a global flag in the isr and then test it in the loop, and if set then print and reset it.
User avatar
By Bilz
#75408 Thank you both.

@trackerj I looked at those drivers and they seem quite expensive. I guess there is another way to make my own board that performs the same function. At the moment, I haven't figured it out, but it doesn't really make sense to me to use that board if I could do the same thing at about a 5th of the price.

@btidey Thanks, I didn't know about that attribute. Though it seemed to help a bit, it wasn't enough.

I have a few spare ATMega328 chips lying around, so my next course of action is to see if I can control the dimming with the ATMega and communicate with it from the nodemcu. If it can perform what I want it to, I can then take a look at the ATTiny. I'll come back when/if I solve the problem like this.