3

So, in a recent batch of purchases from Adafruit, I picked up one of these $2 gadgets:

http://learn.adafruit.com/ir-sensor/overview

It can pick up signals from TV remotes and such. I'm wondering, how much can I do with this on a Pi without a microcontroller? Can I decode the signals to find out what button is being pressed, and if not, can I at least use the remote as one giant button, detecting if I'm pushing or not, but not knowing what button?

I'll be the first to admit I am extremely new to anything hardware or electronics related. I am a computer scientist, though, so I'm not afraid to get my hands dirty programming, if need be.

6

Someone already implemented a module for LIRC (http://aron.ws/projects/lirc_rpi/). Just connect the sensor to the gpio pins. lirc_rpi is already present in current raspbian builds. The only thing you need to take into account is that some IR-sensors don't work on 3.3volt.

Here a detailed explanation of how I added remote control to my pi (my orignal post at: http://www.mightyohm.com/forum/viewtopic.php?f=2&t=3420#p5621):

Any remote will do. I'm using a logitech universal remote (harmony 300), which is programmed to replace my sony-stereo's remote. The Pi's audio is connected to my stereo. If my stereo is set to AUX, most of the button on the remote don't do anything. So I use those buttons to control the Pi. Kind of a strange setup, but it works for me. I did run into one problem, that is, that the sony remote sent out 2 different lengths of pulses. I don't think many remotes will have this though. I fixed by making lirc think that the shorter code where from a different remote (you can setup LIRC to use multiple remotes at the same time).

So here come the instructions for how I set up things:

Connect the TSOP plus to the 3.3V, and ground to ground. I connected the OUT to GPIO 4, which is pin 7 on the board. I added a 2.2K resister just to be sure. Note that lirc_rpi defaults to using PIN12 (GPIO18) for input, and PIN11 (GPIO17) for output. If these pins are free, using those pins would be preferable. The output is for a IR blaster, but I don't need that. So I set output to GPIO 7 as that one isn't connected in my setup.

You'll need the lirc_rpi module. This is available in the latest kernel. Check if it is available in your system by running find /lib/modules/ -name *lirc_rpi*. If nothing is found do the following to upgrade the kernel

sudo wget http://goo.gl/1BOfJ -O /usr/bin/rpi-update && sudo chmod +x /usr/bin/rpi-update
sudo apt-get install git-core
sudo rpi-update

Install lirc

sudo apt-get install lirc

Now load the lirc_rpi module (change gpio number is you are using different ones. note that these are gpio numbers, not pin numbers)

sudo modprobe lirc_rpi gpio_in_pin=4 gpio_out_pin=7

Now to test run

sudo mode2 -d /dev/lirc0

Now press some buttons on the remote. You should see a whole lot of space and pulse lines.

Now config lirc. run sudo pico /etc/lirc/hardware.conf and [b]change[/b] the following lines

    ...
    LIRCD_ARGS="--uinput"
    ...
    DRIVER="default"
    ...
    DEVICE="/dev/lirc0"

If you are using the default pins, you could also change MODULES="" to MODULES="lirc_rpi"

Now we need to led lirc learn the IR-commands sent by the remote.

sudo /etc/init.d/lirc stop
irrecord -n -d /dev/lirc0 ~/lircd.conf
#follow the instructions on the screen
#just learn a few button. Do the rest once everything is working.
#now copy this newly created conf file
sudo mv ~/lircd.conf /etc/lirc/lircd.conf
#start lirc
sudo /etc/init.d./lirc start
#now run irw to check everything
irw
#now press the button on the remote you just learned. The commands should appear on the screen

If all this works go and create some actions to be performed on IR-input. Run pico ~/.lircrc and type something like:

begin
        prog = irexec
        button = pause
        config = mpc toggle
end
begin
        prog = irexec
        button = nextsong
        config = mpc next;mpc play
end
begin
        prog = irexec
        button = prevsong
        config = mpc prev;mpc play
end
begin
        prog = irexec
        button = stop
        config = mpc stop
end

Change the button=xxx so xxx is the name you provided when running irrecord. Add more when needed.

Next we need to run irexec as a background process

irexec -d

Now press e.g. the play button and see/hear what happens.

Final this to do is have modprob and irexec run on startup. To do this edit /etc/rc.local. sudo pico /etc/rc.local

#before exit 0 past the following
(sleep 5;
sudo modprobe lirc_rpi gpio_in_pin=4 gpio_out_pin=7
sleep 5;
sudo -u pi irexec -d
#note: irexec can't run as root. Also note it shuts down if lircd is restarted
)&

(skip the modeprobe line I you are using default pins, and have set MODULES=lirc_rpi in hardware.conf)

I think that is about it.

Good luck

2

According to the URL you gave, you've got an IR detector with the digital output, therefore there's nothing you cannot do on a Pi, because it readily accepts any kind of digital signals. If you connect your IR detector to the GPIO pin, you may read the pin state from the program you write or from the simple script.

On the other hand, if you've got an IR photocell, you'd better use something that has ADC converter to be able to capture incoming data more precisely (RasPi has no ADC by default).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.