Just add a shutdown button, it will be easy, they said ...

Finally, one of our Art projects is selling. My partner asked me to add a power-down button so the
museum personnel has an easy way to power off the installation. Adding that to a Raspberry Pi cannot be very difficult using one of the GPIO pins or so I thought.

So the first iteration was something like this: a small Python program that will detect a falling edge on an input GPIO input. Tests worked ok, I was using the internal pull-up resistor and a normally-open switch would connect the input to ground. Once the falling edge was detected a detailed shutdown sequence would be initiated (to avoid any damage a heated element would need to be retracted by a servo).

As usual, things worked well in theory and in the lab, but failed miserably in the real test. So I thought that, perhaps, the wiring was too long and close to a power line and that might be picking up some noise, that eventually triggered an unwanted shutdown (sometimes even before the system started working ;-)

So the second step was to add an external pull-up resistor, that, as you can guess, did not help. WTF? Not happy with that result, I thought a capacitor across the switch was the answer, but still, random events would trigger an unwanted shutdown. What could be the cause of such a pattern?

Time to get back to the lab, connect a display and keyboard to the Raspberry and start some more debugging. One thing I noticed on the display was the occasional appearance of a lightning bolt sign on the top right area of the display (this is a sign that power supply voltage is too low). Other than that the board seemed to work ok, but I realized the shutdown event was triggered without any change on the input pin.

Not always, but many times, I noticed the under-voltage condition (signaled by the lightning bolt) and the GPIO detecting an unexisting falling edge on the shutdown input happened at the same time. So my guess is that working with such a power supply might be a bad idea. But when I replaced it with another power supply that did not exhibit that problem I still have had a few glitches that detected a non-existent falling edge on the input.

The problem is that the instruction GPIO.add_event_detect(13, GPIO.FALLING, callback=shutdown, bouncetime=100) sometimes performs a callback without the input pin being low for reasons unknown. This is happening in a Raspberry Pi 3 B V1.2.

So my solution has been to add an additional check within the callback function, to double-check whether the input value is low and, if so, to perform the shutdown. Otherwise, just ignore that glitch. It might seem like it could be a debouncing problem but changing the bouncetime did not help either. Besides, the input is now quite low-impedance and my oscilloscope probe cannot catch any offending short-duration edge happening either.

Comments

Popular posts from this blog

VFD control with Arduino using RS485 link

4xiDraw: Another pen plotter

How to get sinusoidal s-curve for a stepper motor