Menu

Home

Johnson Arantes Lima

Welcome to W5IOKeypad Arduíno Library!

This project was started when I needed some directions to use the Waveshare's 5IO Keypad with my Arduíno Mega. From the start I was very lost because no one knew this hardware enough to give me some good directions. So, by my own, I started to test and begin to understand how it works. This library is the answer to those who need to use this keypad and, as I was, do not know how to do it.

NOTE: For the following explanations I will presume that you understand the basics of Arduino digital pins communications and how to use the internal Pull-Up resistors.

How to connect 5IO Keypad to Arduíno:

The first secret about 5IO Keypad is to think in the GND pin as another pin in the same way as IO1, IO2, IO3, IO4, IO5. DO NOT be tempted to put the GND pin in the real GND because you will loose control of it (this was my first mistake on my early tries). This said, you will need to connect them, each one, to a digital pin in Arduino, separately.

How to use this library:

1) Download and install the last Library file from the Arduino's IDE;

2) Include the "W5IOKeypad.h" file in your project;

3) Outside the setup() and loop() procedures (and before them), call the W5IOKeypad constructor with some valid name to your Keypad, giving the pins used on the 5IOKeypad in this order: GND, IO1, IO2, IO3, IO4 and IO5 as parameters. Example:

W5IOKeypad Keypad( 49, 47, 45, 43, 41, 39 );

4) Inside your loop() procedure call the ReadButtons() functions like this:

int IOKey;
do {IOKey=Keypad.ReadButtons();} while (IOKey==0);

5) That's it! If the 5IO Keypad is right conected to Arduino, each time you press any button the 'IOKey' variable will return the key number.

Tip: Within the library directory there is an example Sketch.

How the ReadButtons() function works:

1) Early in the code, the library initializes each pin as INPUT_PULLUP, this is important to IO5Pin specially which will never change this state;

For now on, this what the function does:

2) Starts reading the Joystick buttons: Sets the GND pin as an OUTPUT and send a LOW to it. This way the GNDPin will act as a pure GND. Then, sets all other pins, each one, as INPUT_PULLUP (IO1 to O4, IO5 isn't needed since it will remain as an INPUT_PULLUP forever). When this is set, all pins should report HIGH status except the one which the button has been pressed, so, it starts scanning the the pins from IO1 to IO5 (IN ORDER). The first one which has a LOW condition is the one with the button being pressed. In this case the library exits with an exclusive integer number to identify this Joystick button press;

3) Starts reading the push buttons from the K1-K4 group: Sets the GND pin as an INPUT_PULLUP. Is not needed to send a HIGH to it because it is done automatically by Arduino. This is important because we do not want another pin acting as a GND now, we need to control WHICH pin is acting as GND and WHEN (this is the second secret of 5IO Keypad!). Now, sets the IO1Pin as an OUTPUT and send a LOW to it (now the IO1Pin is the GND, got it?). Then, sets all remaining pins, each one, as INPUT_PULLUP (IO2 to IO4, IO5 isn't needed remember?). Again, when this is set all pins should report HIGH status (including the Joystick ones, but since we are not interested on then now, they will be ignored because GNDPin is NOT acting like a GND anymore, see?). Starts scanning the the pins from IO2 to IO5 (IN ORDER). The first one which has the LOW condition is the one with the button being pressed. In this case exits with an exclusive integer number to identify this push button press;

4) Starts reading the push buttons from the K5-K7 group: Sets the IO1Pin pin as an INPUT_PULLUP (It cannot be a GND anymore, right?) Sets the IO2Pin as an OUTPUT and send a LOW to it (IO2Pin is the new GND). Then, sets all remaining pins, each one, as INPUT_PULLUP (IO3 and IO4, forget IO5). Again, when this is set all pins should report HIGH status (including the Joystick ones and the K1-K4 group ones). Starts scanning the the pins from IO3 to IO5 (IN ORDER). The first one which has the LOW condition is the one with the button being pressed. In this case exits with an exclusive integer number to identify this push button press;

5) Starts reading the push buttons from the K8-K9 group: Sets the IO2Pin pin as an INPUT_PULLUP. Sets the IO3Pin as an OUTPUT and send a LOW to it (IO3Pin is the new GND). Then, the remaining pin as INPUT_PULLUP (only IO4!). Again, when this is set, all pins should report HIGH status (including the Joystick ones, the K1-K4 group ones and the K5-K7 group ones). Starts scanning the the pins from IO4 to IO5 (IN ORDER). The first one which has the LOW condition is the one with the button being pressed. In this case exits with an exclusive integer number to identify this push button press;

6) Starts reading the push buttons from the lonely K10 group: Sets the IO3Pin pin as an INPUT_PULLUP. Sets the IO4Pin as an OUTPUT and send a LOW to it (IO4Pin is the new GND). There in no remaining pins to set as INPUT_PULLUP. Again, when this is set, all pins should report HIGH status (including the Joystick ones, the K1-K4 group ones, the K5-K7 group ones and the K8-K9 group ones). Scans the pin IO5, if it has the LOW condition then the K10 button has been pressed. In this case exits with an exclusive integer number to identify this push button press;

7) Sets the IO4Pin as an INPUT_PULLUP (just in case) and then return an unique code that means that no key has been pressed.

Final Words:

Althogh this library is already working, this is stil a "work in progress". If you have any suggestions or comments, I will be happy to listen!

Project Members: