ByVac I2C Keypad Library

Hi Everyone,

I recently bought a byvac i2c keypad by mistake and figured I might as well use it. I created a library which makes it pretty easy to use.

You can download it here:
http://www.diy-labs.com/arduino/byvac-i2c-keypad-library-arduino

Right now it supports 3 functions

keydown()
numkeys()
getkey()

Usage:

#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 :wink:

I also tried clearing my temp directory ( doesnt this force the IDE to check all libraries? ) - Didnt help…

In function 'void loop()':
error: no matching function for call to 'HardwareSerial::println(<unresolved overloaded function type>)'C:\Program Files (x86)\arduino-0017\hardware\cores\arduino/Print.h:50: note: candidates are: void Print::println()

C:\Program Files (x86)\arduino-0017\hardware\cores\arduino/Print.h:51: note:                 void Print::println(char)

C:\Program Files (x86)\arduino-0017\hardware\cores\arduino/Print.h:52: note:                 void Print::println(const char*)

C:\Program Files (x86)\arduino-0017\hardware\cores\arduino/Print.h:53: note:                 void Print::println(uint8_t)

C:\Program Files (x86)\arduino-0017\hardware\cores\arduino/Print.h:54: note:                 void Print::println(int)

C:\Program Files (x86)\arduino-0017\hardware\cores\arduino/Print.h:55: note:                 void Print::println(unsigned int)

C:\Program Files (x86)\arduino-0017\hardware\cores\arduino/Print.h:56: note:                 void Print::println(long int)

C:\Program Files (x86)\arduino-0017\hardware\cores\arduino/Print.h:57: note:                 void Print::println(long unsigned int)

C:\Program Files (x86)\arduino-0017\hardware\cores\arduino/Print.h:58: note:                 void Print::println(long int, int)

C:\Program Files (x86)\arduino-0017\hardware\cores\arduino/Print.h:59: note:                 void Print::println(double)

Greg.

Whoops! Stupid mistake by me.

Try this:

#include <Wire.h> // i2c
#include <ByVacKeypad.h> // library for byvac i2c keypad


// 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: ");
  int numkeys;
  Serial.print(numkeys);

  delay(2000);

  if(keypad.numkeys() > 0){
    Serial.print("Key Pushed: ");
    int getkey = keypad.getkey();
    Serial.print(getkey);
  }

  delay(2000);

  if(keypad.numkeys() > 0){
    Serial.print("Key Down: ");
    int keydown = keypad.keydown(); 
    Serial.print(keydown);
    // will return 1 if key is down and 0 otherwise
  }

}

Hi Andrew,

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?

Thanks again

Humm, mine doesn't have an int pin. Are you using the lcd/keypad one? I bought a dedicated i2c keypad from byvac by mistake.

Ah....

This is what i have: http://www.i2c.byvac.com/downloads/BV4218%20DataSheet.pdf

Can you advise what part number you have as perhaps its just a case of adjusting the paramters??

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.

Wow... Thanks heaps! Here's a virtual beer - if ever in Sydney, id be pleased to buy you a real one! :)

Hi Greg,

Got that done today. It does compile, but I'm not sure whether it returns the key pressed or the address to the key value.

You can find it here:

http://www.diy-labs.com/arduino/arduino-byvac-lcdkeypad-library

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.

Hi Andrew, Im about to goto work, but had to test this first!

OK loads and responds to keypress ;-)

Results of keys : keypad result 1 15 2 3 4 5 1 6 2 7 4 8 5 9 6 * 8 0 9

10

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?

Thanks again mate.!

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 :wink:
Thank you.

I haven't heard back from Greg on the status of the code. I don't have a spare at the moment, but you're free to use what I've made so far.

If you get it to work let me know.

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! )

Hi Greg,

Did you ever get the value of the lcd.keymaps()?

Nothing is wrong with the hardware, but the result references the memory where the value is stored.

http://www.diy-labs.com/arduino/arduino-byvac-lcdkeypad-library

That code will print it out. The value will help me figure the rest out.

I've also added in the scan code function. It will print that out as well.

Hi Greg,

For the moment I try with lcdkeypad-library (link send by andrew)

http://www.diy-labs.com/arduino/arduino-byvac-lcdkeypad-library

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.

++++++

Hi Pat,

There should be a line that says "Keymap: " Is there a value with it?

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

in keypad = 10

+++++++++

Hi Andrew, Keymap is 16.

PAT77 is this the same value you have?

Thanks again gents... im off to work ;-(

PAt77 - ive just seen your last post...same value. hmm... and looks like you have same results as i had earlier in this thread...