Using a USB LCD Display with your Music Player

Continuing with the theme of making my linux music player more appliance-like, I’ve added a USB LCD display, a Sure Electronics 20×4 LCD Smartie Kit. Since it’s headless, sometimes you might want to see what song is playing instead of pulling out your phone, or just have a cool looking lcd.

There will be two sections. First will be getting mpd data to display using lcdproc and a client called mpdlcd. Then second will be displaying Airport meta data using smartie-utils.

lcd

Displaying mpd data

Install the necessary packages.

sudo apt-get install lcdproc python-pip

python-pip — is a python package download manager. We use it to download mpdlcd which is a python package.

sudo pip install mpdlcd

Download the default mpdlcd configuration from the developer.

sudo wget -O /etc/mpdlcd.conf https://raw.github.com/rbarrois/mpdlcd/master/mpdlcd.conf

This file can be updated so you can display whatever type of data you’d like. This man page will have what’s available. Unfortunately, man mpdlcd doesn’t work.

Let’s get LCDProc to recognize the display. When researching this, I found that most of the sites show the old way of getting the Sure Electronics display to work with LCDProc which required recompiling. Luck and time is on our side because now the driver is built-in! We just need to activate it in the config file.

sudo nano /etc/LCDd.conf

Control-W to find this:
#Driver=SureElec

Uncomment it and any other setting you think you might need to change like screen brightness, contrast, etc.

Normally, even if you only have mpdlcd running, the server screen will still auto rotate in. That is, it will switch between mpdlcd and the default lcdproc daemon screen every few seconds. I found this irritating, so I made this change:

ServerScreen=blank

This prevents the autorotating and also makes the server screen blank which shows when mpdlcd is not turned on.

Daemonizing mpdlcd

Create the script.

sudo nano /etc/init.d/mpdlcd

Add this to the script.

#! /bin/sh
# /etc/init.d/shairport
#
### BEGIN INIT INFO
# Provides:          mpdlcd
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Put a short description of the service here
# Description:       Put a long description of the service here
### END INIT INFO


case "$1" in
  start)
    /usr/local/bin/mpdlcd &
    ;;
  stop)
    killall mpdlcd
    ;;
  *)
    echo "Usage: /etc/init.d/mpdlcd {start|stop}"
    exit 1
    ;;
esac

exit 0
#

Make it executable for all users, and make it run at start up.

sudo chmod a+x /etc/init.d/mpdlcd
sudo update-rc.d mpdlcd defaults

Reboot then hopefully your lcd with mpdlcd will be working.

Displaying Airplay metadata

Install necessary packages

sudo apt-get install tcllib

Make a directory where we can house all the Airport metadata. Then go to it.

sudo mkdir /etc/shairport
cd /etc/shairport

Download the smartie-utils that will allow us to send stuff to the lcd screen. Unzip it, and change the name of the folder.

sudo wget https://smartie-utils.googlecode.com/files/smartie-utils-1.1.0.zip
sudo unzip smartie-utils-1.1.0.zip
sudo mv smartie-utils-1.1.0 smartie

Edit the shairport daemon file.

sudo nano /etc/init.d/shairport

#! /bin/sh
# /etc/init.d/shairport
#
### BEGIN INIT INFO
# Provides:     shairport
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Put a short description of the service here
# Description:       Put a long description of the service here
### END INIT INFO


NAME="Livang Room"

case "$1" in
  start)
    /usr/local/bin/shairport -b 95 -d -a "$NAME" -w -B "mpc stop && killall mpdlcd" -E "/etc/init.d/mpdlcd start" -M /etc/shairport
    ;;
  stop)
    kill -9 `pidof shairport`
    ;;
  *)
    echo "Usage: /etc/init.d/shairport {start|stop}"
    exit 1
    ;;
esac

exit 0
#

This is the meat of the script:

/usr/local/bin/shairport -b 95 -d -a "$NAME" -w -B "mpc stop && killall mpdlcd" -E "/etc/init.d/mpdlcd start" -M /etc/shairport

-B "mpc stop && killall mpdlcd" — Instead of just stopping mpd before airplaying, it also kills mpdlcd which will allow the screen dump script in the next step to work.
-E "/etc/init.d/mpdlcd start" — After Airplay is done playing, it will then relaunch the mpdlcd daemon we created.
-M /etc/shairport — Activate the meta data dump into the /etc/shairport folder we created earlier. Everytime a song plays, the cover is downloaded to this folder, and a fifo file called now_playing will have a continuous data pipe of the new track.

Create a script that dumps the fifo data to the USB lcd screen.

sudo nano shairmeta.sh

Copy this into the script.

#! /bin/sh
cat < /etc/shairport/now_playing | awk -F"=" '!/artwork=/ && !/genre=/ && !/comment=/{print $2 | "tclsh /etc/shairport/smartie/smartie-tail.tcl -tty /dev/ttyUSB0"}' &

Daemonizing the shairmeta.sh script. Another daemon?!

Create the script.

sudo nano /etc/init.d/shairmeta

Add this to the script.

#! /bin/sh
# /etc/init.d/shairmeta
#
### BEGIN INIT INFO
# Provides:     shairport
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Put a short description of the service here
# Description:       Put a long description of the service here
### END INIT INFO


case "$1" in
  start)
    sh /etc/shairport/shairmeta.sh
    ;;
  stop)
    kill -9 `pidof shairmeta`
    ;;
  *)
    echo "Usage: /etc/init.d/shairmeta {start|stop}"
    exit 1
    ;;
esac

exit 0
#

Make it executable for all users, and make it run at start up.

sudo chmod a+x /etc/init.d/shairmeta
sudo update-rc.d shairmeta defaults

Reboot and hopefully this will work too. When you Airplay something, it first stops mpd and mpdlcd. Then the Airplay metadata pipes to the fifo file where the shairmeta script dumps the contents to lcd via smartie-utils. Then the song will play. Once Airplay is paused, mpdlcd turns back on and takes over the lcd.

This daemon doesn’t really take much resources compared to the mpdlcd script. mpdlcd refreshes every .5 second (you can change this in the configuration file). While this one, though cat is running continuously, it doesn’t do anything until the fifo file has something to send.

Leave a Comment

Your email address will not be published. Required fields are marked *