Keypad status for ESP32?

Posted on
  • I'm trying to use the keypad module without success. The recommended:

    require("KeyPad").connect([B2,B3,B4,B5],­[B6,B7,B8,B9], function(e) {

    is never called back.

    I also tried

    var keypad = require("KeyPad").connect([B2,B3,B4,B5],­[B6,B7,B8,B9]);

    and printed output of in a while loop. This produced output like 38 28 08 312 212 012 etc. depending on the key pressed.

    I tested the same keypad using the same pin connections on the same device in an arduino sketch where it worked perfectly.

    Anyway, since there was at least some output, I was going to start hacking on the source code but in the meantime, is anyone using a keypad successfully?

    Thanks for any pointers ...

  • Also posted as an issue on GitHub:­/issues/691

  • Sorry about posting there as well and since it is closed, progress here.

    Firmware was originally 2v17.118_esp32 but updated now to latest 2v17.120_esp32.

    Your tip about use of for (var i in rows) { loops was very relevant and changing them to for (var i of rows){ and for (var i=0;i<rows.length;i++) { loops fixed the return values for so that's all good now.

    The callback version is still a problem although there was some progress after fixing those loops, since pinMode() and setWatch() were being fed with strings rather than numbers. With some added print()s I can see them being set up correctly now. However the onWatch() callback is still never executed.

    I tested the same pins separately with a mechanical switch e.g.

    var onWatch = function() { print("XXX"); };
    pinMode(D22, "input_pulldown");
    setWatch(onWatch, D22, {repeat:true, edge:'both' });

    and it works fine for all the pins being used for the keypad. Nevertheless, still no luck with the keypad itself.

    More digging needed and any help appreciated ...

  • Thanks - well that's an odd one.

    What happens if you do:

    var onWatch = function() { print("XXX"); };
    setWatch(onWatch, D22, {repeat:true, edge:'both' });
    pinMode(D22, "input_pulldown");

    ... so swapping the two around? It's possible that on ESP32 setting the pin mode disables the watch somehow when it shouldn't?

  • I updated firmware to 2v18.1_esp32 today.

    Unfortunately no change swapping those calls around. In fact I can remove pinMode() altogether for the extra button and it still works.

  • Could the problem have something to do with the keypad type? I ran the following code:

    function onWatchX () {
    setWatch(onWatchX, D22, {repeat:true, edge:'both'});
    setWatch(onWatchX, D21, {repeat:true, edge:'both'});
    setWatch(onWatchX, D19, {repeat:true, edge:'both'});
    setWatch(onWatchX, D18, {repeat:true, edge:'both'});

    where the first 3 pins are connected to column outputs of 4x3 membrane type keypad and last pin is connected to a single mechanical switch. The first three watches never trigger a callback whereas the last one always triggers the callback.

    I separately tried the mechanical switch on all of three pins used above for the 4x3 keypad columns and the mechanical switch triggered the callback every time.

    This all leads me to suspect something about the keypad itself. It's the same style as the first shown in the Espruino KeyPad Matrix page. I've tried both a 4x4 and a 4x3, both of which work using the plain yet don't seem watchable.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview

Keypad status for ESP32?

Posted by Avatar for chris.willing @chris.willing