How to work with DALI Arduino Library and an industrial PLC

Arduino IDE Library and DALI for industrial control
June 17, 2020 by
How to work with DALI Arduino Library and an industrial PLC
Boot & Work Corp. S.L., DAVID SEGOVIA LOPEZ

Introduction

DALI stands for Digital Addressable Lighting Interface. A DALI network consists of an industrial controller and one or more lighting that have DALI interfaces. The PLC controller (DALI master) can monitor and control each lighting by means of a bi-directional data exchange.

The communication is via a two-wire, low-voltage bus that operates at a low speed (1200 bits per second). Signal levels are defined as 0±4.5 V for logical '0' and 16±6.5 V for logical '1'. The idle state of the bus is the logical '1'. Manchester coding is used with 16-bit forward frames  (plus start and stop) and 8-bit return frames. In Manchester coding, the bit status is defined by a transition in the center of the bit window: positive-going transition = '1', negative-going transition = '0'. The DALI protocol enables the luminaires to be addressed individually. It also incorporates Group and Scene broadcast messages to address multiple luminaires simultaneously. A single DALI network can control up to 64 lighting devices.


Each bit takes two periods. The defined DALI bit rate is 1200 bps. Therefore, a 1-bit period is ~834 µsec. A frame is started by a start bit and ends with two high-level stop bits (no phase shift). Data is first transmitted with the MSB. Between frames, the bus is in an idle (high) state.


DALI bit rate - How to work with DALI Arduino Library and an industrial PLC
How to work with DALI Arduino Library and an industrial PLC

Requirements

In order to work with the DALI Arduino Library, you will need the following items:


Software
Arduino-DALI Library implements the DALI communication protocol in the Arduino-based M-Duino-DALI family of programmable logic controllers.

Getting Started

This section shows the necessary prerequisites and installation of Industrial Shields boards to use this library.


Installing

Steps to install Industrial Shields Boards on Arduino IDE:

    1. Open the Arduino IDE, version 1.8.10 or higher.

    2. Press the “Preferences” option from the “File” menu and open the preferences window.

    3. In the “Additional boards manager URLs” text box, add the address:

    http://apps.industrialshields.com/main/arduino/boards/package_industrialshields_index.json

    4. Close the preferences window with the “Ok” button.

    5. Click on “Tools” menu and open the “Boards” submenu, and click the “Boards Manager” option, to open the Boards Manager window.

    6. Find “industrialshields” in the search filter and select the list and click “Install”. Download the 1.1.24 version or upper.

    7. Close the “Boards Manager”.


Once you have done all the steps, you can select each PLC Arduino for industrial automation solutions you wish to work with on “Tools” > “Boards


DALI Library for Arduino IDE

The DALI library sends and receives data via DALI pins used in the M-Duino DALI family and Ardbox DALI family controllers. Refer to the DALI family PLC user's manual of your DALI family PLC to see the location of the data transfer pins via DALI. Our company offers two examples in order to provide an introduction to DALI.

To work properly you must include our library DALI.h provided in the integration of Industrial Shields boards.

#include "DALI.h"


First of all, we have to call the following statement to tell your DALI family controllers the internal connections between the Arduino board and the attached DALI module inside the industrial Arduino automation PLC.

DALI dali;


Inside the setup function, we must call the begin() function to set up the DALI hardware. For the DALI, no argument has to be passed. 

dali.begin()


If any DALI communication has not been used before or the drivers’ addresses are unknown, you must initialize the nodes, as they will be necessary for reliable communication. The initNodes() function will be called after the beginning statements. If there only is a driver to set up, an uint8_t address will be provided. In this example, we are initializing node 6:

int initNodes(6);


To control two or more nodes; a constant list of uint8_t addresses has to be declared along with the maxim number of nodes that we want to set up. We will pass these two parameters to the initNodes()function like the following example. Five nodes will be initialized:

const uint8_t addresses[] = { 6, 7, 8, 9, 10 };
const int maxAddresses = sizeof(addresses) / sizeof(uint8_t);

int initNodes(const uint8_t* addresses, uint8_t numAddresses);


A test has been implemented, setting up 5 drivers and printing which address has been assigned to each node.

void setup() {
  Serial.begin(9600UL);
  dali.begin();
  Serial.println("Initialize DALI nodes...");
  int numAddresses = dali.initNodes(addresses, maxAddresses);
  Serial.println("Found nodes:");
  for (int i = 0; i < numAddresses; ++i) {
    Serial.print("Node number: ");
    Serial.print(i, DEC);
    Serial.print(", node address: ");
    Serial.println(addresses[i], HEX);
  }
}


The values of the DALI nodes are controlled with 3 functions. An uint8_t address has to be passed to all of them, as it will be the managed node.

void turnOff(uint8_t nodeAddress);
void setMax(uint8_t nodeAddress);
void setValue(uint8_t nodeAddress, uint8_t value);

The turnoff() function, as its name indicates, turns off the lights connected to the corresponding node, while the setMax() function will turn them on. In the event that greater precision is required, by providing the exact value to the setValue() function, the desired intensity can be set. This value ranges from 0 to 254.

The following code has been made for testing. Inside the Arduino Ideloop() function, we will increase the LEDs corresponding to driver no. 6 by 10 almost every 5 milliseconds.

void loop() {
  if (millis() - lastStepTime > 5) {
    value += 10;
    if (value > 254) {
      value = 0;
    }
    dali.setValue(6, value);
    lastStepTime = millis();
  }
}

Want to learn more about DALI applications with Industrial Arduino PLCs?

Contact us, we will help you.

​Search in our Blog

How to work with DALI Arduino Library and an industrial PLC
Boot & Work Corp. S.L., DAVID SEGOVIA LOPEZ June 17, 2020
Share this post

Looking for your ideal Programmable Logic Controller?

Take a look at this product comparison with other industrial controllers Arduino-based. 

We are comparing inputs, outputs, communications and other features with the ones of the relevant brands.


Industrial PLC comparison >>>