Thursday 8 August 2013

Control your wall lights with raspberry Pi

Hello again, it´s been a while. I have decided to move on from Openelec and installed xBian on my Raspberry Pi. It all went smoothly and super fast and I am pretty happy with how it works. The reason for this decision was that Openelec has a read only file system… and I love tampering. I found a nice german guy that described a way to create a very cheap electronic expansion board and bundle it with a raspberry pi to effectively manage to control equipment such as this or this or even this. Wanna see how it`s done? Read on!

Ok, let me assume that you have already successfully installed xBian on your raspberry Pi (follow the link if you have not). You will be needing one of those (if the arduino comment scares you, don´t worry, it will work with the Pi) or those (if you live in the EU and want to get it pretty fast).
The module is very straightforward to wire: just connect the Pin GND of the module to Pin 6 on the Pi, Pin VCC of the module to Pin 2 on the Pi and finally Pin 2 (Data In) of the module to Pin 11 on the Pi. Finished. Could it get any easier?
Well… Yes. Try to use a Breadboard and some jumper cables to avoid soldering. This is what mine looks like in the end (The resistors on the picture are irrelevant to the project, I just left them there from another project):
Don´t forget to build your own antenna! This is VERY important, it will not work without one. For the 433MHz band you need approximately 17cm length of a cable. You can see mine; it is the white one on the pics.
The next step is entering a couple of code lines in the ssh console of the raspberry pi:
sudo mkdir /opt/rc-switch
cd /opt/rc-switch

sudo git clone git://git.drogon.net/wiringPi
cd wiringPi/
sudo ./build


cd /opt/rc-switch
sudo git clone https://github.com/domfi/rcswitch-pi.git
cd rcswitch-pi/
sudo make

Sometimes, not all necessary libraries have already been installed prior to compiling wiringPi. If you receive error messages, try to see which component is missing and install it first by typing:
sudo apt-get install gcc git

(I remember that I had needed gcc and git since they are not there by default on xbian but unfortunately cannot remember what else; repeat the command above and replace gcc with anything else missing).

Btw, wiringPi is a library that can be used to control the GPIO interface of the Raspberry Pi. In our case it is used to simulate the use of the HX2262 chip that can be found in the original remote control of the devices mentioned on the first paragraph. And it works pretty well I must say.

If everything is installed and the final make command is not interrupted, you should try the whole thing as follows:

sudo nice –19 /opt/rc-switch/rc-switchpi/./send 10001 3 1

the sequence of numbers represent the switches inside the original remote: 10001 corresponds to on,off,off,off,on. This can be found if you open your remote control (the original that came with the power plugs). Number 3 refers to the 3rd button, the one marked with C. The last number describes the state that we want, in this case ON.

“nice” is actually a very nice linux command that manipulates the command execution priority. xBian is quite heavy with XBMC and all and I noticed that my commands tended to be ignored. “nice” nicely fixed that problem.

Don´t forget to adjust the antenna! not too far away from the power sockets but not too close either. Correctly positioning the antenna is the key here.

Enjoy! And post your problems if you have any.
(Special, very special thanks to Mr. JG. and his awesome blog)

1 comment:

  1. I've used RCSwitch to send signals to a remote outlet on Arduino without issue, but every time I try to send the data on the PI, it does not work. If I receive and analyze the signal sent from the PI, I see that the pulseLength is always 350 (the default on RCSwitch). My signal should have been sending a pulseLength of 183 since I used the setPulseLength() function appropriately before transmitting. Is there a limit to how fast I can send this signal? I would think there would be no issues at sending this shorter pulse length. Any advice would be appreciated.

    ReplyDelete