Wednesday, May 28, 2014

XBMC project - Post 7 - Interfacing IR Remote to Raspberry Pi

Story Board:
Post 1
Post 2
Post 3
Post 4
Post 5
Post 6

Raspberry Pi as XBMC media device without a remote control... !!! Something is wrong. Of course we can use Android and iPhone apps to control using Wi-Fi. But after using for a while, it feels very awkward to look for phone, unlock it, search for the app, launch it, press desired button .. may be to pause the movie ?? Uff not a good idea. How about having our TV or any other existing IR remote to control our XBMC. This post explains how

What you need:
If you having completed installation of XBMC on Raspberry Pi, you just need one Hardware for IR remote to work..I bought IR module from ebay -

It looks something as below. It works directly with Raspberry Pi, no soldering etc required

Very straight forward connections, VCC will get 3.3V pin, that is first pin on left lane on GPIO stack. GND will goto any of ground pin. Data pin goes to any of GPIO pins, I selected pin 18. 6th on right stack. As shown below

Settings to be done on OpenElec
Step 1: Update and Upgrade your OpenElec
This is the way you can keep your system upto date. You can do it from XBMC user interface itself.
check this link

Step 2: Install LIRC

Log into OpenElec from a computer using SSH. You can use PuTTy from windows. Default user name and password - root / openelec

Execute following command to install LIRC

sudo apt-get install lirc

This will install LIRC. 

Step 2: Configure LIRC
For IR receiver to work properly you need to configure few settings..

First off OpenElec needs to be know which remote you are going to use and which buttons means what. This information is obtained from a config file called lircd.conf. This file needs to be placed in /storage/.config/lircd.conf

For this to be achieved there is a Utility called irreccord as part of LIRC which can be used.

first all kill all running LIRC services.

killall lircd

Now start the utility

irrecord /storage/.config/lircd.conf

The instructions are straight forward. However you need to name the keys in a specific format.

You can use following names as it explains:

Step 3: Start the LIRC services
Following command starts the LIRC services. Make sure you have attached data wire to pin 18 as shown above

modprobe lirc_rpi gpio_in_pin=18 gpio_out_pin=1

You can also start the service automatically every time the OpenElec boots, by creating a file /storage/.config/ with below content

modprobe lirc_rpi gpio_in_pin=18 gpio_out_pin=1

Make the above file executable
chmod ugo+x  /storage/.config/

Now you are all set. Reboot the system and try using the remote

Watch below video for full explanation .. Don't worry about initial circuit design he has given, you would not need those additional resistors and capacitors..

Thursday, May 15, 2014

Home automaton - RPI - Software Needs - Post 3

Story board
Post 1 - Synopsys
Post 2 - Hwardware Requirements

Status: Just yesterday (14th May 2014), I completed this project and it is working liker a charm :) ... #feeling_achieved

Software design: 
Idea is to control the electrical switch (Relay) from anywhere.. So, we need to softwares in 2 parts

  1. One which triggers relay from Raspberry Pi
  2. The other which manages the web part of it. 

Software program in Raspberry Pi
One of most fascinating features of Pi board is that it has got GPIO (General Purpose Input Output) pins. We have got GPIO libraries, that can be imported into programs to work with GPIO pins in a very easy fashion. Most common programming language used in RPi is Python. The same is used in my project as well. 

Setting up GPIO pins and passing the commands to them. 
As the name suggests, we can set GPIO pins either as input or outputs. For our case we need to set one pin as Output pin. Following code snippet would do that

import RPi.GPIO as  GPIO

Above code initializes GPIO pins and sets pin #22 to Output mode.
Below pic can be used as a reference to GPIO pin layout. Note that the numbers are not in any sequence :) 

To set a digital HIGH or digital LOW following code would help

GPIO.output(22, False)
GPIO.output(22, True)

The GPIO pin 22, 8th in the left side will be connected to Relay input pin as shown in my previous post.

Now logic can be written when to turn on relay or turn it off...
More on Software related to web control in next post