RPi 3, Hifiberry AMP2, rotary encoder, on/off switch

Raspberry Pi related support

Re: RPi 3, Hifiberry AMP2, rotary encoder, on/off switch

Postby breizheau » 30 Dec 2017, 12:49

Thank you for the tips an remark.

So i need 5VDC relay (i have some) who will be fed by the 5VDC of the USB port.

I start to understand....

The RPI is switched OFF :
- no 5VDC at the output of the USB port
- the RED LED is fed by the 5VDC of the GPIO to show that RPI is OFF or not started yet
- so the relay is OFF, the only thing you can do is to feed the P6 (RUN) contact to "reset" the RPI and start it

The RPI starts after pushing the momentary switch :
- the RED LED is still RED until the GPIO26 (for you) is fed after the start of the RPI

The RPI is ON :
- the relay is fed by the 5VDC of the USB port, the contacts switch
- the "momentary button contact" of the relay switches so P6 (RUN) cannot be fed by doing a mistake
- the "LED contact" of the relay switches so the RED LED is not fed anymore but the GREEN YES
- the only action you do is to switch off

Very clever !!!!!!

I think this function can be be done easily with the Runeaudio GPIO addon (see the attached file)
Attachments
RUNEAUDIO - GPIO PLUGIN - ON FUNCTION.JPG
RUNEAUDIO - GPIO PLUGIN - ON FUNCTION.JPG (57.8 KiB) Viewed 2543 times
Rpi 3 B V2 (2015)
RuneAudio last Beta 0.4b version (2017)
NAS Synology
breizheau
 
Posts: 4
Joined: 29 Dec 2017, 17:52

Re: RPi 3, Hifiberry AMP2, rotary encoder, on/off switch

Postby pez » 30 Dec 2017, 17:40

Oh yes, that's nice!
Actually, that would have spared me the soldering on the USB+5V pins...
But pay attention to the current drawn by the relais. I guess it would be important to use a transistor just like for the LEDs to amplify the GPIO signal to a higher current from the +5V supply.
Also i realise that a simple script on startup to turn on a GPIO could have done the job too. Maybe i'll try that, not using the USB+5V.
EDIT: Here's an my actual scheme for the relais and the script is:
Code: Select all
#!/usr/bin/env python2
# relais.py

# IMPORTS
import RPi.GPIO as GPIO

#GPIO Setup
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)

RELAIS = 16

GPIO.setup(RELAIS,GPIO.OUT, initial=GPIO.HIGH)

# end of programm
Attachments
relais_simple2.png
relais_simple2.png (35.98 KiB) Viewed 2521 times
RPi 3 model B
Hifiberry AMP2
runeaudio 0.4 beta
work on autonomous hifibox in progress:
Rotary encoder, I/O witch, status and volume LEDs: DONE
design of housing: almost done
pez
 
Posts: 20
Joined: 19 Nov 2017, 18:20
Location: Austria

Re: RPi 3, Hifiberry AMP2, rotary encoder, on/off switch

Postby breizheau » 31 Dec 2017, 08:40

I have a small well integrated +5VDC PSU in a box and i think i'll use it. No need to have an overkilled one for this function !

I have to build a pretty nice one (16 or 18VDC) to power the AMP2 'coz i don't want to use a laptop switching PSU.
I did few years ago DIY my own amp, DAC (external, balanced ouputs, modified output stages with Beyerdynamic microphone transformers and symetric chips, a nice job based on "almost ready to use" project).

I have to check my boxes to find transistors, resistors, relays and so on. I think i still have audio grade toroids transformers with multi outputs.

For the hardware part, i have good skill.
But i'll need help for the software part...... To be honest, i have no idea HOW to integrate your code lines in Runeaudio !!!!!

I have only succeeded to activate the add-ons option with SSH connection and copy/paste. That was for me a challenge !!!!!

I have to find out my encoders. I'll take photos to show what i have and what i'll like to do..... ;)
Rpi 3 B V2 (2015)
RuneAudio last Beta 0.4b version (2017)
NAS Synology
breizheau
 
Posts: 4
Joined: 29 Dec 2017, 17:52

Re: RPi 3, Hifiberry AMP2, rotary encoder, on/off switch

Postby sonycman » 31 Dec 2017, 13:13

Merry Christmas to you, guys!

pez
Can you, please, show me contents of the hw_poweroff.py script?
Very interested in making a solid case with power supply for my RuneAudio RPi3 so that it could power on/off (completely cut off the power from RPi) by the front panel button.

Your schematics was very helpful, thanks again!
sonycman
 
Posts: 11
Joined: 30 Dec 2017, 14:33

Re: RPi 3, Hifiberry AMP2, rotary encoder, on/off switch

Postby pez » 01 Jan 2018, 15:21

Hi sonycman,
here's the poweroff script:

Code: Select all
#!/usr/bin/env python2
# hw-poweroff.py
import RPi.GPIO as GPIO
# import time
import subprocess
GPIO.setmode(GPIO.BCM)

# Select unused GPIO header pin to be used for shutdown
InputPin = 26

