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

How to work with DALI Arduino Library and an industrial PLC

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 centre 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 idle (high) state.



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:

  • Arduino IDE Software

  • An Industrial Shields controller Arduino: M-Duino-DALI family


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 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 examplesin 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 a reliable communication. The initNodes() function will be called after the begin statements. If there only is a driver to set up, an uint8_t address will be provided. In this example we are initializing the 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 nodes that we want to set up. We will pass these two parameters to the initNodes() function as 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 evcent that greater precision is required, by providing the exact value to the setValue() function, a desired intensity can be set. This value ranges from 0 to 254.

The following code has been made for testing. Inside the Arduino Ide loop() function we will increase the LEDs corresponding to driver no. 6 by 10 at the most 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.

Share the DALI post on your favourite social network      

Do you want more information?

Open Source technology allows you to develop your installations.

Just fill the form and we will contact you as soon as we can.

Send