Introduction: Easy Setup IR Remote Control Using LIRC for the Raspberry PI (RPi) - Updated Oct 2021 [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 python3.

--------------Part 1----------------------|-----Part 2---------------

Remote -->[IR Receiver + RPI] <--> LIRC <--> Python3


Note: YOU MUST build with PYTHON3 (NOT python2 or python) or you will receive an error in the import in Line1. The LIRC module is only installed in Python3!

Supplies

none

Step 1: Hide Devinput.lircd.conf

Update: October 2021 This step is NOT required and can be SKIPPED!

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.

Update: October 2021

REMEMBER YOU MUST build with PYTHON3 (NOT python2 or python) or you will receive an error in the import in Line1. The LIRC module is only installed in Python3!

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[1]
        command = data[2]
        
        #ignore command repeats
        if (sequence != "00"):
           return
        
        print(command)        
            
#define Global
conn = RawConnection()
print("Starting Up...")
while True:         
      ProcessIRRemote()