← Communication I2C | Sommaire | Suivant : Utilisation avancée →
Ordinateurs monocartes
Connexion de DimmerLink à Raspberry Pi, Orange Pi, Banana Pi et autres SBC.
Vue d'ensemble
Tous les ordinateurs monocartes fonctionnent en logique 3,3V — connexion directe à DimmerLink sans convertisseur de niveau.
| SBC | I2C | UART | OS |
|---|---|---|---|
| Raspberry Pi 3/4/5 | ✓ | ✓ | Raspberry Pi OS |
| Orange Pi | ✓ | ✓ | Armbian |
| Banana Pi | ✓ | ✓ | Armbian |
Raspberry Pi
Câblage
| Raspberry Pi | DimmerLink | Fonction |
|---|---|---|
| Pin 1 (3.3V) | VCC | Alimentation |
| Pin 6 (GND) | GND | Masse |
| Pin 3 (GPIO2) | SDA | I2C Data |
| Pin 5 (GPIO3) | SCL | I2C Clock |
Pour UART :
| Raspberry Pi | DimmerLink | Fonction |
|---|---|---|
| Pin 1 (3.3V) | VCC | Alimentation |
| Pin 6 (GND) | GND | Masse |
| Pin 8 (GPIO14) | RX | UART TX → RX |
| Pin 10 (GPIO15) | TX | UART RX ← TX |
Activation des interfaces
sudo raspi-config
- I2C : Interface Options → I2C → Enable
- UART : Interface Options → Serial Port → Enable
Redémarrage après modifications :
sudo reboot
Vérification de l'I2C
# Install utilities (if not installed)
sudo apt install i2c-tools
# Scan I2C bus for devices
i2cdetect -y 1
Résultat attendu — adresse 50 dans le tableau :
0 1 2 3 4 5 6 7 8 9 a b c d e f
00: -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: 50 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Contrôle via CLI
I2C :
# Set brightness to 50%
i2cset -y 1 0x50 0x10 0x32
# 💡 Tip: 0x32 in HEX = 50 in decimal. You can use decimal numbers: i2cset -y 1 0x50 0x10 50
# Read current brightness
i2cget -y 1 0x50 0x10
# Read mains frequency
i2cget -y 1 0x50 0x20
UART :
# Configure port
stty -F /dev/serial0 115200 cs8 -cstopb -parenb
# Set brightness to 50% (requires xxd or printf)
printf '\x02\x53\x00\x32' > /dev/serial0
# Or using a Python one-liner
python3 -c "import serial; s=serial.Serial('/dev/serial0', 115200); s.write(bytes([0x02,0x53,0x00,50])); print(s.read(1).hex())"
Python + I2C (smbus2)
# Install library
pip install smbus2
from smbus2 import SMBus
import time
DIMMER_ADDR = 0x50
REG_LEVEL = 0x10
REG_CURVE = 0x11
REG_FREQ = 0x20
bus = SMBus(1)
# Read mains frequency
freq = bus.read_byte_data(DIMMER_ADDR, REG_FREQ)
print(f"Mains frequency: {freq} Hz")
# Set brightness to 50%
bus.write_byte_data(DIMMER_ADDR, REG_LEVEL, 50)
print("Brightness set: 50%")
# Read current brightness
level = bus.read_byte_data(DIMMER_ADDR, REG_LEVEL)
print(f"Current brightness: {level}%")
bus.close()
Python + UART (pyserial)
# Install library
pip install pyserial
import serial
import time
ser = serial.Serial('/dev/serial0', 115200, timeout=0.1)
# Set brightness to 50%
ser.write(bytes([0x02, 0x53, 0x00, 50]))
resp = ser.read(1)
if resp and resp[0] == 0x00:
print("Brightness set: 50%")
# Get mains frequency
ser.write(bytes([0x02, 0x52]))
resp = ser.read(2)
if len(resp) == 2 and resp[0] == 0x00:
print(f"Mains frequency: {resp[1]} Hz")
ser.close()
Script de démarrage automatique (systemd)
Créer le fichier /etc/systemd/system/dimmer.service :
[Unit]
Description=Dimmer Controller Service
After=multi-user.target
[Service]
Type=simple
ExecStart=/usr/bin/python3 /home/pi/dimmer_control.py
Restart=on-failure
User=pi
[Install]
WantedBy=multi-user.target
⚠️ Important : Remplacez
/home/pi/dimmer_control.pypar le chemin de votre script.
Activation :
sudo systemctl daemon-reload
sudo systemctl enable dimmer.service
sudo systemctl start dimmer.service
Orange Pi
Particularités
- La plupart des modèles sont compatibles GPIO avec Raspberry Pi
- OS : Armbian (recommandé)
- Les utilitaires I2C/UART sont similaires à ceux du Raspberry Pi
Activation de l'I2C
Sous Armbian :
sudo armbian-config
# System → Hardware → enable i2c
Ou via les overlays dans /boot/armbianEnv.txt :
overlays=i2c0
📘 Orange Pi fonctionne généralement sous Armbian. Instructions d'installation d'Armbian
Câblage (Orange Pi Zero)
| Orange Pi Zero | DimmerLink |
|---|---|
| Pin 1 (3.3V) | VCC |
| Pin 6 (GND) | GND |
| Pin 3 (PA12/SDA) | SDA |
| Pin 5 (PA11/SCL) | SCL |
Vérification
# Scan for devices
i2cdetect -y 0 # May be i2c-0 instead of i2c-1
Code Python
Le code est similaire à celui du Raspberry Pi, mais le numéro de bus peut différer :
from smbus2 import SMBus
# Orange Pi may use bus 0
bus = SMBus(0) # or SMBus(1) — depends on model
Banana Pi
Particularités
- Brochage GPIO compatible avec Raspberry Pi
- OS : Armbian, BPI-WiringPi
Câblage (Banana Pi M2)
| Banana Pi M2 | DimmerLink |
|---|---|
| Pin 1 (3.3V) | VCC |
| Pin 6 (GND) | GND |
| Pin 3 (GPIO2) | SDA |
| Pin 5 (GPIO3) | SCL |
Activation de l'I2C
sudo armbian-config
# System → Hardware → enable i2c
Recommandations générales
Résistances de rappel pour l'I2C
| Carte | Pull-up intégré | Recommandation |
|---|---|---|
| Raspberry Pi | 1,8kΩ | Généralement suffisant |
| Orange Pi | Variable selon le modèle | Vérifier, ajouter 4,7kΩ |
| Banana Pi | Variable selon le modèle | Vérifier, ajouter 4,7kΩ |
| Pico | Aucun | Ajouter 4,7kΩ |
Longueur des câbles
- I2C : jusqu'à 30 cm sans problème
- UART : jusqu'à 1–2 mètres
Alimentation
- DimmerLink consomme un courant minimal
- L'alimentation via la broche 3,3V du SBC est généralement suffisante
- En cas de fonctionnement instable, utiliser une alimentation séparée
Dépannage
- L'I2C ne fonctionne pas :
- Vérifier
i2cdetect— l'adresse 0x50 est-elle visible - Vérifier les résistances de rappel
-
S'assurer que l'I2C est activé dans le système
-
L'UART ne fonctionne pas :
- Vérifier TX↔RX (câblage croisé)
- S'assurer que l'UART est activé
-
Vérifier les droits d'accès à
/dev/serial0 -
Permission denied error:
bash sudo usermod -a -G i2c,dialout $USER # Log out and back in after this
What's Next?
- Utilisation avancée — USB-UART, modules sans fil
- FAQ — dépannage
- Exemples de code — scripts prêts à l'emploi
← Communication I2C | Sommaire | Suivant : Utilisation avancée →