Sample: Arduino & LED-Warrior09

This is the place where we write about ideas and projects made with our products

Moderator: Guido Körber

Post Reply
User avatar
Christoph Jung
Posts: 670
Joined: Sun Oct 08, 2006 3:43 pm
Location: Germany / Berlin
Contact:

Sample: Arduino & LED-Warrior09

Post by Christoph Jung »

Small sample how to use LED-Warrior09 with Arduino

Code: Select all

//Codemercs used a Arduino/Genuino 101 !

#include <Wire.h>

//Defines: DALI commands (Datasheet page 4)
#define DALI_OFF                0x00
#define DALI_UP                 0x01
#define DALI_DOWN               0x02
#define DALI_STEP_UP            0x03
#define DALI_STEP_DOWN          0x04
#define DALI_MAX                0x05
#define DALI_MIN                0x06
#define DALI_STEP_DOWN_OFF      0x07
#define DALI_ON_STEP_UP         0x08
#define DALI_SCENE              0x10  //0x10 - 0x1F

//Defines: I2C register (Datasheet page 3)
#define REG_STATUS 		0x00
#define REG_CMD 		  0x01
#define REG_CONFIG		0x02
#define REG_I2CADR		0x03

//Defines: DALI constants
#define DALI_MODE_DACP			0x00	//dimm values
#define DALI_MODE_COMMAND		0x01	//commands (MAX, MIN, OFF, etc.)

#define DALI_MAX_SHORT			0x3F	//0...63 -> 64 devices
#define DALI_MAX_GROUP			0x0F	//0...15 -> 16 groups
#define DALI_MAX_SCENE			0x0F	//0...15 -> 16 scenes


//Defines: dafauls I2C address
#define I2C_ADDR    0x20


//Some buttons to execute events
const int btn1 = 12;
const int btn2 = 13;

void setup() 
{
  pinMode(btn1, INPUT);
  pinMode(btn2, INPUT);
  Wire.begin();
}

void loop() 
{
    //Use an input from arduino as button
    if(digitalRead(btn1) == HIGH) 
    {
      SendCommand(0, DALI_MAX);
    }

    //Use an input from arduino as button
    if(digitalRead(btn2) == HIGH)
    {
      SendCommand(0, DALI_MIN);
    }

  delay(100); //Slow down
}

//mode -> 0 = dacp, 1 = command
byte GetShortAddress(int dali_adr, int mode)
{
	//DALI address format: 0 AAA AAA S
	return ((0x00 & ((dali_adr & DALI_MAX_SHORT) << 1)) | mode);
}

//mode -> 0 = dacp, 1 = command
byte GetGroupAddress(int dali_grp, int mode)
{
	//DALI address format: 1 AAA AAA S
	return ((0x80 & ((dali_grp & DALI_MAX_GROUP) << 1)) | mode);
}

//mode -> 0 = dacp, 1 = command
byte GetBroadcastAddress(int mode)
{
	//DALI address format: 1 111 111 S
	return (0x80 | 0x7E | mode);
}

void SendCommand(int dali_adr, int value)
{ 
	//DALI address format: Y AAA AAA S
	byte adr = GetShortAddress(dali_adr, DALI_MODE_COMMAND);

	Wire.beginTransmission(I2C_ADDR);
	Wire.write(REG_CMD);  		//Register: command
	Wire.write(adr);  			//DALI address
	Wire.write((byte)value);  	//Value
	Wire.endTransmission();
}

void SendDACP(int dali_adr, int value)
{
	//DALI address format: Y AAA AAA S
	byte adr = GetShortAddress(dali_adr, DALI_MODE_DACP);

	Wire.beginTransmission(I2C_ADDR);
	Wire.write(REG_CMD);  				//Register: command
	Wire.write(adr);  					//DALI address
	Wire.write((byte)(value & 0xFE));   //Value 0...254 
	Wire.endTransmission();
}

Abteilung: Softwareentwicklung
Folge uns auf Twitter
Follow us on twitter
smartvisionary
Posts: 5
Joined: Thu Sep 14, 2023 2:30 pm

