Keypad and PCF8574

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Keypad and PCF8574

#1 Post by budman1758 » 06 Dec 2017, 21:33

Hello all.

I'm trying to put together a keypad setup and I am using one of these keypads https://www.adafruit.com/product/419 and a PCF8574 IO expander. I am using the DEV 12 "testing" version of the firmware and it has a testing version for keypads with PCF8574/MCP23017 chips.

I have the wiring from the keypad going direct to the pins on the PCF8574 (in no particular order) and it will register some but not all keypresses and its also pretty random when it does register at all. I cant find any specific wiring info for this particular setup and was just looking for help from anyone who has some experience with this. My keypad is a 3x4 array and has a 7 pin connector and I assume a 4x5 array has more than that but I figured I could make it work somehow. Here is a shot of the device setup..
keypad test.png
keypad test.png (47.47 KiB) Viewed 11275 times

Also worth noting is when I put 2.2k resistors on the I2C bus I get zero response to the keypad. This is observed from watching the log output. Also sometimes I get 2 outputs when it registers a keypress. for example when I press "1" I get "Scancode 0x31" and right after "Scancode 0x0". This is not always the case tho... Its pretty random.

I have the column and row mapping for my keypad but still have no idea how that is supposed to map to the IO expander.

Anybody out there have any experience with this? Any help would be appreciated. The actual goal here is a remote keypad box that will send an http request to another unit to open and close a garage door when a certain 4 number sequence is punched in.
"The glass is twice as big as it needs to be".

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Keypad and PCF8574

#2 Post by budman1758 » 07 Dec 2017, 00:01

OK. Did a little rewiring and things are starting to make sense. I wired the column outputs to the first 4 ports on the PCF8574 and the row outputs to the next 3 ports. So using ports 1-7.
Put 10K resistors on the Ic2 line and now I get much better signals in the log output. They also got a lot more informative when I remembered to enable the rules on the module too. :oops:

Now when I press "1" for example it gives 2 values. Here is a screenshot.
Log output 1.JPG
Log output 1.JPG (99.81 KiB) Viewed 11270 times
After every press I get the second 2 lines also. Not sure why on that. I guess the real question here now is, How to write a set of rules to read a certain sequence of codes within a certain amount of time and then trigger an event. I am thinking say press * or # to start a timer and during that period of time a 4 number code and * or # must be entered to trigger the "successful code entered" event. Something like....

Press # to start timer
press 1234 as a code
press * to "send" the code

Obviously the code has to be a certain sequence for this to work. Any ideas on the rules for something like this? Is it even possible?
"The glass is twice as big as it needs to be".

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Keypad and PCF8574

#3 Post by grovkillen » 07 Dec 2017, 12:30

I suggest you use a dummy to store the values and by each tap on a number you add a multiple.

Dummy 1: store the sequence [1234567890]
Dummy 2: store the multiple [10^n]

For each tap:
<Dummy 1>+<Key number>*10^<Dummy>
Also
Add +1 to the dummy 2 after each tap

When using * or # you publish dummy 1 and then zero both dummy

Only work for numbers below 10!
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Keypad and PCF8574

#4 Post by budman1758 » 09 Dec 2017, 04:58

Well..... Ya kinda lost me there. I am using dummy devices to temporarily store the input values. My approach was to store the key inputs as they were punched in then compare the result to a predetermined value.
These are the numbers that the PCF8574 plugin are producing per keypad press...
1 = 0x00 = 17
2 = 0x12 = 18
3 = ox13 = 19
4 = 0x21 = 33
5 = 0x22 = 34
6 = 0x23 = 35
7 = 0x31 = 49
8 = 0x32 = 50
9 = 0x33 = 51
0 = 0x42 = 66
* = 0x41 = 65
# = 0x43 = 67
The log output for a keypress is for example 5...
KPad : ScanCode=0x22
EVENT: keypad#ScanCode=34.00
KPad : ScanCode=0x0
EVENT: keypad#ScanCode=0.00

I dont have any idea what hat these numbers come out of but my approach so far is to push the ScanCode number to a dummy value. I have 4 set up and if the correct 4 numbers are pressed it will write all 4 values. So for the pin "1758" we push 17, 49, 34 and 50. Now we press the * key and it puts "65" into a 5th dummy value. At this point we start an event and the idea is to add the first 4 values and if it is = to 150 we send the signal to open the door. Here are the rules I have. It actually works except for the add all 4 up part.

