• WANTED: Happy members who like to discuss audio and other topics related to our interest. Desire to learn and share knowledge of science required as is 20 years of participation in forums (not all true). There are daily reviews of audio hardware and expert members to help answer your questions. Click here to have your audio equipment measured for free!

Guide: EVAL1 off/on trigger

MSL

Member
Joined
Sep 19, 2021
Messages
17
Likes
19
Location
Denmark
I would like to share my setup which is used for AirPlay, and nothing more than that.
My equipment is as follows:
Purifi EVAL1
smps1200a400
SMSL SU-8s
Raspberry PI4
Elac FS407

My goal was to achieve the greatest possible user-friendliness, while not compromising on quality.

The first thing I did was buy two of these: https://www.conrad.com/p/tru-compon...cal-number-of-pins-2-mono-black-1-pcs-1567107
One connected to the smps1200a400 (GPIO / GND to PIN J5.1 / J5.5) and the other to the Raspberry PI (GPIO / BCM pin 21 and GND39) then just connect the PI to the smps1200a400 via a minijack cable
Notice my 5A fastblow fuse, unbelievable he does not add it :(

tempImageWrNPhp.jpg


My wish is that my PI should turn on my amplifier when music is playing, and turn it off when nothing is playing and after 5 minutes.

And here I must admit that I came across a difficult task. Because I can not code anything. And I could not find anything that lived up to what I want. Yes. Volumio has a plugin, it only works during play / pause and not when the music stops by itself.

So ... I had to get started :)

The following is code without explanation. The purpose is as written to get my amplifier to turn on when music is playing and turn off when no music is playing and after 5 min

Download, install Raspberry Lite https://www.raspberrypi.com/software/

Write an empty text file named "ssh" (no file extension) to the root of the directory of the card.

Create a text file called wpa_supplicant.conf, and place it in the root directory of the microSD card.

Code:
country=DK
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
network={
scan_ssid=1
ssid=“your_ssid”
psk="your_wifi_password"
}

From Mac via terminal
ssh [email protected]
Password:raspberry

Change the password!!!
sudo raspi-config

******************************
Update Raspiberry
******************************
sudo apt-get update
sudo apt-get upgrade
sudo reboot
******************************
Install shairport
******************************
https://github.com/mikebrady/shairport-sync/blob/master/INSTALL.md

sudo apt install --no-install-recommends build-essential git xmltoman autoconf automake libtool libpopt-dev libconfig-dev libasound2-dev avahi-daemon libavahi-client-dev libssl-dev libsoxr-dev

git clone https://github.com/mikebrady/shairport-sync.git
cd shairport-sync
autoreconf -fi
./configure --sysconfdir=/etc --with-alsa --with-soxr --with-avahi --with-ssl=openssl --with-systemd
make
sudo make install

sudo systemctl enable shairport-sync
sudo systemctl start shairport-sync
******************************
Shairport settings
******************************

sudo nano /etc/shairport-sync.conf

Code:
general =
{
        name = "Eigentakt";
        volume_range_db = 80 ;
        volume_control_profile = "flat";
};
sessioncontrol =
{
        run_this_before_entering_active_state = “home/pi/pyh/stop.py";
        run_this_after_exiting_active_state = “home/pi/pyh/start.py";
        active_state_timeout = 300.0;
};
alsa =
{
        output_device = "hw:1";
};

******************************
On/off on play/pause/music stops via GPIO
******************************

sudo apt install python3-gpiozero

sudo usermod -aG gpio shairport-sync

sudo mkdir pyh

cd pyh
sudo nano start.py

Code:
#!/bin/python3
from gpiozero import LED
from signal import pause

led = LED(21)
led.on()

pause()

sudo nano stop.py

Code:
#!/bin/python3
from gpiozero import LED
from signal import pause

led = LED(21)
led.off()

pause()

sudo chmod +x pyh/start.py
sudo chmod +x pyh/stop.py

******************************
Off on boot via GPIO
******************************

sudo mkdir logs

cd pyh
sudo nano launcher.sh
Code:
#!/bin/sh
# launcher.sh
# navigate to home directory, then to this directory, then execute python script, then back home

cd /
cd home/pi/pyh
sudo python3 start.py
cd /

sudo chmod 755 launcher.sh

sudo crontab -e
Code:
@reboot sh /home/pi/pyh/launcher.sh >/home/pi/logs/cronlog 2>&1

sudo reboot
Play and forget
 
Last edited:
OP
M

MSL

Member
Joined
Sep 19, 2021
Messages
17
Likes
19
Location
Denmark
If you find that the music stops and starts, then you are probably using the built-in wifi (Do not) use a cable.
If you do not want it, or have no other options, try the following:

