#include <OneWire.h> // one wire library for i2c
#include <Wire.h> // i2c
#include <ByVacKeypad.h> // library for byvac i2c keypad
#include <WProgram.h> // not sure if this is necessary???
// default is 0x62 which is 8 bits, 0x31 is 7 bit address
ByVacKeypad keypad = ByVacKeypad(0x31);
void setup() {
keypad.init(); // initialize the keypad. just clears buffer
Serial.begin(9600);
}
void loop(){
Serial.print("Keys In Buffer: ");
Serial.println(keypad.numkeys);
delay(2000);
if(keypad.numkeys() > 0){
Serial.print("Key Pushed: ");
Serial.println(keypad.getkey());
}
delay(2000);
if(keypad.numkeys() > 0){
Serial.print("Key Down: ");
Serial.println(keypad.keydown());
// will return 1 if key is down and 0 otherwise
}
}
The only limitation right now is I don’t let the keys build up in the buffer at all because I don’t know how to read all of them back at once. Currently it will read back the value of the last key pressed (getkey()) and then clear the buffer.
It works for my application, but if you want to change it let me know so I can change my version too.
Hope you guys like it. It’s my first contribution to the Arduino project.
Hi Andrew,
Thanks again for your work on this.
Ive just soldered up some wires to my keypad and the byvac backpack, and just now downloaded/extracted your lib and fired up the IDE ( v0017 )
Pasting in your example above however fails with the following. Any idea what could be wrong? It compiles if i comment out the three lines with " Serial.println" , but obviously thats no solution
I also tried clearing my temp directory ( doesnt this force the IDE to check all libraries? ) - Didnt help…
I quickly tried this before leaving for the office and it does compile.... however, when the sketch runs on the arduino, the serial monitor just replies with
"Keys in Buffer: 0 " (repeated )
Pressing any keys on the keypad does not return any values.
Ill recheck my wiring.
Pls confirm i dont need to connect anything to the "int" pin ( Interupt O/P ) on the byvac Backpack do i?
Got it. Ok, the ByVacLCD library is what we'll need for this, but it doesn't do it yet. I'll start working on this as it shouldn't be too hard to implement. I won't be able to test it since I don't have another 4218 or another keypad. I should be able to get it finished in a day or two.
There's also example code. It compiles as well, but is untested. Let me know the values of each print statement and I'll fix anything that needs fixing.
Ive not looked at your code, but i presume there is some sort of mapping? and presumably this may need to be changed by each user due to differences in the way each button is connected to each col/row electrically?
Yeah, I didn't figure it would return the right key number. I need to get the key map start address and than just add it in as an offset.
I'll put up some modified code later tonight that you can test.
Put up the modified code that gets the keymap address. I don't really understand how it works, but factory default is 16. I'm thinking you should subtract the lcd.get_key value from the keymap value and that should work.
ie. 16 - 15 = 1 which is the correct number pushed although the rest of the keys don't match this. Fiddle around with the code and let me know what you come up with.
You might also want to play around with clearing the buffer. lcd.clear_buffer().
Hi guys,
I just receive yesterday my BV4218, and i’m very interested on your discussion, because I don’t find any library that working fine with BV4218.
To display on LCDI use wire.h library, but for the moment I’m not able to use my keypad…
Another virtual beer for you
Thank you.
Hi all - sorry for not getting back regarding status of code.
I think/thought i had a problem with the keypad not responding to anything on the C0 ( col 0) connection..so i spoke to Jim who very kindly sent me another module. It arrived today and ive hooked it up quickly....same result.
So im now thinking it must somehow be something to do with software....but unsure how.
Ill email Jim again tomorrow and see if he can help....
Pat77 - have u tried Andrew's code? It would be interesting to see your results!
Sorry again for lack of feedback ( had an exam and also a nice week away camping! )
With this wire conection between Keypad and bv4218:
on keypad row1=C0 on BV4218
on keypad row2=C1 on BV4218
on keypad row3=C2 on BV4218
on keypad row4=C3 on BV4218
on keypad COL1=R0 on BV4218
on keypad COL2=R1 on BV4218
on keypad COL3=R2 on BV4218
Here my result when I press keys :
1 in keypad = 10
2 in keypad = 9
3 in keypad = 8
4 in keypad = 6
5 in keypad = 5
6 in keypad = 4
7 in keypad = 2
8 in keypad = 1
9 in keypad = 0
I don't have the last line I have stoped and moved my conexion before...
I hope this can help you.
sorry,
I have writed bad information,
Here the exact information :
wiring :
on keypad row1=C0 on BV4218
on keypad row2=C1 on BV4218
on keypad row3=C2 on BV4218
on keypad row4=C3 on BV4218
on keypad COL1=R0 on BV4218
on keypad COL2=R1 on BV4218
on keypad COL3=R2 on BV4218
Result:
Keymap: 16
No clic on keypad = 15
Key Pushed fonction :
1 in keypad =
2 in keypad =
3 in keypad =
4 in keypad = 0
5 in keypad = 1
6 in keypad = 2
7 in keypad = 4
8 in keypad = 5
9 in keypad = 6
* in keypad = 8
0 in keypad = 9