Skip to main content
Share Your Experience: Take the 2024 Developer Survey
9 votes

Debouncing buttons with RPi.GPIO -- too many events detected?

As @joan points out, the bouncetime parameter in RPi.GPIO does almost exactly the wrong thing: it means when your switch bounces, you'll get the very first event, but that may not actually be ...
larsks's user avatar
  • 653
5 votes

Debouncing buttons with RPi.GPIO -- too many events detected?

The RPi.GPIO module does not really debounce switches. The parameter is used to ignore all subsequent changes for the bouncetime after the first change is reported. A correct implementation would ...
joan's user avatar
  • 71.1k
4 votes
Accepted

Why isn't gpio_set_debounce working in my Raspberry Pi Zero kernel module?

Looking at the header it appears gpio_set_debounce isnt actually implemented which would explain why your code changes didnt make a difference static inline int gpio_set_debounce(unsigned gpio, ...
Shreyas Murali's user avatar
4 votes
Accepted

Explanation of /proc/interrupts output

To the best of my knowledge, when you write software dealing with the interrupts, the IRQ number you will handle always comes from the first column. That's what the CPU is seeing. The 4th column ...
Dmitry Grigoryev's user avatar
4 votes

How do I implement an interrupt service routine on Raspberry Pi?

wiringPi uses interrupts, e.g. with the wiringPiISR function. pigpio uses interrupts, e.g. with the gpioSetISRFunc function. lgpio uses interrupts. e.g. with the gGpioSetAlertsFunc function. None of ...
joan's user avatar
  • 71.1k
3 votes

Debouncing buttons with RPi.GPIO -- too many events detected?

you can debounce buttons in software as described above. If you have an oscilloscope you can find the settling time and wait to take your measurement of button state. However, this can seriously ...
Inflexionist's user avatar
3 votes
Accepted

Fastest Hardware Interrupt software?

Python may not be the best choice if you have high or sustained data rates. You would be much better off using C. Try the following Python. It should capture all the interrupts although if you have ...
joan's user avatar
  • 71.1k
3 votes
Accepted

SPI control of WS2801 LEDs, fails when using GPIO interrupts

You may have identified the problem with a comment in your code. # Idle loop while 1: # Should I be doing something else here? pass The while loop will be using up all the spare CPU in the "...
joan's user avatar
  • 71.1k
3 votes
Accepted

How do I implement an interrupt service routine on Raspberry Pi?

There is no way to call userspace code from an ISR. Unlike system calls which run on the stack of the userspace program, interrupt handlers use internal kernel memory for the stack. Since that memory ...
Dmitry Grigoryev's user avatar
2 votes
Accepted

Inconsistency between GPIO block diagram and interrupt table in the BCM2835 datasheet

The BCM2835 datasheet that you referenced was written for the first generation Raspberry Pi, in which there were only 2 banks of GPIO pins. On the BCM2837 (the SoC used in the Raspberry Pi 3), there ...
John Duda's user avatar
2 votes
Accepted

RPi.GPIO interrupt

I am not sure about RPi.GPIO but Joan's pigpio library also offers callbacks so I will try to explain how this could be achieved with pigpio as an example assuming the technique can be transferred to ...
Ghanima's user avatar
  • 15.9k
2 votes

Use of gpio interrupt 2 rather than interrupt 3

I think you mean "gpio_int[0] to gpio_int[3]", right? Not "gpio_int[0] to gpio_int[4]". There is no gpio_int[4] mentioned in that manual. The bcm2835 manual that you referenced was written for the ...
John Duda's user avatar
2 votes
Accepted

SPI xfer2 callback possible?

When the spi.xfer2() call returns the SPI transfer has been completed. So unless you are doing the transfers in multiple threads there is no problem. E.g. the following will work. while True: ...
joan's user avatar
  • 71.1k
2 votes

GPIO.add_event_detect requires root

I'm not sure what is going wrong. My Python knowledge is sketchy. I'd dump the lambda and try the following (which works for me). #!/usr/bin/env python import RPi.GPIO as GPIO import time def ...
joan's user avatar
  • 71.1k
2 votes
Accepted

Communicate with GPIO HIGH/LOW between 2 PIs

No problem. It is safest to introduce a resistor. Connect any Pi ground pin to any of the other Pi's ground pins. Connect any Pi GPIO pin to any of the other Pi's GPIO pins via a resistor (if you ...
joan's user avatar
  • 71.1k
2 votes

How to use GPIO interrupts without going to multi-threading

This is a pretty general question. Not specific to the Pi. Anyhow what you need to do is set a flag in your callback. Something like was_called. Check this variable regularly in the main loop and ...
joan's user avatar
  • 71.1k
2 votes

GPIO configured as interrupts detects noise of the engine even if isolated

Any GPIO which is not connected to a voltage will float between high and low. You need to give the GPIO a fixed voltage by supplying a pull to 3V3 or a pull to ground. The weak internal pulls (about ...
joan's user avatar
  • 71.1k
1 vote

GPIO.wait_for_edge and signal.signal()

After changing the doTask function from From: def doTask(): """ A task that will be a daemon """ print "\n" print "Registering handler for:SIGTERM\n" signal.signal(signal.SIGTERM, ...
Pradeep Prakash's user avatar
1 vote
Accepted

GPIO switch interrupts work just once?

The main issue is that your calling main() from within the interupt handlers, this means they never fully finish. And usually global interupts are disabled while an interupt is being handled. Since it ...
Chad G's user avatar
  • 1,053
1 vote
Accepted

GPIO interrupt detecting wrong values

There are a couple of possibilities. button bounce delayed read In your case a combination of both is the most likely problem. Mechanical switches quite often make and break contact several times ...
joan's user avatar
  • 71.1k
1 vote

Unosquare.RaspberryIO: unregister from InterruptCallback

Surprisingly, there is no way. Here is the code: https://github.com/unosquare/raspberryio/blob/master/src/Unosquare.RaspberryIO/Gpio/GpioPin.cs The InterruptCallback cannot be changed once it is set (...
OyaMist's user avatar
  • 1,119
1 vote

GPIO.add_event_detect requires root

I just changed the GPIO setup and it works for me (remote connection to rpi over ssh). This is my complete code. I added the pullup, changed the pin to 12 and because I was lazy used the setmode GPIO....
Martin's user avatar
  • 13
1 vote

Giving a process exclusive use of a CPU core on a Pi 3

I'm not sure. You can use sched_setaffinity to limit a process to a single core. You can also use sched_setaffinity to tell another process not to use that core. man sched_setaffinity That might ...
joan's user avatar
  • 71.1k
1 vote

Clear GPIO Event Detect Status

You're right, it does seem illogical, although it is quite common in this scenario. Remember that you're not actually writing to memory - just the register that's mapped to that address. Although for ...
calcinai's user avatar
  • 179
1 vote
Accepted

Clear GPIO Event Detect Status

The values read/written to that peripheral address are under the control of the GPIO peripheral firmware. The firmware knows the difference between a read and a write and will perform the appropriate ...
joan's user avatar
  • 71.1k
1 vote
Accepted

How do I use a hardware interrupt to restart a main loop?

You need to check the state of the GPIO at regular points in your main loop and if necessary issue the continue command to restart the loop. e.g. if read(MY_INTERRUPT_GPIO) == 1: # high means ...
joan's user avatar
  • 71.1k
1 vote

Access Raspberry Pi3 Timer using Python

I want to know and manage all interrupts etc. There is no way to achieve what you want under Linux. Linux handles all interrupts. That being the case you will need to go bare metal or find an ...
joan's user avatar
  • 71.1k
1 vote

How can I detect how long a button is pressed?

Pushing the button for more than 4 seconds, there are two valid IF conditions. You can use else if and use a range for the second condition: if .1 <= buttonTime < 2: # Ignore noise ...
Joe Platano's user avatar
1 vote
Accepted

Volume dial - ADC interrupts with SPI

The datasheet will specify if the chip generates an interrupt or not. I don't see why it would. The normal procedure is assert SPI slave select and send command (which triggers a reading) then read ...
joan's user avatar
  • 71.1k

Only top scored, non community-wiki answers of a minimum length are eligible