ChristopheDupriez
Posts: 16
Joined: Tue Dec 25, 2012 8:38 am

GPIO Matrix Keypad driver installation

Fri Jan 01, 2016 5:13 pm

Hi!

My application needs to read input from a simple 3x4 matrix keypad ("telephone" like).

I started from this article:
http://www.instructables.com/id/Using-a ... pberry-Pi/

I have been trying Rpi.GPIO but after about an hour, the Raspbian Kernel is crashing in diverse way (I have plenty of photographs of the console screen).
(I made the latest update for Raspbian and RPi firmware)
I replaced Rpi.GPIO by "pigpio": it is crashing a bit later but it is still crashing.
If I do not read the keypad (no GPIO polling), no kernel crashes, even after some whole days.

I am trying to go the "matrix keypad driver way" hoping that the Kernel will be less endangered.
I try to install a Device Tree overlay (see below).
I see it installed using

Code: Select all

sudo vcdbg log msg
or

Code: Select all

dtc -I fs /proc/device-tree
.
The keypad has no effect on console input (My Keymap is still bad but I should at least have an effect)

My questions:
* Any explanation of Kernel crashes with an intense use of Rpi.GPIO or pigpio ?
* CONFIG_KEYPAD_MATRIX is NOT SET in the Raspbian Kernel configuration : could this means that the device tree cannot refer to it without kernel recompilation ?
* How good is my overlay definition below (inline but not attached because extensions "dts" and "txt" are not allowed here) ?

I think this is a rather common case and solving it should help many users

Thanks A LOT for your help !

Christophe

/boot/overlays/34keypad.dts:

Code: Select all

/dts-v1/;
/plugin/;
/ {
       compatible = "brcm,bcm2835", "brcm,bcm2708", "brcm,bcm2709";

       [email protected] {
          target-path = "/soc";
          __overlay__ {
             keypad: keypad {
                compatible = "gpio-matrix-keypad";
                debounce-delay-ms = <5>;
                col-scan-delay-us = <2>;

                row-gpios = <&gpio 18 0
                             &gpio 23 0
                             &gpio 24 0
                             &gpio 25 0>;

                col-gpios = <&gpio 4 0
                             &gpio 17 0
                             &gpio 22 0>;

                linux,keymap = <0x0000008B
                                0x0100009E
                                0x0100009E
                                0x0100009E
                                0x0100009E
                                0x0100009E
                                0x0100009E
                                0x0100009E
                                0x02000069
                                0x0001006A
                                0x0101001C
                                0x0201006C>;

             };
          };
       };
  };

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 2226
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: GPIO Matrix Keypad driver installation

Fri Jan 01, 2016 8:09 pm

1) I'm not aware of any reason for GPIO activity crashing the kernel - please upload/link to any logs that you have, ideally as an issue here.

2) The absence of CONFIG_KEYBOARD_MATRIX=m is a big problem. Without that option the matrix-keypad module won't be built, meaning that the driver can never be loaded. If you go here again and ask for the option to be added to the standard configurations, explaining what it does and why, it is likely to be accepted (options that only cause a module to be built are generally uncontroversial).

3) Your overlay looks OK (I haven't tried it), except that it seems you haven't understood the "linux,keymap" property. Each entry is a packed (row,col,key) triple, e.g. 0x0201006c binds keycode 0x6c to row 2, column 1. The problems with your keymap are that it only covers 3 rows and 2 columns (like the example...) while you have 4 rows and 3 columns, and that it has repeated entries (which makes no sense).

ChristopheDupriez
Posts: 16
Joined: Tue Dec 25, 2012 8:38 am

Re: GPIO Matrix Keypad driver installation

Mon Jan 04, 2016 11:13 am

Thanks a lot PhilE for the precise information !

As you suggested, I submitted a documented issue on Github:
https://github.com/raspberrypi/linux/issues/1249

I will correct the Keymap and retry... But I am unsure of the hardware configuration expected by the driver (I suspect it needs external pull ups that I did not placed). So before changing that, I will see if the somebody knows a solution about the Kernel crashes...

I wish you a very nice day (and New Year !!! ),

Christophe

ChristopheDupriez
Posts: 16
Joined: Tue Dec 25, 2012 8:38 am

Re: GPIO Matrix Keypad driver installation

Tue Jan 05, 2016 10:58 am

Indeed, reading the code of the Linux Matrix Keypad driver shows that external pulldown resistors are needed (internal pulldown are not activated). A configurable option should be added for that: to test it: to develop that I would need to invest in a Kernel compilation framework: not much time for that... Probably easier to add room for resistors (and probably some for surge protection too) on our future PCB...

User avatar
joan
Posts: 14019
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: GPIO Matrix Keypad driver installation

Tue Jan 05, 2016 11:53 am

You posted pigpio code as part of the github issue.

I corrected it not compiling by commenting out lines 66 and 67. I then commented out the sleeps in lines 131 and 132 so it runs much faster.

After 6 hours there have been no crashes.

I suggest you look at what else you are doing on the Pi as the source of the kernel messages.

ChristopheDupriez
Posts: 16
Joined: Tue Dec 25, 2012 8:38 am

Re: GPIO Matrix Keypad driver installation

Wed Jan 06, 2016 4:35 pm

Thanks Joan !

As I transfer files by cut&paste from the PuTTY windows to my PC browser, lines 66&67 in keypadClass2.py.txt where indeed duplicated. Sorry about that.

Nothing serious runs in the Rpi (RpiMonitor has now been added tough).
As I explain on GitHub ( https://github.com/raspberrypi/linux/issues/1249 ), I arrive to the conclusion that the culprit is changing too often back and forth from input to output mode. I can live without changing it and it seems to work now (I have to wait for tomorrow!)

It does not happen on your computer and this may be a clue: I am running on the latest firmware and Raspbian + Rpi 2 Model B.
Are you running an older version? with/without the device tree ?

User avatar
joan
Posts: 14019
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: GPIO Matrix Keypad driver installation

Wed Jan 06, 2016 4:42 pm

I tested on a Pi Zero with 4.1.15+ #830. I have no idea how up to date Raspbian would have been. I guess fairly up to date.

I'll try on a Pi2 at some stage unless this is resolved.

Your screen shot shows 1-wire being read. What is reading 1-wire and how often?

ChristopheDupriez
Posts: 16
Joined: Tue Dec 25, 2012 8:38 am

Re: GPIO Matrix Keypad driver installation

Fri Feb 26, 2016 7:08 am

I read 1-Wire sensors every 15 seconds (two of them for the moment) through an I2C interface (AB Electronics 1-Wire interface for RPi).

I went to directly scan the matrix with GPIO, encounter a bug with mode switching (see other post viewtopic.php?f=66&t=108461&p=913326#p913326 ) and gave up with this approach...

Return to “Device Tree”