Lirc Serial Receiver Howto
Looking around the web, there seems to be some confusion in exactly how to get LIRC running on the Raspberry Pi with recent Raspbian images. Hopefully, this post will demystify some of the software components and how they’re used. Don’t worry, it’s really not that bad.
I’m using a Raspberry Pi 3 but the model really shouldn’t matter. I just wanted the wireless functionality. Looks like I’ve got a version of Raspbian based on Debian 8 (Jessie) installed on it:
LIRC can function with a number of serial and USB IR “dongles”. At some point, someone created a kernel driver for the Raspberry Pi that uses GPIO instead. Here is the author’s website and original instructions. But we won’t need to do any patching or compiling as the code is already included in Raspbian.
The only problem I have at the moment is: Back on yaVDR I installed and configured lirc. I have a 'Homebrew'-device which means some IR-receiver that is connected to the serial port of my motherboard. I am completely lost how to start configuring it in LibreElec. WinLIRC is an abandoned Windows port of LIRC for simple interrupt-based serial port receivers; WinLIRC was last developed in 2003.
The newer Raspbian images allow you to easily enable overlays in the /boot/config.txt file. This greatly simplifies things by automatically configuring GPIO, loading drivers, etc. The line you need is already in the file, we just need to uncomment it.
By default, GPIO 17 will be used for IR output and GPIO 18 will be used for input. If you need to use different GPIO, you can add parameters to override the default pins, like so:
Now, if you reboot the Pi you should have a new device file /dev/lirc0. This is the interface to the kernel driver that handles the IR signals. It’s also the device that the LIRC tools and daemon will use. So, now we can install them:
In my experience, the LIRC daemon (lircd) won’t start without changes to the configuration files in /etc/lirc. This is good as it leaves /dev/lirc0 available to use with the LIRC tools that we’ll use to capture the IR codes.
NOTE: In order to keep the topic flow here, I’ll be describing the hardware setup in a second post.
The /etc/lirc/lircd.conf file contains the IR remote button definitions for for lircd. There are configuration files for some common remotes (mostly A/V equipment) already available. Use them if you can. The file format is described here.
I’m going to control the General Electric A/C unit in my office. I couldn’t find anything pre-defined so I’ll need to create a new remote control definition for it. First, let’s test everything and make sure that we’re receiving data from the hardware and the kernel:
Mode2 is an LIRC debug utility. It displays the IR timing information from the kernel driver when pressing a key on the remote. Note that I had to specify the /dev/lirc0 device. By default, it was looking for /dev/lirc which won’t work.
Now to capture the timing information and create a remote configuration file for lircd:
Again, I had to specify the device file. Myanimelist zegapain. I disabled the “namespace” check (-n) so I could name the keys as I pleased. The irrecord utility will ask you to name the keys as you press them on the remote. It will compare the name to a “well known” list of keys which didn’t quite match up to what I needed. Of course, you can always hand-edit the file later.
I also had to force “raw” mode (-f) because I kept getting “Something went wrong” errors. Not sure what it was about the remote’s encoding that it didn’t like. But forcing raw mode fixed it.
I opened the file in an editor and fixed up the header and naming. Then, copied it into place:
OK, one last thing before we can start lircd. We need to edit the /etc/lirc/hardware.conf file to point to the device and tell it not to try and load drivers. Here’s the final file:
That should do it. I probably rebooted but you should also be able to tell systemd to start lircd:
Now lircd should be running:
When lircd started, it parsed the remote configuration file. Now it should understand your button names and the timing. We can query the buttons that it knows about with the irsend tool. Note that I named my remote GE_AC in the configuration file.
Perfect! Those are all of the buttons that I named in the configuration file. Now let’s check the receive path. The irw tool will listen to events decoded by lircd:
Pressing the power button on the remote returned the correct value as decoded by lircd. You can see that a “repeat count” is also returned.
Now to turn my AC on or off, I just issue the command:
Prototyped IR interface for LIRC
My plan is to use the Power HAT to have the Raspberry Pi power up on a schedule to turn the AC on and off. I might also add temperature and humidity detection and factor that into the control as well.
Here’s a link to the final files. Hope this post helps your project!