Introduction: Easy Setup IR Remote Control Using LIRC for the Raspberry PI (RPi) - July 2019 [Part 2]
In Part 1 I demonstrated how to assemble the RPi + VS1838b and configure Raspbian's LIRC module to receive IR commands from an IR remote. All hardware and LIRC setup issues are discussed in part 1. Part 2 will demonstrate how to interface the hardware + LIRC module we setup in Part 1 with python.
--------------Part 1----------------------|-----Part 2---------------------------------
Remote -->[IR Receiver + RPI] <--> LIRC <--> Python<-->display (or send).
Step 1: Hide Devinput.lircd.conf
Your remote configuration file(s) will be placed in the /etc/lirc/lircd.conf.d directory. LIRC will find any file in this directory as long as it has a .conf extension (ie: JVC.lircd.conf). We will not be using the devinput.lircd.conf file so we will hide it by changing the extension as follows by renaming devinput.lircd.conf to devinput.lircd.conf.copy
$ sudo mv /etc/lirc/lircd.conf.d/devinput.lircd.conf /etc/lirc/lircd.conf.d/devinput.lircd.conf.copy
Step 2: Download .conf File for Your Remote
By far the easiest way to obtain a remote .conf file is to download it from the huge library at lirc.sourceforge.net Even if your particular remote model is not listed it is VERY likely that another model from the same manufacturer will work fine. Just find the manufacturer of your remote and click on a model that is close. If you are unsure which model is close you can look at the contents of each model and find one that is close to yours.
The hard way to get a .conf file is to create your own using the built in tool irrecord but I was VERY unsuccessful trying to create a file using this utility despite much effort. There are lots of other folks with similar difficulties using irrecord and I highly recommend the easy route of downloading a .conf file from lirc.sourceforge.net
Your remote configuration file(s) will be placed in the /etc/lirc/lircd.conf.d directory. LIRC will find any file in this directory as long as it has a .conf extension (ie: JVC.lircd.conf).
Step 3: Python Code
Here is some code to test.
from lirc import RawConnection
def ProcessIRRemote(): #get IR command #keypress format = (hexcode, repeat_num, command_key, remote_id) try: keypress = conn.readline(.0001) except: keypress="" if (keypress != "" and keypress != None): data = keypress.split() sequence = data command = data #ignore command repeats if (sequence != "00"): return print(command)
#define Global conn = RawConnection()