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

**URL:** <https://community.volumio.com/t/mypiamp-project-volumio-rpi-dac-ir-remote-lcd/3279>\
**Category:** Diy Volumio Projects\
**Created:** [October 14, 2015, 11:02pm UTC](https://community.volumio.com/t/mypiamp-project-volumio-rpi-dac-ir-remote-lcd/3279 "2015-10-14T23:02:16Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![pparreira](https://community.volumio.com/letter_avatar_proxy/v4/letter/p/df788c/32.png) [@pparreira](https://community.volumio.com/u/pparreira)\
**Post date:** [October 14, 2015, 11:02pm UTC](https://community.volumio.com/t/mypiamp-project-volumio-rpi-dac-ir-remote-lcd/3279/1 "2015-10-14T23:02:16Z")

</div>

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/](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](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](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](http://www.ebay.com/itm/251681224398?_trksid=p2060353.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT)
5. Apple TV Remote - [support.apple.com/pt-pt/HT5822](https://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](https://www.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](http://www.volumio.org)

Step 2: Install DAC

> [@](#):
>
> ASSUMPTION: DAC IS ALREADY PHYSICALLY INSTALLED ON YOUR RASPBERRY PI 2

Installation the DAC on this software is relatively simple:

2.1 \> Access Volumio pointing your browser to [your.volumio.IP.address](http://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…

```auto
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

```auto
.........
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.

```auto
3.4 >sudo nano /boot/config.txt 
```

your file should look like this…

```auto
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)

```auto
3.5 > sudo reboot
```

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

```auto
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…

```auto
3.7 > sudo modprobe lirc_rpi 
```

Test it

```auto
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.

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

Record your keys

```auto
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

```auto
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.

```auto
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

```auto
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]

> [@](#):
>
> \*NOTE:  
> on ON KEY\_VOLUMEUP and KEY\_VOLUMEDOWN the ‘CONFIG’ enntry do not include ‘MPC’ as the volume control is in charge of a python script instead of direct IR command.

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

```auto
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]

> [@](#):
>
> Note : On changelog reading exit with “q” not “ctrl-C”

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

```auto
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:

> [@](#):
>
> [6.263337] cdc\_acm 1-1.2:1.0: ttyACM0: USB ACM device

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:

```auto
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)

```auto
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

```auto
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

```auto
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:

```auto
6.1 > $ sudo apt-get install python-lirc
```

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

```auto
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 🙂  
# 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

```auto
6.1	> Chmod +x <scriptname.py>
```

Execute as daemon it this way

```auto
6.2	> ./<scriptname.py&
```

Make it executable at boot level

```auto
6.3	> sudo nano /etc/rc.local
```

And just before exit(0) insert your line

```auto
/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.

```auto
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

```auto
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/

```auto
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](https://community.volumio.com/uploads/default/original/2X/4/48a396f0bf4190006093956b8126daf6ee249c37.jpeg)  
 ![IMG_0527.JPG](https://community.volumio.com/uploads/default/original/2X/d/da678400b9975d4385a6f5c910fe3038194deb71.jpeg)  
 ![IMG_0524.JPG](https://community.volumio.com/uploads/default/original/2X/3/3b70842e40b4591252169b75b25082113f531a9b.jpeg)

---

<div class="post-metadata">

**Author:** ![guussie](https://community.volumio.com/letter_avatar_proxy/v4/letter/g/bc8723/32.png) [@guussie](https://community.volumio.com/u/guussie)\
**Post date:** [November 18, 2015, 2:50pm UTC](https://community.volumio.com/t/mypiamp-project-volumio-rpi-dac-ir-remote-lcd/3279/2 "2015-11-18T14:50:41Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![pparreira](https://community.volumio.com/letter_avatar_proxy/v4/letter/p/df788c/32.png) [@pparreira](https://community.volumio.com/u/pparreira)\
**Post date:** [November 19, 2015, 10:42am UTC](https://community.volumio.com/t/mypiamp-project-volumio-rpi-dac-ir-remote-lcd/3279/3 "2015-11-19T10:42:52Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![ptit\_lu](https://community.volumio.com/letter_avatar_proxy/v4/letter/p/4af34b/32.png) [@ptit\_lu](https://community.volumio.com/u/ptit_lu)\
**Post date:** [December 21, 2015, 12:30am UTC](https://community.volumio.com/t/mypiamp-project-volumio-rpi-dac-ir-remote-lcd/3279/4 "2015-12-21T00:30:19Z")

</div>

Wouw, great job ! Should sound very well ! 😛

---

<div class="post-metadata">

**Author:** ![dish67](https://community.volumio.com/letter_avatar_proxy/v4/letter/d/9dc877/32.png) [@dish67](https://community.volumio.com/u/dish67)\
**Post date:** [August 5, 2016, 4:01am UTC](https://community.volumio.com/t/mypiamp-project-volumio-rpi-dac-ir-remote-lcd/3279/5 "2016-08-05T04:01:41Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dish67](https://community.volumio.com/letter_avatar_proxy/v4/letter/d/9dc877/32.png) [@dish67](https://community.volumio.com/u/dish67)\
**Post date:** [August 25, 2016, 9:29pm UTC](https://community.volumio.com/t/mypiamp-project-volumio-rpi-dac-ir-remote-lcd/3279/6 "2016-08-25T21:29:08Z")

</div>

​super !! all work good ,

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

any help will be appreciated

---

<div class="post-metadata">

**Author:** ![envagyok](https://community.volumio.com/letter_avatar_proxy/v4/letter/e/d9b06d/32.png) [@envagyok](https://community.volumio.com/u/envagyok)\
**Post date:** [August 26, 2016, 12:41pm UTC](https://community.volumio.com/t/mypiamp-project-volumio-rpi-dac-ir-remote-lcd/3279/7 "2016-08-26T12:41:32Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![kysior](https://community.volumio.com/letter_avatar_proxy/v4/letter/k/c37758/32.png) [@kysior](https://community.volumio.com/u/kysior)\
**Post date:** [April 1, 2019, 8:30pm UTC](https://community.volumio.com/t/mypiamp-project-volumio-rpi-dac-ir-remote-lcd/3279/8 "2019-04-01T20:30:04Z")

</div>

I have the same problem. Have you solved it?
