Problem: values set in rules don't match real values

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
groovy
Normal user
Posts: 39
Joined: 14 Oct 2016, 11:32
Location: Chemnitz, Germany

Problem: values set in rules don't match real values

#1 Post by groovy » 11 May 2017, 15:01

First of all: sorry for the long post, but I would like to describe the problem as accurate as I can.

I'm trying to get a 4x4 matrix keypad, connected to a PCF8574A module, to work.
Because this keypad is passive and the PCF8574A needs logic levels, I need to do some magic to read the pressed key. So I searched the good old Internet and came up with this, where the steps are described as follows:
Finding out which button was pressed is done in two phases: the first phase finds the row, and the second phase finds the column. First phase: scan the row lines and see which line is now low. Second phase: set column lines high and row lines low and see which column line is low (one column line is pulled low by the short circuit in the keypad even though you just set the column lines high).
So I created some rules to get the actual pressed key.
At boot, all GPIOs on the PCF8574A are in HIGH state. Therefore, my first rule ist this:

Code: Select all

On System#Boot do
 pcfgpio,97,0
 pcfgpio,98,0
 pcfgpio,99,0
 pcfgpio,100,0
 pcfgpio,101,1
 pcfgpio,102,1
 pcfgpio,103,1
 pcfgpio,104,1
EndOn
This sets the columns to LOW and the rows to HIGH and works.

Lets assume, the key I press is at column 1 (which is pfcgpio 101 and device K5) and on row 2 (which is pcfgpio 98 and device K2). The rules for this actually read the correct column, but fail at the row. First I set the GPIOs for the columns to HIGH and for the rows to LOW and create an event. As long as the key is pressed, the correct state LOW can be measured at the PCF8574A pin, because the LOW row state pulls the column state also to LOW, even if I did set it to HIGH with the pcfgpio command.

Code: Select all

On K5#Switch do
 pcfgpio,97,1
 pcfgpio,98,1
 pcfgpio,99,1
 pcfgpio,100,1
 pcfgpio,101,0
 pcfgpio,102,0
 pcfgpio,103,0
 pcfgpio,104,0
 Event K5pressed
EndOn
Then I actually try to get the key, write to the connected LCD and restore the GPIOs:

Code: Select all

On K5pressed do
  if  [K4#Switch]=0
    lcd,1, 8, A
  endif
  if [K3#Switch]=0
    lcd,1, 8, B
  endif
  if [K2#Switch]=0
    lcd,1, 8, C
  endif
  if [K1#Switch]=0
    lcd,1, 8, D
  endif
 pcfgpio,97,0
 pcfgpio,98,0
 pcfgpio,99,0
 pcfgpio,100,0
 pcfgpio,101,1
 pcfgpio,102,1
 pcfgpio,103,1
 pcfgpio,104,1
EndOn
The physical (measured) values when the event is triggered are:

Code: Select all

 pcfgpio,97,1
 pcfgpio,98,0
 pcfgpio,99,1
 pcfgpio,100,1
 pcfgpio,101,0
 pcfgpio,102,0
 pcfgpio,103,0
 pcfgpio,104,0
but ESPEasy thinks, they are:

Code: Select all

 pcfgpio,97,0
 pcfgpio,98,0
 pcfgpio,99,0
 pcfgpio,100,0
 pcfgpio,101,1
 pcfgpio,102,1
 pcfgpio,103,1
 pcfgpio,104,1
because it did set them so in the rules itself. So the problem is, that the values set in rules seem to be preferred over the real values.
Any idea, how this can be solved, if it's possible at all?
I have seen an effort for getting such a keypad to work in this thread. So maybe some others are interested too?


Thanks,

daniel

paxi
Normal user
Posts: 121
Joined: 02 Feb 2017, 00:48
Location: Germany

Re: Problem: values set in rules don't match real values

#2 Post by paxi » 15 May 2017, 03:01

Hmm, hard to get the head around this... ;)

I'm not sure if it is a general problem to permanently alter between input and output.
The PCF8575A's datasheet says
The I/Os should be high before being used as inputs.
this seems to be met.

The only potential error I can spot in your rules is

Code: Select all

On K5#Switch do
it triggers on both edges and should read

Code: Select all

On K5#Switch=0 do
I'm not sure why the second step doesn't work, maybe a 100ms delay between changing the output states and reading the pins again will help - reading is done at the usual ten_per_second heartbeat for plugins.

groovy
Normal user
Posts: 39
Joined: 14 Oct 2016, 11:32
Location: Chemnitz, Germany

Re: Problem: values set in rules don't match real values

#3 Post by groovy » 15 May 2017, 07:59

paxi wrote: 15 May 2017, 03:01 The only potential error I can spot in your rules is

Code: Select all

On K5#Switch do
it triggers on both edges and should read

Code: Select all

On K5#Switch=0 do
Thanks. I changed this, but the behaviour stays the same.
paxi wrote: 15 May 2017, 03:01 I'm not sure why the second step doesn't work, maybe a 100ms delay between changing the output states and reading the pins again will help - reading is done at the usual ten_per_second heartbeat for plugins.
I played around with delays, but this didn't help either.
By watching the Log and the actual device state, I found out, that it doesn't switches the GPIOs at all.
The Log shows that it triggers the GPIOs:
Bildschirmfoto von »2017-05-15 07-44-41«.png
Bildschirmfoto von »2017-05-15 07-44-41«.png (24.43 KiB) Viewed 4683 times

But at the same time, the device status says, that only K5 is HIGH:
Bildschirmfoto von »2017-05-15 07-30-55«.png
Bildschirmfoto von »2017-05-15 07-30-55«.png (39.23 KiB) Viewed 4683 times

paxi
Normal user
Posts: 121
Joined: 02 Feb 2017, 00:48
Location: Germany

Re: Problem: values set in rules don't match real values

#4 Post by paxi » 15 May 2017, 11:46

Did you reload the device page after the event was executed? It doesn't update in real time.

I'm not familiar enough with the source code to tell if its a limitation in espeasy. Probably the suggestion in the thread you found - use an arduino to decode the keypad or adopt the plugin to espeasy - is the only solution.

Post Reply

Who is online

Users browsing this forum: No registered users and 45 guests