GPIO amplifier control


#1

Hi, I did my best to search this forum for answer with no success.

I’m trying to find a way how to turn on and off amplifier using raspberry’s GPIO. Hardware is no problem. But I would like to know if there is a way how to control GPIO based on Mopidy activity? Like linking status “is playing” to GPIO, or to have a set of scripts running when stream started/stopped.

I found there is complex API for Mopidy, but that is far beyond my skills.

Any ideas? Thank you.


#2

I wouldn’t call the API complex, in fact I found it very easy to start with writing my own code :slight_smile: To run some code on player state changes just create a class deriving from mopidy.core.CoreListener and implement playback_state_changed method (docs: https://docs.mopidy.com/en/latest/api/core/#core-events).

Or You can take another aproach which I did and use pulseaudio events - this approach is better if You plan to use other audio sources on Your device (for example bluetooth playback or spotify connect). I wrote simple python script to handle this: https://github.com/mczerski/MyMusicBox/blob/master/usr/local/bin/speaker-on-off. If You use only alsa there is also a way to do same thing but You need to dig the internet for the solution.


#3

Your pulse event solution is nice, not come across that before.