[Python] Control LCTech Relay X2 using Python and serial commands via serial port

Discussão em 'Python' iniciado por Stack, Abril 23, 2025.

  1. Stack

    Stack Membro Participativo

    So I bought the following relay and board (comes with ESP-01 8266 module) that I want to control directly via serial commands. https://www.aliexpress.com/item/100....order_list.order_list_main.10.37361802KCpL9f

    The board has a MCU that controls the relays based on serial commands. I have made it work as such using Tasmota flashed on the ESP chip and which then sends the serial commands. See: https://templates.blakadder.com/LC-Relay-ESP01-2R-5V.html

    But my ultimate goal is to not use the ESP module at all and just control directly via serial commands from a Python script for this particular project and for more flexibility.

    Here is my current script to try and trigger the relays from Python via a UART usb dongle with the proper rx/tx connections (same UART/FT232 dongle I use to flash Tasmota to ESP8266). This results in no response from the relay module...is there something obvious that I am not doing correctly to communicate with the module correctly? I have limited experience with serial communication so I am sure I most likely doing something wrong here.

    import serial
    import codecs
    import time

    ser = serial.Serial('/dev/ttyUSB0', 115200)

    ser.write(codecs.decode(b'A00101A2','hex'))
    time.sleep(5)
    ser.write(codecs.decode(b'A00100A1','hex'))
    ser.close()

    Continue reading...

Compartilhe esta Página