Numpad mit LCD-I2C 16x2 Display

Hallo zusammen,

folgende Aufgabenstellung: Ich möchte gerne ein 4x4 Numpad mit einem LCD-Display verbinden. Also ich drücke z.B. die Nummer 1 (Numpad) und es "ploppt" auf dem Display ein Satz bzw. Wort auf. Jedoch findet man im Internet kaum irgendwas dazu.

Arduino Uno habe ich mit dem Display über I2C verbunden, das Numpad hab ich auch verbunden bekommen.

Könnt Ihr mir helfen?

Danke euch!

Das glaube ich dir nicht.

Wie wäre es denn hiermit ?
Den Rest kannst du sicher selbst dazu schreiben.

1 Like

Danke dir. Die Frage ist nur wie definiere ich die Tasten für das Numpad, in dem Beispiel von dir sind die Tasten am Display...bei mir ist es extra und es ist ja auch ein 4x4 Numpad. Alles andere sollte machbar sein....hoffentlich :smiley:

Woher sollen wir das wissen ?
Da hast du nichts von geschrieben.
Also poste Links von deinen Teilen.

// lib: https://github.com/Chris--A/Keypad
#include <Keypad.h>

const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] =
{
  {'0', '1', '2', '3'},
  {'4', '5', '6', '7'},
  {'8', '9', 'A', 'B'},
  {'C', 'D', 'E', 'F'}
};
byte rowPins[ROWS] = {3, 2, 1, 0}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {7, 6, 5, 4}; //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()
{
  Serial.begin(9600);
}

void loop()
{
  char customKey = customKeypad.getKey();
  if (customKey)
  {
    Serial.println(customKey);
  }
  switch (customKey)
  {
    case '0':
      Serial.println(F("Hier geht es weiter...."));
      // Hier der Aufruf fürs LCD
      break;
    case '1':
      Serial.println(F("Letzter Eintrag...."));
      // Und hier auch der Aufruf fürs LCD
      break;
  }
}

Einfach mal etwas in der Umgebung des anderen Links umschauen.

Gruß Tommy

Hello guys,

how do I get it so that when I press Number "1" on the numpad, one sentence comes up on the display. Likewise, how do I make the sentence disappear automatically after 20 seconds?

That's how far I have come now:

#include <Keypad.h>
#include <LiquidCrystal_I2C.h>

const int ROW_NUM    = 4; // four rows
const int COLUMN_NUM = 4; // four columns

char keys[ROW_NUM][COLUMN_NUM] = {
  {'D','#','0','*'},
  {'C','9','8','7'},
  {'B','6','5','4'},
  {'A','3','2','1'}
};

byte pin_rows[ROW_NUM] = {6, 7, 8, 9};      // connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {2, 3, 4, 5}; // connect to the column pinouts of the keypad

Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows

int cursorColumn = 0;

void setup(){
  lcd.init(); // initialize the lcd
  lcd.backlight();
}

void loop(){
  char key = keypad.getKey();

  if (key) {
    lcd.setCursor(cursorColumn, 0); // move cursor to   (cursorColumn, 0)
    lcd.print(key);                 // print key at (cursorColumn, 0)

    cursorColumn++;                 // move cursor to next position
    if(cursorColumn == 16) {        // if reaching limit, clear LCD
      lcd.clear();
      cursorColumn = 0;
    }
  }
}

A more advanced task would be:

If I make a typo, I press "A" on the numpad and the sentence gets deleted.

I hope you understand the problem and could help me.

Cheers! :smiley:

Hello guys,

how do I get it so that when I press Number "1" on the numpad, one sentence comes up on the display. Likewise, how do I make the sentence disappear automatically after 20 seconds?

That's how far I have come now:

#include <Keypad.h>
#include <LiquidCrystal_I2C.h>

const int ROW_NUM    = 4; // four rows
const int COLUMN_NUM = 4; // four columns

char keys[ROW_NUM][COLUMN_NUM] = {
  {'D','#','0','*'},
  {'C','9','8','7'},
  {'B','6','5','4'},
  {'A','3','2','1'}
};

byte pin_rows[ROW_NUM] = {6, 7, 8, 9};      // connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {2, 3, 4, 5}; // connect to the column pinouts of the keypad

Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows

int cursorColumn = 0;

void setup(){
  lcd.init(); // initialize the lcd
  lcd.backlight();
}

void loop(){
  char key = keypad.getKey();

  if (key) {
    lcd.setCursor(cursorColumn, 0); // move cursor to   (cursorColumn, 0)
    lcd.print(key);                 // print key at (cursorColumn, 0)

    cursorColumn++;                 // move cursor to next position
    if(cursorColumn == 16) {        // if reaching limit, clear LCD
      lcd.clear();
      cursorColumn = 0;
    }
  }
}

