Define ZUNO Channel

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Black Cat
Posts: 62
Joined: 02 Mar 2016 00:52

Define ZUNO Channel

Post by Black Cat »

The simple sensor example http://z-uno.z-wave.me/examples/SimpleSensor/ uses:

/ channel number
#define ZUNO_CHANNEL_NUMBER_ONE 1

which I assume is a definition?

I don't see any reference to this in the Reference Section, there is a ZUNO_SET_CHANNELS which is used later but not the above.

Further in the example (which works as is), if 1 is deleted, the compiler returns an error.
Further in the sketch I find:

zunoSendReport(ZUNO_CHANNEL_NUMBER_ONE); // send report over the Z-Wave to the controller

if 1 is used in the definition, then why isn't it used in the above fragment. eg.

zunoSendReport(1) or zunoSendReport(ZUNO_CHANNEL_NUMBER_ONE 1)
A.Harrenberg
Posts: 201
Joined: 05 Sep 2016 22:27

Re: Define ZUNO Channel

Post by A.Harrenberg »

Hi,

I am not sure if I understood your problem...

Code: Select all

#define ZUNO_CHANNEL_NUMBER_ONE 1
This just defines the "pseudo constant" ZUNO_CHANNEL_NUMBER_ONE which is to be replaced with the assigned value (1 in this case) by the pre-processor prior to compiling.

In the example this is just to use a more readable channel-number for the zunoSendReport().

You can remove the define statement and directly use

Code: Select all

zunoSendReport(1)
instead, but the syntax of

Code: Select all

zunoSendReport(ZUNO_CHANNEL_NUMBER_ONE 1)
is wrong and would not work.

So, what exactly is the problem with the "#define"?

Regards,
Andreas.
fhem.de - ZWave development support
Black Cat
Posts: 62
Joined: 02 Mar 2016 00:52

Re: Define ZUNO Channel

Post by Black Cat »

Thanks for the reply,

The problem is that there is no documentation about Channels, why are they required and how they are setup.

I have deduced that there are 10 channels and assume that they are numbered from 1 to 10 and that they are required to send a report back to the controller however as there is no documentation it took me a day of tinkering to work this out.

In this case the example came from the simple sensor, you may ask why? Because I nedd a physical switch and feedback as to it's status in the UI.
I used that example to expand it to 2 toggle switches eventually 4.
So far the code used works 2 switches form the UI but only physical switch1 commands LED1, physical switch2 does nothing.

Code below for 2 switch.

Hopefully you might have some suggestions?

Code: Select all



// LED pin number

#define LED_PIN1 9    //  9 pin - user LED of Z-Uno board
#define LED_PIN2 10   // 10 pin - user LED of Z-Uno board


byte currentLEDValue1;  // Last saved LED1 value
byte currentLEDValue2;  // Last saved LED2 value



byte lastButtonState1;  // variable to store current button1 state
byte lastButtonState2;  // variable to store current button2 state

// button pin number

#define BTN_PIN1     18 // 18 pin - button(BTN1) of Z-Uno board
#define BTN_PIN2     19 // 19 pin - button(BTN2) of Z-Uno board

// channel number
#define ZUNO_CHANNEL_NUMBER_ONE 1
#define ZUNO_CHANNEL_NUMBER_TWO 2


ZUNO_SETUP_CHANNELS(
  ZUNO_SWITCH_BINARY(getterSwitch1, setterSwitch1),
  ZUNO_SWITCH_BINARY(getterSwitch2, setterSwitch2)
  );


// the setup routine runs once when you press reset:
void setup() {
  pinMode(LED_PIN1, OUTPUT); // setup pin as output
  pinMode(BTN_PIN1, INPUT_PULLUP); // set button pin as input
  pinMode(LED_PIN2, OUTPUT); // setup pin as output
  pinMode(BTN_PIN2, INPUT_PULLUP); // set button pin as input
}
// the loop routine runs over and over again forever:
void loop() {
  byte currentButtonState1 = digitalRead(BTN_PIN1);


  if (currentButtonState1 != lastButtonState1) { // if state changes
    lastButtonState1 = currentButtonState1; // save new state
    zunoSendReport(ZUNO_CHANNEL_NUMBER_ONE); // send report over the Z-Wave to the controller
    if (currentButtonState1 == LOW) { // if button is pressed
      digitalWrite(LED_PIN1, HIGH);  // turn the LED on
    } else {                        // if button is released
      digitalWrite(LED_PIN1, LOW);   // turn the LED off
    }
  }
}

