MyPIAmp Project # Volumio+RPI+DAC+IR Remote+LCD #

Introduction
After a Pioneer VSX-920-K receiver melted down and a repair offer pricier than a new one…my decision was to scrap and recycle it.

later when looking at all that electronic garbage, inside the box, looking at a spare Raspberry PI 2 and a broken four input selector laying around, it will only take to get a cheap Class D amplifier and put everything inside that box… That’s how MyPIAmp project started…

Here is the overall Idea:

Use RPI as player. For that I’ve equipped it with dedicated DAC, USB LCD (as no physical pins available due to the DAC).
Use a Class D amplifier. And to reuse existing inputs from the old amplifier box. A broken input selector was used to switch between RPI and additional 3 existing entries on the box. (the “Phones” output was converted to 5mm phones input). To complete the scenario an Apple TV remote was added as well an old USB HDD to enable a standalone music player even without network access.

Hardware list

  1. Raspberry PI 2 RevB - https://www.raspberrypi.org/products/raspberry-pi-2-model-b/
  2. DAC: Audio Sound Card I2S Interface Special PCM5122 http://www.ebay.com/itm/Raspberry-pi-B-2B-HIFI-DAC-Audio-Sound-Card-I2S-Interface-Special-PCM5122/171924975592?_trksid=p2047675.c100012.m1985&_trkparms=aid%3D222007%26algo%3DSIC.MBE%26ao%3D1%26asc%3D20131230161411%26meid%3D179f6bd08590483297d0c57b1b997afb%26pid%3D100012%26rk%3D1%26rkt%3D10%26sd%3D181752350958
  3. TPA3116D2 Class D Digital Stereo Amplifier Board 50W+50W 12-24V Dual Channel Car - http://www.ebay.com/itm/201396078431?_trksid=p2060353.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT
  4. Audio Input signal Selector Relay Board / Signal Switching Amplifier Board+ RCA (Broken. Used only for Powering the leds and the custom wired 3p4T selector) - http://www.ebay.com/itm/251681224398?_trksid=p2060353.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT
  5. Apple TV Remote - support.apple.com/pt-pt/HT5822
  6. Box and some reused components of a broken Pioneer VSX-920-K 7.1 receiver
  7. Adafruit USB + Serial Backpack Kit with 16x2 RGB backlight negative LCD - adafruit.com/products/784
  8. 12V DC power transformer
  9. 5V 2.5A power transformer
  10. USB powered hub
  11. Other small parts and accessories

Design Compromises
As the input selector is based on a 4p3T selector and a nonfunctional audio input relay, it was used this component as it was previously assembled in a PCB and mounted with resistors for led utilization. Was needed to solder some wires on 4P3T selector to use it on a personalized way…
One of T’s was used for power selection to light up the leds, the other 2 T’s were used for left and right channel. With this setup I need to use a common ground for all audio inputs and common reference for +12VDC leds power.

Another compromise was to use the Phono jack in the front box as input rather than output. This decisions was based on the objective for MyPIAmp and to enable mobile devices to connect via Phono jack (a 5mm to 3,5mm adapter is used) as one of the features is to play without network connected (no web radios as well)
USB port in the front panel is used to connect a keyboard. At this stage and not yet addressed is an issue concerning USB HDD storage that disappears if a USB dongle is plugged in on that port, as Volumio mounts it on the same mount point : /mnt/USB.
Documentation says that Volumio merges file contents into the DB, but the mount point itself is swapped for the USB stick and files are not there anymore…to get things back is needed to unplug USB stick and reboot RPI to get USB HDD back…

SOFTWARE
On this section, are described the main steps to put the logic onto all the hardware setup and all the customizations done in this project

Software Levels
• 3.18.5-v7+ #748 SMP PREEMPT Wed Feb 4 21:33:52 GMT 2015 armv7l GNU/Linux
• Lirc armhf 0.9.0~pre1-1.2
• LCDproc 0.5.7
• python-lirc_1.2.1-1_armhf.deb
• Volumio 1.55PI

STEP 1: Install Volumio
1.1 Just follow instructions as described in http://www.volumio.org

Step 2: Install DAC

Installation the DAC on this software is relatively simple:

2.1 > Access Volumio pointing your browser to your.volumio.IP.address
2.2 > Go to [Menu]  [System]
2.3 > Go to [Activate I2S Driver] and select [HIFIBerry DAC+]
2.4 > Hit [Apply]
2.5 > Reboot your RPI and you’re done

Step 3: Install lirc
Assuming that you are using Linux Jessie version, some stuff as changed and we will need to go through slightly different process than in older versions…

3.1	 > sudo apt-get update
3.2	 > sudo apt-get install lirc
3.3	 > sudo nano /etc/lirc/hardware.conf

And change below entries

.........
LIRCD_ARGS="--uinput"
..........
DRIVER="default"
...........
DEVICE="/dev/lirc0"
...........
MODULES="lirc-rpi"

Save and close editor (Ctrl-O / Ctrl -X)

As Debian jessie uses “Device Tree, overlays and parameters” system configuration, we need to add device overlay for RPI Lirc. lirc overlay uses GPIO pin 17 and 18 by default.
Make sure that lirc-rpi entry is inserted before hifiberry-dacplus entry and that you change default gpio pins as they collide with DAC ones. Some nasty results were experienced with this….

Gpios pins used were gpio_in_pin=26 and gpio_out_pin=27.

3.4 >sudo nano /boot/config.txt 

your file should look like this…

gpu_mem=16
hdmi_drive=2
dtoverlay=lirc-rpi,gpio_out_pin=27,gpio_in_pin=26
dtoverlay=hifiberry-dacplus

Save and close editor (Ctrl-O / Ctrl -X)

3.5 > sudo reboot

You should get lirc working by now…to verify use:

3.6 > ls /dev

You should see a list of /dev entries. Search for ‘/lirc0’ entry. If you see it, you’ve got it. Now let’s if it is working properly…

3.7 > sudo modprobe lirc_rpi 

Test it

3.8 > mode2 -d /dev/lirc0

Press your remote keys to see if some pulse space messages appear…

Setting up your remote

The best way to setup your remote is by recording each key press.
First, plan ahead what you want to do with all the remote keys.
In this case is easy as apple remote as only a few keys (7 keys only). Just like to keep UI simple…
Before record your remote keys you need to stop lirc.

3.9 >sudo /etc/init.d/lirc stop

Record your keys

3.10 irrecord -n -d /dev/lirc0 /etc/lirc/lircd.conf

For apple remote Following names were recorded:

]UP key --> KEY_VOLUMEUP
DOWN key --> KEY_VOLUMEDOWN
RIGHT key --> KEY_NEXT
LEFT Key --> KEY_PREVIOUS
PLAY/PAUSE key --> KEY_PLAYPAUSE
SELECT key --> KEY_PLAY
MENU key --> KEY_SHUFFLE

To record the keys, just follow the instructions presented on the screen:

Start Lirc

3.11 >sudo /etc/init.d/lirc start

Check if you’re remote is working. Issue the below command and press your remote keys. If it is working you should receive proper feedback on your screen.

3.12 irw

Now you want to remote control your mpd under volumio. To achieve that you must edit lircrc file to map you’re named keys with Music Player Daemon (MPD) actions.
Take a note on prog = irexec entry. That entry will be important for controlling your LCD at a later stage. Also note that you need to map the button entry with the recorded keys in step 3.10

3.13> sudo nano /etc/lirc/lircrc

and type following code

[code]begin
prog = irexec
button = KEY_PLAYPAUSE
config = mpc toggle
end
begin
prog = irexec
button = KEY_NEXT
config = mpc next;mpc play
end
begin
prog = irexec
button = KEY_PREVIOUS
config = mpc prev;mpc play
end
begin
prog = irexec
button = KEY_VOLUMEUP
config = volume +1
end
begin
prog = irexec
button = KEY_VOLUMEDOWN
config = volume -1
end
begin
prog = irexec
button = KEY_SHUFFLE
config = mpc shuffle
end
begin
prog = irexec
button = KEY_PLAY
config = mpc play
end

[/code]

Save your file with Ctrl-o and Ctrl-x and restart your system

3.14 sudo reboot

Now you should have your Volumio system controlled by your remote.

Step 4: Install lcdproc

LCDproc is a client/server suite including drivers for all kinds of nifty LCD displays.
The server LCDd makes it possible to display text and other data on an LCD display. As well LCDd can handle certain input devices.

[code]4.1> sudo apt-get update

4.2 > sudo apt-get install lcdproc[/code]

Connect the LCD backpack to a USB port, then type:

4.3 > dmesg

Near the bottom of the list you should find some references to a USB device. One of the references should include a tty name… for example:

Take note on the name “ttyACM0” or whatever other name that may have been assigned to your LCD Backpack. You will need it for configuring the software.

Configure LCDd, the LCD daemon

LCDd will control your LCD and uses LCDd.conf file. The location of this file may vary depending on the installation method that you’ve used. Best way to find it is issue the command:

4.4 > sudo find / -name LCDd.conf -print

Most likely you will find it on /etc/LCDd.conf

Edit the file (note that this file must be edited as root)

4.5 > sudo nano  /etc/LCDd.conf

make your file look like this:

[code]## This file was written by cme command.

You can run 'cme edit ’ to modify this file.

Run ‘cme list’ to get the list of applications available on your system

You may also modify the content of this file with your favorite editor.

[server]
#DriverPath=/usr/lib//lcdproc/
DriverPath=/usr/lib/arm-linux-gnueabihf/lcdproc/
Driver=MtxOrb
NextScreenKey=Right
PrevScreenKey=Left
ReportToSyslog=no
ToggleRotateKey=Enter
#Foreground=yes
Serverscreen=no

[menu]
DownKey=Down
EnterKey=Enter
MenuKey=Escape
UpKey=Up

[MtxOrb]
Device=/dev/ttyACM0
Size=16x2
Type=lkd
Contrast=900
brightness=400
hasAdjustableBacklight=yes
Bind=127.0.0.1
Port=13666
User=nobody[/code]

Now let’s do a test run

4.6 sudo /etc/LCDd

If it throws an error message the most probable cause is that you specified the wrong device, or the driver path does not point to the correct driver place (or misses the end slash) or LCDd.conf is on the wrong location…

If everything runs ok, you should view on your LCD a greeting message from LCDd server that is waiting for a client to bind and start to display the messages…

Issue Ctrl-C to stop the server (if you have uncommented entry Foreground=yes otherwise you should issuesudo service LCDd stop) to complete LCD configuration

If you made your install using apt-get, it should be already auto-starting… otherwise you need to go through optional steps and google for it…

STEP 5: LIRC Driver with LCDd

The lirc driver enables your remote to interact with LCDd server and any client that can handle inputs. For this to work you need a working lirc configuration. Refer to step 3 of this guide

2.1 Build LCDd with the lirc driver

First you need to add lirc to the --enable -drivers=<list.> then run make.
Configure LCDd to use lirc driver

2.2	> sudo /etc/LCDd.conf 

Add following entries

[code]Driver=lirc

[lirc]
Prog=irexec[/code]

Just as follow LCDd.conf file

[code]## This file was written by cme command

You can run 'cme edit ’ to modify this file.

Run ‘cme list’ to get the list of applications available on your system

You may also modify the content of this file with your favorite editor.

[server]
#DriverPath=/usr/lib//lcdproc/
DriverPath=/usr/lib/arm-linux-gnueabihf/lcdproc/
Driver=MtxOrb
Driver=lirc
NextScreenKey=Right
PrevScreenKey=Left
ReportToSyslog=no
ToggleRotateKey=Enter
#Foreground=yes
Serverscreen=no

[menu]
DownKey=Down
EnterKey=Enter
MenuKey=Escape
UpKey=Up

[MtxOrb]
Device=/dev/ttyACM0
Size=16x2
Type=lkd
Contrast=900
brightness=400
hasAdjustableBacklight=yes
Bind=127.0.0.1
Port=13666
User=nobody

[lirc]
Prog=irexec[/code]

STEP 6 - Python Script
Build python script both to control your LCD and some functions of MPD, is needed to include the lirc module to python in order to capture lirc triggers into python script.

python-lirc` is in the main repositories for Raspbian. If you’re on a RaspberryPi you can just run:

6.1 > $ sudo apt-get install python-lirc

Otherwise, download the latest release from
(https://github.com/tompreston/python-lirc/releases) and install with:

6.2 > $ sudo dpkg -i python-lirc_1.2.1-1_armhf.deb

To put everything working a python script is needed to be able to control myPIAmp using remote and display custom messages and do interact with the system

Main objective is:
o Display custom information about what is playing
[list]Screen 0, 1 and 2
o Load 2 kinds of playlists
• Screen3: Load USB disk Music Directory
• Screen 4: Load radios.m3u custom playlist
o Change 2 playing parameters
• Screen 5: Random = on | off
• Screen: 6: Crossfade = [0,5,10,15,20]
• Screen 7: Volume [0…100%]
[/list:u]

To achieve that a python script was developed:

[code]#!/usr/bin/env python

import telnetlib;
import time;
import os;
import subprocess;
import lirc;

function BarGraph

display a custom bar graph in a 16 chars long

def BarGraph(Percent, type): # string passed in format xxx%; type = 0 Full 16 chars lenght [bbbbbbbbbbbbbbb]; type = 1; format = 999%[bbbbbbbbbb]
RSTR = “” # Return variable
num =0 # counter for for next loop
Percval=0 # Variable to hold integer of percentage
PercStr = “” # Variable to hold Percentage String
if type == 1:
StartBracket = “%[” # Symbol starting Graph
EndBracket = “]” # Symbol terminating graph
Step = 10 # jumping Percentage values as 10 blocks to display 100%
else:
StartBracket = “[”
EndBracket = “]”
Step = int(100/14)

    PercStr = Percent.strip()                    # remove all spaces from argument
    PercStr = Percent.strip('()%')       	# remove all marked chars
    PercVal = int(PercStr)

if type == 1:
        # add spaces depending on len of number...
    	if PercVal < 10:
            	PercStr = " " + PercStr + StartBracket
    	elif PercVal <100:
            	PercStr =  PercStr + StartBracket
    	else:
            	PercStr = PercStr + StartBracket

else:
	PercStr = StartBracket

    # build the  bargraph   047%[####______]
for num in range(0,99,Step+1):
	if num+Step <= PercVal:
		RSTR += chr(219)
	else:
		RSTR += "_"
	
   
Percent = PercStr + RSTR + EndBracket
    return Percent

host=‘127.0.0.1’;
port=‘13666’;
data = “”

click = 0

tn = telnetlib.Telnet(host, port)
tn.write(“hello\r”);

data += tn.read_until("\n");
tn.write(“screen_add my_screen\n”);
data += tn.read_until("\n");

tn.write(“screen_set my_screen 1 -heartbeat off\n”);
data += tn.read_until("\n");

tn.write(“widget_add my_screen 1 scroller\n”);
data += tn.read_until("\n");

tn.write(“widget_add my_screen 2 scroller\n”);
data += tn.read_until("\n");

isnet = 0 # Tem rede ? 1=sim
xfade = 0
screenid = 0
select = 0
var = 1;
spacer = " " # 16 spaces
mpc_start = 0
PLAYLIST_MSG = []
NUM_STATIONS = 0
STATION = 0
keyup =0
keydn =0

togglescr0 = 0

while var == 1 :
sockid = lirc.init(“irexec”, blocking = False) #???
codeIR = lirc.nextcode() # get IR command
if codeIR:
if codeIR[0] ==‘volume +1’:
if screenid<>7:
click += 1
else:
keyup = 1
elif codeIR[0] ==‘volume -1’:
if screenid<>7:
click -= 1
else:
keydn = 1
elif codeIR[0] ==‘mpc play’:
select = 1
screenid = click % 8

cmd1 = “mpc --format ‘%artist%’ | head -n 1” #gets the currently playing artist from mpc
process = subprocess.Popen(cmd1, stdout=subprocess.PIPE , shell=True)
os.waitpid(process.pid, 0)[1]
mpc_artist = process.stdout.read().strip()
mpc_artist
if len(mpc_artist) > 16:
mpc_artist += spacer

cmd2 = “mpc | grep vol | cut -d% -f1 | sed ‘s/[^0-9]*//g’” #gets the volume level from mpc
process = subprocess.Popen(cmd2, stdout=subprocess.PIPE , shell=True)
os.waitpid(process.pid, 0)[1]
mpc_vol = process.stdout.read().strip()
if len(mpc_vol)==0:
mpc_vol=“100%”

cmd3 = “mpc | head -2 | tail -1 | awk ‘{print $1}’” # gets the player state ie paused playing etc
process = subprocess.Popen(cmd3, stdout=subprocess.PIPE , shell=True)
os.waitpid(process.pid, 0)[1]
mpc_state = process.stdout.read().strip()

cmd4 = “hostname -I” #gets the current ip of RPI
process = subprocess.Popen(cmd4, stdout=subprocess.PIPE , shell=True)
os.waitpid(process.pid, 0)[1]
ip_addr = process.stdout.read().strip()
if len(ip_addr)>0:
isnet=1
else:
isnet=0

cmd5 = “netstat -t | grep rfe” #check if a user is connected via airplay
process = subprocess.Popen(cmd5, stdout=subprocess.PIPE , shell=True)
os.waitpid(process.pid, 0)[1]
airplay = process.stdout.read().strip()

cmd7 = “mpc --format ‘%title%’ | head -n 1” # nome da musica
process = subprocess.Popen(cmd7, stdout=subprocess.PIPE , shell=True)
os.waitpid(process.pid, 0)[1]
mpc_song = process.stdout.read().strip()
if len(mpc_song) > 16:
mpc_song += spacer

cmd8 = “mpc --format ‘%album%’ | head -n 1” # nome do album
process = subprocess.Popen(cmd8, stdout=subprocess.PIPE , shell=True)
os.waitpid(process.pid, 0)[1]
mpc_album = process.stdout.read().strip()
if len(mpc_album) > 16:
mpc_album += spacer

cmd10 = “mpc --format ‘%name%’ | head -n 1” # titulo
process = subprocess.Popen(cmd10, stdout=subprocess.PIPE , shell=True)
os.waitpid(process.pid, 0)[1]
mpc_name = process.stdout.read().strip()
if len(mpc_name) > 16:
mpc_name += spacer

cmd11 = “mpc | head -n 2 | tail -n 1 | awk {‘print $4’}” # % current position (xx%)
process = subprocess.Popen(cmd11, stdout=subprocess.PIPE , shell=True)
os.waitpid(process.pid, 0)[1]
mpc_pos = process.stdout.read().strip()
if len(mpc_pos) > 16:
mpc_pos += spacer

cmd12 = “mpc | head -n 2 | tail -n 1 | awk {‘print $3’}” # % current elapsedtime/time (xx%)
process = subprocess.Popen(cmd12, stdout=subprocess.PIPE , shell=True)
os.waitpid(process.pid, 0)[1]
mpc_elapsed = process.stdout.read().strip()
if len(mpc_elapsed) > 16:
mpc_elapsed += spacer

cmd13 = “mpc | head -n 2 | tail -n 1 | awk {‘print $2’}” # % current position in playlist / total
process = subprocess.Popen(cmd13, stdout=subprocess.PIPE , shell=True)
os.waitpid(process.pid, 0)[1]
mpc_playlistpos = process.stdout.read().strip()
if len(mpc_playlistpos) > 16:
mpc_playlistpos += spacer

cmd14 = “mpc crossfade | head -n 1 | tail -n 1 | awk {‘print $2’}” # % current position in playlist / total
process = subprocess.Popen(cmd14, stdout=subprocess.PIPE , shell=True)
os.waitpid(process.pid, 0)[1]
mpc_crossfade = process.stdout.read().strip()
if len(mpc_crossfade) > 16:
mpc_crossfade += spacer
xfade = int(mpc_crossfade)

cmd15 = “mpc | head -n 3 | tail -n 1 | awk {‘print $6’}” # % current random setting
process = subprocess.Popen(cmd15, stdout=subprocess.PIPE , shell=True)
os.waitpid(process.pid, 0)[1]
mpc_random = process.stdout.read().strip()
if len(mpc_random) > 16:
mpc_random += spacer

cmd16 = “mpc --format ‘%file%’ | head -n 1” #gets the path of current song from mpc
process = subprocess.Popen(cmd16, stdout=subprocess.PIPE , shell=True)
os.waitpid(process.pid, 0)[1]
mpc_file = process.stdout.read().strip()
mpc_file
if len(mpc_file) >= 16:
mpc_file += spacer

cmd17 = “mpc playlist | head -n 1 | tail -n 1 | awk {‘print $1’}” # % current position in playlist / total
process = subprocess.Popen(cmd17, stdout=subprocess.PIPE , shell=True)
os.waitpid(process.pid, 0)[1]
mpc_playlist = process.stdout.read().strip()
if len(mpc_playlist) == 0:
mpc_playlist =“n/a”

if mpc_state != “[playing]”: ##If airplay is in use, pause MPC and display Airplay Mode on LCD else display mpc data as normal
tn.write(“widget_set my_screen 1 1 1 16 1 m 4 “MyPIAmp V1.0”\n”);
data += tn.read_until("\n");
if airplay: # someone is connected via airplay
tn.write(“widget_set my_screen 2 1 2 16 2 m 4 “Airplay: %s “\n” % (“On”));
data += tn.read_until(”\n”);
else:
if mpc_state =="[paused]":
tn.write(“widget_set my_screen 2 1 2 16 2 m 4 " PAUSE “\n”);
data += tn.read_until(”\n");
else:
tn.write(“widget_set my_screen 2 1 2 16 2 m 4 “Playlist:%s Status:%s IP:%s “\n” % (mpc_playlist,mpc_state,ip_addr));
data += tn.read_until(”\n”);

# check if Playlist is not empty and if it is, load the default one...
if mpc_playlist == 'n/a' and mpc_start == 0:
tn.write("widget_set my_screen 2 1 2 16 2 m 4 \"Loading...\"\n");
    data += tn.read_until("\n");
    CS4 = "mpc clear" # clear playlist   
    process = subprocess.Popen(CS4, stdout=subprocess.PIPE , shell=True)
    os.waitpid(process.pid, 0)[1]
    CS4 = "mpc ls USB/Music | mpc add" # add default playlist from USB disk   
    process = subprocess.Popen(CS4, stdout=subprocess.PIPE , shell=True)
    os.waitpid(process.pid, 0)[1]
CS4 = "mpc random on" # start playing   
    process = subprocess.Popen(CS4, stdout=subprocess.PIPE , shell=True)
    os.waitpid(process.pid, 0)[1]
tn.write("widget_set my_screen 2 1 2 16 2 m 4 \"Playlist:%s Status:%s IP:%s \"\n" % (mpc_playlist,mpc_state,ip_addr));
    data += tn.read_until("\n");
mpc_start = 1
NUM_STATIONS=0

else:
mpc_start = 1 # flag that says mpc started at least once playing: good signal :slight_smile:
# screen 0
if screenid == 0:
if len(mpc_artist)==0:
tn.write(“widget_set my_screen 1 1 1 16 1 m 4 “%s " \n” % (mpc_name));
data += tn.read_until(”\n");
else:
tn.write(“widget_set my_screen 1 1 1 16 1 m 4 “%s " \n” % (mpc_artist));
data += tn.read_until(”\n");
if select==1:
togglescr0 += 1
togglescr0 = togglescr0 % 2
select = 0
if togglescr0 == 1:
tn.write(“widget_set my_screen 2 1 2 16 2 m 2 “%s " \n” % (mpc_album));
data += tn.read_until(”\n");
select = 0
if togglescr0 == 0:
tn.write(“widget_set my_screen 2 1 2 16 2 m 2 “%s " \n” % (mpc_song));
data += tn.read_until(”\n");

# screen 1
if screenid == 1:
tn.write("widget_set my_screen 1 1 1 16 1 m 4 \"%s \" \n" % (mpc_file));
    data += tn.read_until("\n");

if select==1:
            togglescr0 += 1
            togglescr0 = togglescr0 % 2
            select = 0
    if togglescr0 == 1:
            tn.write("widget_set my_screen 2 1 2 16 2 m 2 \"#%s##  \" \n" % (mpc_playlistpos));
            data += tn.read_until("\n");
            select = 0
    if togglescr0 == 0:
	if len(mpc_name)==0:
		mpc_name="No info..."
            tn.write("widget_set my_screen 2 1 2 16 2 m 2 \"%s \" \n" % (mpc_name));
            data += tn.read_until("\n");

# Screen 2
if screenid == 2:
tn.write("widget_set my_screen 1 1 1 16 1 m 4 \"%s \" \n" % (BarGraph(mpc_pos, 0)));
    data += tn.read_until("\n");
tn.write("widget_set my_screen 2 1 2 16 2 m 4 \"%s %s\"\n" % (mpc_elapsed,mpc_pos));        
    data += tn.read_until("\n");
# Screen 3
if screenid == 3:
PLAYLIST_MSG = []
NUM_STATIONS = 0
    tn.write("widget_set my_screen 1 1 1 16 1 m 4 \"WEB Radio\" \n");
    data += tn.read_until("\n");
    tn.write("widget_set my_screen 2 1 2 16 2 m 4 \"Load Playlist  Y\"\n");
    data += tn.read_until("\n");
if select==1:
	tn.write("widget_set my_screen 2 1 2 16 2 m 4 \"Loading...\"\n");
            data += tn.read_until("\n");
	PLAYLIST_MSG = []
    	NUM_STATIONS = 0
	CS4 = "mpc stop" # stop playing   
            process = subprocess.Popen(CS4, stdout=subprocess.PIPE , shell=True)
            os.waitpid(process.pid, 0)[1]
	CS4 = "mpc clear" # clear playlist   
            process = subprocess.Popen(CS4, stdout=subprocess.PIPE , shell=True)
            os.waitpid(process.pid, 0)[1]

	# Run shell script to add all stations  
	# to the MPC/MPD music player playlist
	CS4 = "mpc load radios"
	process = subprocess.Popen(CS4, stdout=subprocess.PIPE , shell=True)
            os.waitpid(process.pid, 0)[1]  
	# output = run_cmd("~/mypiampradiolist.sh")  
 		# Load PLAYLIST_MSG list  ~/mypiampradiolist.sh

	process = subprocess.Popen(cmd13, stdout=subprocess.PIPE , shell=True)
	os.waitpid(process.pid, 0)[1]
	mpc_playlist = process.stdout.read().strip()
	NUM_STATIONS = mpc_playlist   
	# Load PLAYLIST_MSG list  ~/mypiampradiolist.sh

	tn.write("widget_set my_screen 2 1 2 16 2 m 4 \"Loaded %s Stations\"\n" % (NUM_STATIONS));
            data += tn.read_until("\n");
	
	CS4 = "mpc random off" # start playing   
            process = subprocess.Popen(CS4, stdout=subprocess.PIPE , shell=True)
            os.waitpid(process.pid, 0)[1]

            CS4 = "mpc play" # start playing   
            process = subprocess.Popen(CS4, stdout=subprocess.PIPE , shell=True)
            os.waitpid(process.pid, 0)[1]
            select = 0
	time.sleep(3)
	click=0	
# Screen 4
if screenid == 4:
    tn.write("widget_set my_screen 1 1 1 16 1 m 4 \"USB Playlist\" \n");
    data += tn.read_until("\n");
    tn.write("widget_set my_screen 2 1 2 16 2 m 4 \"Load Playlist  Y\"\n");
    data += tn.read_until("\n");
if select == 1:
	tn.write("widget_set my_screen 2 1 2 16 2 m 4 \"Loading...\"\n");
    	data += tn.read_until("\n");

	CS4 = "mpc stop" # stop playing   
            process = subprocess.Popen(CS4, stdout=subprocess.PIPE , shell=True)
            os.waitpid(process.pid, 0)[1]

	CS4 = "mpc clear" # clear playlist   
	process = subprocess.Popen(CS4, stdout=subprocess.PIPE , shell=True)
	os.waitpid(process.pid, 0)[1]

	CS4 = "mpc ls USB/Music | mpc add" # add default playlist from USB disk   
            process = subprocess.Popen(CS4, stdout=subprocess.PIPE , shell=True)
            os.waitpid(process.pid, 0)[1]

	CS4 = "mpc random on" # start playing   
            process = subprocess.Popen(CS4, stdout=subprocess.PIPE , shell=True)
            os.waitpid(process.pid, 0)[1]

	CS4 = "mpc play" # start playing   
            process = subprocess.Popen(CS4, stdout=subprocess.PIPE , shell=True)
            os.waitpid(process.pid, 0)[1]                
	select = 0
	click=0
# Screen 5
if screenid == 5:
    tn.write("widget_set my_screen 1 1 1 16 1 m 4 \"Random play\" \n");
    data += tn.read_until("\n");
    tn.write("widget_set my_screen 2 1 2 16 2 m 4 \"%s \"\n" % mpc_random);
    data += tn.read_until("\n");
if select ==1:
	if mpc_random == "on":
		CS5 = "mpc random off"  #set random off
		process = subprocess.Popen(CS5, stdout=subprocess.PIPE , shell=True)
		os.waitpid(process.pid, 0)[1]
	else:
		CS5 = "mpc random on"  #set random on
                    process = subprocess.Popen(CS5, stdout=subprocess.PIPE , shell=True)
                    os.waitpid(process.pid, 0)[1]
	select = 0
# Screen 6
if screenid == 6:
    tn.write("widget_set my_screen 1 1 1 16 1 m 4 \"Crossfade\" \n");
    data += tn.read_until("\n");
    tn.write("widget_set my_screen 2 1 2 16 2 m 4 \"%s \" \n" % (mpc_crossfade));
    data += tn.read_until("\n");
if select == 1:
	xfade = (xfade + 5) % 25
	CS6 = "mpc crossfade " + str(xfade)  # set crossfade   
            process = subprocess.Popen(CS6, stdout=subprocess.PIPE , shell=True)
            os.waitpid(process.pid, 0)[1]
	select = 0

# Screen 7 - Volume control
if screenid == 7:
if keyup==1:
	keyup=0
	#volume up
	CS6 = "mpc volume +1"  
            process = subprocess.Popen(CS6, stdout=subprocess.PIPE , shell=True)
            os.waitpid(process.pid, 0)[1]
if keydn==1:
	keydn=0
	#volume down
            CS6 = "mpc volume -1"
            process = subprocess.Popen(CS6, stdout=subprocess.PIPE , shell=True)
            os.waitpid(process.pid, 0)[1]
if select==1:
	click+=1
    tn.write("widget_set my_screen 1 1 1 16 1 m 4 \"VOL:    OK>exit\" \n");
    data += tn.read_until("\n");
    tn.write("widget_set my_screen 2 1 2 16 2 m 4 \"%s\"\n" % (BarGraph(mpc_vol,1)));
    data += tn.read_until("\n");

time.sleep(0.4)
lirc.deinit()
[/code]

Put your script on /home/volumio

Make it executable

6.1	> Chmod +x <scriptname.py>

Execute as daemon it this way

6.2	> ./<scriptname.py&

Make it executable at boot level

6.3	> sudo nano /etc/rc.local

And just before exit(0) insert your line

/home/volumio/./<yourscript.py>&

voilá…

To enhance the project a couple of additional steps were added…

7. Sync HDD local Music Folder with your Remote Music Folder

As Music is stored in NAS server controled by a SSH capable device rsync was used to keep sync.

Create a shell script to sync your local USB drive with your music server directory. Please refer to rsync command for further info.

7.1	sudo nano syncmypiamp.sh

[code]#!/bin/bash
#clear

Script to sync local HDD with NAS Audio Files database

echo “Syncing HDD USB with Music DB server…”
echo “Start”
for dir in /volumeUSB1/usbshare/iTunes/iTunes\ Media/Music ; do
rsync -avz --ignore-existing --protect-args -e “ssh -p " @:”$dir" “/mnt/USB/”
done
echo “Syncing complete”
echo “Updating MPC database…”
mpc update
echo “Please check if MPC is updated before load music into playlist!!”
echo “bye now”[/code]

and make it executable

7.2	Chmod +x syncmypiamp.sh

Execute it for sync. This script is manually executed and it’s intention is to sync your local DB with your NAS music server everytime you update it or when you get myPIAmp on line…
Syncmypiamp.sh is locate on Volumio home folder
$ ~/
$ /home/volumio/

7.3	/home/volumio/./syncmypiamp

8. Radio Playlist
On this project was used a national FM radio list and beside there are a lots of default internet radios on volumio WEBRADIO folder pre-installed, nothing as have on a custom playlist a set of specific stations. For that was used an m3u playlist with selected contents… and with information to be displayed on MyPIAmp LCD, if no info is available from the radio station itself!

You should place your m3u playlist into /var/lib/mpd/playlists/

m3u contents

#EXTM3U #EXTINF:-1,Radio Renascenca http://7719.live.streamtheworld.com:80/RADIO_RENASCENCAAAC_SC #EXTINF:-1,RFM http://7719.live.streamtheworld.com:80/RFM_SC #EXTINF:-1,Mega Hits http://7739.live.streamtheworld.com:80/MEGA_HITSAAC_SC #EXTINF:-1,RFM - Oceano Pacifico http://11073.live.streamtheworld.com:3690/OCEANPACIFICAAC_SC #EXTINF:-1,RFM Clubbing (Dance Music) http://7749.live.streamtheworld.com:3690/RFMCLUBBINGAAC_SC #EXTINF:-1,Orbital FM http://centova.radios.pt:8401/stream #EXTINF:-1,Popular Radio - Musica Portuguesa http://195.8.58.150:32281/ #EXTINF:-1,M2 Chillout http://live.m2stream.fr/m2chillout-128.mp3

and that’s it.

This is a compilation and adaptation od several tutorials and DIY that I’ve digged around in Internet and I thank you all that shared your projects. That’s why I’m sharing mine. You can use it as you will.
IMG_0531.JPG
IMG_0527.JPG
IMG_0524.JPG

Very nice description!

I have been struggling with the IR on the same dac board and I will try your description!

How does your new integrated amp sound?

This system sounds great.
I even consider that it sounds better than the broken one especially when connected on the same speakers set (4ohm 70w Jamo speakers)

Wouw, great job ! Should sound very well ! :stuck_out_tongue:

Hi

I cant see the picture
who have this files / picture

Thank you

FICHIERS JOINTS
IMG_0531.JPG
Input switch cabling
IMG_0531.JPG (97.08 Kio) Vu 3172 fois
IMG_0527.JPG
Top view and overall layout
IMG_0527.JPG (142.52 Kio) Vu 3172 fois
IMG_0524.JPG
Overall View of MyPIAmp v1,0
IMG_0524.JPG (92.4 Kio) Vu 3172 fois

​super !! all work good ,

But I had only one problem with Volume Up ans Down with my remote !!

any help will be appreciated

At lirc install step 3.10 i have problem:
volumio@volumio:~$ irrecord -n -d /dev/lirc0 /etc/lirc/lircd.conf
irrecord: file “/etc/lirc/lircd.conf” does not contain valid data
What makes i wrong?
Maybe i ssh to volumio/volumio, not root?
Because the new image isnt accept root/volumio login

Edit: When i change lircd.conf to lirc.conf, then work. Maybe mistyped the guide?

I make the remote part, but no control my remote. (not apple, but when i push buttons, the mode2 test write out numbers, and when i programmed, then record too)

3.12:
root@volumio:/home/volumio# irw
connect: No such file or directory

Maybe the problem that i use volumio 2?

volumio-0.979-2016-08-20-pi.img

I have the same problem. Have you solved it?