on keypad#ScanCode do
if [keypad#ScanCode]=17
TaskValueSet,2,1,17
endon

on keypad#ScanCode do
if [keypad#ScanCode]=49
TaskValueSet,2,2,49
endon

on keypad#ScanCode do
if [keypad#ScanCode]=34
TaskValueSet,2,3,34
endon

on keypad#ScanCode do
if [keypad#ScanCode]=50
TaskValueSet,2,4,50
endon

on keypad#ScanCode do
if [keypad#ScanCode]=65
TaskValueSet,3,1,65
endon

on pinaccept#key5=65 do
if [pin1#key1]=17&[pin1#key2[=49&[pin1#key3]=34&[pin1#key4]=150 <<<<This does not work only the first value is used
TimerSet,1,5
pulse,2,1,2000
endon

On Rules#Timer=1 do
TaskValueSet,2,1,0
TaskValueSet,2,2,0
TaskValueSet,2,3,0
TaskValueSet,2,4,0
TaskValueSet,3,1,0
endon

Here are the device screenshots

devices 3.JPG
devices 3.JPG (73.66 KiB) Viewed 11220 times
devices 2.JPG
devices 2.JPG (83.77 KiB) Viewed 11220 times
devices 1.JPG
devices 1.JPG (83.44 KiB) Viewed 11220 times
This sort of works. it does not add the values and no matter how I format that section of the rule it doesnt work. How to you add several values together?
The last part of the rules is to clear the codes because if you dont just pressing the star key will open the door. Not good!! :D

Also of note. Dunno if its my keypad or how its wired but its very flaky as to registering the key presses. Only way it works is to enter them VERY slowly. nor more than 1 key per second and a second or 2 in between. Otherwise it misses them.

Sorry this post is so long. Any takers?
"The glass is twice as big as it needs to be".

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Keypad and PCF8574

#5 Post by budman1758 » 10 Dec 2017, 19:02

After watching the serial output for a bit I can verify why the keypad input is so flaky. Whenever the unit is "doing something" the keypad inputs are not captured. It the module is outputting ANYTHING to the serial output no keys are sensed. If this is normal then I believe it will be useless. If not normal then I hope someone can point me in the right direction. I am still not completely sure about the wiring of the PCF8574. It has an interrupt pin that is not hooked up. Perhaps that needs to enter into the mix?
"The glass is twice as big as it needs to be".

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Keypad and PCF8574

#6 Post by grovkillen » 10 Dec 2017, 20:42

If possible, could you try to change the keypad from task 1 to task 5? Just as a test since the first 4 tasks are used for pulse counter devices, they are interrupted more frequently.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Keypad and PCF8574

#7 Post by budman1758 » 10 Dec 2017, 21:29

grovkillen wrote: 10 Dec 2017, 20:42 If possible, could you try to change the keypad from task 1 to task 5? Just as a test since the first 4 tasks are used for pulse counter devices, they are interrupted more frequently.
I just tried that and cannot see any noticeable difference.
"The glass is twice as big as it needs to be".

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Keypad and PCF8574

#8 Post by budman1758 » 10 Dec 2017, 21:53

I am beginning to see several problems with my approach....

grovkillen wrote: 07 Dec 2017, 12:30 I suggest you use a dummy to store the values and by each tap on a number you add a multiple.

Dummy 1: store the sequence [1234567890]
Dummy 2: store the multiple [10^n]

For each tap:
<Dummy 1>+<Key number>*10^<Dummy>
Also
Add +1 to the dummy 2 after each tap

When using * or # you publish dummy 1 and then zero both dummy

Only work for numbers below 10!
Can you elaborate on this? I'm not really following you. All the dummy tasks only have 4 values available. It would take 5 dummy devices alone to store 20 values unless I am missing something. (always possible :shock: )
I don't know how to add values together to get another either. Thanks.
"The glass is twice as big as it needs to be".

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Keypad and PCF8574

#9 Post by grovkillen » 10 Dec 2017, 22:38

Something like this:

Code: Select all

On System#Boot Do
  Event,ClearCode
Endon

On keypad#keycode Do
  If [keypad#keycode] = 10 //In your example # is = 67
    Event,SendCode
  Endif
  If [keypad#keycode] = 11 //In your example * is = 65
    Event,ClearCode
  Endif
  Event,TypeCode
Endon

On ClearCode Do
  TaskValueSet,1,1,0 //Set code to "0"
  TaskValueSet,1,2,0 //Set the 10^N to "0" 10^0=1
Endon

On SendCode Do
  Publish TopicOfCode,[Dummy#TempCode] //This will send the typed in code but remember it will be backwards (is possible to change if the PIN is of fixed length, but no user will ever really see this...)
  Event,ClearCode
Endon

On TypeCode Do
  TaskValueSet,1,1,[Dummy#TempCode]+[keypad#keycode]*10^[Dummy#TempTenth]
  TaskValueSet,1,2,[Dummy#TempTenth]+1 //You can (need to) change this to let's say +3 for use with numbers above 10, that would give you trailing zeros between NN values
Endon
Given that the dummy is on task 1 and the dummy value 1 is called "TempCode" and dummy value 2 is called "TempTenth".

Say you press "2, 2, 1, 8, 9" as your pin. This would happen to the dummy value 1:

0+2*10^0 = 2
2+2*10^1 = 22
22+1*10^2 = 122
122+8*10^3 = 8122
8122+9*10^4 = 98122

So only two dummy values are used.

Please understand that I do not have the hardware to test and is writing the rule out of memory. You'll need to adapt it to your setup.
Last edited by grovkillen on 20 Dec 2017, 08:54, edited 1 time in total.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Keypad and PCF8574

#10 Post by budman1758 » 12 Dec 2017, 06:18

Thanks grovkillen. With a couple minor mods I have that working quite well. I actually made it so it creates a different event for each possible keypress.

The problem now is still the time it takes to enter the code. As I mentioned earlier the key press is not captured at all when the module is "working" Consequently, it takes 2 or 3 seconds time between presses for them all to register. Your talking 10 to 12 seconds to enter a 5 digit code. This is kind of a show stopper. Methinks the plugin for this needs to somehow interrupt the module for a couple or 3 seconds to read the keypad and then get to processing the codes. There is nothing else going on this module. No other sensors or anything at all.

I'm using the test version of Dev-12. Is anybody else trying to set up a keypad application? Any feedback is greatly appreciated. Can possibly the dev who put the test version of this plugin in the firmware chime in? Or does that kinda conversation happen on Github? I don't want to step on any wrong toes here. :mrgreen:
"The glass is twice as big as it needs to be".

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Keypad and PCF8574

#11 Post by grovkillen » 12 Dec 2017, 06:29

I don't have your hardware so I cannot confirm what you experience. Sounds like a problem with the plugin as you mention, open a issue on GitHub.

By the way, have you experimented with the message delay setting under the advanced menu? Setting it to 200mSec or maybe even 100mSec might speed things up?
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Keypad and PCF8574

#12 Post by budman1758 » 12 Dec 2017, 06:47

grovkillen wrote: 12 Dec 2017, 06:29 By the way, have you experimented with the message delay setting under the advanced menu? Setting it to 200mSec or maybe even 100mSec might speed things up?
I have not tried that. Isn't that only related to the controller though? I am not using any right now. I will give it a go...
"The glass is twice as big as it needs to be".

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Keypad and PCF8574

#13 Post by grovkillen » 12 Dec 2017, 06:51

budman1758 wrote: 12 Dec 2017, 06:47
grovkillen wrote: 12 Dec 2017, 06:29 By the way, have you experimented with the message delay setting under the advanced menu? Setting it to 200mSec or maybe even 100mSec might speed things up?
I have not tried that. Isn't that only related to the controller though? I am not using any right now. I will give it a go...
No it's related to how often it is polling the plugins, at least I think so. I use it when I need my switch presses to be more responsive.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Keypad and PCF8574

#14 Post by budman1758 » 12 Dec 2017, 19:42

grovkillen wrote: 12 Dec 2017, 06:51
budman1758 wrote: 12 Dec 2017, 06:47
grovkillen wrote: 12 Dec 2017, 06:29 By the way, have you experimented with the message delay setting under the advanced menu? Setting it to 200mSec or maybe even 100mSec might speed things up?
I have not tried that. Isn't that only related to the controller though? I am not using any right now. I will give it a go...
No it's related to how often it is polling the plugins, at least I think so. I use it when I need my switch presses to be more responsive.
Changed it to 100 and 10 ms and cannot see any difference. :(
"The glass is twice as big as it needs to be".

User avatar
grovkillen
Core team member
Posts: 3621
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Keypad and PCF8574

#15 Post by grovkillen » 12 Dec 2017, 20:28

Then you might want to open a issue on GitHub.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

User avatar
budman1758
Normal user
Posts: 301
Joined: 15 Apr 2017, 05:13
Location: Riverside CA USA

Re: Keypad and PCF8574

#16 Post by budman1758 » 16 Dec 2017, 05:33

Just in case anybody is interested I purchased a HT16K33 keypad/matrix driver chip and set it up and it behaves the same. Still have to wait a few seconds between keypresses so that they are not missed. This chip is designed for this sort of thing so I thought perhaps it would behave differently. Guess thats what I get for thinking... :roll: Oh well.

https://www.ebay.com/itm/HT16K33-LED-Do ... 2749.l2649
"The glass is twice as big as it needs to be".

Post Reply

Who is online

Users browsing this forum: No registered users and 31 guests