Pirate audio, Shutdown button

Hi there,

So I am currently using the pirate audio “headphones” board and I was wondering if there was a way to have one of the buttons (for example the play/pause one) do a different action when hold (you will have understood, a shutdown).
Any idea?

Thx!

There is likely a couple of ways to do that.
There is a dtoverlay for shut down, dtoverlay=gpio-shutdown
By default its tied to GPIO 3, grounding GPIO 3 will have Raspbian do a proper shut down. It can be mapped to another pin though. If you wanted it mapped to Button X it would be as follows
dtoverlay=gpio-shutdown,gpio_pin=16,active_low=1,gpio_pull=up
I don’t know how you set it for a long button press though?
The Pirate audio pinout is here, which shows what GPIO the buttons are wired too.

In python you can run os.system("sudo shutdown now -P") and Raspbain will do a shutdown. You’d have to code up a file to watch the button for a long press. And have that file run on bootup with crontab etc. I do it this way on a couple of my headless setups, I just add the shutdown to my already running python file. I do it via GPIO commands. GPIO.add_event_detect(5, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)
. There is more to it than that one line but that’s the gist of how it goes.

Thanks! However, will it not interfere with the predefined actions of the button?

With no detection of a long press, Yes it will overide the normal function.
Looking for a long button press should be doable with the GPIO Python method.
Another way is to add another button, say with the Button shim and use one of its buttons.

Okay thanks I’ll try to do this then 😊
(I’m trying not to had any hardware if possible but thx!)

The Button Shim requires soldering, just so you know. I was hoping it was like the Fan Shim or LED Shim but it’s not. You could solder it right to the Pi Zero’s GPIO, then plug the Pirate Audio in on top.
I don’t see any GPIO conflicts, the Button Shim uses i2c and the Pirate Audio doesn’t.

Hey! so you know, it worked perfectly ^^
take a look at my whole project here : https://github.com/G-a-v-r-o-c-h-e/PIpod-Nano !

Nice, thanks for posting back with your results and your how to link.=)

1 Like