zunoSendReport() reset pin mode

Discussion about Z-Uno product. Visit http://z-uno.z-wave.me for more details.
Post Reply
Konsta24
Posts: 2
Joined: 20 Aug 2016 18:03

zunoSendReport() reset pin mode

Post by Konsta24 »

Hello!

I have following problem.

One of Z-uno pins is set to OUTPUT mode with HIGH position.

pinMode(13, OUTPUT);
digitalWrite(13, HIGH);

When I try to send report to controller with zunoSendReport(1), pin 13 is drop to LOW.


Could you give any advice how to solve this issue?
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

Re: zunoSendReport() reset pin mode

Post by PoltoS »

There might be two reasons:
1) bug in the code ;) please tell us the version you use. Please check same on 2.0.5 (test branch) or 2.0.6 (to be release this week)
2) you might have something in getter that makes it go LOW.
Chiquitoloco
Posts: 17
Joined: 11 Sep 2016 11:26

Re: zunoSendReport() reset pin mode

Post by Chiquitoloco »

I have noticed the same behaviour.

It's look like HIGH and LOW are reverse.

There is my debug sketch

Code: Select all

void setup() {
  // put your setup code here, to run once:
  pinMode(22, OUTPUT);      //LED / Relay 01
  pinMode(21, OUTPUT);      //Relay02
  pinMode(20, OUTPUT);      //Relay03
  pinMode(19, OUTPUT);      //Relay04
  pinMode(13, OUTPUT);      //USER LED

  pinMode(18, INPUT);       //SERVICE BUTTON
  pinMode(17, INPUT);       //BP01  
  pinMode(12, INPUT);       //BP02
  pinMode(11, INPUT);       //BP03
  pinMode(10, INPUT);       //BP04

  Serial.begin(9600);
  Serial.println("Serial OK");


}

void loop() {
  // put your main code here, to run repeatedly:


 //RELAY 01 + BP 01
 //digitalWrite(22, (digitalRead(17) == HIGH) ? HIGH : LOW);
 //RELAY 02 + BP 02
 //digitalWrite(21, (digitalRead(12) == HIGH) ? HIGH : LOW);
 //RELAY 03 + BP 03
 //digitalWrite(20, (digitalRead(11) == HIGH) ? HIGH : LOW);
 //RELAY 04 + BP 04
 //digitalWrite(19, (digitalRead(10) == HIGH) ? HIGH : LOW);
 //USER LED + SERVICE BUTTON
 digitalWrite(13, (digitalRead(18) == HIGH) ? HIGH : LOW);

 if (digitalRead(17) == HIGH){
  digitalWrite(22, HIGH);
 }
 else
 {
  digitalWrite(22, LOW);
 }

 Serial.print("PIN 22 RELAY ");
 Serial.println(digitalRead(22));
 Serial.print("PIN 17 Button ");
 Serial.println(digitalRead(17));

 Serial.print("PIN 21 RELAY ");
 Serial.println(digitalRead(21));
 Serial.print("PIN 12 Button ");
 Serial.println(digitalRead(12));

 Serial.print("PIN 20 RELAY ");
 Serial.println(digitalRead(20));
 Serial.print("PIN 11 Button ");
 Serial.println(digitalRead(11));

 Serial.print("PIN 19 RELAY ");
 Serial.println(digitalRead(19));
 Serial.print("PIN 10 Button ");
 Serial.println(digitalRead(10));

 Serial.print("PIN 13 USER LED ");
 Serial.println(digitalRead(13));
 Serial.print("PIN 18 Service Button ");
 Serial.println(digitalRead(18));
}
On my breadboard i've no button, only some LED that i've call "RELAY" in the sketch.

Here the debug in the serial consol

Code: Select all

PIN 22 RELAY 1
PIN 17 Button 1
PIN 21 RELAY 0
PIN 12 Button 1
PIN 20 RELAY 0
PIN 11 Button 1
PIN 19 RELAY 0
PIN 10 Button 1
PIN 13 USER LED 1
PIN 18 Service Button 1
As you can see all my button are 1 (HIGH) but i've any buttons plug in.
For the SERVICE BUTTON is release but you can read 1 and the LED is ON on the board but display 0...

Now if i pressed the SERVICE BUTTON there is the debug

Code: Select all

PIN 22 RELAY 1
PIN 17 Button 1
PIN 21 RELAY 0
PIN 12 Button 1
PIN 20 RELAY 0
PIN 11 Button 1
PIN 19 RELAY 0
PIN 10 Button 1
PIN 13 USER LED 0
PIN 18 Service Button 0
It's display 0 / LOW.

I don't think i did a mistake in the sketch, it's a simple one.

My branch version is 2.0.5
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

Re: zunoSendReport() reset pin mode

Post by PoltoS »

First of all, never use == HIGH. Like in most MCU, we return actual pin mask, so 0 is LOW, but HIGH might be any power of 2 (depending on pin number). This is tricky. We will make sure to also fix it to always have digitalRead return you 0 or 1 and not power of 2.

I think this will fix the problem.
Chiquitoloco
Posts: 17
Joined: 11 Sep 2016 11:26

Re: zunoSendReport() reset pin mode

Post by Chiquitoloco »

EDIT : try with push button and LED connected on the Pin Board and it's OK.

0 when it's release
1 when it's pressed

Ok thank you for the advice, i've change my sktech with 1 or 0.

But i still don't know why the result return 1 when the button is release and 0 when is pressed.
It's look like the PIN board are normaly close.

When i try with my arduino, i've "1/HIGH" when i press the button, that means the circuit is close and "0/LOW" when i release the button, the circuit is open.


Code

Code: Select all

 if (digitalRead(18) == 1){
  digitalWrite(13, HIGH);
 }
 else
 {
  digitalWrite(13, LOW);
 }
 Serial.print("PIN 13 USER LED ");
 Serial.println(digitalRead(13));
 Serial.print("PIN 18 Service Button ");
 Serial.println(digitalRead(18));
Debug

Code: Select all

PIN 13 USER LED 1
PIN 18 Service Button 1
User avatar
PoltoS
Posts: 7565
Joined: 26 Jan 2011 19:36

Re: zunoSendReport() reset pin mode

Post by PoltoS »

The user button is indeed pulled up to return 0 on pressed and 1 on released.
Post Reply