Thank you for your donation!

Pi Zero w with Hifiberry miniamp question

I'm running moOde on a rpi zero w with hifiberry's miniamp which i integrated in an old bluetooth speaker (gutted the original internals) but i've run into an issue.

When the playback is stopped there's a low frequency hum on the speaker. Could this be because the miniamp stays turned on? Is there a way to add a function to moOde that when the playback stops it then turns off or mutes the power stage of the miniamp?

In the miniamp documentation there's a note that GPIO16 can be used to mute the power stage and GPIO26 can shut down the power stage completely but i have no idea how to add this or which config i would need to edit.

I did a bit of testing and searching on the forum. 

I found that if i bridge GPIO16 (mute) to GND the buzzing stops, great that's exactly what i want

Now for the code i found this thread

Maybe i can reuse the code posted there with a few adaptations. Will try that now. 

Any input or help is still greatly appreciated!
.:Biological Insanity:.
Ok, so i made this bash script (basically just swapped pin23 for pin16 from the link earlier)

set -e

#       Exports pin to userspace
echo "16" > /sys/class/gpio/export

# Sets pin 16 as an output
echo "out" > /sys/class/gpio/gpio16/direction

#time to wait untill the amplifier is turned off in seconds

#set variables

while true
       if cat /proc/asound/card0/pcm0p/sub0/status | grep -i RUNNING > /dev/null

       if [[ "$last_is_playing" -eq "0" && "$is_playing" =eq "1" ]]
               echo "Turning amplifier on"
               echo "1" > /sys/class/gpio/gpio16/value

       if [[ "$last_is_playing" -eq "1" && "$is_playing" -eq "0" ]]

       if [ "$off_timer" -ne "0" ]
               if [ "$off_timer" =eq "$off_timer_time" ]
                       echo "Turning amplifier off"
                       echo "0" > /sys/class/gpio/gpio16/value

       sleep 1

but when i run it i get line 6: echo: write error: Device or resource busy

i get that something's wrong in line 6, but i have no idea how to fix it  Sad
.:Biological Insanity:.

The gpio logic is more complicated than was allowed for in the script you copied.

If a gpio pin is already been exported then you'll get the message you see when you try to export it again. 

I suggest you consult Raspberry Pi documentation and forums to learn more and then expand your script to test whether the pin is already exported (and either use it or first unexport it and then export it again).


Forum Jump: