Add IR Remote Control


# STEP16

# OPTIONAL: Add A Remote Control Management
# this tutorial and the next one is about controlling the audio server with a remote control to play, pause, stop, go next / prev song, launch playlist, drive equalizer,…
# this one use a very easy to use tool named Triggerhappy and the other use Lirc a more complete implementation supporting hundreds remote controls
# IMPORTANT: some devices like Intel NUC needs to enable Enhanced Consumer IR in BIOS to work with remote control

# Add a remote control management

# install triggerhappy (should be already installed)

  1. $ sudo apt-get install triggerhappy

# create a configuration file
# pressing ZERO button select the default (first) audio output

  1. $ sudo nano /etc/triggerhappy/triggers.d/triggers.conf


# add your key to play, stop,… copy/paste the lines below:
# in addition to the standard play, stop, pause,… commands,
# this remote control config will
# start playing playlist 1 to 3 random order by pressing the corresponding key 1, 2 or 3
# select 2 EQ setup by pressing key 6 or 9
# select the default audio output (NO EQ) by pressing 0 (zero)
#

KEY_PLAY 0 mpc play >/dev/null
KEY_STOP 0 mpc stop >/dev/null
KEY_PAUSE 0 mpc toggle >/dev/null
KEY_PLAYPAUSE 0 mpc toggle >/dev/null 
KEY_NEXT 0 mpc next >/dev/null
KEY_PREVIOUS 0 mpc prev >/dev/null
KEY_FASTFORWARD 0 mpc seek +10 >/dev/null
KEY_REWIND 0 mpc seek -10 >/dev/null
KEY_RECORD 0 /home/pi/scripts/./playlist.sh >/dev/null
KEY_LEFTCTRL+KEY_P 0 mpc play >/dev/null
KEY_LEFTCTRL+KEY_S 0 mpc stop >/dev/null
BTN_MIDDLE 0 mpc toggle >/dev/null
BTN_LEFT 0 mpc prev >/dev/null
KEY_LEFTCTRL+KEY_B 0 mpc prev >/dev/null
KEY_LEFTCTRL+KEY_F 0 mpc next >/dev/null
KEY_HOME 0 mpc toggle >/dev/null
KEY_LEFTSHIFT+KEY_B 0 mpc seek -10 >/dev/null
KEY_LEFTSHIFT+KEY_F 0 mpc seek +10 >/dev/null
KEY_NUMERIC_1 0 /home/pi/scripts/./playlist1.sh >/dev/null 
KEY_NUMERIC_2 0 /home/pi/scripts/./playlist2.sh >/dev/null
KEY_NUMERIC_3 0 /home/pi/scripts/./playlist3.sh >/dev/null
KEY_NUMERIC_6 0 /home/pi/scripts/./lowbass.sh >/dev/null
KEY_NUMERIC_9 0 /home/pi/scripts/./jbleq.sh >/dev/null
KEY_NUMERIC_0 0 mpc enable only 1 && mpc play >/dev/null
KEY_0 0 mpc enable only 1 && mpc play >/dev/null
KEY_1 0 /home/pi/scripts/./playlist1.sh >/dev/null 
KEY_2 0 /home/pi/scripts/./playlist2.sh >/dev/null 
KEY_3 0 /home/pi/scripts/./playlist3.sh >/dev/null 
KEY_6 0 /home/pi/scripts/./lowbass.sh >/dev/null
KEY_9 0 /home/pi/scripts/./jbleq.sh >/dev/null

# CTRL+O to save
# CTRL+X to exit

# activate triggerhappy

  1. $ sudo systemctl enable triggerhappy


  1. $ sudo systemctl start triggerhappy


  1. $ sudo systemctl status triggerhappy


# DEBUG THE KEY CODES
# useful if your remote control is not working, skip this during install
# if your remote control do not send the correct key use the dump function to identify the correct key and change your cmds in triggers.conf
# To dump all events received through your remote control (useful to get the corresponding keys):

  1. $ sudo thd --dump /dev/input/event*
EV_KEY KEY_5 1 /dev/input/event4
# KEY_5 1 command
EV_KEY KEY_5 0 /dev/input/event4
# KEY_5 0 command
EV_KEY KEY_5 1 /dev/input/event4
# KEY_5 1 command
EV_KEY KEY_5 0 /dev/input/event4
# KEY_5 0 command
EV_KEY KEY_5 1 /dev/input/event4
# KEY_5 1 command
EV_KEY KEY_5 0 /dev/input/event4
# KEY_5 0 command


# CTRL+C to exit


# OPTIONAL
# if you need to run script as root from triggerhappy (default user is nobody) do the following:
# giving root access is risky but if know what you’re doing this can be useful to run script to set parametric EQ or load playlist with the remote
# useful to drive ALSAEQ (equalizer plugin) for example

  1. $ sudo nano /lib/systemd/system/triggerhappy.service

change
–user nobody
to
–user root

# CTRL+O to save
# CTRL+X to exit

  1. $ sudo nano /etc/default/triggerhappy



# comment

#DAEMON_OPTS=""

# uncomment

DAEMON_OPTS="--user root"

# CTRL+O to save
# CTRL+X to exit

  1. $ sudo systemctl daemon-reload


  1. $ sudo systemctl restart triggerhappy


  1. $ sudo systemctl status triggerhappy

# add a playlist script
# if you followed our tutorials the playlist/ and scripts/ directory are already created

# from a remote PC, open the share point playlists and copy 2 playlists into it
# for example my_classical_albums.m3u and my_jazzy_albums.m3u

# create the script

  1. $ sudo nano ~/scripts/playlist1.sh
#!/bin/bash
#
# Script to load playlist
 
echo "start playlist"
mpc stop
mpc clear
mpc enable only 1
mpc load my_classical_albums
mpc random "on"
mpc crossfade 0
mpc play

# CTRL+O to save
# CTRL+X to exit

# set exec permission

  1. $ sudo chmod +x ~/scripts/playlist1.sh

# create the script

  1. $ sudo nano ~/scripts/playlist2.sh
#!/bin/bash
#
# Script to load playlist
 
echo "start playlist"
mpc stop
mpc clear
mpc enable only 1
mpc load my_jazzy_albums
mpc random "on"
mpc crossfade 0
mpc play

# CTRL+O to save
# CTRL+X to exit

# set exec permission

  1. $ sudo chmod +x ~/scripts/playlist2.sh

# now pressing key 1 or 2 of the remote control plays the playlist classical or jazzy

# obviously for this to work you need to save your playlists in the playlists directory


# in our example of configuration above we have key 6 and 9 assigned to ALSA EQ,
# by pressing key 6 or 9 you are going to trigger the lowbass.sh or the jbjeq.sh which drive the ALSA Equalizer plugin to shape your sound
read the tutorial on how to add a real time EQ to your audio system to complete the installation of this 2 scripts

# more info: triggerhappy by Stefan Tomanek <stefan.tomanek+th@wertarbyte.de>
http://github.com/wertarbyte/triggerhappy/

Click the button NEXT below to continue…