3x4 Keypad detecting "*" instead of "0"

Following all tutorials online, I've got my keypad connected successfully to my Arduino Pro Mini and program uploaded...
Keys 1-9, * and # all display correctly... but when I try to type 0, it just displays * (most of the time!... very rarely it will display 0 but I can't reliably replicate).

Completed troubleshooting:

  • Confirmed there are no shorts
  • The direct code for the keypad is correct
  • Tested multiple keypads with the exact same outcome

The only thing different from my setup and the tutorials I've found, is I have an SD card reader and I2C LCD display connected.

The LCD wired to A4, A5, power and ground.
The SD card reader connected to pins 10-13, power and ground.
Both components have their initial test code implemented to ensure they work...

The only thing I can think of, is I remember that pin 10 can be troublesome? Something about SPI or slave/master for it?
I've done no programming to accommodate for that...

Can having my SD card connected to pin 10 interfere with the keypad output?
How can I get my keypad to work correctly?

Start by posting your code and preferably a schematic too

The easier you make it to read and copy your code the more likely it is that you will get help

Please follow the advice given in the link below when posting code , use code tags and post the code here

If you get errors when compiling please copy them from the IDE using the "Copy error messages" button and paste the clipboard here in code tags

I don't know. Are you using Pin 10 as one of your keypad pins? How about Pin 0 or Pin 1 and Serial?

SHOW YOUR SKETCH.

Hi, @bluebell

Please post a circuit diagram, a pen(cil) and paper will be fine?
Please label components and pins and include any external power supplies.

Thanks.. Tom... :smiley: :+1: :coffee: :australia:

As requested... my sketch, complete with the test code of my SD Card and LCD...

#include <Wire.h> 
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <SD.h>
#include <Keypad.h>

File root;
LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};
byte rowPins[ROWS] = {5, 6, 7, 8}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {2, 3, 4}; //connect to the column pinouts of the keypad

//Create an object of keypad
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup() {

  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

//------------------------------------LCD----------------------------------------
  lcd.init(); // initialize the lcd 
  lcd.backlight(); //Backlight on
//  lcd.noBacklight(); // Backlight off
  lcd.setCursor(1,0); // Set cursor to 1 character in, on line zero
  lcd.print("hello everyone"); // Print a message to the LCD.
  lcd.setCursor(1,1); // Set cursor to 1 character in, on 2nd line
  lcd.print("konichiwaa"); // Print message
//------------------------------------LCD----------------------------------------

//------------------------------------SD CARD------------------------------------
  Serial.print("Initializing SD card...");
  if (!SD.begin(10)) {
    Serial.println("initialization failed!");
    while (1);
  }
  Serial.println("initialization done.");
  root = SD.open("/");
  printDirectory(root, 0);
  Serial.println("done!");
//------------------------------------SD CARD------------------------------------
}

void loop() {
//------------------------------------KEYPAD-------------------------------------
  char customKey = keypad.getKey();
  if (customKey){
    Serial.println(customKey);
  }
//------------------------------------KEYPAD-------------------------------------
}

//------------------------------------SD CARD------------------------------------
void printDirectory(File dir, int numTabs) {
  while (true) {
    File entry =  dir.openNextFile();
    if (! entry) {
      // no more files
      break;
    }
    for (uint8_t i = 0; i < numTabs; i++) {
      Serial.print('\t');
    }
    Serial.print(entry.name());
    if (entry.isDirectory()) {
      Serial.println("/");
      printDirectory(entry, numTabs + 1);
    } else {
      // files have sizes, directories do not
      Serial.print("\t\t");
      Serial.println(entry.size(), DEC);
    }
    entry.close();
  }
}
//------------------------------------SD CARD------------------------------------
// End sketch

And the wiring diagram that I had sketched up on my phone to match... Sorry the pins aren't labeled, but hopefully can still be deciphered.


EDIT 1: The battery/charge controller/switch are not currently connected to my circuit... not that it matters for this issue.

