Is there anybody on the forum who can help me get a Dali 2 Click working with an Arduino, please?
I've tried two C++ libraries but have reached a point where I feel out of my depth.
Is there anybody on the forum who can help me get a Dali 2 Click working with an Arduino, please?
I've tried two C++ libraries but have reached a point where I feel out of my depth.
What is Dali 2 Click? My Google is broken. Perhaps you could attach a copy of it.
It's a board that provides galvanic isolation between a micro controller and the DALI lighting system control BUS, which runs at up 16v.
This is a forum where you receive help on code that you've written.
So, perhaps you'd be kind enough to post the code you've already written (use Code Tags) and links to the libraries you've tried (use the 'link' icon so your links are click-able). And, how about a link explaining what ever the heck a "DALI lighting system" is.
What did the code you've already written do? How is that different that what you want it to do?
Have you tried their libraries?
https://libstock.mikroe.com/projects/download/2333/7785/1517849223_dali_2_click_mikroc_avr.mpkg
gfvalvo:
This is a forum where you receive help on code that you've written.So, perhaps you'd be kind enough to post the code you've already written (use Code Tags) and links to the libraries you've tried (use the 'link' icon so your links are click-able). And, how about a link explaining what ever the heck a "DALI lighting system" is.
What did the code you've already written do? How is that different that what you want it to do?
Well, there's a lot of C++ code. But I will post it. I'm not sure anyone can solve this without having had a Dali 2 Click. Where should I post?
DKWatson:
Have you tried their libraries?
https://libstock.mikroe.com/projects/download/2333/7785/1517849223_dali_2_click_mikroc_avr.mpkg
I've just arranged for them to send me that library as that mkpg would not unpack on my Mac.
But that library is written for an AVR - so would it run on a MegaAVR? Mikro Elektronika do not support Arduino.
The Arduino uses an AVR chip so the library should be fine as long as it's not dependent on their compiler. I'm not Mac so I can't unpack the library. Sounds like you should avoid their proprietary stuff and write your own.
DKWatson:
The Arduino uses an AVR chip so the library should be fine as long as it's not dependent on their compiler. I'm not Mac so I can't unpack the library. Sounds like you should avoid their proprietary stuff and write your own.
Thank-you for your input
Arduino uses an AVR chip so the library should be fine
That sounds hopeful.
write your own
re. writing my own. Thank-you for your suggestion. The trouble is that we are talking about bit-by-bit communications which are time-critical. And I think it's beyond my capabilities to write a whole library.
There are two libraries already written. The first one I could not get to work after two attempts and no response from the DALI controller, and the second one has no example Arduino code that show hows to send a DALI command. I'm not even sure the library is finished or not.
This is aside from the questions about wiring the DALI board to the Arduino, which is also slightly confusing - in one case specifying the pin out and the pin in are to be shorted out.
I may be able to extract the things I am stuck with and tackle them one-by-one.
Sorry
simon_lucas:
The trouble is that we are talking about bit-by-bit communications which are time-critical. And I think it's beyond my capabilities to write a whole library.
we will not accept that attitude here. If it was done by others it can be done by you. All you need is the patience to learn.
DKWatson:
Sorry we will not accept that attitude here. If it was done by others it can be done by you. All you need is the patience to learn.
Ok, thank-you. So, perhaps you could help with this specific question, please:
The DALI library I am using (see link below), uses pins 18 (for tx) and 19 (for rx). It also closes pins 2 and 3 for a reason I do not understand. Like this:
dali1.begin(18,-3);
dali2.begin(-2,19);
My Dali 2 Click mounted on an Arduino Click Shield (mikroBus) requires that i use pins A2 for TX and digital 4 for RX. I don't know why but that is the way the shield seems to connect everything, based on this:
And this document which has the DALI 2 Click to mikroBus pinouts table:
How can I adapt the library to use the pins I need, please?
The original author is using the PIN numbers of the chip, not the Arduino's PIN numbers. So not sure how the set-up in the 'rx' interrupt section needs to be fixed.
The Dali class 'begin' function I have added below after the library itself:
DALI 'PQ' library:
http://blog.perquin.com/wp-content/uploads/pq_Dali.zip
//###########################################################################
// Dali Class
//###########################################################################
void Dali::begin(int8_t tx_pin, int8_t rx_pin) {
this->tx_pin=tx_pin;
this->rx_pin=rx_pin;
this->tx_state = IDLE;
this->rx_state = RX_IDLE;
//setup tx
if(this->tx_pin>=0) {
//setup tx pin
pinMode(this->tx_pin, OUTPUT);
DALI_BUS_HIGH();
//setup tx timer interrupt
TCCR1A = 0;
TCCR1B = 0;
TCNT1 = 0;
OCR1A = (F_CPU+(DALI_BAUD))/(2*(DALI_BAUD)); // compare match register 16MHz/256/2Hz
TCCR1B |= (1 << WGM12); // CTC mode
TCCR1B |= (1 << CS10); // 1:1 prescaler
TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt
//setup timer interrupt hooks
for(uint8_t i=0;i<DALI_HOOK_COUNT;i++) {
if(IsrTimerHooks[i] == NULL) {
IsrTimerHooks[i] = this;
break;
}
}
}
//setup rx
if(this->rx_pin>=0) {
//setup rx pin
pinMode(this->rx_pin, INPUT);
//setup rx pinchange interrupt
// 0- 7 PCINT2_vect PCINT16-23
// 8-13 PCINT0_vect PCINT0-5
//14-19 PCINT1_vect PCINT8-13
if(this->rx_pin<=7){
PCICR |= (1<<PCIE2);
PCMSK2 |= (1<< (this->rx_pin));
IsrPCINT2Hook = this; //setup pinchange interrupt hook
}else if(this->rx_pin<=13) {
PCICR |= (1<<PCIE0);
PCMSK0 |= (1<< (this->rx_pin-8));
IsrPCINT0Hook = this; //setup pinchange interrupt hook
}else if(this->rx_pin<=19) {
PCICR |= (1<<PCIE1);
PCMSK1 |= (1<< (this->rx_pin-14));
IsrPCINT1Hook = this; //setup pinchange interrupt hook
}
}
}
DKWatson:
Sorrywe will not accept that attitude here. If it was done by others it can be done by you. All you need is the patience to learn.
I am of course aware that with enough time, patience and endurance I or anyone could write a library for this board, but practically I do not have time.
One of the problems with this project is that working with a DALI controller is like working with a black box. So, when you send example commands you have no way of knowing why they do not work. Whether they are command errors, BUS communication errors or electronic communication errors.
With 4 years since anyone here or elsewhere has looked at this kind of work - on the Arduino-Dali interface, and none of them communicating about their work and libraries any more, I feel that, this is a dead-end for the moment.
Thanks for your time.
The DALI device doesn't really do anything extraordinary. Is there an alternative you can use or are you stuck with it?