sudo nano /etc/network/if-up.d/off-power-manager
Code:
#!/bin/sh
/sbin/iwconfig wlan0 power off

sudo chmod +x /etc/network/if-up.d/off-power-manager

or


aplay -l

sudo nano /etc/asound.conf
Code:
pcm.!default {
    type plug
    slave.pcm {
        type dmix
        ipc_key 1024
        slave {
            pcm "hw:1"
            period_time 0
            period_size 1920
            buffer_size 19200
        }
    }
}
ctl.!default {
    type hw
    card 1
}
 
Last edited:

bigjacko

Addicted to Fun and Learning
Joined
Sep 18, 2019
Messages
673
Likes
323
If you find that the music stops and starts, then you are probably using the built-in wifi (Do not) use a cable.
Thanks for documenting your way, although I can't follow much. Do you mean the built in wifi on pi is bad, and we should use ethernet cable or usb wifi module? I want to just use wifi as is, I would really hope the wifi on pi just works.:oops:
 
OP
M

MSL

Member
Joined
Sep 19, 2021
Messages
17
Likes
19
Location
Denmark
No. But all the problems I have had have been related to bad wifi connection and I have good connection and on a 1000/1000. If you experience that the music stops and starts inappropriately, then I experience that it is bad wifi.
If you want to follow my example, just take one line at a time :)
 

Honken

Active Member
Joined
Mar 10, 2020
Messages
279
Likes
443
Location
Scania
Many use metal cases for their Pis, that can make getting good reception difficult with the built in Wi-Fi. Not sure why people see this as an absolute must, at least not for audio applications.

Built in Wi-Fi or not, power saving should be disabled for your Wi-Fi interface if you wish to stream to your computer over Wi-Fi.
 
OP
M

MSL

Member
Joined
Sep 19, 2021
Messages
17
Likes
19
Location
Denmark
Many use metal cases for their Pis, that can make getting good reception difficult with the built in Wi-Fi. Not sure why people see this as an absolute must, at least not for audio applications.

Built in Wi-Fi or not, power saving should be disabled for your Wi-Fi interface if you wish to stream to your computer over Wi-Fi.
I can well understand you want to wrap it nicely. One just has to be aware that it has its drawbacks.

Regarding wifi, therefore:
Code:
#!/bin/sh
/sbin/iwconfig wlan0 power off
 
OP
M

MSL

Member
Joined
Sep 19, 2021
Messages
17
Likes
19
Location
Denmark
The pi>smps>amp
The smps get 0V from the pi on play and 3.3V on stop/pause
 
OP
M

MSL

Member
Joined
Sep 19, 2021
Messages
17
Likes
19
Location
Denmark
Hypex1200a400 have that functionality

Audio jack Socket connected to the smps1200a400 ( PIN J5.1/J5.5) and the other to the Raspberry PI (GPIO/BCM pin 21 and GND39)
 
Last edited:

abdo123

Master Contributor
Forum Donor
Joined
Nov 15, 2020
Messages
6,229
Likes
6,223
Location
Brussels, Belgium
Hypex1200a400 have that functionality

Audio jack Socket connected to the smps1200a400 ( PIN J5.1/J5.5) and the other to the Raspberry PI (GPIO/BCM pin 21 and GND39)

Oh cool thanks for sharing. I wish you did a thorough breakdown on these sort of details because that’s really what makes all of this possible.
 
OP
M

MSL

Member
Joined
Sep 19, 2021
Messages
17
Likes
19
Location
Denmark
By the way, I can add if you need 3V, and not 0V to trigger your smps to turn on, then swap these start.py and stop.py so it looks like this:

Code:
run_this_before_entering_active_state = “home/pi/pyh/start.py";
run_this_after_exiting_active_state = “home/pi/pyh/stop.py";
 
OP
M

MSL

Member
Joined
Sep 19, 2021
Messages
17
Likes
19
Location
Denmark
Update to stop.py and start.py

Code:
#!/bin/python3
from gpiozero import LED
from signal import pause

led = LED(21)
led.off()

pause()

There is no need to spend resources on keeping a script running, so therefore:

Code:
#!/bin/python3
import sys
from gpiozero import OutputDevice
from signal import pause

sys.path.append("/home/pi/pyh/start.py")
amp_on = OutputDevice(21)
amp_on.off()
quit()

And update start.py

Code:
#!/bin/python3
from gpiozero import OutputDevice
from signal import pause

amp_off = OutputDevice(21)
amp_off.on()
pause()

Find the right pin: https://pinout.xyz/pinout/pin40_gpio21
 
Top Bottom