4x4 Keypad odd behaviour

Utilising a 4 x 4 keypad in my project, the keys (A, B, C, D) do not print using Serial.println(). The other keys print fine.

I have built a rather long sketch (my own version of an irrigation controller). All has been going well, until i added the keypad. Up to now I have been using serial i/o from the PC for testing.

I am using the common 4x4 tactile keypad with the following code:

#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the symbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
byte rowPins[ROWS] = {22, 26, 30, 34}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {38, 42, 46, 50}; //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);

void setup(){

void loop(){
char customKey = customKeypad.getKey();

if (customKey){

This code (by itself) when used as a sketch works as expected, printing all keys correctly. However when I add this code to my sketch, only the first 3 columns print, not the last column (A,B,C,D).

The only difference in my code is that I call the code shown here in loop() from a separate procedure. Otherwise there is no difference whatsoever.

As I have a few keypads, I have tried them all. Same results as above.

Can anyone give me some ideas as to what to try next?


Could it be that your full sketch uses Pin 50 for something else? Perhaps you have something connected via SPI (like an SD card or Ethernet Shield)?

Doh! It's the ethernet shield causing the problem. Due to a lack of sleep and my inexperience with the Mega :frowning:

Thank you sir for taking the time to point out the obvious. It is appreciated :slight_smile: