Optical fibre streamer

 

Optical fibre streamer

By Lennart Linderoth / Website

HifiBerry Digi for streaming to amplifier.
The main reason for my projekt is to deliver an optical output to my wireless headphones, but any amplifier that can take TOS-link or coax will do. I had an old Raspbery v2 laying around, but a 2B/3 is also good. Just select the appropriate DIGI-board. The Raspberry with the board is hosted in a cabinet where I have an ON- and OFF-button so the Raspberry can be switched on and given a shutdown command by hand.
The Raspberry´s 5V is fed through a relay that is held on by a GPIO-out as long as the Pi is running. By pressing the OFF-button, a script issue the shutdown-sequence and takes down the GPIO-pin. The relay switches of after about 60 s by a timer and the Pi looses it´s 5V.
All is built in a neat box with the buttons at the front. The software I use for playing music is Volumio and it´s version 1.55. Haven´t tried on veresion 2 yet as it´s still under changes.

Which parts where used for this project?

HifiBerry Digi, Raspberry 2, Some electronics and a relay, A 5V/2A PSU, Buttons and a cabinet.

Anything else you like to tell us about your project?

The code that runs to control the relay-pin and the shutdown sequence is here: Sorry for the formatting. It dissapears in the uplopad. Make a python script and call it shutdown.py. I create mine in a directory /usr/bin/start-stop cd / cd /usr/bin/ sudo mkdir start-stop cd /start-stop sudo nano shutdown.py ----------------------------------------------------------------------------- #!/usr/bin/python # Version 0.1 # Original by LLh 2015 # The Pi uses GPIO24 and GPIO25 to communicate to the supply module. The GPIO24 # and GPIO25 pin is located on pin 18 and 22 of the board. # Import the modules to send commands to the system and access GPIO pins from subprocess import call import RPi.GPIO as GPIO # Set pin numbering to Broadcom numbering GPIO.setmode(GPIO.BCM) # Define a function to run when an interrupt is called def shutdown(): call('sudo halt', shell=True) # set GPIO 24 (pin 18) to input, and enable the internal pull-up resistor GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP) # Set up GPIO 25 (pin 22) as output and set HIGH. Enable pull-down resistance GPIO.setup(25, GPIO.OUT, pull_up_down=GPIO.PUD_DOWN) GPIO.output(25, GPIO.HIGH) # This definition will detect a falling edge on channel and debounce it # with 200mSec.The interrupt service routine halt gets called when the event # is detected and that code will handle the shutdown GPIO.wait_for_edge(24, GPIO.FALLING, bouncetime=200) # Write a low to indicate that the supply can be shutdown GPIO.output(25, GPIO.LOW) #Run the shutdown function (the edge has been detected) shutdown() ----------------------------------------------------------------------------- [ctrl]-O and save the file [ctr]-X to exit nano Make a bash script in the same directory as the shutdown.py (/usr/bin/start-stop) and call this shutdown.sh: sudo nano shutdown.sh ----------------------------------------------------------------------------- #!/bin/sh cd / cd /usr/bin/start-stop sudo python shutdown.py cd / ----------------------------------------------------------------------------- [ctrl]-O and save the file [ctrl]-X to exit nano ----------------------------------------------------------------------------- Make the shell-script executable: sudo chmod 755 shutdown.sh ----------------------------------------------------------------------------- In Volumio -Switch to superuser: su - password: volumio ----------------------------------------------------------------------------- Test the script by typing: sh shutdown.sh ----------------------------------------------------------------------------- Next, create a directory for crontab logs (if you want it): mkdir var/shutdown-logs Finally, add an entry to the root crontab to start the bash script at boot with: sudo crontab -e @reboot sh /usr/bin/start-stop/shutdown.sh >/var/shutdown-logs/cronlog 2>&1 ----------------------------------------------------------------------------- [ctrl]-O and save the file [ctrl]-X to exit Reboot and you will see a new file in your shutdown-logs (if you created the output) directory called cronlog that will contain this to show that it's watching pin 24 - shutdown.py:8: RuntimeWarning: A physical pull up resistor is fitted on this channel! GPIO.setup(24, GPIO.IN, pull_up_down=GPIO.PUD_UP) ----------------------------------------------------------------------------- If you don´t want the log, redirect it to /dev/null: sudo crontab -e @reboot sh /usr/bin/start-stop/shutdown.sh >/dev/null 2>&1 ----------------------------------------------------------------------------- [ctrl]-O and save the file [ctrl]-X to exit