byte getterSwitch1() {
  if (lastButtonState1 == 0) { // if button is pressed
    return 0xff;              // return "Triggered" state to the controller
  } else {                    // if button is released
    return 0;                 // return "Idle" state to the controller
  }
}
        

void setterSwitch1(byte value1) {
  // value is a variable, holding a "new value"
  // which came from the controller or other Z-Wave device
  if (value1 > 0) {               // if greater then zero
    digitalWrite (LED_PIN1, HIGH); //turn the LED on (HIGH is the voltage level)
  } else {                         // if equals zero
    digitalWrite(LED_PIN1, LOW);   //turn the LED off by making the voltage LOW
  }
  // we'll save our value for the situation, when the controller will ask us about it
  currentLEDValue1 = value1;


  
byte currentButtonState2 = digitalRead(BTN_PIN2);


  if (currentButtonState2 != lastButtonState2) { // if state changes
    lastButtonState2 = currentButtonState2; // save new state
    zunoSendReport(ZUNO_CHANNEL_NUMBER_TWO); // send report over the Z-Wave to the controller
    if (currentButtonState2 == LOW) { // if button is pressed
      digitalWrite(LED_PIN2, HIGH);  // turn the LED on
    } else {                        // if button is released
      digitalWrite(LED_PIN2, LOW);   // turn the LED off
    }
  }
}

byte getterSwitch2() {
  if (lastButtonState2 == 0) { // if button is pressed
    return 0xff;              // return "Triggered" state to the controller
  } else {                    // if button is released
    return 0;                 // return "Idle" state to the controller
  }
}
        

void setterSwitch2(byte value2) {
  // value is a variable, holding a "new value"
  // which came from the controller or other Z-Wave device
  if (value2 > 0) {               // if greater then zero
    digitalWrite (LED_PIN2, HIGH); //turn the LED on (HIGH is the voltage level)
  } else {                         // if equals zero
    digitalWrite(LED_PIN2, LOW);   //turn the LED off by making the voltage LOW
  }
  // we'll save our value for the situation, when the controller will ask us about it
  currentLEDValue2 = value2;
}


A.Harrenberg
Posts: 201
Joined: 05 Sep 2016 22:27

Re: Define ZUNO Channel

Post by A.Harrenberg »

Hi,

just a short feedback...
You mixed up the code a little bit ,-)

In the main loop() you have to put the two blocks that check the button 1 and 2. In the current code the block that is checking for button 2 is inside the setterswitch1() function... (which means the button is only checked when the channel 1 is set from the controlling software...)

When you move this block to the loop() then it should work. ;)

