Amplifier automatic on/off

Build/modify/repair equipment and improve systems performance by yourself

Amplifier automatic on/off

Postby dwijtsma » 20 Feb 2015, 09:55

I already started such a topic in the feature request section, but this is a better place for it.

What I find so great about Runeaudio is that it makes live easier. No fiddling around with CD's or LP's, just all music at one place. To make live even more easy (read lazy 8-) ), I don't want to turn on my amplifier by hand any more.

So yesterday I started reading and coding. I now have a python script that toggles an LED. :lol: The LED turns on when music is streamed and turns off 15 minutes after streaming is stopped. Using systemd it also runs after a reboot. I want to replace the LED with a simple circuit that turns the amplifier on and off.

I will post the circuit diagram this evening. Constructive criticism is welcome!
Last edited by dwijtsma on 25 Mar 2015, 12:21, edited 1 time in total.
Audio gear: RuneAudio on Raspberry Pi 2 + Dr. DAC nano, Marantz pm66se, Avalon Avatar
dwijtsma
 
Posts: 51
Joined: 03 Nov 2014, 20:16

Re: Auto amplifier on/off

Postby dwijtsma » 20 Feb 2015, 14:45

Here the circuit diagram:
Image

Switch S1 can be set in three positions:
1 - Amplifier on/off controlled by raspberry
2 - Amplifier off
3 - Amplifier on

The raspberry pi GPIO controls the relay. Capacitor added because I don't want the raspberry to reset because of a brown out. The B+ and Pi 2 already reset at 4.65V if I'm correct.

Here the python script I use:
Code: Select all
#!/usr/bin/python

import RPi.GPIO as GPIO
import time
from mpd import MPDClient

#Auto switch off time in seconds
AsoTime = (15*60)

#Initialise amplifier control pin
CtlPin = 38
GPIO.setmode(GPIO.BOARD)
GPIO.setup(CtlPin, GPIO.OUT)

#Connect to MPD
try:
   client = MPDClient()
   client.connect("localhost", 6600)
except:
   print('Could not connect to MPD client')

try:
   Timer = 0      #ASO timer
   Output = 0      #Output level of amplifier control pin
   while True:
      #client.status()['state'] can be 'play', 'stop' or 'pause'
      if client.status()['state'] == 'play':
         Output = 1
         Timer = 0
      #'stop' or 'pause'
      else:
         #Set timer
         if Timer == 0 and Output == 1:
            Timer = AsoTime
         #Count down
         if Timer > 0:
            Timer -= 1
            if Timer == 0:
               Output = 0

      time.sleep(1)
      print(Timer)
      GPIO.output(CtlPin, Output)

except KeyboardInterrupt:
   print('Program stopped')
   print('GPIO cleaned up')
   #Free IO
   GPIO.cleanup()

except:
   print('Unknown error or exception occurred!')


Here the service file used by systemd:
Code: Select all
[Unit]
Description=Amplifier power control
After=network.target

[Service]
ExecStart=/usr/bin/python /usr/local/test/gpio_test.py
TimeoutSec=0
Restart=always
RestartSec=1
StartLimitInterval=30
StartLimitBurst=20

[Install]
WantedBy=multi-user.target

If still need to search for a nice case for this. Any good ideas? Feedback appreciated.
Audio gear: RuneAudio on Raspberry Pi 2 + Dr. DAC nano, Marantz pm66se, Avalon Avatar
dwijtsma
 
Posts: 51
Joined: 03 Nov 2014, 20:16

Re: Auto amplifier on/off

Postby hondagx35 » 21 Feb 2015, 00:29

Hi dwijtsma,

nice project you are working on.

What I find so great about Runeaudio is that it makes live easier.

You only forgot to mention that it sounds good.

Thank you for the detailed description, I'm sure that this topic will be useful for somebody in the future.
Sharing your project is a good way to contribute to this project!

Frank
User avatar
hondagx35
 
Posts: 3041
Joined: 11 Sep 2014, 22:06
Location: Germany

Re: Auto amplifier on/off

Postby dwijtsma » 22 Feb 2015, 13:28

My current script doesn't check if airplay is used. So I now connect to the redis server and check if 'activePlayer' is 'Airplay', but is their a way to check if airplay is really streaming music or not? Help appreciated!
Audio gear: RuneAudio on Raspberry Pi 2 + Dr. DAC nano, Marantz pm66se, Avalon Avatar
dwijtsma
 
Posts: 51
Joined: 03 Nov 2014, 20:16

Re: Auto amplifier on/off

Postby hondagx35 » 23 Feb 2015, 18:28

Hi dwijtsma,

but is their a way to check if airplay is really streaming music or not

No there is no simple solution for that.

What would work for all players is to check the alsa state.

playing:
Code: Select all
[root@runeaudio ~]# cat /proc/asound/card1/pcm0p/sub0/hw_params
access: RW_INTERLEAVED
format: S16_LE
subformat: STD
channels: 2
rate: 44100 (44100/1)
period_size: 64
buffer_size: 16320


not playing:
Code: Select all
[root@runeaudio ~]# cat /proc/asound/card1/pcm0p/sub0/hw_params
closed
User avatar
hondagx35
 
Posts: 3041
Joined: 11 Sep 2014, 22:06
Location: Germany

Re: Auto amplifier on/off

Postby dwijtsma » 23 Feb 2015, 19:17

Thanks for the tip! This is a much beter way to go.
Audio gear: RuneAudio on Raspberry Pi 2 + Dr. DAC nano, Marantz pm66se, Avalon Avatar
dwijtsma
 
Posts: 51
Joined: 03 Nov 2014, 20:16

Re: Auto amplifier on/off

Postby dwijtsma » 18 Mar 2015, 20:35

This topic has been silence for a while, but my project has made some big steps. I abandoned my previous approach and went full analog! 8-)

My amplifier has two inputs: Rune audio and my TV. Therefore I made some electronics to turn my amplifier on if any of the two plays music and turn it off after roughly 20 minutes without music. Next to that I use a signal relay to send the right audio signal to my amplifier.

Now I won't have to touch my amplifier ever again! :ugeek:

For anyone that also wants to build it, here is the schematic:
Image

And a picture of the result:
Image

I tested it and it works nicely after some small changes. Hopefully I have it build in a case next week. More pictures will come.

PS: A lot of credits go to Rod Elliott for his nice designs that I used: http://sound.westhost.com/project38.htm
Audio gear: RuneAudio on Raspberry Pi 2 + Dr. DAC nano, Marantz pm66se, Avalon Avatar
dwijtsma
 
Posts: 51
Joined: 03 Nov 2014, 20:16

Re: Amplifier automatic on/off

Postby regs » 18 Dec 2015, 18:00

Hi There!

Great project!
I'm also thinking something similar so I may use your schematics.

I also noticed that many times internet radios go silent after a while.
So first of all I think I will use your code and modify it to detect if the output is silent for a half minute then turn the playing off and on again.

Anyway great project, Thank you!
Cheers!
regs
 
Posts: 2
Joined: 18 Dec 2015, 17:47

Re: Amplifier automatic on/off

Postby dunghnguyen » 02 Apr 2016, 06:31

This is great ! Thanks there :)
dunghnguyen
 
Posts: 228
Joined: 08 Mar 2016, 07:48

Re: Amplifier automatic on/off

Postby dunghnguyen » 03 Apr 2016, 04:03

@regs: got what you are worried but his dyi is just off after 15 ~ 20 minutes without signal ;)
dunghnguyen
 
Posts: 228
Joined: 08 Mar 2016, 07:48

support RuneAudio Donate with PayPal

Next

Return to DIY and tweaks

Who is online

Users browsing this forum: No registered users and 0 guests