AC Dimmer it possible.

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
straga
Posts: 14
Joined: Mon Apr 17, 2017 7:38 am

AC Dimmer it possible.

Post by straga » Sun Jul 25, 2021 1:47 pm

AC Dimmer with Zero Cross. Micropython can control that (esp32, stm32)?
From native code or Arduino it is possible. But from micropython ?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: AC Dimmer it possible.

Post by pythoncoder » Mon Jul 26, 2021 9:22 am

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.
Peter Hinch
Index to my micropython libraries.

straga
Posts: 14
Joined: Mon Apr 17, 2017 7:38 am

Re: AC Dimmer it possible.

Post by straga » Mon Jul 26, 2021 10:17 am

https://stackoverflow.com/questions/557 ... icropython

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

straga
Posts: 14
Joined: Mon Apr 17, 2017 7:38 am

Re: AC Dimmer it possible.

Post by straga » Tue Jul 27, 2021 5:21 pm

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.

pidou46
Posts: 101
Joined: Sat May 28, 2016 7:01 pm

Re: AC Dimmer it possible.

Post by pidou46 » Wed Jul 28, 2021 9:00 am

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)
nodemcu V2 (amica)
micropython firmware Daily build 05/31/2016

straga
Posts: 14
Joined: Mon Apr 17, 2017 7:38 am

Re: AC Dimmer it possible.

Post by straga » Wed Jul 28, 2021 12:51 pm

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 2660 times

Post Reply