On my journey of using the Rasberry Pi 2 for something useful, the moment has come where I want to plug an Infra-Red-receiver to it.
I’m not new to this, for years I used one plugged to my PC’s serial port (RS232). On the software side I used LIRC via the lirc_serial kernel module.
Just typing “lirc rasperry pi 2” on any available search engine gives me hints and How-Tos and motivation telling me that it won’t be difficult. Basically plugging the data-out-line (Vs) to a GPIO (the default being GPIO18), the 3.3V-line to a 3.3-volt-supply and the GND-line to ground should do the trick on the hardware side. An IR-receiver has three “legs”: Vs, 3.3V and GND. Mine has the GND in the middle, Vs left and 3.3V right (from the front view, where the half-bulb is).
I’m using Raspian Jessie and thus a recent kernel which uses DeviceTree for configuring the board’s hardware capabilities (previously this low-level board-layout-configuration was compiled into the kernel). To make the lirc_rpi-module work, the system needs to reserve GPIOs for it at boot-time. On a fresh jessie-installation that means I only need to un-comment one line (a DeviceTreeOverlay-line) of the config.txt-file in /boot:
# Uncomment this to enable the lirc-rpi module dtoverlay=lirc-rpi
I plug the device using GPIO18 for data-in, I check the voltage, I chang the config.txt, I reboot, I run the mode2-tool and tap on my remote-controls. And nothing appears.
Fortunately, to debug such issues, I have access to superior tools, in this case an oscilloscope and, even more important, a competent colleague with hardware-knowledge. We, or better he, find(s) the problem within 2 minutes. Alone I would have wondered and doubted everything.
After plugging the Raspi and its IR-receiver to the oscilloscope (probing the data-line of course) and putting the trigger level low enough we can observe the following sequence appearing when playing around with a remote control:
As my colleague takes the first glimpse at this curve he immediately shouts: “it is missing a pull-up-resistor”. What makes him say that is the amplitude-delta of only 1 volt compared to the expected 3.3 volt.
This IR-receiver is an active-low receiver: it forces or drives the line to 0 when it wants to transmit a zero and it does nothing on the line to signal a one. To have the signal bounce back to the 3.3 volt when the device releases a pull-up-resistor is needed. Which is a high-Ohm-resistor (10K for example) coupling the data-line with the 3.3 volt supply line. The opposite is a pull-down-resistor: coupling the data-line with the ground for devices which are active-high and thus driving a 1 to signal a one and nothing to signal a zero.
Neither-nor is present in my setup which is the reason for the 1-values to be stuck at ~1 volt. Depending on the load here and there on the GPIO-PADs of the Raspi we could have also seen 2 volt or even nothing.
While my colleague looks for a high-Ohm resistor I’m sure that the chip-maker has thought of this problem and that there is an internal pull-up or pull-down on each GPIO-pad which can be activated. After quick search I find indeed what I was looking for: setting a GPIO-pull-up (or down) is a parameter to the dtoverlay of lirc-rpi.
# Uncomment this to enable the lirc-rpi module dtoverlay=lirc-rpi dtparam=gpio_in_pull=up
After applying this change and rebooting, running mode2 gives me the numbers printed out I expect and on the oscilloscope a clean amplitude of 3.3 volts is seen:
I am having a heck of a time getting LIRC to work on Jessie. Could you share some code to get me going? I want to have a Pi Zero send IR commands to my TV and STB as part of my home IOT. But first, I need to capture the existing remote’s IR codes.
Try to use the
mode2
tool to check whether anything is captured on the pins assigned to the lirc-receiver.Thank you so much Patrick! You saved my day. I just added “dtparam=gpio_in_pull=up” to /boot/config.txt and it worked on my Raspbian Stretch distro.
Thank you so much for taking the time to post this – I spent hours trying to get my TSOP1136 working before I came across your page and now with the dtparam to apply an internal pullup it’s working sweetly.
Everything used to work fine on my Raspi3 with stretch. Suddenly it stopped working, maybe it was because of the kernel update in december 2017..
Anyhow, I’ve also added the “dtparam=gpio_in_pull=up” to config.txt and now everything is working fine. OMG, thanks!!
Thank you so much! I was trying to get my IR receiver to work with LIRC on Raspberry Pi Zero W, but I couldn’t get anything from mode2, except when I plug in or pull out the receiver from breadboard. After reading your post and adding “dtparam=gpio_in_pull=up” to /boot/config.txt, it worked!