Passa al contenuto

← Computer a scheda singola | Indice | Avanti: Integrazione ESPHome →

Utilizzo avanzato

Modi non standard per collegare e controllare DimmerLink.




Adattatori USB-UART

Controllare DimmerLink da un computer tramite adattatore USB-UART.


Chip Driver Note
CH340/CH341 Spesso integrato nel SO Economico, diffuso
CP2102/CP2104 Silicon Labs Stabile
FT232RL FTDI Professionale
PL2303 Prolific Obsoleto, problemi con i driver


Cablaggio

USB-UART DimmerLink
VCC (3.3V o 5V) VCC
GND GND
TXD RX
RXD TX

ℹ️ Nota: DimmerLink supporta livelli logici a 1.8V, 3.3V e 5V — usate la tensione fornita dal vostro adattatore.


Driver

Windows:
- CH340: usually installs automatically, or download from manufacturer's website
- CP2102: Silicon Labs VCP Driver
- FTDI: FTDI VCP Driver

Linux:
- Drivers are usually already in the kernel
- Device will appear as /dev/ttyUSB0 or /dev/ttyACM0

macOS:
- CH340: may require driver from manufacturer
- CP2102/FTDI: built into the system


Controllo dal PC (Python)

python
import serial
import time

# Windows: 'COM3', Linux: '/dev/ttyUSB0', macOS: '/dev/tty.usbserial-*'
ser = serial.Serial('COM3', 115200, timeout=0.1)

def set_level(level):
    ser.write(bytes([0x02, 0x53, 0x00, level]))
    resp = ser.read(1)
    return len(resp) > 0 and resp[0] == 0x00

def get_frequency():
    ser.write(bytes([0x02, 0x52]))
    resp = ser.read(2)
    if len(resp) == 2 and resp[0] == 0x00:
        return resp[1]
    return None

# Usage
print(f"Mains frequency: {get_frequency()} Hz")
set_level(50)
print("Brightness: 50%")

ser.close()


Programmi terminale

Per il debug e il test:

Programma Piattaforma Modalità HEX
RealTerm Windows
SSCOM Windows
CoolTerm Windows/Mac/Linux
PuTTY Windows/Linux No (solo testo)
picocom Linux No

Example in RealTerm:
1. Port → select your COM port
2. Baud: 115200
3. Send → "Send Numbers" tab
4. Enter: 02 53 00 32 (HEX)
5. Click "Send Numbers"




WiFi-UART (ESP-01)

Controllo wireless tramite ESP-01 o ESP8266.


Schema

python
[Computer/Phone] ←WiFi→ [ESP-01] ←UART→ [DimmerLink] → [Dimmer]


Cablaggio ESP-01

ESP-01 DimmerLink
VCC VCC (3.3V)
GND GND
TX RX
RX TX


Firmware ESP-01 (Arduino IDE)

cpp
#include 
#include 

const char* ssid = "YOUR_WIFI";
const char* password = "YOUR_PASSWORD";

ESP8266WebServer server(80);

void setup() {
    Serial.begin(115200);

    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) {
        delay(500);
    }

    server.on("/set", handleSet);
    server.on("/get", handleGet);
    server.begin();
}

void handleSet() {
    if (server.hasArg("level")) {
        int level = server.arg("level").toInt();
        if (level >= 0 && level <= 100) {
            uint8_t cmd[] = {0x02, 0x53, 0x00, (uint8_t)level};
            Serial.write(cmd, 4);

            delay(10);
            if (Serial.available()) {
                uint8_t resp = Serial.read();
                server.send(200, "text/plain", resp == 0x00 ? "OK" : "ERROR");
            } else {
                server.send(500, "text/plain", "NO_RESPONSE");
            }
        } else {
            server.send(400, "text/plain", "INVALID_LEVEL");
        }
    } else {
        server.send(400, "text/plain", "MISSING_LEVEL");
    }
}

void handleGet() {
    uint8_t cmd[] = {0x02, 0x47, 0x00};
    Serial.write(cmd, 3);

    delay(10);
    if (Serial.available() >= 2) {
        uint8_t status = Serial.read();
        uint8_t level = Serial.read();  // Already in percent 0-100!
        if (status == 0x00) {
            server.send(200, "text/plain", String(level));
        } else {
            server.send(500, "text/plain", "ERROR");
        }
    } else {
        server.send(500, "text/plain", "NO_RESPONSE");
    }
}

void loop() {
    server.handleClient();
}


Utilizzo

bash
# Set brightness to 50%
curl "http://192.168.1.100/set?level=50"

# Get current brightness
curl "http://192.168.1.100/get"



Bluetooth (HC-05/HC-06)

Controllo da smartphone o computer tramite Bluetooth.


Cablaggio

HC-05/HC-06 DimmerLink
VCC VCC (3.3V o 5V)
GND GND
TXD RX
RXD TX

📝 Nota: HC-05 è impostato di default a 9600 baud. Riconfigurate a 115200 tramite comandi AT.


