My first idea was to get Mia Robocat to be able to turn lights on and off, turn appliances like television on as well as change channels. So I bought the following 433MHz rf receiver and transmitter which are very cheap (about £2).

433rf

To be honest I had to do quite a bit of reading around the subject on the internet. Some of the resources can be found at Stavros’ Stuff and Princetonics. I then proceeded to connect the transmitter and receiver to my mini arduino on the robocat. Part of the reason for this is that the arduino can utilize 5v for the receiver whereas the Raspberry Pi will fry on that voltage level. Using the code from the Home Easy project I was able to grab the codes from the Nexa remote control and fire them off to turn the nexa sockets on and off. But the main problem with this was the programming space on the arduino. I couldn’t use the arduino to run the robocat motors as well as receive and transmit 433rf signals so the project went on the backburner for a while.

I got back to this project after getting the pizero free from the magazine MagPi. I proceeded to solder on the pins and got back re-reading the stuff around Home Automation. Why I decided to write my own program was that all the things I could find available on the internet weren’t exactly what I needed. Some were too specific to the arduino rather than the Raspberry Pi. Many were very specific to one kind of switch and most concentrated too much on transmitting rather than receiving. I had by now got a Blyss wireless doorbell which I wanted to capture and play my own tunes rather than the provided ding-dong.

Luckily I found a very good tutorial at Instructables which I recommend. Not only does it explain clearly, but it also gives the code in Python which is much easier to understand than most languages. My work started where this finishes really. Source code and instructions can be found here.

I would recommend to anyone who wants to do things with the gpio pins of the raspberry pi to install wiringPi. One of the problems is that the numbering of the pins across the web is really inconsistent and left me scratching my head a lot. If you run the following command gpio readall it will give you a map of the pin numbering for your version of the Pi.

pi@raspberrypi ~/RF433Ctrl $ gpio readall
 +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 |   IN | 1 |  3 || 4  |   |      | 5V      |     |     |
 |   3 |   9 |   SCL.1 |   IN | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 1 | ALT0 | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | ALT0 | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI |   IN | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO |   IN | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK |   IN | 0 | 23 || 24 | 1 | IN   | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 1 | IN   | CE1     | 11  | 7   |
 |   0 |  30 |   SDA.0 |   IN | 1 | 27 || 28 | 1 | IN   | SCL.0   | 31  | 1   |
 |   5 |  21 | GPIO.21 |   IN | 1 | 29 || 30 |   |      | 0v      |     |     |
 |   6 |  22 | GPIO.22 |   IN | 1 | 31 || 32 | 0 | IN   | GPIO.26 | 26  | 12  |
 |  13 |  23 | GPIO.23 |   IN | 0 | 33 || 34 |   |      | 0v      |     |     |
 |  19 |  24 | GPIO.24 |   IN | 0 | 35 || 36 | 0 | IN   | GPIO.27 | 27  | 16  |
 |  26 |  25 | GPIO.25 |   IN | 0 | 37 || 38 | 0 | IN   | GPIO.28 | 28  | 20  |
 |     |     |      0v |      |   | 39 || 40 | 0 | IN   | GPIO.29 | 29  | 21  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+---Pi 2---+---+------+---------+-----+-----+
 pi@raspberrypi ~/RF433Ctrl $

The project consists of two parts really. A toolkit which should make it easy to track down the codes sent from the 433rf device. Given that there is plenty of noise it is sometimes difficult to see the wood for the trees. The toolkit simplifies by smoothing and clustering the message and plots the code so you can visually see what it is doing. The full list of parameters are below.

           -rec      will record raw signals from 433mhz receiver
           -read      will read values from file
                     use - for default filename
           -write     option to write the values to file
                     use - for default filename
           -trim     will remove low signal at the beginning and
                     smooth out signals of less than 20u
           -mean     works out the mean signal values and applies
                     across the signal thereby rationalizing
           -block    will attempt to find repeating blocks
           -display  displays signal lengths in ms as /HIGH\ and _LOW_
           -plot     alternatively plots the values to graph

To get started I would use the option sudo python toolkitRF433.py -rec -display to get a feel for things and see that you are getting some signal through. Then use gksudo — python toolkitRF433.py -rec -plot to see where you are getting the signal amongst the noise. Then add the -write – option and run either of the previous commands again. If you have a fairly clean signal – you should see several blocks in the middle of the graph then press Y to confirm saving. Then instead of the -rec option use -read – to read the signal from the saved file. Then you could use -block option which will also run the -trim and -mean options and if you are lucky you will get a clean consistent small block of signal consisting of a latch followed by codes representing 1s and 0s. At any point you can edit the receive.dat file manually to cut out noise and repeating blocks.

Once you have captured the protocol of the message you can then enter this protocol json file provided and then by using the receiveRF433Ctrl.py you can listen out for codes of this type. This works for both Nexa and Blyss at present.

I haven’t yet included the transmitter code but that won’t be a huge problem. I also need to change to 5v as the recieve range on 3.3v is too short. I can see that there may be efficiency issues as the receiver would need to be on constantly. I am hoping in future to convert it to an interrupt based approach as described here.

 

Advertisements