# Set selected pin to input, and enable internal pull-up
GPIO.setup(InputPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)

# Wait for a button press on the selected pin (pulled to ground, falling edge)
GPIO.wait_for_edge(InputPin, GPIO.FALLING)

# When pressed, execute a shutdown, or any other command
print "*** Soft shutdown activated ***"
subprocess.call("shutdown now", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

# End of program


And here the service file to start that at boot:
Code: Select all
[Unit]
Description=RuneAudio Poweroff
After=mpd.service

[Service]

ExecStart=/usr/bin/python2 /home/root/hw-control/hw_poweroff.py

[Install]
WantedBy=multi-user.target


It's gonna be interesting how you will manage to completely and safely cut power from the Pi with a script. Looking forward to that!

@breizheau:
I can try to guide you through the coding part, although my focus is more on the hardware side too and i'm also copy pasting code snippets. :?
Do you know the basic unix commands to navigate in your filesystem?
If not here they are:
https://wiki.archlinux.org/index.php/core_utilities#Basic_commands
You will mainly use cd, cp, ls, nano (text editor) and chmod +x
Use cd.. to move up 1 directory and cd /root to get to your home directory

I have created a directory for all my script in /root
If you want a script to be started at boot you have to create a service file like the one above in this directory:
Code: Select all
/usr/lib/systemd/system


For both script and service it is important to make them executable with
Code: Select all
chmod +x


I think, that with the latest runeuadio installation you won't need anything more to install to run a simple python2 script like the one above, maybe be Frank can confirm that?

To try out whether a script works, you can simply type
Code: Select all
python2 scriptname.py


Is that about what you needed to start off?
Cheers and i am glad to help,
P
RPi 3 model B
Hifiberry AMP2
runeaudio 0.4 beta
work on autonomous hifibox in progress:
Rotary encoder, I/O witch, status and volume LEDs: DONE
design of housing: almost done
pez
 
Posts: 20
Joined: 19 Nov 2017, 18:20
Location: Austria

Re: RPi 3, Hifiberry AMP2, rotary encoder, on/off switch

Postby hondagx35 » 01 Jan 2018, 17:34

Hi pez,

Code: Select all
.....
# When pressed, execute a shutdown, or any other command
print "*** Soft shutdown activated ***"
subprocess.call("shutdown now", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

You should call "/svr/http/command/rune_shutdown poweroff" before this to stop mpd and unmount your shares.

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

Re: RPi 3, Hifiberry AMP2, rotary encoder, on/off switch

Postby sonycman » 01 Jan 2018, 18:00

Hello pez!
Thanks for the script.

I`am planning to use external small microcontroller which will process a power button presses and switch on or off dedicated linear supply which feeding RPi.

Power On is simple - press the button, mcu switches on the supply and RPi boots up.
Power Off is a little harder - mcu will monitor the USB +5v volatge from RPi (as on your schematics) and when it disappears switches off the supply completely.
Or in case the button was pressed to power RPi off - mcu will pull down GPIO pin 26 then wait for shutdown to complete (USB +5v disappear) then disable the power supply.

MCU will have his own power supply (little switcher), of course.

Seems not so hard :)
Vlad.

You should call "/svr/http/command/rune_shutdown poweroff" before this to stop mpd and unmount your shares.

Oh, thanks, Frank, I will take it into account.

But how it must be stated is the script, the right way? I`am a complete newbie in python :(
sonycman
 
Posts: 11
Joined: 30 Dec 2017, 14:33

Re: RPi 3, Hifiberry AMP2, rotary encoder, on/off switch

Postby pez » 04 Jan 2018, 12:48

Hey sonycman,
try that:
Code: Select all
print "*** Soft shutdown activated ***"
subprocess.call("/svr/http/command/rune_shutdown poweroff", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
subprocess.call("shutdown now", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)


pez
RPi 3 model B
Hifiberry AMP2
runeaudio 0.4 beta
work on autonomous hifibox in progress:
Rotary encoder, I/O witch, status and volume LEDs: DONE
design of housing: almost done
pez
 
Posts: 20
Joined: 19 Nov 2017, 18:20
Location: Austria

Re: RPi 3, Hifiberry AMP2, rotary encoder, on/off switch

Postby gasket » 03 Sep 2021, 12:25

Hi and sorry to return to this older thread. But I'd be interested to build @pez 's circuit. Judging by the schematic, I'll need:
- R1: 3k3
- R5: 43
- R4: 220
- On-Off-Switch
- LED1: green
- LED2: red
- Relais: FTR-B4G
- Transistor: BC337-40

I'm not so good at reading those things, but I gather that the middle row in the schematic represents the different legs on the relais?

For me it would be really helpful to have another image where I can see better what connects where on the relais. As far as I know, a relais has two connectors which control it and then another few that switch the secondary circuit.

Thanks in advance!
gasket
 
Posts: 1
Joined: 03 Sep 2021, 12:07

support RuneAudio Donate with PayPal

Previous

Return to Raspberry Pi

Who is online

Users browsing this forum: No registered users and 1 guest