← Обзор | Содержание | Next: Hardware Connection →
Быстрый старт
Это руководство поможет вам запустить DimmerLink за несколько минут.
What You'll Need
- DimmerLink — плата контроллера
- Диммер — модуль TRIAC с поддержкой внешнего управления
- Микроконтроллер или одноплатный компьютер — Arduino, ESP32, Raspberry Pi и т.д.
- Соединительные провода
- Лампа для тестирования (лампа накаливания или диммируемый светодиод)
Шаг 1: Выберите интерфейс
| Параметр | UART | I2C |
|---|---|---|
| Схема подключения | TX/RX перекрёстно | SDA/SCL напрямую |
| Сложность кода | Командные пакеты | Доступ к регистрам |
| Рекомендация | Для опытных пользователей | Для начинающих |
💡 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.
Шаг 2: Схема подключения
Разъёмы DimmerLink
Вход (к вашему проекту):
| Пин | Назначение |
|---|---|
| VCC | Питание 3.3V |
| GND | Земля |
| TX/SDA | UART TX или I2C SDA |
| RX/SCL | UART RX или I2C SCL |
Выход (к модулю диммера):
| Пин | Назначение |
|---|---|
| VCC | Питание |
| GND | Земля |
| Z-C | Сигнал перехода через ноль |
| Dim | Управление TRIAC |
Схема соединений
[Your Project] ←→ [DimmerLink] ←→ [Dimmer] ←→ [Mains + Lamp]
Подробные схемы подключения диммера и нагрузки (лампы, нагреватели): Подключение питания и нагрузки диммеров
Шаг 3: Загрузка кода
Вариант A: I2C (рекомендуется)
Arduino:
#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):
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):
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)
Вариант 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:
// 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:
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")
Шаг 4: Проверка работы
- Загрузите код в микроконтроллер
- Подайте питание на DimmerLink
- Наблюдайте — лампа должна изменять яркость
Проверка соединения
I2C — Сканирование устройств
Arduino:
#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 (командная строка):
# Install if not present:
sudo apt install i2c-tools
# Scan for devices:
i2cdetect -y 1
Ожидаемый результат — 50 на пересечении строки 5 и столбца 0.
UART — Проверка ответа
Отправьте команду запроса частоты сети:
HEX: 02 52
Expected response:
- 00 32 — OK, frequency 50 Hz
- 00 3C — OK, frequency 60 Hz
Не работает?
| Проблема | Решение |
|---|---|
| Нет ответа | Проверьте схему подключения и питание |
| Ошибка 0xFC | Ошибка записи EEPROM |
| I2C doesn't see device | Проверьте соединения и подтягивающие резисторы |
| Некорректная яркость | Проверьте логические уровни (3.3V/5V) |