-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GPIO: polling a keyboard crashes the kernel after an hour or two... #1249
Comments
A few questions:
|
Thanks pelwell ! I am not overclocking.
The whole application works perfectly when I do not poll the keypad. I tested with two different RPi 2 model B. Have a nice day! |
keypadClass2.py.txt It crashes the Kernel even faster ! Pull-downs could be the problem for the Kernel ? |
My issue seems similar to: |
How are you using pigpio? Could you link to a full listing? pigpio C does allow the use of the SYSFS interface but it is discouraged except in exceptional circumstances which do not apply in your application. |
Dear Joan2937, In keypadClass.py.txt (1st message) and keypadClass2.py.txt (NOW 2 messages above) you will find the calls to pigpio Python interface. I also tested Rpi.GPIO with the same problems (may be a bit worse) _As the bug happens without key presses, one can test on any RPi even without any keypad plugged._ |
The answer to the question below may be the explanation + solution: |
@christophe-dupriez As the author of pigpio I'll point out that is rubbish. pigpio makes more use of /dev/mem than wiringPi which makes more use of /dev/mem than RPi.GPIO. |
Please excuse me, I did not meant to be rude in any way. _What I know:_ using Rpi.GPIO or pigpio, I have a Kernel Crash. _What I still have to test:_ using WiringPi, will it go better? Have a nice evening, Christophe |
Just had a look to WiringPi source code: it uses /dev/mem and recently began to use /dev/gpiomem too. |
Kernel crashes as fast with /dev/gpiomem (latest WiringPi2) than with /dev/mem ... I stopped changing pin modes from output to input (please look attached file keypadClass3.py.txt) and the Kernel seems to resist for now (3 hours later): wait & see after some days... |
Joan, as written here: |
So after 36h, the Rpi is still up & running.
My workaround being to alternate output for columns from 1 to 0, the danger is to shortcut two GPIOs when two button are pressed together on the same row: I will have to add resistors to my PCB: 1K ohms to limit current to 3ma when 2 keys on the same row are pressed at same time. |
I suspect a minimal test script (just a single .py file) that uses RPi.GPIO (which is the 'officially supported' GPIO python interface) that reliably causes the kernel to crash, will be a great help to the kernel developers in diagnosing this problem. |
Now it has been running for days without a hitch (KeypadClass4.py.txt above). I suspect mode change (input+pull-down / output) to be the problem: so the failing python file cannot be really simpler than KeypadClass3.py.txt (one to two hour before failure) provided above. I will modify it for RPi.GPIO Wednesday or Thursday, which is rather a straightforward task. (Suffix ".txt" added to the file name to make it accepted by this forum) |
I suspect if you can make your standalone-test-script crash the kernel in a shorter time-period (maybe by doing your mode-switches at a faster rate?) that would be useful too ;-) |
After "Fail Fast", "Crash Fast" ? I'll do my best! More seriously, I think it is a question of timing for the different operations. Like receiving an input interrupt when already switched to output mode. Or something related to setting input mode and then only the pull-down (would it be possible to switch both at the same time?)... To clear this issue (or document a good workaround) will be beneficial for everyone and especially me as I would not be obliged to add resistors to protect output GPIOs from being shortcircuited. |
Attached is a version of the program without sleep (except between write and read) and using the latest RPi.GPIO. It has crashed my Kernel in 15 minutes on a RPi 2 model B: I hope it is fast enough... |
@christophe-dupriez, did you make any progress? Today I had a crash on the current |
@PeterPablo What really solved my problem was to change the polling of GPIO for the keypad matrix so the pinmode is NEVER changed (I always read the 4 rows and send signal to the 4 cols). I suspect the GPIO Linux driver has some kind of interrupt being pushed too often if a pinmode change happens at some bad moment. But I do not have the time and the background needed to dig in the Linux GPIO driver code... |
Thank you for your instant response. I never change the pinmode, so my issue might be unrelated. I'll investigate, whether my python script could be changed to an interrupt kind of approach. My goal is to observe a rather slow TTL-like signal concerning it's state. |
I never got the kernel to crash when I tried - reproducibility has always been the problem. |
About 10 times per second, I change the value of 4 GPIO pins and read the value of 4 others. Removing the pinmode changes completely stabilized the system. @pelwell : 20th of January I attached above a version which was crashing after a quarter: did you tested it ? |
I did, but it didn't work for me. |
Oh Oh! This means I should try it also in different hardware configurations... |
Oh well, so I gave this another spin today and had reproduceable lockups after less then one minute, even when the USB hub was active (own power supply). @christophe-dupriez, your comment about NEVER changing the pinmode made me anxious and so I double checked my python script. I have two functions |
As my problematic version of the script would |
I am happy that publishing my problems saved some time to somebody else! As I am not using multiple process in parallels, I suspect the issue could be around interrupt processing at a low level in the GPIO driver, where somehow mode change could interfere with pin reading and/or writing. For instance, receiving an interrupt for an input pin change when the mode just changed for "writing". It could be even hardware interrupts not returning for some reason and stacking themselve as the crash is so violent, so rare and corrupting memory so badly. I have no time before Monday to try reproduce the problem on a RPi 3 without any connection with GPIO instead of RPi 2 with a keypad connected. |
My test ran for 24 hours without problems! Great! The message I once saw on the serial terminal was |
@christophe-dupriez has your issue been resolved? If so, please close this issue. Thanks. |
I did not heard anybody claiming the GPIO driver has been corrected. But I will test with a freshly updated machine... |
On 4.4 I still see the message |
The message is removed in the current kernel (c376c9f). On topic -- I reliable solved the kernel crashes by switching from "frequent polling/readout of the current GPIO state from several python processes" to "setting up the same interrupt in several python processes and only determining the GPIO state inside that function, which happens a lot less frequency". |
Closing this issue as questions answered/resolved. |
In Python, I poll rows and columns of a numerical keypad using GPIOs without added resistors
(I use the input pullups).
I followed this article:
http://www.instructables.com/id/Using-a-keypad-with-Raspberry-Pi/
_As the bug happens without key presses, one can test on any RPi even without any keypad plugged._
The GPIOs I use for rows and columns are:
ROW = [18,23,24,25]
COLUMN = [4,17,22]
After an hour or two, the kernel crashes badly using either "Rpi.GPIO" or "pigpio" (pigpio may be a bit longer to crash). The crashes are never the same and even the console frame buffer may be garbled.
I attach the keypadClass.py (.txt to make it accepted by GitHub) and keytest.py
I also attach photos of the Rpi console...
My question is: " what kind of workaroung could I follow to protect the Kernel from crashing when polling a keyboard ? "
Thanks a lot for your help !
Christophe
keypadClass.py.txt
keytest.py.txt
The text was updated successfully, but these errors were encountered: