Page 1 of 1

AC Dimmer it possible.

Posted: Sun Jul 25, 2021 1:47 pm
by straga
AC Dimmer with Zero Cross. Micropython can control that (esp32, stm32)?
From native code or Arduino it is possible. But from micropython ?

Re: AC Dimmer it possible.

Posted: Mon Jul 26, 2021 9:22 am
by pythoncoder
STM32 could definitely do it and I'm pretty sure it could be done with ESP32 - the one caveat on that platform being interrupt latency. Best without SPIRAM.

You'll need a good grasp of electronic design, though.

Re: AC Dimmer it possible.

Posted: Mon Jul 26, 2021 10:17 am
by straga
https://stackoverflow.com/questions/557 ... icropython

I get Robodyn AC dimmer.
Try from example always zero-crosse detect drift.

Re: AC Dimmer it possible.

Posted: Tue Jul 27, 2021 5:21 pm
by straga
micropython + stm32 f411: works, need add i2c_slave
https://github.com/straga/hardware_prob ... r_stm32.py

esp8266+i2cslave:
https://github.com/straga/hardware_prob ... sp8266.ino
control from micropython:
https://github.com/straga/hardware_prob ... er_test.py

esp32: not work, irq + timer, not stability all-time drift. I don't know how that doit.

Re: AC Dimmer it possible.

Posted: Wed Jul 28, 2021 9:00 am
by pidou46
Hello I'm working on a project with AC dimmer and ESP32s

The aim is to adjust a boiler power, with a AC dimmer. Set point come from a mqtt server.

To ensure the most stable status, I have used 2 x esp32 mcus.

The first one run a simple script who detect the cross zero signal on one pin and set the current cutting signal wit some precise delay.
The delay is set via UART communication, this allow me to switch off the wifi. I've also switched off wifi to get best response time and stability. checked with an oscilloscope.

here is the code:

Code: Select all

from machine import UART, Pin, freq
from time import sleep, sleep_us
import network

p_zvd=Pin(32,Pin.IN)
p_scr=Pin(33,Pin.OUT)
p_tx=17
p_rx=16
delay=0

def pin_cb(p):
    global delay
    sleep_us(delay)
    p_scr.on()
    sleep_us(400)
    p_scr.off()

#enable max CPU frequency to avoid jittering
#freq(240000000)

#disable wifi to avoid jitter in IRQ
sta_if=network.WLAN(network.STA_IF)
ap_if=network.WLAN(network.AP_IF)
sta_if.active(False)
ap_if.active(False)

#setup irq callback
p_zvd.irq(trigger=Pin.IRQ_FALLING | Pin.IRQ_RISING, handler=pin_cb)

#setup UART
uart1=UART(1, baudrate=115200, tx=p_tx,rx=p_rx)

timeout=0

while True:
    try:
        consigne = uart1.readline()
    except e:
        print(e)
    if consigne == None:
        print('none')
        # setup a timeout
        # ensure full power if communication failed
        # to avoid cold water situation
        timeout+=1
        if timeout>=10:
            delay=0
    else:
        try:
            delay=int(consigne.decode('utf-8'))
        except:
            delay=0    
        print('{}'.format(delay))
        #reset timeout counter when communication resume
        timeout=0
    sleep(5)
The second esp32 run mqtt-as client to fetch setpoint from mqtt broker in asynchronous behaviour. It converts power percentage setpoint to delay and send it periodically to the first one.
I plan to use use it for no time-critical stuff like input temperature sensor, ect...

The code is in WIP but working status.

Be careful with zero volt reference when experimenting with AC dimmer, you may fry at least your mcu or yourself...
I would advice to use a laptop unplugged from grid (or USB isolator)

Re: AC Dimmer it possible.

Posted: Wed Jul 28, 2021 12:51 pm
by straga
Now I use:
esp32 as main board (wifi, webUI, Mqtt, Websocket and other) <- (uart communications) -> stm32 (weAct board) .
STM32: Triac Control: CrosZero + Puls Triac Open
stm32_triac control.jpg
stm32_triac control.jpg (48.09 KiB) Viewed 3071 times