Markdown source

#Dali - Implementing the protocol in bit-banging mode

DALI, Digital Appliance Lighting Interface, is a standard wired communications protocol used for Home & Building lighting applications. 
The interface was originally specified to support connectivity for fluorescent light ballasts, but has also been designed to support other lighting technologies. 

## Drive DALI devices with OpenHAB

In OpenHAB there is no specific binding for DALI protocol. A simple Python test program ([]( can be arranged adding RGB values as input parameters:

<pre class="terminal">
if len(sys.argv)==4:
	RedV = int(sys.argv[1])
	GreenV = int(sys.argv[2])
	BlueV = int(sys.argv[3])
	if RedV > 254: RedV = 254
	if GreenV > 254: GreenV = 254
	if BlueV > 254: BlueV = 254
	if RedV < 0: RedV = 0
	if GreenV < 0: GreenV = 0
	if BlueV < 0: BlueV = 0


Adding the specific functions:

<pre class="terminal">
def send_color_red(value):
	global LED_RED
def send_color_green(value):
	global BIT_DELAY
	global GPIO_TX_LINE
def send_color_blue(value):
	global BIT_DELAY
	global GPIO_TX_LINE

With a rule you can read an item status (a slider type for example) that returns the HSB values of the selected color. Those HSB values can be converted in RGB and sent as parameters to the Python program in order to setup the desired color.

<pre class="terminal">
var HSBType hsb
var red = 0
var green = 0
var blue = 0
var Cmd="/home/openhabian/"

rule "HSBtoRGB"
        Item DaliColor changed
        hsb = DaliColor.state as HSBType
        red   = ( * 2.55).intValue
        green = ( * 2.55).intValue
        blue  = ( * 2.55).intValue
        val results = executeCommandLine(Cmd+"@@"+red+"@@"+green+"@@"+blue,5000)

## Testing DALI protocol through bit-banging Raspberry GPIOs

* [](

GPIOs used:
* TX - GPIO 31

<img src="./raspberry_pinout.jpg" class="img-responsive center-block" width="50%"/>

* [Hardware details on CM3-Home](
* [DALI commands](./dali_commands.pdf)

## Bus and protocol

The physical interface consists of 2 wires, DALI Power and DALI Data. The DALI system consists of one DALI Control module with up to 63 DALI devices.

* DALI Power line provides the power only for the communication protocol of a maximum 22.5V and limits the current for the system to 250mA. 
* The DALI Data line provides the half duplex communication at a data rate of 1200 bits/second using a bi-phase (Manchester) decoding.

Bi-phase decoding is accomplished with the following: 

* a logical zero consists of sending a physical low signal for 416 µs immediately followed with a physical high signal for 416 µs. 
* a logical one consists of sending firstly a physical high signal for 416 µs followed by a physical low signal. 

A physical high signal on the DALI Data line is a voltage level between +9.5V and +22.5V. A physical low signal 
on the DALI Data line is a voltage level between -6.5V and +6.5V.

<img src="./figura7.jpg" class="img-responsive center-block"/>

The DALI digital layer consists of 2 frames, a forward frame and a backward frame. 

* A forward frame is a frame sent from a DALI controller to a DALI ballast. It is constructed by a START bit (always logical 1), followed by 1byte Address,1byte Command and two STOP bits (a high level with no transitions).
* A DALI ballast communicates back to the DALI control using only a 1byte backward frame consisting of a START bit,1byte,2 STOP bits.

<img src="./figura8.jpg" class="img-responsive center-block"/>

The DALI protocol allows a master controller options to address all ballasts by either broadcast to all, Groups of ballasts, 
and individual addressing. 

The most commonly used direct commands allow the controller to modify lighting brightness, scene 
settings for groups, fading capability and varying rates. Also including are Query command that request the ballast to send 
a backward frame with configuration data such as, power levels, scene levels, current address. 

Using “extended” Configuration 
command the DALI controls can modify addresses of each ballast thus eliminating manual configuration of the DALI system. 

The “extended” configuration command will follow immediately after a DALI controller sends an INITIALIZE ($A5) command, 
which informs all other DALI devices on the bus to ignore further commands until a TERMINATE command is observed 
or 30 s elapses in time.

<img src="./figura9.jpg" class="img-responsive center-block"/>

* [Original article](

## Hardware

The DALI bus depends on the specific power supply, this is an example used in a development board:

<img src="./DaliPWR.png" class="img-responsive center-block" width="50%"/>

With kind of schematic the voltage on the bus depends too much from the load. How is shown on the graphs Vout begins to go down before the current is half of the maximum load. The DALI specification imposes a 2mA maximum load for each device on the bus, but analyzing some of the available devices, it's evident that this limit is often exceeded. Furthermore, most of the real devices consume this current constantly. This kind of power supply would be too much limited on the maximum number of the connectable device.

<img src="./PWR-Transistor.png" class="img-responsive center-block" width="50%"/>

Using an integrated, current limited power supply, the circuit works much better, with a much more accurate Imax regulation and, above all, a sharper knee at the current threshold. The voltage is stable until the intervention of the current limiter.

<img src="./PWR-Enhanced.png" class="img-responsive center-block" width="50%"/>

The DALI system is designed to be realized in an easy and cheap way, it's very tolerant both on voltage and on signals shape. These are the specifications:

<img src="./Dali-Spec.png" class="img-responsive center-block" width="35%"/>

The circuit has been designed to stay widely within specifications, in order to be able to tolerate any degradation when the bus is not perfectly realized or with strange loads.

A generator that injects a 50% duty cycle, 3.3V square wave to the TX input composes the test bench. The measurement is on the RX output. The DALI bus is in loopback by nature: TX and RX are connected on the same pair of wires. The circuit parameters have been fine tuned to have on the output a signal as close as possible to the one at the input. 

The graph shows a shape well within the specifications even with a frequency double of the working one.

<img src="./2400.png" class="img-responsive center-block" width="50%"/>

A the extreme, the signal is still acceptable at 10 times the working frequency. 

<img src="./10000.png" class="img-responsive center-block" width="50%"/>

* [Specifications](
* [Sistema DALI per il controllo digitale - Flyier Osram](
* [ARPN Journal of Engineering and Applied Sciences]( 
* Mikroel DALI Click
  * [Product description](
  * [Schematic](
* [Microchip USB to DALI interface]( 
* Atmel
  * [DALI Master with ATxmega32E5 Reference Design]( 

* Application Notes
	* [Microchip]( 
	* [Renesas](
	* [STM]( 

* Schematics examples
	* [1](1.png)
	* [2](2.png)
	* [3](3.png)
	* [4](4.png)


Le attività del TanzoLab si svolgono ogni mercoledi sera, salvo casi speciali, dalle ore 18:30 presso i locali della Acme Systems srl e consistono in:

  • Talk monotematici a cura di professionisti in vari settori tecnologici
  • Workshop pratici su elettronica embedded, produzione e informatica
  • Progettazione e realizzazione di nuovi prodotti embedded per l'IT

Le attività vengono coordinate tramite questo sito, in cui vengono pubblicati tutti i lavori svolti o in via di sviluppo, e tramite un gruppo Telegram con cui per interagire direttamente via chat con gli altri membri.