Labels

lego (12) Linux (39) pi (20) Thinkpads (4)

Tuesday, 17 December 2013

Adding IR to your Raspberry Pi [day 6 of 20-days-of-posts series]

If you are going to use your Raspberry Pi as an XBMC player, you will eventually have a desire to use an IR remote.

There are alternatives, including using a USB/bluetooth keyboard/mouse, a USB multimedia remote (such as Lenovo's Multimedia Remote), or just use an iOS 6+ or Android 4+ device (XBMC Remote app).

If your newer TV supports HDMI CEC (which none of my TVs do), you can control your Raspberry Pi using your TV's IR port.

But if you're in my situation, your best bet would be to add an IR receiver to the GPIO port on the Pi.  It's very easy to do and doesn't require any soldering.

Shopping list:

  • 38KHz TSOP4838 or compatible IR receiver (source: ebay in quantities, about $0.20 - $1 each depending on qty)
  • 3 jumper cables (female on both ends) (source: ebay in quantities, pennies each)
One of the hardest parts is making sure you place the proper cables on the proper pins.

First the IR.  The rounded end is the front or top.  The pin alignment start from left to right as shown below:


Pin 1 will most likely be the OUT pin on most models.  However, the voltage and ground can be either 2 and 3 or 3 and 2, depending on the model.  You can check the specification guide that I've uploaded to see if your IR model is listed, it will tell you which pin is voltage and ground.  You can also refer to the specifications that were sent with your device.  I am assuming a model TSOP4838 throughout this post, therefore, according to the specification, pin 2 (middle) is ground and pin 3 is voltage.  Pin 1 is OUT.

If you proceed with the wrong pin alignment (ground and voltage are switched), you will potentially burn out the IR receiver, if you invert them by mistake.

Slide the jumper cables onto the IR pins so that they stay in place but are not loose.



Now, the second tricky part.  I have provided a GPIO pin lineup below.  Although the older vs revised Pi units have some variations, the pins we will use are the same on all Raspberry Pi units, regardless of model or revision.


It is important to situate the board correctly and count the pins correctly so that you don't get confused and plug the IR into the wrong pins.  We position the board where the USB port(s) are pointing down (due south), and we will count pins from left to right, from top to down.  So the most left and top pin is pin #1 (noted as 3V3 in the diagram).



IR pin 1 (OUT) will be connected to GPIO12.  Counting from top-left to bottom-right, this is GPIO pin #12 on the GPIO (right side, 6 pins down from the top).  IR pin 2 (ground/GND) will be connected to GPIO pin #6 (right side, 3 pins down from the top).  IR pin 3 (voltage/V) will be connected to GPIO pin #1 (3V3) (left side, top most pin).

Compare your setup with the photo provided below.



When you startup your Pi, you should see the existence of a /dev/lirc0 device.  Whether you are using Raspbmc or Raspbian, connect to a terminal console (such as SSH into the device).

Test your device, run the following:
  1. sudo /etc/init.d/lirc restart
  2. sudo modprobe lirc_rpi
  3. sudo mode2 -d /dev/lirc0
Take any IR remote and press a bunch of keys.  You should see output of those key presses on screen.  This confirms the IR receiver is properly connected and in working order.

To create a configuration for a given remote, run the following:

  1. sudo /etc/init.d/lirc stop
  2. sudo irrecord -d /dev/lirc0 ~/lircd.conf

Follow the prompts to learn your remote.  It will generate a configuration file lircd.conf in your home directory.  This lircd.conf can be referenced in your XBMC remote settings so that you may use your remote to control XBMC.

Now just modify your case to situate your IR receiver.  You can to maximize the space around the IR so signals are picked up.




That's it, for now.


    No comments:

    Post a comment