Hi,
When I was trying to ‘capture’ my doorbell button press using an input, I got some strange signals. Sometimes my code said that the bell was pressed while nothing was going on, so I started to look at the readings. Instead of using the digital input, I now used the analog input.
The strange thing I noticed, is when using the methods to directly read an input like ‘automationhat.input.three.is_on()’ or ‘automationhat.analog.three.read()’ I get a different reading then when using ‘input.read()’ or ‘analog.read()’. See my simple test program below and some output snippets:
#!/usr/bin/env python
import time
import automationhat
x = 0
if automationhat.is_automation_hat():
automationhat.light.power.write(1)
while True:
print(x)
print(automationhat.input.read())
print(automationhat.analog.read())
print(automationhat.analog.three.read())
time.sleep(0.5)
x = x + 1
…
27
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.56, ‘three’: 0.0, ‘two’: 0.03, ‘one’: 0.03}
0.05
28
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.57, ‘three’: 0.03, ‘two’: 0.03, ‘one’: 0.03}
-0.06
29
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.55, ‘three’: 0.06, ‘two’: 0.03, ‘one’: 0.03}
4.42
30
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.55, ‘three’: 0.03, ‘two’: 0.03, ‘one’: 0.03}
0.03
31
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.55, ‘three’: 0.03, ‘two’: 0.03, ‘one’: 0.03}
0.03
32
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.57, ‘three’: 0.0, ‘two’: 0.03, ‘one’: 0.03}
-0.03
33
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.57, ‘three’: 0.0, ‘two’: 0.03, ‘one’: 0.03}
0.03
34
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.54, ‘three’: 0.0, ‘two’: 0.03, ‘one’: 0.03}
4.44
35
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.55, ‘three’: 0.0, ‘two’: 0.03, ‘one’: 0.03}
0.05
36
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.57, ‘three’: -0.02, ‘two’: 0.03, ‘one’: 0.03}
0.08
37
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.54, ‘three’: 0.0, ‘two’: 0.03, ‘one’: 0.03}
0.03
38
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.55, ‘three’: 0.05, ‘two’: 0.03, ‘one’: 0.03}
0.06
39
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.57, ‘three’: 0.0, ‘two’: 0.03, ‘one’: 0.03}
0.05
…
170
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.57, ‘three’: -0.05, ‘two’: 0.03, ‘one’: 0.03}
0.08
171
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.55, ‘three’: 0.0, ‘two’: 0.03, ‘one’: 0.03}
-0.02
172
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.56, ‘three’: 0.11, ‘two’: 0.03, ‘one’: 0.03}
-0.05
173
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.55, ‘three’: 0.03, ‘two’: 0.03, ‘one’: 0.03}
4.47
174
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.56, ‘three’: 0.06, ‘two’: 0.03, ‘one’: 0.03}
0.0
175
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.57, ‘three’: 0.05, ‘two’: 0.03, ‘one’: 0.03}
0.0
176
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.55, ‘three’: 0.03, ‘two’: 0.03, ‘one’: 0.03}
0.06
177
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.56, ‘three’: 0.03, ‘two’: 0.03, ‘one’: 0.03}
0.03
178
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.58, ‘three’: -0.02, ‘two’: 0.03, ‘one’: 0.03}
0.06
179
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.55, ‘three’: 0.05, ‘two’: 0.03, ‘one’: 0.03}
0.0
180
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.56, ‘three’: 0.05, ‘two’: 0.03, ‘one’: 0.03}
0.02
…
205
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.55, ‘three’: 0.03, ‘two’: 0.03, ‘one’: 0.03}
0.06
206
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.56, ‘three’: -0.02, ‘two’: 0.03, ‘one’: 0.03}
0.06
207
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.55, ‘three’: 0.0, ‘two’: 0.03, ‘one’: 0.03}
4.42
208
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.55, ‘three’: 0.09, ‘two’: 0.03, ‘one’: 0.03}
-0.05
209
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.57, ‘three’: 0.0, ‘two’: 0.03, ‘one’: 0.03}
-0.05
210
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.54, ‘three’: 0.05, ‘two’: 0.03, ‘one’: 0.03}
0.0
…
223
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.56, ‘three’: -0.03, ‘two’: 0.03, ‘one’: 0.03}
0.08
224
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.55, ‘three’: 0.09, ‘two’: 0.03, ‘one’: 0.03}
0.03
225
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.55, ‘three’: 0.0, ‘two’: 0.03, ‘one’: 0.03}
4.45
226
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.56, ‘three’: 0.05, ‘two’: 0.03, ‘one’: 0.03}
-0.05
227
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.55, ‘three’: 0.05, ‘two’: 0.03, ‘one’: 0.03}
0.0
228
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.55, ‘three’: 0.0, ‘two’: 0.03, ‘one’: 0.05}
-0.03
229
{‘three’: 0, ‘two’: 0, ‘one’: 0}
{‘four’: 0.55, ‘three’: -0.03, ‘two’: 0.03, ‘one’: 0.03}
0.09
…
What you see happening is that when reading all analog inputs at once, they array shows a value that I would expect as nothing was connected just two wires (one on Hat 5V and one on ADC input 3) which where NOT connected. But when reading analog three directly, I sometimes get a high value (4.xx). Similar behavior was found when reading the digital input. Sometimes it unexpectedly reported 1 (high) or true when using ‘is_on()’.
Does anyone have a clue why/how this happens? For now I stick with reading all inputs at once and use the result array, but as the library provides nicer functions for this I would expect it to work the same.