Issue displaying string from Matrix Keypad password to display on lcd screen


I am working on a project to type a 6 digit order number on a matrix keypad and this number will be stored in a character string and then this string will be displayed/ updated on an lcd screen as the buttons are pressed. I was previously using a PIC 32 and I had it working as desired (see my original code below). I am now trying to transition to a stm32 Nucleo with a similar code and I am not getting the same results. I am using the lcd and keypad libraries on Mbed and have them working fine, however whenever I press a button, multiple characters appear at a time, and the number of characters does not get capped at 6 like I have it set, it keeps flooding the screen. I have both the serial monitor using sprintf/printf and the lcd print command displaying the information. I have tried messing with the delay but it doesn’t

stop the flooding of button presses it just increases the time between time to accept them. I am assuming I need to implement some sort of button debouncing but im not sure how to do this with the keypad library. Does anyone have any suggestions? A better way to solve this problem ? My current code is also shown below.


you not linked what a library you exactly use. But it seems like this one

It is correct?

Just for inspiration, you can try something like this

    int i = 0
    char prevKey = 0;
    while(i < 6) {
        char key = keypad.getKey();
        if(key && key != prevKey){
            inpassword[i++] = key;
            // here print out one by one
        prevKey = key;
    sprintf(test, "Order Number:\n#%s", inpassword);

You also need to manage the cursor of LCD, when you printing (putc or printf)to the display.
So, when you prints a string again and again to same place, you need to call a cls() method for clear the display, that also relocate the cursor to position 0. Otherwise, the cursor moves forward automatically and the original string will be not override.


Also if you need print something to a specific place you can use


BR, Jan

Hey Jan, the location function fixes part of my problem so thank you for that. However multiple characters are still appearing for a single button press. I tried to do what you had suggested but the keypad.getkey reads in a character to key, so comparing char with prevkey (int will not work) I tried making prevKey of type char but this lead to more errors.

I’m glad something helped.
Yes, you are right, I badly check the .h file of that library. Unfortunately, I don’t have this hardware, so I can’t tune it in real.

BR, Jan