There are situations where it is not very convenient to use the phone or tablet to control the music. Sometimes you just need to quickly change the volume, pause the playback or skip a song on a playlist, and this can be done much easier using a IR remote.
Adding an infrared remote to the Raspberry Pi is very simple. This story is a continuation of the previous blog post about multi-room audio. It enhances the functionality and allows you to control volume instantly with a simple remote, without to have a phone or tablet with an app open with you. All you need is just a TSOP38238, an IR receiver module for remote control systems which is a component that converts IR signal into electrical pulses that will go to GPIO digital input of the Pi. Then you also need a HW remote, you can use some spare you have at home, or buy a one that suits your purpose. For my family I decided to use small and simple remotes from Apple purchased on eBay. These are very tiny with just few basic functions, and especially for the kids these are easy to use. And finally there is a utility called LIRC (Linux Infrared Remote Control) which is a package that allows you to decode and send infra-red signals of many commonly used remote controls.
How to do it step by step
1) HW preparation, obtain a TSOP38238 module (around 0.5 EUR a piece)
2) According to the datasheet connect the module to 3.3V, GND and GPIO 25 (Pin 22). The GPIO number might be different depending on your other HW you use with your Raspberry. For HiFiBerry audio boards please refer to this page to find an unused pin. GPIO 25 works well with HiFiBerry AMP2. I do not recommend direct soldering to the board as you might lose the warranty, pin connectors are recommended here.
3) Check again the wiring with the diagram and power on the Raspberry
4) Go to the web Max2Play config, enable LIRC support on Raspberry Settings tab and set the right GPIO IN
5) Reboot needed.
6) Remotely connect to your Raspberry Pi From Windows for example:
- Start cmd
- ssh user@yourhifiberry (“pi” is the default in Max2Play setup)
- pass: (default password is “max2play”)
7) Now log as a superuser
- su -
- pass: (password needs to be defined in the web console if you don’t know it)
Now you can use the Midnight Commander and its quick and easy built-in editor, or command line and VI if you prefer.
8) Update the following lines in /etc/lirc/lirc_options.conf
- driver = default
- device = /dev/lirc0 ?? or auto
9) Check your HW is working properly and pulses are being recognized
To test if lirc driver is working:
- $ sudo /etc/init.d/lircd stop
- $ mode2 -d /dev/lirc0
Press a key in remote and you should see multiple lines like below:
10) /etc/lirc/lircd.conf Here the remote commands needs to be specified for your custom remote (each remote requires different config) you can tweak the command mapping here. See mine below for Apple remote.
# this config file was automatically generated # using lirc-0.8.1(iguanaIR) on Fri Mar 30 19:20:40 2007 # # contributed by Matthias Urlichs <matthias|urlichs.de> # # brand: Apple # model no. of remote control: A1156 # devices being controlled by this remote: new (late 2006) MacBook # # This config files are for non-Apple receivers only. # Use the lircd.conf.macmini file when you are using the Apple receiver. # begin remote name Apple_A1156 bits 8 flags SPACE_ENC eps 30 aeps 100 header 9065 4484 one 574 1668 zero 574 547 ptrail 567 repeat 9031 2242 pre_data_bits 16 pre_data 0x77E1 post_data_bits 8 post_data 0xC5 gap 37600 toggle_bit 0 ignore_mask 0x80ff begin codes KEY_PAUSE 0x20 # Was: play KEY_VOLUMEUP 0xD0 KEY_NEXT 0xE0 # Was: ffwd KEY_PREVIOUS 0x10 KEY_VOLUMEDOWN 0xB0 # Was: minus KEY_POWER 0x40 # Was: menu end codes end remote
11) Add the support into Squeezelite by adding “-I” switch (see here) in Audioplayer/Advanced options, and check update squeezelite and save.
12) Wait until the update procedure finishes, it takes about 4 minutes to complete. Reboot now message will appear at the end of the yellow messaging dialog. Reboot.
13) Test the remote, it should be working now. If not, the commands are not properly set in the /etc/lirc/lircd.conf
Now you should be able to use the remote as an additional controller.
Now the next thing to tackle would be to control the Air Conditioner units using the Raspberry units placed in the rooms. Sounds simple, not an easy task though. See more details in the forum: https://smarthome.exposed/community/interesting-other-projects/sending-infrared-commands-to-air-conditioners-using-raspberry-pi/