Re: Sample: Arduino & LED-Warrior09

Post by smartvisionary »

Hello there,

I am trying to run the example code provided by you, and even the one provided by codemasters for the LW-09 01module. I am trying to usit with a MW PWM-120-24DA converter (https://asset.conrad.com/media10/add/16 ... ievate.pdf) with DALI output for a DALI controller. The code which was provided has failed to set the pwms for the LEDsconnected to the MW PWM-120-24DA converter. I am using an arduino nano every to controll the LW09 via I2C BUS.
Do you have any suggestionwhat am I doing wrong.

Thank you for advance for any help
Guido Körber
Site Admin
Posts: 2856
Joined: Tue Nov 25, 2003 10:25 pm
Location: Germany/Berlin
Contact:

Re: Sample: Arduino & LED-Warrior09

Post by Guido Körber »

Do you have a bus power supply connected to the bus? DALI needs a special kind of power supply that provides the power for the bus itself to function. Like our LED-Warrior11.
smartvisionary
Posts: 5
Joined: Thu Sep 14, 2023 2:30 pm

Re: Sample: Arduino & LED-Warrior09

Post by smartvisionary »

The bus did it as you suggested. May I have one more question about the addressing process. I have a PWM-120-24DA converter dali device connected and is working only if I send broadcast commands but I need to find out the address for the send_command procedure. Is there a way to get the devices address or do I have to make one. I already tried to iterate through 0 -63 and 0-255 to try every possible address, but only the broadcast 255 address triggers a response.
User avatar
Christoph Jung
Posts: 670
Joined: Sun Oct 08, 2006 3:43 pm
Location: Germany / Berlin
Contact:

Re: Sample: Arduino & LED-Warrior09

Post by Christoph Jung »

Most DALI devices will have no short address by default.
You have to set one by yourself using the "random procedure" DALI devices supports or setting it by send a DALI address using the DTR register method. The DTR methodis not recommended if you have a running bus, because each device on the bus will get this address if you are send this via broadcast

However, the LW08 is not designed for this type of commands. For this you need a LW14 or another DALI Master.
Abteilung: Softwareentwicklung
Folge uns auf Twitter
Follow us on twitter
smartvisionary
Posts: 5
Joined: Thu Sep 14, 2023 2:30 pm

Re: Sample: Arduino & LED-Warrior09

Post by smartvisionary »

Thank you very much. I will try the LW14.
smartvisionary
Posts: 5
Joined: Thu Sep 14, 2023 2:30 pm

Re: Sample: Arduino & LED-Warrior09

Post by smartvisionary »

Is there a chance you have an example how to trigger the random "procedure" or to set DTR on the lw-14, please?
User avatar
Christoph Jung
Posts: 670
Joined: Sun Oct 08, 2006 3:43 pm
Location: Germany / Berlin
Contact:

Re: Sample: Arduino & LED-Warrior09

Post by Christoph Jung »

If you using the LW14 as a module, we have no sample code for addressing with the "random address" method.
The DTR method will work but for this I have to build some sample code (not part of our githib repository at the moment).

Or you using the LW14U-DR, for this we have a Windows appliction to setup DALI devices incl. set, change and switch addresses.
Abteilung: Softwareentwicklung
Folge uns auf Twitter
Follow us on twitter
User avatar
Christoph Jung
Posts: 670
Joined: Sun Oct 08, 2006 3:43 pm
Location: Germany / Berlin
Contact:

Re: Sample: Arduino & LED-Warrior09

Post by Christoph Jung »

I found a git repository which using the LW14-Mod and supports the Addressing. Maybe this is worth a look: https://github.com/SorX14/dali_master
Abteilung: Softwareentwicklung
Folge uns auf Twitter
Follow us on twitter
smartvisionary
Posts: 5
Joined: Thu Sep 14, 2023 2:30 pm

Re: Sample: Arduino & LED-Warrior09

Post by smartvisionary »

The library above does not work well with an arduino but I've found an alternative to it https://github.com/davideloba/daliMaster. I ll try it with the lw-14 when it arrives. Thanks for your help.
Post Reply