Hardware TUYA in line dimmer - xoseperez/espurna GitHub Wiki

TUYA in-line dimmer

TUYA Dimmer

Property Value
Manufacturer TUYA
Product page
Additional info https://tasmota.github.io/docs/TuyaMCU-Devices/#dm_wf_mdv4-leading-edge-dimmer
Build flag TUYA_GENERIC_DIMMER

Introduction

110-240VAC in-line leading edge dimmer with maximum load of 300W. Board is marked up as: DM_WF_MDV4 Leading edge dimmer. Original testing is detailed in post #1729. The WiFi control side is done using a TYWE3S but the dimmer control is via a STM8S003F3 MCU under the board rather than PWM from a GPIO. The external button connects to the MCU rather than the TYWE3S.

The LED is a dual colour, RED/GREEN. The green is controlled via GPIO 14 but the red seems to be controlled by the output, possibly directly from the MCU.

Top of the board

Top of the board

Bottom of the board

Bottom of the board

GPIO Usage
0 Can be modified for local control. See 'Mods' below.
14 Green LED

Flashing

4 pins can be soldered to the header holes to allow flashing, but the Tx/Rx need to be connected directly to the TYWE3S pins.

To flash, the fourth pin 'Flash' needs to be held at GND before power is applied, and kept at GND during flashing. I think it disables Tx/Rx communication to the MCU. You then need to boot with the GPIO 0 pin held to GND, then released a few seconds after boot.

Data Pins

Data pins

Mods

With reference to #2422 the built-in hardware button can be re-configured to allow local ON/OFF and dimming. By cutting the track on the back and connecting a wire from the switch to GPIO0 on the TYWE3S, you'll be able to use the hardware button. You either use it to "GND during boot" to allow flashing with the TX/RX pins or control the device during normal operation. Using the build definition below, a 3-10 second long press will toggle the output, double click will dim and triple click will brighten. I disabled click and press so it didn't accidentally toggle ON/OFF during a double/triple click event.

    // Buttons
    #define BUTTON_MQTT_SEND_ALL_EVENTS     1
    #define BUTTON1_PIN  0     //USE GPIO0 for push button
    #define BUTTON1_CONFIG  BUTTON_PUSHBUTTON | BUTTON_SET_PULLUP | BUTTON_DEFAULT_BOOT
    #define BUTTON1_RELAY 1
    #define BUTTON1_PRESS BUTTON_ACTION_NONE
    #define BUTTON1_CLICK  BUTTON_ACTION_NONE
    #define BUTTON1_DBLCLICK  BUTTON_ACTION_DIM_DOWN
    #define BUTTON1_TRIPLECLICK  BUTTON_ACTION_DIM_UP
    #define BUTTON1_LNGCLICK  BUTTON_ACTION_TOGGLE
    #define BUTTON1_LNGLNGCLICK  BUTTON_ACTION_TOGGLE

Issues

I have not been able to get any of the other GPIOs on the TYWE3S to work as input GPIOs. They may need external pull-up resistors to help?