A more advanced task would be:

If I make a typo, I press "A" on the numpad and the sentence gets deleted.

I hope you understand the problem and could help me.

Cheers! :smiley:

Three topics, one subject.
Bad ratio.

Sorry :confused:

Please do confirm to start with that you have actually got your LCD 1602 display working.

Yea it's working. If I press all keys on the NumPad then the display also shows the number or *, #, A-D.

create an array of sentences you want to see on the LCD

const char * sentences[] = {
"sentence 1", // index = 0
"sentence 2", // index = 1
"sentence 3",
"sentence 4",
"sentence 5",
"sentence 6",
"sentence 7",
"sentence 8",
...
};

create a global variable to remember when the last display was and how long you want it to last as well as a variable that remembers the state of the display

unsigned long lastDisplay;
const unsigned long displayDuration = 20000; // 20s in ms
bool displayActive = false;

Then to make the mapping easy, don't define the keys as such

char keys[ROW_NUM][COLUMN_NUM] = {
  {'D','#','0','*'},
  {'C','9','8','7'},
  {'B','6','5','4'},
  {'A','3','2','1'}
};

but use

char keys[ROW_NUM][COLUMN_NUM] = {
  {'D','#', 1,'*'},
  {'C', 10, 9,  8},
  {'B',  7, 6,  5},
  {'A',  4, 3, 2}
};

this way the key you get when the keypad is pressed is the index+1 you want to use in the sentences array. Don't start the numbering at 0 because that's the value of NO_KEY that is returned when noting is pressed when you call keypad.getKey()

char key = keypad.getKey();
switch(key) {
  case 0: break; // no key
  case 'A': ... break;
  case 'B': ... break;
  case 'C': ... break;
  case 'D': ... break;
  case '*': ... break;
  case '#': ... break;
  default: // then it's the index + 1 in the sentence array
     lcd.setCursor(0,0);
     lcd.print(sentences[key-1]);
    lastDisplay = millis();
    displayActive = true;
    break;
}

you could decide to use also indexes for '#' or '*' or 'B' etc...

then to clear the display after some timeOut, you just do

if (displayActive && (millis() - lastDisplay  >= displayDuration)) {
  lcd.clear();
  displayActive = false;
}
1 Like

Hi @destrix01,

try this code:

RV mineirin

#include <Keypad.h>
#include <LiquidCrystal_I2C.h>

const int ROW_NUM    = 4; // four rows
const int COLUMN_NUM = 4; // four columns

char keys[ROW_NUM][COLUMN_NUM] = {
  {'D', '#', '0', '*'},
  {'C', '9', '8', '7'},
  {'B', '6', '5', '4'},
  {'A', '3', '2', '1'}
};

byte pin_rows[ROW_NUM] = {6, 7, 8, 9};      // connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {2, 3, 4, 5}; // connect to the column pinouts of the keypad

Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
LiquidCrystal_I2C lcd(0x27, 16, 2); // I2C address 0x27, 16 column and 2 rows
unsigned long myTime = 20 * 60;               // Time control 20 seconds
unsigned long passTime = 0;                   // Time flow
int cursorColumn = 0;
//-----------------------------------------------------------------------------
void setup() {
  lcd.init(); // initialize the lcd
  lcd.backlight();
}
//-----------------------------------------------------------------------------
void loop() {
  char key = keypad.getKey();

  if (key == '1') {
    lcd.setCursor(cursorColumn, 0); // move cursor to   (cursorColumn, 0)
    lcd.print("sentence ");                 // print key at (cursorColumn, 0)
    passTime = millis();                    // Recharge time flow
  }
  if (millis() - passTime > myTime)        // If time has go
  {
    lcd.clear();                            // Clear LCD
  }
}
1 Like

I now regret answering because you double post. Shame on you. I'm out.

Sorry. I wasn't sure if I chose the right category.
Nevertheless, I thank you very much for the quick and hopefully solvable answer.

@destrix01
Ich habe alle Ihre Themen zum gleichen Thema zu einem zusammengeführt. Ich habe mich für das Deutsche entschieden, zum Teil weil es das Original ist und zum Teil, weil ich vermute, dass Deutsch Ihre Muttersprache ist. Wenn Sie weiterhin mehrere Themen zum gleichen Thema posten, erhalten Sie ein Postenverbot.

Übersetzt mit Google Übersetzer.

Lesen Sie bitte:

Dankeschön.

2 Likes