Stereo remote control

Wouldn't it be nice if I could use the hifi remote control to control mpd?

It turns out many wishes can come true when one has a GPIO board.

A friend of mine had a pile of IR receiver components in his stash and gave me one. It is labeled "38A 1424A", and the closest matching datasheet I found is this one.

I wired the receiver with the control pin on GPIO port 24, and set up lirc by following roughly this guide.

Enable lirc_rpi support

I had to add these lines to /boot/config.txt to enable lirc_rpi support:

dtoverlay=lirc-rpi,gpio_in_pin=24,gpio_out_pin=22
dtparam=gpio_in_pull=up

At first I had missed configuration of the internal pull up resistor, and reception worked but was very, very poor.

Then reboot.

Install and configure lirc

apt install lirc

I added these lines to /etc/lirc/hardware.conf:

DRIVER="default"
DEVICE="/dev/lirc0"
MODULES="lirc_rpi"

Stopped lircd:

systemctl stop lirc

Tested that the receiver worked:

mode2 -d /dev/lirc0

Downloaded remote control codes for my hifi and put them in /etc/lirc/lircd.conf.

Started lircd

systemctl start lirc

Tested that lirc could parse commands from my remote control:

$ irw
0000400405506035 00 CD_PAUSE RAK-SC304W
0000400405506035 01 CD_PAUSE RAK-SC304W
0000400405506035 02 CD_PAUSE RAK-SC304W
0000400405505005 00 CD_PLAY RAK-SC304W
0000400405505005 01 CD_PLAY RAK-SC304W

Interface lirc with mpd

I made this simple lirc program and saved it in ~pi/.lircrc:

begin
     prog = irexec
     button = CD_NEXT
     config = mpc next
end

begin
     prog = irexec
     button = TAPE_FWD
     config = mpc next
end

begin
     prog = irexec
     button = TAPE_REW
     config = mpc prev
end

begin
     prog = irexec
     button = CD_PREV
     config = mpc prev
end

begin
     prog = irexec
     button = TAPE_PAUSE
     config = mpc pause
end

begin
     prog = irexec
     button = CD_PAUSE
     config = mpc pause
end

begin
     prog = irexec
     button = CD_PLAY
     config = mpc toggle
end

begin
     prog = debug
     button = TAPE_PLAY_RIGHT
     config = mpc toggle
end

Then wrote a systemd unit file to start irexec and saved it as /etc/systemd/system/mpd-irexec.service:

[Unit]
Description=Control mpd via lirc remote control
After=lirc mpd

[Service]
Type=simple
ExecStart=/usr/bin/irexec
Restart=always
User=pi
WorkingDirectory=~

[Install]
WantedBy=multi-user.target

Then systemctl start mpd-irexec to start irexec, and systemctl enable mpd-irexec to start irexec at boot.

Profit!

All of this was done by me, with almost no electronics training, following online tutorials for the hardware parts.

To connect components I used a breadboard and female-male jumper leads, so I didn't have to solder, for which I have very little practice.

Now the Raspberry Pi is so much a part of my hifi component that I can even control it with the hifi remote control.

Given that I disconnected the CD and tape players, there are now at least 16 free buttons on the remote control that I can script however I like.