Configurazione HC-05 (comandi AT)

  1. Collegate HC-05 in modalità AT (tenete premuto il pulsante durante l'accensione)
  2. Aprite un terminale a 38400 baud
  3. Enter:
    AT+UART=115200,0,0 AT+NAME=Dimmer AT+PSWD=1234


App Android

Use any Bluetooth Serial app:
- Serial Bluetooth Terminal
- Bluetooth Electronics

Inviate i comandi HEX direttamente.




Moduli LoRa

Controllo a lunga distanza tramite LoRa (fino a diversi chilometri).


Schema

python
[Controller + LoRa TX] ~~~radio~~~ [LoRa RX + DimmerLink]

⚠️ Configurazione E32: I moduli E32 richiedono una preconfigurazione tramite RF Setting — velocità, canale, indirizzo. Default: 9600 baud — deve essere cambiato a 115200 per DimmerLink, oppure usate un MCU come ponte per la conversione di velocità.


  • E32 (SX1278) — interfaccia UART semplice
  • Ra-02 — richiede libreria SPI
  • RFM95 — per LoRaWAN


Cablaggio E32-TTL-100

E32 DimmerLink
VCC VCC (3.3V o 5V)
GND GND
TXD RX
RXD TX


Considerazioni

  • Latenza: 50–200 ms a seconda delle impostazioni
  • Larghezza di banda: limitata (1–50 kbps)
  • Affidabilità: usate conferma e tentativi di reinvio


Esempio (trasmettitore)

cpp
// Arduino + E32 (transmitter)
void sendCommand(uint8_t* cmd, int len) {
    Serial1.write(cmd, len);  // Send via LoRa
}

void loop() {
    // Set brightness to 50%
    uint8_t cmd[] = {0x02, 0x53, 0x00, 0x32};
    sendCommand(cmd, 4);
    delay(1000);
}



Moduli GSM/GPRS

Controllo remoto tramite SMS o Internet.


  • SIM800L — compatto, 2G
  • SIM900 — classico
  • SIM7600 — 4G LTE


Schema

python
[Server/Phone] ←GSM→ [SIM800L + MCU] ←UART→ [DimmerLink]


Cablaggio SIM800L

SIM800L Arduino/ESP
VCC 4V (alimentazione separata!)
GND GND
TXD RX
RXD TX

📝 Nota: Il SIM800L richiede un'alimentazione stabile di 3.7–4.2V con una corrente fino a 2A durante la trasmissione.


Controllo tramite SMS

cpp
#include 

SoftwareSerial gsm(7, 8);  // RX, TX for SIM800L
SoftwareSerial dimmer(10, 11);  // RX, TX for DimmerLink

void setup() {
    gsm.begin(9600);
    dimmer.begin(115200);

    // Configure SIM800L for SMS
    gsm.println("AT+CMGF=1");  // Text mode
    delay(100);
    gsm.println("AT+CNMI=2,2,0,0,0");  // SMS notifications
    delay(100);
}

void loop() {
    if (gsm.available()) {
        String message = gsm.readString();

        // Parse SMS "SET 50"
        if (message.indexOf("SET ") >= 0) {
            int idx = message.indexOf("SET ") + 4;
            int level = message.substring(idx).toInt();

            if (level >= 0 && level <= 100) {
                uint8_t cmd[] = {0x02, 0x53, 0x00, (uint8_t)level};
                dimmer.write(cmd, 4);
            }
        }
    }
}



Considerazioni sulla comunicazione wireless


Latenza

Tipo di connessione Latenza tipica
USB-UART < 1 ms
WiFi (rete locale) 5–50 ms
Bluetooth 10–50 ms
LoRa 50–500 ms
GSM (SMS) 1–10 sec
GSM (GPRS) 100–500 ms


Buffering

Nella comunicazione wireless, i dati possono essere bufferizzati. Raccomandazioni:

  1. Send commands as a whole — don't split into individual bytes
  2. Aggiungete un ritardo tra i comandi (50–100 ms)
  3. Attendete la conferma prima del comando successivo


Affidabilità

Per applicazioni critiche:

  1. Verificate la risposta — il comando ha avuto successo solo se si riceve 0x00
  2. Riprovate in caso di errore — 2–3 tentativi con ritardo
  3. Timeout — se non c'è risposta entro 1–2 secondi, riprovate
python
def reliable_set_level(ser, level, retries=3):
    for attempt in range(retries):
        ser.write(bytes([0x02, 0x53, 0x00, level]))
        ser.flush()

        resp = ser.read(1)
        if resp and resp[0] == 0x00:
            return True

        time.sleep(0.1)

    return False



Limitazioni di I2C attraverso i ponti

I2C is not suitable for wireless communication due to:
- Strict timing requirements (clock stretching)
- Lack of buffering in the protocol
- Need for bidirectional synchronous communication

Soluzione: Per il controllo wireless, usate UART.

Se avete un collegamento I2C e necessitate di accesso wireless — aggiungete un MCU (Arduino/ESP) come ponte:

python
[WiFi/BT] → [ESP32 (UART)] → [DimmerLink (I2C)]



What's Next?

← Computer a scheda singola | Indice | Avanti: Integrazione ESPHome →