For pimoroni pirate audio device users - python code to unleash the power of your hat

My unsolicited feature wish list!

  • Dim or turn off screen after X minutes of no audio playing. (so I can keep it in my room plugged in at night)
  • Wake screen when audio starts playing

Fantastic work AxLED. Im delighted with the way it works. Thanks a ton.
Also just wanted to point out that the volume up key is not working. Expecting a fix soon. :slightly_smiling_face:
Thank you very much

@spinkman
@sidrakes

at my installation [pi zero w] (also on 2nd SD-Card with clean install) it is working.

  • which button is not working?
    • X (upper right) or Y (lower right)?
    • i heared there are some pirate audio revisions that user different GPIO for one button, but if my plugin worked before the latest release should also work
  • did you try to deactivate and re-activate the plugin?
  • did you do a restart after plugin installation?
  • can you post your content of /boot/config.txt and /boot/userconfig.txt ?

@spinkman: you can turn of display by deactivating the plugin, if this works as workaround for your night dim request.

AxLED

@AxLED
My installation is also on a pi zero w with Pirate audio headphone dac. I downloaded and flashed volumio few hours back on a freshly formatted sd card. Answer to the other questions are as follows

  1. button Y is not working (both volume up function in the now playing menu and down function in the other menu are not working). And its only today that I read this thread and got information about this plugin being available in volumio. So didn’t get a chance to try the previous version.

  2. yes i tried deactivating and reactivating the plugin

  3. yes i restarted few times

  4. i will post the boot content shortly

Thank you
Regards
Sid

Have you tried the GPIO Control plugin, works well for me.
Pin 13 On when playing, Off when paused or stopped.

1 Like

I’m having trouble ‘coming back’ to volumio from airplay. The display and buttons sometimes freeze. Difficult to be certain how to replicate the problem, working on being a bit more helpful.

New build, Pirate audio plugin.

userconfig

### Start of parameters for pirateaudio plugin ###
dtoverlay=hifiberry-dac
gpio=25=op,dh
dtparam=spi=on
### Fix for Button X, Y of pirate audio ###
gpio=16=pu
gpio=20=pu
gpio=13=op,dl
### End of parameters for pirateaudio plugin ###
### Start of parameters for pirateaudio plugin ###
dtoverlay=hifiberry-dac
gpio=25=op,dh
dtparam=spi=on
### Fix for Button X, Y of pirate audio ###
gpio=16=pu
gpio=20=pu
### End of parameters for pirateaudio plugin ###
# Add your custom config.txt options to this file, which will be preserved during updates

config.txt

initramfs volumio.initrd
gpu_mem=32
max_usb_current=1
dtparam=audio=on
audio_pwm_mode=2
dtparam=i2c_arm=on
disable_splash=1
hdmi_force_hotplug=1
dtparam=spi=on
include userconfig.txt

#### Volumio i2s setting below: do not alter ####
dtoverlay=hifiberry-dac

looks like the update added to the bottom of the userconfig. might need to clean that up. i’m not sure what GPIO the ‘Y’ button uses. will have to troubleshoot after work :stuck_out_tongue:
thanks all!

I did find this pinout site that mentions

On older boards you might find button Y on GPIO 20. On newer boards this has been moved to GPIO 18 to free up PCM Data-in.

no mention of GPIO 18 in the userconfig.txt

I tried updating userconfig.txt
gpio=18=pu
that didn’t work

then I found GitHub - pimoroni/pirate-audio: Examples and documentation for the Pirate Audio range of Raspberry Pi add-ons that mentions the Y button is on GPIO 24 and that broke things more…

putting it all back… going back to work hehehe

@spinkmantest_gpio.zip (1,0 KB)
@sidrakes

lets start debugging.
Attached you will find the file test_gpio.py

  1. unpack the zip
  2. copy this file to your pi
  3. make it executable by sudo chmod +x test_gpio.py (in the folder where test_gpio.py is located)
  4. stop pirateaudio plugin via volumio GUI
  5. start test script by python test_gpio.py
  6. press your buttons, the script should output the GPIO number

If not all 4 buttons are working, try to change line 20 of test_gpio.py with a different GPIO number for the button which didnt work.

If you can tell me the gpio your hat uses, i try to guide you to a solution.

@spinkman
@sidrakes
about the output of your /boot/userconfig.txt. The values shouldn’t be twice.
The right values/content should be:

### Start of parameters for pirateaudio plugin ###
dtoverlay=hifiberry-dac
gpio=25=op,dh
dtparam=spi=on
### Fix for Button X, Y of pirate audio ###
gpio=16=pu
gpio=20=pu
gpio=13=op,dl
### End of parameters for pirateaudio plugin ###

Explanation:

  • gpio 25 is to make the pirate audio hat work at all
  • gpio 16 and 20 ar to set pull ups for button X an Y
  • gpio 13 is for controlling backlight led

AxLED

1 Like

@AxLED

volumio@ohc-speaker:~$ python test_gpio.py
buttons.py - Detect which button has been pressed
This example should demonstrate how to:
1. set up RPi.GPIO to read buttons,
2. determine which button has been pressed
Press Ctrl+C to exit!

Button press detected on pin: 6 label: B
Button press detected on pin: 5 label: A
Button press detected on pin: 16 label: X
initalisiere Shutdown

The Y button didn’t detect/show anything, no matter what order. I even reboot and tried again.
The button does work. I confirmed using the Mopidy build I had before and I tested it with another SD card.

I replaced my userconfig.txt with yours, rebooted, re-enabled the pirateaudio plugin. no dice. Y still doesn’t work. Eagerly looking forward to a solution! and perhaps I might fiddle with putting the back light on a timer or a timeout… but one thing at a time.

@spinkman

so your button Y is not working (so far), and it isn’t pin 20 (and not 5,6,16)
Your hat: pirate audio amp 3W

Please try the following:

  • stop pirateaudio plugin via volumio GUI
  • change line 20 in test_gpio from BUTTONS = [5, 6, 16, 20] to BUTTONS = [5, 6, 16, 18]
  • change line in /boot/userconfig.txt from gpio=20=pu to gpio=18=pu
  • start test script by python test_gpio.py in commandline
  • press your buttons, the script should output the GPIO number

AxLED

@AxLED

My hat: Pirate Audio 3w

Changed button 20 to 18.
output

volumio@ohc-speaker:~$ python test_gpio.py
buttons.py - Detect which button has been pressed
This example should demonstrate how to:
1. set up RPi.GPIO to read buttons,
2. determine which button has been pressed
Press Ctrl+C to exit!

Button press detected on pin: 5 label: A
Button press detected on pin: 6 label: B
Button press detected on pin: 16 label: X
initalisiere Shutdown
Button press detected on pin: 6 label: B
Button press detected on pin: 6 label: B
Button press detected on pin: 16 label: X
initalisiere Shutdown
Button press detected on pin: 5 label: A

The difference this time is that after the X button is pressed, I’m able to continue to press other buttons. still no Y button tho…

Oh!
success!!
Changed button 18/20 to 24

Button press detected on pin: 5 label: A
Button press detected on pin: 6 label: B
Button press detected on pin: 16 label: X
initalisiere Shutdown    
Button press detected on pin: 24 label: Y
Button press detected on pin: 24 label: Y

so, it is back to the link I posted that mentions the Y button is on GPIO 24 but I didn’t understand how to assign the button… I’ll play around some more.

@spinkman

thanks for your response, so your Y button is 24.
Your hat: pirate audio amp 3W

Please try the following:

  • stop pirateaudio plugin via volumio GUI
  • change directory to path /data/plugins/miscellanea/pirateaudio
  • change line 80 in display.py from BUTTONS = [5, 6, 16, 20] to BUTTONS = [5, 6, 16, 24]
  • change line 436 in display.py from if pin == 20: to if pin == 24:
  • change line in /boot/userconfig.txt from gpio=20=pu to gpio=24=pu
  • reboot your pi
  • activate pirateaudio plugin via volumio GUI

AxLED

100% success!

change line 80 in display.py from BUTTONS = [5, 6, 16, 20] to BUTTONS = [5, 6, 16, 24]
change line 436 in display.py from if pin == 20: to if pin == 24:
change line 458 in display.py from for x in [5, 6, 16, 20]: to for x in [5, 6, 16, 24]:

I had already changed line 80 in testing but didn’t venture that far down in display.py
Thank you @AxLED for your support. much appreciated.

In my attempts to free up some GPIO pins by wiring the Pimoroni to the pi rather than plugging it into the pi socket I used this diagram from the web (although I can’t remember where I found it)

However, after much fiddling, I found that my board also needs pin 17 (3.3v) to work. Hope this saves someone some time!

For info: the image above can be found at Pirate Audio 3W Amp at Raspberry Pi GPIO Pinout.

1 Like