EDIT 2: Included Serial Output after punching in the keypad numbers left to right, top to bottom...

Initializing SD card...initialization done.
SYSTEM~1/
	INDEXE~1		76
	WPSETT~1.DAT		12
README~1.TXT		1225
VANQUI~1.XLS		13905
X-TERR~1.XLS		13903
done!
1
2
3
4
5
6
7
8
9
*
*
#

Hi,
Sorry that Fritzy picture will not do.

PLEASE draw it with pen(cil) and paper, INCLUDE pin and connection labels, component labels.

That Fritzy does not tell us SD connection or the important keypad connections.

If you wrote this program in stages, when did you come across this problem.
If you wrote it in stages, you should already have a code JUST for the keypad.

If not, then write code JUST for the keypad, see what you get.

Thanks... Tom.. :smiley: :+1: :coffee: :australia:

I did write it in stages and only come across the issue when getting to the keypad stage.
Even when using a fresh sketch with only the required keypad code, I get the same outcome.

I'll get to work on a new sketch.

Hi,
It sounds like you have a faulty keypad.

Do you have a DMM?n
You can use it in Ohm or Continuity Mode to test the pinouts as you press the keys.

Tom.. :smiley: :+1: :coffee: :australia:

just to be sure, unplug everything from your Arduino besides the keypad and run this code

#include <Keypad.h>
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns

char keys[ROWS][COLS] = {
  {'1', '2', '3'},
  {'4', '5', '6'},
  {'7', '8', '9'},
  {'*', '0', '#'}
};

byte rowPins[ROWS] = {5, 6, 7, 8}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {2, 3, 4}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup() {
  Serial.begin(9600);
}

void loop() {
  char customKey = keypad.getKey();
  if (customKey != NO_KEY)  Serial.println(customKey);
}

if you still don't see the '0' then indeed you likely have a faulty keypad

Hopefully this is legible.

if you were to do

byte rowPins[ROWS] = {8,7,6,5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {4,3,2}; //connect to the column pinouts of the keypad

the drawing would be nicer :slight_smile:

I'd rather not 'unplug' as everything is soldered on, and will thus become a tomorrow issue.
I can hot-swap keypads however and I find it hard to believe I have 2 faulty keypads, giving the exact same issue... different designs from different suppliers but still 3x4 pads.

ah ,that's a good reason... do you have another arduino where you can swap the keypad ?

I have only identified that change after soldering the wires as per the tutorial I found for wiring... but after playing around with a separate coding tutorial, I realized the way you suggested is if the keypad is wired to the arduino in order of its wire output... instead the wiring tutorial i blindly followed got my to wire it backwards, as per my drawing.

EDIT:
and yes, i do have a spare Arduino, but no headers are currently soldered on... thus also making it a tomorrow problem

OK

did you solder this part?
image

or you just have pins getting into the female header?

the challenge with only 1 key not working is hinting for a hardware issue

I'm kind of thinking that is the culprit...
Those coloured wires are soldered onto male headers, heat shrunk, and hot-glued to make a male header. Other end of wires then soldered onto the arduino.

The female header that is equip on both keypads can then just be plugged into my DIY male header... but while sitting and waiting for a reply, i'm mashing this 0 key and squeezing/moving wires around to see if there's a fault... rarely ill see a 0 flick up.. sometimes if i squeeze the headers a certain way it will flash two '*'... so something just isn't right with it

EDIT: now simply squeezing the DIY header can trigger the *

who needs a membrane keypad when headers and hot glue can do :slight_smile:

Joke aside, I think you are onto something there. Likely a short circuit

F this thing! hahaha. I just used a blade to slice between the 2 closest soldered/glued wires that happen to be R4 and C1 on my drawing and jimmied them apart a little... works like a charm now.
Although it wasn't the cleanest plug, one would have though heat shrink and glue would stop a short circuit.

Cheers mate.

great ! have fun

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.