Moode Forum

Full Version: power control an external amplifier
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
There are several options available to use the GPIO to control the rasperry (as input), but I'm looking for the other way arround. I have an external amplifier I want to switch on / off by moode with an relay controlled by the GPIO pins.

There is a script available see below, but it would be nice if that could be integrated into moode software / GUI direct, maybe even have the option to display a button which then activates a GPIO pin.



moodeaudio.org > Moode Forum › moOde audio player › FAQ and Guides › Activate relay upon audio output with python
The challenge is that there are many different scenarios for Amp On/Off. For example below is a script that can handle 2 Amps. IIRC it was run from some selections on the main Menu. Other users want the Amp to turn off when Menu, Power, Shutdown. Other requests I've seen are to turn the Amp off after a delay when music has stopped playing or turn it off based on Clock Radio off time.

Code:
#!/bin/bash

# Initialize GPIOs
if [[ $1 = "init" ]]; then
    /usr/local/bin/gpio -g mode 23 out
    /usr/local/bin/gpio -g mode 24 out
    exit
fi

# Switch On/Off
if [[ $1 = "switch" ]]; then

# Amp 1
    if [ $2 = "On" ]; then
        /usr/local/bin/gpio -g write 23 1
    fi
    if [ $2 = "Off" ]; then
        /usr/local/bin/gpio -g write 23 0
    fi

# Amp 2
    if [ $3 = "On" ]; then
        /usr/local/bin/gpio -g write 24 1
    fi
    if [ $3 = "Off" ]; then
        /usr/local/bin/gpio -g write 24 0
    fi
    exit
fi

If the feature could be generalized to easily accommodate the different usage scenarios it would prolly be something that could be added to moOde.

ETA: Added the example script.
(09-28-2021, 07:56 PM)Tim Curtis Wrote: [ -> ]The challenge is that there are many different scenarios for Amp On/Off. For example below is a script that can handle 2 Amps. IIRC it was run from some selections on the main Menu. Other users want the Amp to turn off when Menu, Power, Shutdown. Other requests I've seen are to turn the Amp off after a delay when music has stopped playing or turn it off based on Clock Radio off time.

... and amps are all different. If you want to get the power state of mine, you need to send #01,1\r over a serial line (9600 baud), read the response and then flag the "power button" as on if the amp sends #02,1,01 as reponse, and off if the response is #02,1,0\r

On top you could read out the input source selector, which adds 10 additional responses to a command...

I don't see a chance to implement any amp steering software into the frontend of moode, because as said: too many options. The web page for steering mine (still working on it) currently looks the following way:[Image: MhhqdCI.png]

It still lacks the power button to shut down the pi on command and to display the current state (on/off) and will run as webserver on an ESP8266 with the required connectors. The idea is to use the ESP to turn on/off the amp, mute it, change the input source and either automatically shutdon the pi when I turn the amp off (by constantly monitoring the power state of the amp or override this shutdown if I enable a yet to be defined switch, or shut it down on command (another power button).

Side note: as I have no clue if the ESP can run the (async) webserver pluse the constant monitoring loops and handle the shutdown protection flag, I might have to use another SBC as man in the middle to forward the software requests to the amp (2x serial data in/out) and the pi monitoring/shutdown. An arduino pro mini 3.3V looks promising, even without sleep commands it only adds 13mA/3.3V to the total power consumption of around 75ma/3.3V the ESP requires - which by the way is way lower than the 200mA/5V a pi draws even when shut down.
(09-28-2021, 07:56 PM)Tim Curtis Wrote: [ -> ]
Code:
#!/bin/bash

# Initialize GPIOs
if [[ $1 = "init" ]]; then
    /usr/local/bin/gpio -g mode 23 out
    /usr/local/bin/gpio -g mode 24 out
    exit
fi

# Switch On/Off
if [[ $1 = "switch" ]]; then

# Amp 1
    if [ $2 = "On" ]; then
        /usr/local/bin/gpio -g write 23 1
    fi
    if [ $2 = "Off" ]; then
        /usr/local/bin/gpio -g write 23 0
    fi

# Amp 2
    if [ $3 = "On" ]; then
        /usr/local/bin/gpio -g write 24 1
    fi
    if [ $3 = "Off" ]; then
        /usr/local/bin/gpio -g write 24 0
    fi
    exit
fi

Example script

I think it would be nice to add an on/off switch to the main menu (e.g. above the "Power" option), and once moOde done booting up, use this switch to turn the amp on or off as you like.