But you stated in the other thread that you are trying to build a 16 channel device, that is not possible, Z-Uno is limited to 10 channels (see documentation here and you would need more input pins for the buttons (that could be done easily with multiplexer or a I2C / SPI chip), but the limit of 10 channels is inside the firmware of the Z-Uno.

You might overcome this by sending a 16bit value where each bit represents the status of a channel, but you need then a decoding function in the controlling automation system to seperate the status of the 16 channels.

Hope that helps,
Andreas.
fhem.de - ZWave development support
Black Cat
Posts: 62
Joined: 02 Mar 2016 00:52

Re: Define ZUNO Channel

Post by Black Cat »

Thanks for the reply, however, I'm confused as to what has to be moved and how it it separated in the loop()?

I have tried {} but I only get compile errors.

I'm just not seeing how to do this.

If I understand this is the part I have incorrect is in between 1 & 2, see the // part in CAPS below in the code.

Code: Select all

// the loop routine runs over and over again forever:
void loop() {
  byte currentButtonState1 = digitalRead(BTN_PIN1);


  if (currentButtonState1 != lastButtonState1) { // if state changes
    lastButtonState1 = currentButtonState1; // save new state
    zunoSendReport(ZUNO_CHANNEL_NUMBER_ONE); // send report over the Z-Wave to the controller
    if (currentButtonState1 == LOW) { // if button is pressed
      digitalWrite(LED_PIN1, HIGH);  // turn the LED on
    } else {                        // if button is released
      digitalWrite(LED_PIN1, LOW);   // turn the LED off
    }
  }
}

byte getterSwitch1() {
  if (lastButtonState1 == 0) { // if button is pressed
    return 0xff;              // return "Triggered" state to the controller
  } else {                    // if button is released
    return 0;                 // return "Idle" state to the controller
  }
}
        

void setterSwitch1(byte value1) {
  // value is a variable, holding a "new value"
  // which came from the controller or other Z-Wave device
  if (value1 > 0) {               // if greater then zero
    digitalWrite (LED_PIN1, HIGH); //turn the LED on (HIGH is the voltage level)
  } else {                         // if equals zero
    digitalWrite(LED_PIN1, LOW);   //turn the LED off by making the voltage LOW
  }
  // we'll save our value for the situation, when the controller will ask us about it
  currentLEDValue1 = value1;

// IF I UNDERSTAND YOUR REPLY A COMMAND MUST GO HERE TO SEPARATE THE FUNCTION IN THE LOOP.  IS that what you mean?
  
byte currentButtonState2 = digitalRead(BTN_PIN2);


  if (currentButtonState2 != lastButtonState2) { // if state changes
    lastButtonState2 = currentButtonState2; // save new state
    zunoSendReport(ZUNO_CHANNEL_NUMBER_TWO); // send report over the Z-Wave to the controller
    if (currentButtonState2 == LOW) { // if button is pressed
      digitalWrite(LED_PIN2, HIGH);  // turn the LED on
    } else {                        // if button is released
      digitalWrite(LED_PIN2, LOW);   // turn the LED off
    }
  }
}

byte getterSwitch2() {
  if (lastButtonState2 == 0) { // if button is pressed
    return 0xff;              // return "Triggered" state to the controller
  } else {                    // if button is released
    return 0;                 // return "Idle" state to the controller
  }
}

       
Lets not discuss the 16 channel Irrigation controller until I get a meaningful understanding of this code.

I need a little bit of hand holding to fully understand this.

Thanks for your help on this.
Black Cat
Posts: 62
Joined: 02 Mar 2016 00:52

Re: Define ZUNO Channel

Post by Black Cat »

I attempted to clean up the code and add the extra 2 channels.
I find that UISwitch1 controls UISwitch4, also Button Switch 1 controls Button Switch 4.
I still don't see where the interference is as 2 and 3 work as is expected.

I think the coding is easier to read in this format, but I do not know if it is acceptable format?

Code: Select all

// LED pin number

#define LED_PIN1 9    //  9 pin - user LED of Z-Uno board
#define LED_PIN2 10   // 10 pin - user LED of Z-Uno board
#define LED_PIN3 11
#define LED_PIN4 12

byte currentLEDValue1;  // Last saved LED1 value
byte currentLEDValue2;  // Last saved LED2 value
byte currentLEDValue3;
byte currentLEDValue4;


byte lastButtonState1;  // variable to store current button1 state
byte lastButtonState2;  // variable to store current button2 state
byte lastButtonState3;
byte lastButtonState4;

// button pin number

#define BTN_PIN1     18 // 18 pin - button(BTN1) of Z-Uno board
#define BTN_PIN2     19 // 19 pin - button(BTN2) of Z-Uno board
#define BTN_PIN3     20
#define BTN_PIN4     21


// channel number
#define ZUNO_CHANNEL_NUMBER_ONE 1
#define ZUNO_CHANNEL_NUMBER_TWO 2
#define ZUNO_CHANNEL_NUMBER_THREE 3
#define ZUNO_CHANNEL_NUMBER_FOUR 4

ZUNO_SETUP_CHANNELS(
  ZUNO_SWITCH_BINARY(getterSwitch1, setterSwitch1),
  ZUNO_SWITCH_BINARY(getterSwitch2, setterSwitch2),
  ZUNO_SWITCH_BINARY(getterSwitch3, setterSwitch3),
  ZUNO_SWITCH_BINARY(getterSwitch4, setterSwitch4)
  );
// the setup routine runs once when you press reset:
void setup() {
  pinMode(LED_PIN1, OUTPUT); // setup pin as output
  pinMode(BTN_PIN1, INPUT_PULLUP); // set button pin as input
  pinMode(LED_PIN2, OUTPUT); // setup pin as output
  pinMode(BTN_PIN2, INPUT_PULLUP); // set button pin as input
  pinMode(LED_PIN3, OUTPUT); // setup pin as output
  pinMode(BTN_PIN3, INPUT_PULLUP); // set button pin as input
  pinMode(LED_PIN4, OUTPUT); // setup pin as output
  pinMode(BTN_PIN4, INPUT_PULLUP); // set button pin as input
}


// the loop routine runs over and over again forever:
void loop() {
  byte currentButtonState1 = digitalRead(BTN_PIN1);
  byte currentButtonState2 = digitalRead(BTN_PIN2);
  byte currentButtonState3 = digitalRead(BTN_PIN3);
  byte currentButtonState4 = digitalRead(BTN_PIN4);

  
  if (currentButtonState1 != lastButtonState1) { // if state changes
    lastButtonState1 = currentButtonState1; // save new state
    zunoSendReport(ZUNO_CHANNEL_NUMBER_ONE); // send report over the Z-Wave to the controller
    if (currentButtonState1 == LOW) { // if button is pressed
      digitalWrite(LED_PIN1, HIGH);  // turn the LED on
    } else {                        // if button is released
      digitalWrite(LED_PIN1, LOW);   // turn the LED off
    }
  }

  if (currentButtonState2 != lastButtonState2) { // if state changes
    lastButtonState2 = currentButtonState2; // save new state
    zunoSendReport(ZUNO_CHANNEL_NUMBER_TWO); // send report over the Z-Wave to the controller
    if (currentButtonState2 == LOW) { // if button is pressed
      digitalWrite(LED_PIN2, HIGH);  // turn the LED on
    } else {                        // if button is released
      digitalWrite(LED_PIN2, LOW);   // turn the LED off
    }
  }

 
  if (currentButtonState3 != lastButtonState3) { // if state changes
    lastButtonState3 = currentButtonState3; // save new state
    zunoSendReport(ZUNO_CHANNEL_NUMBER_THREE); // send report over the Z-Wave to the controller
    if (currentButtonState3 == LOW) { // if button is pressed
      digitalWrite(LED_PIN3, HIGH);  // turn the LED on
    } else {                        // if button is released
      digitalWrite(LED_PIN3, LOW);   // turn the LED off
    }
  }


  if (currentButtonState4 != lastButtonState4) // if state changes
    {lastButtonState4 = currentButtonState4; // save new state
      zunoSendReport(ZUNO_CHANNEL_NUMBER_FOUR); // send report over the Z-Wave to the controller
     if (currentButtonState4 == LOW) { // if button is pressed
       digitalWrite(LED_PIN4, HIGH);  // turn the LED on
      } else {                        // if button is released
        digitalWrite(LED_PIN4, LOW);   // turn the LED off
      }
    }
  }
//switch 2 below

byte getterSwitch1() {
  if (lastButtonState1 == 0) { // if button is pressed
    return 0xff;              // return "Triggered" state to the controller
  } else {                    // if button is released
    return 0;                 // return "Idle" state to the controller
  }
}    

byte getterSwitch2() {
  if (lastButtonState2 == 0) { // if button is pressed
    return 0xff;              // return "Triggered" state to the controller
  } else {                    // if button is released
    return 0;                 // return "Idle" state to the controller
  }
}

byte getterSwitch3() {
  if (lastButtonState3 == 0) { // if button is pressed
    return 0xff;              // return "Triggered" state to the controller
  } else {                    // if button is released
    return 0;                 // return "Idle" state to the controller
  }
}

byte getterSwitch4() {
  if (lastButtonState4 == 0) { // if button is pressed
    return 0xff;              // return "Triggered" state to the controller
  } else {                    // if button is released
    return 0;                 // return "Idle" state to the controller
  }
}

void setterSwitch1(byte value1) {
  // value is a variable, holding a "new value1"
  // which came from the controller or other Z-Wave device
  if (value1 > 0) {               // if greater then zero
    digitalWrite (LED_PIN1, HIGH); //turn the LED on (HIGH is the voltage level)
  } else {                         // if equals zero
    digitalWrite(LED_PIN1, LOW);   //turn the LED off by making the voltage LOW
  }
  // we'll save our value for the situation, when the controller will ask us about it
  currentLEDValue1 = value1;
}    

void setterSwitch2(byte value2) {
  // value is a variable, holding a "new value2"
  // which came from the controller or other Z-Wave device
  if (value2 > 0) {               // if greater then zero
    digitalWrite (LED_PIN2, HIGH); //turn the LED on (HIGH is the voltage level)
  } else {                         // if equals zero
    digitalWrite(LED_PIN2, LOW);   //turn the LED off by making the voltage LOW
  }
  // we'll save our value for the situation, when the controller will ask us about it
  currentLEDValue2 = value2;
}

void setterSwitch3(byte value3) {
  // value is a variable, holding a "new value3"
  // which came from the controller or other Z-Wave device
  if (value3 > 0) {               // if greater then zero
    digitalWrite (LED_PIN3, HIGH); //turn the LED on (HIGH is the voltage level)
  } else {                         // if equals zero
    digitalWrite(LED_PIN3, LOW);   //turn the LED off by making the voltage LOW
  }
  // we'll save our value for the situation, when the controller will ask us about it
  currentLEDValue3 = value3;
  }

void setterSwitch4(byte value4) {
  // value is a variable, holding a "new value4"
  // which came from the controller or other Z-Wave device
  if (value4 > 0) {               // if greater then zero
    digitalWrite (LED_PIN4, HIGH); //turn the LED on (HIGH is the voltage level)
  } else {                         // if equals zero
    digitalWrite(LED_PIN4, LOW);   //turn the LED off by making the voltage LOW
  }
  // we'll save our value for the situation, when the controller will ask us about it
  currentLEDValue4 = value4;
   
}

A.Harrenberg
Posts: 201
Joined: 05 Sep 2016 22:27

Re: Define ZUNO Channel

Post by A.Harrenberg »

Hi,

I think the code looks ok now, are you shure that you hade made the association with the channels correctly inside ZWay?

BR,
Andreas
fhem.de - ZWave development support
Black Cat
Posts: 62
Joined: 02 Mar 2016 00:52

Re: Define ZUNO Channel

Post by Black Cat »

Thanks, but why would I make or need an association?

This is not controlling another device. It is the device, I just need to have the UI indicate correctly. MAybe I have missed something or not understanding a principle?

I'm using Home Seer, will test it on Vera over the weekend to see if there is any change. If anyone has another controller, perhaps they could test the code and report back their finding?
Black Cat
Posts: 62
Joined: 02 Mar 2016 00:52

Re: Define ZUNO Channel

Post by Black Cat »

Clipboard01.jpg
Clipboard01.jpg (36.37 KiB) Viewed 15734 times
This is the UI when Binary 1 is switched ON. BInary4 indicates ON, but is not actually ON, it only indicates ON.

Perhaps there is some logic that can be added to turn the UI off? Not sure just thinking out aloud?
Black Cat
Posts: 62
Joined: 02 Mar 2016 00:52

Re: Define ZUNO Channel

Post by Black Cat »

Now this really starts to get weird.

I had initially thought that it might be due to the PINOUTS and had today intended play around with them, but after I plugged the ZUNO into my PC prior to uploading a new sketch I thought I should check the current sketch.

What I found was that the UI indication when selecting Switch 1 also turned Binary Switch 3 ON.
Clipboard02.jpg
Clipboard02.jpg (37.12 KiB) Viewed 15684 times
I think that PIN 17 has something to do with this and intend to try different PINOUTS today to test this theory.
Post Reply