Passa al contenuto

← Comunicazione I2C | Indice | Avanti: Uso avanzato →

Computer a scheda singola

Collegamento di DimmerLink a Raspberry Pi, Orange Pi, Banana Pi e altri SBC.


Panoramica

Tutti i computer a scheda singola operano con logica a 3,3V — collegamento diretto a DimmerLink senza convertitori di livello.

SBC I2C UART OS
Raspberry Pi 3/4/5 Raspberry Pi OS
Orange Pi Armbian
Banana Pi Armbian

Raspberry Pi

Cablaggio

Raspberry Pi DimmerLink Funzione
Pin 1 (3.3V) VCC Alimentazione
Pin 6 (GND) GND Massa
Pin 3 (GPIO2) SDA I2C Data
Pin 5 (GPIO3) SCL I2C Clock

Per UART:

Raspberry Pi DimmerLink Funzione
Pin 1 (3.3V) VCC Alimentazione
Pin 6 (GND) GND Massa
Pin 8 (GPIO14) RX UART TX → RX
Pin 10 (GPIO15) TX UART RX ← TX

Abilitazione delle interfacce

bash
sudo raspi-config
  • I2C: Interface Options → I2C → Enable
  • UART: Interface Options → Serial Port → Enable

Riavvio dopo le modifiche:

bash
sudo reboot

Verifica dell'I2C

bash
# Install utilities (if not installed)
sudo apt install i2c-tools

# Scan I2C bus for devices
i2cdetect -y 1

Output previsto — indirizzo 50 nella tabella:

plaintext
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:          -- -- -- -- -- -- -- -- -- -- -- -- --
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
30: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
50: 50 -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

Controllo tramite CLI

I2C:

bash
# 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:

bash
# 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)

bash
# Install library
pip install smbus2
python
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)

bash
# Install library
pip install pyserial
python
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 di avvio automatico (systemd)

Creare il file /etc/systemd/system/dimmer.service:

ini
[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

⚠️ Importante: Sostituire /home/pi/dimmer_control.py con il percorso del proprio script.

Attivazione:

bash
sudo systemctl daemon-reload
sudo systemctl enable dimmer.service
sudo systemctl start dimmer.service

Orange Pi

Caratteristiche

  • La maggior parte dei modelli è compatibile con i GPIO di Raspberry Pi
  • OS: Armbian (consigliato)
  • Le utilità I2C/UART sono simili a quelle di Raspberry Pi

Abilitazione dell'I2C

In Armbian:

bash
sudo armbian-config
# System → Hardware → enable i2c

Oppure tramite overlay in /boot/armbianEnv.txt:

plaintext
overlays=i2c0

📘 Orange Pi di solito utilizza Armbian. Istruzioni per l'installazione di Armbian

Cablaggio (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

Verifica

bash
# Scan for devices
i2cdetect -y 0   # May be i2c-0 instead of i2c-1

Codice Python

Il codice è simile a quello di Raspberry Pi, ma il numero del bus può differire:

python
from smbus2 import SMBus

# Orange Pi may use bus 0
bus = SMBus(0)  # or SMBus(1) — depends on model

Banana Pi

Caratteristiche

  • Piedinatura GPIO compatibile con Raspberry Pi
  • OS: Armbian, BPI-WiringPi

Cablaggio (Banana Pi M2)

Banana Pi M2 DimmerLink
Pin 1 (3.3V) VCC
Pin 6 (GND) GND
Pin 3 (GPIO2) SDA
Pin 5 (GPIO3) SCL

Abilitazione dell'I2C

bash
sudo armbian-config
# System → Hardware → enable i2c

Raccomandazioni generali

Resistenze di pull-up per I2C

Scheda Pull-up integrato Raccomandazione
Raspberry Pi 1,8kΩ Generalmente sufficiente
Orange Pi Varia in base al modello Verificare, aggiungere 4,7kΩ
Banana Pi Varia in base al modello Verificare, aggiungere 4,7kΩ
Pico Nessuno Aggiungere 4,7kΩ

Lunghezza dei cavi

  • I2C: fino a 30 cm senza problemi
  • UART: fino a 1–2 metri

Alimentazione

  • DimmerLink assorbe una corrente minima
  • L'alimentazione dal pin 3,3V del SBC è generalmente sufficiente
  • In caso di funzionamento instabile, utilizzare un alimentatore separato

Risoluzione dei problemi

  1. I2C not working: - Check i2cdetect — is address 0x50 visible - Check pull-up resistors - Make sure I2C is enabled in the system

  2. UART not working: - Check TX↔RX (crossed wiring) - Make sure UART is enabled - Check access permissions for /dev/serial0

  3. Permission denied error:
    bash sudo usermod -a -G i2c,dialout $USER # Log out and back in after this


What's Next?

← Comunicazione I2C | Indice | Avanti: Uso avanzato →