Se rendre au contenu

← Vue d'ensemble | Sommaire | Next: Hardware Connection →

Démarrage rapide

Ce guide vous aidera à mettre en service DimmerLink en quelques minutes.


What You'll Need

  1. DimmerLink — carte contrôleur
  2. Variateur — module TRIAC avec prise en charge du contrôle externe
  3. Microcontrôleur ou SBC — Arduino, ESP32, Raspberry Pi, etc.
  4. Câbles de connexion
  5. Lampe pour les tests (incandescente ou LED dimmable)

Étape 1 : Choisir une interface

Caractéristique UART I2C
Câblage TX/RX croisé SDA/SCL direct
Complexité du code Paquets de commandes Accès aux registres
Recommandation Pour utilisateurs avancés Pour débutants

💡 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.


Étape 2 : Câblage

Entrée (vers votre projet) :

Broche Fonction
VCC Alimentation 3.3V
GND Masse
TX/SDA UART TX ou I2C SDA
RX/SCL UART RX ou I2C SCL

Sortie (vers le module variateur) :

Broche Fonction
VCC Alimentation
GND Masse
Z-C Signal de passage par zéro
Dim Commande TRIAC

Schéma de connexion

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

Schémas détaillés de connexion du variateur et de la charge (lampes, radiateurs) : Connexion de la puissance et de la charge des variateurs


Étape 3 : Téléverser le code

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)

Option 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")

Étape 4 : Vérifier le fonctionnement

  1. Téléversez le code sur votre microcontrôleur
  2. Alimentez DimmerLink
  3. Observez — la lampe devrait varier en luminosité

Vérification de la connexion

I2C — Scan des périphériques

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 (ligne de commande) :

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

# Scan for devices:
i2cdetect -y 1

Résultat attendu — 50 à l'intersection de la ligne 5 et de la colonne 0.

UART — Vérification de la réponse

Envoyez la commande de demande de fréquence secteur :

plaintext
HEX: 02 52

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


Ça ne fonctionne pas ?

Problème Solution
Pas de réponse Vérifier le câblage et l'alimentation
Erreur 0xFC Erreur d'écriture EEPROM
I2C doesn't see device Vérifier les connexions et les résistances de pull-up
Luminosité incorrecte Vérifier les niveaux logiques (3.3V/5V)

What's Next?

← Vue d'ensemble | Sommaire | Next: Hardware Connection →