Passa al contenuto

← Panoramica | Indice | Next: Hardware Connection →

Avvio rapido

Questa guida ti aiuterà a mettere in funzione DimmerLink in pochi minuti.


What You'll Need

  1. DimmerLink — scheda controller
  2. Dimmer — modulo TRIAC con supporto al controllo esterno
  3. Microcontrollore o SBC — Arduino, ESP32, Raspberry Pi, ecc.
  4. Cavi di collegamento
  5. Lampada per i test (a incandescenza o LED dimmerabile)

Passo 1: Scegliere un'interfaccia

Caratteristica UART I2C
Cablaggio TX/RX incrociato SDA/SCL diretto
Complessità del codice Pacchetti di comandi Accesso ai registri
Raccomandazione Per utenti avanzati Per principianti

💡 Tip: We recommend I2C for most projects — simpler code, easier debugging, and more robust than UART.

⚠️ Important — DimmerLink ships in UART mode. Out of the box the board listens on UART. To use I2C, first send the switch-to-I2C command over UART once (02 5B); the setting is stored, so you only do this one time. See I2C Communication for details.

🔌 I2C wiring: I2C requires 4.7 kΩ pull-up resistors on both SDA and SCL to the bus voltage (3.3 V). Without them the device will not be detected by an I2C scan.

ℹ️ You can test communication with no AC connected. DimmerLink powers from its logic VCC, so it responds to UART/I2C commands (including the frequency-request check) even before mains is wired. The on-board status LEDs, however, only light when AC is present.


Passo 2: Cablaggio

Ingresso (verso il tuo progetto):

Pin Funzione
VCC Alimentazione 3.3V
GND Massa
TX/SDA UART TX o I2C SDA
RX/SCL UART RX o I2C SCL

Uscita (verso il modulo dimmer):

Pin Funzione
VCC Alimentazione
GND Massa
Z-C Segnale di passaggio per lo zero
Dim Controllo TRIAC

Schema di collegamento

plaintext
[Your Project] ←→ [DimmerLink] ←→ [Dimmer] ←→ [Mains + Lamp]

Schemi dettagliati di collegamento dimmer e carico (lampade, riscaldatori): Collegamento di potenza e carico dei dimmer


Passo 3: Caricare il codice

Arduino:

cpp
#include 

#define DIMMER_ADDR 0x50
#define REG_LEVEL   0x10

void setup() {
    Wire.begin();
}

void loop() {
    // Smooth brightness change
    for (int level = 0; level <= 100; level += 10) {
        setLevel(level);
        delay(500);
    }
    for (int level = 100; level >= 0; level -= 10) {
        setLevel(level);
        delay(500);
    }
}

void setLevel(uint8_t level) {
    Wire.beginTransmission(DIMMER_ADDR);
    Wire.write(REG_LEVEL);
    Wire.write(level);
    Wire.endTransmission();
}

MicroPython (ESP32, Raspberry Pi Pico):

python
from machine import I2C, Pin
import time

# ESP32: scl=22, sda=21
# Raspberry Pi Pico: scl=5, sda=4
i2c = I2C(0, scl=Pin(22), sda=Pin(21), freq=100000)
DIMMER_ADDR = 0x50
REG_LEVEL = 0x10

def set_level(level):
    i2c.writeto_mem(DIMMER_ADDR, REG_LEVEL, bytes([level]))

# Smooth brightness change
while True:
    for level in range(0, 101, 10):
        set_level(level)
        time.sleep(0.5)

Python (Raspberry Pi):

python
from smbus2 import SMBus
import time

bus = SMBus(1)
DIMMER_ADDR = 0x50
REG_LEVEL = 0x10

def set_level(level):
    bus.write_byte_data(DIMMER_ADDR, REG_LEVEL, level)

# Set brightness to 50%
set_level(50)

Opzione B: UART

⚠️ UART is timing-sensitive. If you see random bytes, dropped replies, or disconnects: give the board time to answer (allow ~100–200 ms between sending a command and reading the reply), and read all returned bytes for each command — a leftover unread byte desynchronizes the next exchange. Fixed 115200 8N1, raw HEX packets. If UART stays unreliable, switch to I2C (see note in Step 1) — it is the more robust interface.

Arduino:

cpp
// Use Serial1 (or SoftwareSerial for Uno)
#define DIMMER_SERIAL Serial1

void setup() {
    DIMMER_SERIAL.begin(115200);
    checkConnection();
}

void loop() {
    setLevel(50);  // 50%
    delay(2000);
    setLevel(100); // 100%
    delay(2000);
}

void setLevel(uint8_t level) {
    uint8_t cmd[] = {0x02, 0x53, 0x00, level};
    DIMMER_SERIAL.write(cmd, 4);

    // Wait for response
    delay(10);
    if (DIMMER_SERIAL.available()) {
        uint8_t response = DIMMER_SERIAL.read();
        // 0x00 = OK
    }
}

// Connection check — request mains frequency
void checkConnection() {
    uint8_t cmd[] = {0x02, 0x52};
    Serial1.write(cmd, 2);

    delay(50);
    if (Serial1.available() >= 2) {
        uint8_t status = Serial1.read();
        uint8_t freq = Serial1.read();
        if (status == 0x00) {
            Serial.print("OK! Mains frequency: ");
            Serial.print(freq);
            Serial.println(" Hz");
        }
    }
}

Python:

python
import serial
import time

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

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

# Set brightness to 50%
if set_level(50):
    print("OK")
else:
    print("Error")

Passo 4: Verificare il funzionamento

  1. Carica il codice sul tuo microcontrollore
  2. Alimenta DimmerLink
  3. Osserva — la lampada dovrebbe variare di luminosità

Verifica della connessione

I2C — Scansione dispositivi

Arduino:

cpp
#include 

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

    Serial.println("Scanning for I2C devices...");

    Wire.beginTransmission(0x50);
    if (Wire.endTransmission() == 0) {
        Serial.println("DimmerLink found at 0x50");
    } else {
        Serial.println("Device not found!");
    }
}

void loop() {}

Raspberry Pi (riga di comando):

bash
# Install if not present:
sudo apt install i2c-tools

# Scan for devices:
i2cdetect -y 1

Risultato atteso — 50 all'incrocio tra la riga 5 e la colonna 0.

UART — Verifica della risposta

Inviare il comando di richiesta della frequenza di rete:

plaintext
HEX: 02 52

Expected response:
- 00 32 — OK, frequency 50 Hz
- 00 3C — OK, frequency 60 Hz


Non funziona?

Problema Soluzione
Nessuna risposta Verificare cablaggio e alimentazione
Errore 0xFC Errore di scrittura EEPROM
I2C doesn't see device Verificare i collegamenti e le resistenze di pull-up
Luminosità non corretta Verificare i livelli logici (3.3V/5V)

What's Next?

← Panoramica | Indice | Next: Hardware Connection →