Look for in our Blog. You will find multiple applications, solutions, code examples. Navigate using the tag cloud or search using specific criteria

DALI Library for Arduino based PLC

Introduction

DALI stands for Digital Addressable Lighting Interface. DALI is a standard protocol specified by the International Elctrotechnical commission.

DALI protocol uses the Master slave architecture where one master can monitor and control each light point. The communication is via two-wire, low-voltage bus running at low baud rate (1200 bits per second). Signal levels are defined between 0 to 4.5V for logical 0 and between 11.5V to 22.5V for logical 1.

Odoo CMS - a big picture
Odoo CMS - a big picture

Arduino community have developed a library to control DALI slaves.  DALI library >>

At the moment you cannot get responses from the device, but you can find whether device give response or not. It's enough to control and initialize DALI lights.


Software

Below is showed and example code of how to use DALI library:

#include<Dali.h>
constint DALI_TX = 3;
constint DALI_RX_A = 0;
#defineBROADCAST_DP0b11111110
#defineBROADCAST_C0b11111111
#defineON_DP0b11111110
#defineOFF_DP0b00000000
#defineON_C0b00000101
#defineOFF_C0b00000000
defineQUERY_STATUS0b10010000
defineRESET0b00100000
voidsetup() {
  Serial.begin(74880);
  dali.setupTransmit(DALI_TX);
  dali.setupAnalogReceive(DALI_RX_A);
  dali.busTest();
  dali.msgMode = true;
  Serial.println(dali.analogLevel);
help(); //Show help
}
voidhelp() {
  Serial.println("Enter 16 bit command or another command from list:");
  Serial.println("help - command list");
  Serial.println("on - broadcast on 100%");
  Serial.println("off - broadcast off 0%");
  Serial.println("scan - device short address scan");
  Serial.println("initialise - start process of initialisation");
  Serial.println();
}
voidsinus () {
uint8_t lf_1_add = 0;
uint8_t lf_2_add = 1;
uint8_t lf_3_add = 2;
uint8_t lf_1;
uint8_t lf_2;
uint8_t lf_3;
int i;
int j = 0;
while (Serial.available() == 0) {
for (i = 0; i < 360; i = i + 1) {
if (Serial.available() != 0) {
  dali.transmit(BROADCAST_C, ON_C);
break;
  }
  lf_1 = (intabs(254 * sin(i * 3.14 / 180));
  lf_2 = (intabs(254 * sin(i * 3.14 / 180 + 2 * 3.14 / 3));
  lf_3 = (intabs(254 * sin(i * 3.14 / 180 + 1 * 3.14 / 3));
  dali.transmit(lf_1_add << 1, lf_1);
delay(5);
  dali.transmit(lf_2_add << 1, lf_2);
delay(5);
  dali.transmit(lf_3_add << 1, lf_3);
delay(5);
delay(20);
  }
  }
}
voidtestReceive () {
  dali.transmit(0254);
delay(200);
  dali.transmit(10x90);
  Serial.println(dali.receive());
}
voidloop() {
constint delaytime = 500;
int i;
int cmd1;
int cmd2;
  String comMsg;
// Read command from port
delay(delaytime);
while (Serial.available()) {
  comMsg = comMsg + (char)(Serial.read());
  }; // read data from serial
if (comMsg == "sinus") {
sinus();
  };
if (comMsg == "scan") {
  dali.scanShortAdd();
  }; // scan short addresses
if (comMsg == "on") {
  dali.transmit(BROADCAST_C, ON_C);
  }; // broadcast, 100%
if (comMsg == "off") {
  dali.transmit(BROADCAST_C, OFF_C);
  }; // broadcast, 0%
if (comMsg == "initialise"or comMsg == "ini") {
  dali.initialisation();
  }; // initialisation
if (comMsg == "help") {
help();
  }; //help
if (comMsg == "test") {
testReceive();
  }; //graph
if (dali.cmdCheck(comMsg, cmd1, cmd2)) {
  dali.transmit(cmd1, cmd2);  // command in binary format: (address byte, command byte)
  }
delay(delaytime);
};