Getting start with rfrpi card v1.0 – rf433 for raspberry pi

rfrpi_2RfRpi card is a RF433 emitter and receiver add-on of Raspberry Pi. This card is based on high quality receiver and transmitter I have selected after tests you can find here and here. This article describes how to get start with this shield.

To buy this shield the best way is to sent me a comment on this post, the price is 60€

The Shield is now working with Raspberry PI B+ and previous versions. The Shield is also working with Raspberry PI 2+. For these two last version you need to compile a kernel driver.

 

1 – Get the shield

You can order this shield contacting me (add a comment to this post)

The shield in V1.2 (for RaspberryPI B+ / A+) looks like this:

Raspberry Pi B+ - RFRPI Shield
Raspberry Pi B+ – RFRPI Shield

The shield in V1.1 (for RaspberryPi A&B) looks looks like this (this photo is not contractual, leds & antenna particularly can differ) :

RFPRI shield - High Quality RF433 for raspberry
RFPRI shield – High Quality RF433 for raspberry

The shield is delivered with an antenna and 3 programmable leds

2 – Plug the shield

The first step is to plug the shield, no need to detail how to do it, if you are not sure, just don’t do it ! It’s you own responsibility to plug and use this shield you do it at your own risk.

Once on the RPI is looks like :

RF433 Raspberry PI shield v1.0
RF433 Raspberry PI shield v1.0

For a model B+, I recommend to use this box :

 

rpi_bplus_case

The shield has been done to fit in a raspberry pi A/B box like this one : cyntech-model-a-raspberry-pi-case-black-1-498x498So you can close it in a such box after having created the needed hole for leds & antenna.

This look like this at the end (depending of the used antenna), this photo is not contractual !

rfrpi_3

3 – Install a Raspbian image

This tutorial is based on 2014-01-07-wheezy-raspbian.zip (be careful, this link is pointing to the latest. It should be work be it should not be the one I used)

The first step is to get the zip file and flash the Sdcard with its content, you can refer to this tutorial for doing it : http://elinux.org/RPi_Easy_SD_Card_Setup

On Mac, but it is also working on Linux, in a terminal type mount (or dmesg) to identify what disk is associated to the Sdcard once plugged in. You can also use the follwoing tool:

In case the SD Card has been mounted automatically you can unmount

Then umount the partition of this disk if they have been auto-mounted.  At end, fire the flash command line :

# dd if=/path/to/the/raspbian.img of=/dev/diskX bs=1m

The flashing procedure is long, by pressing CTRL+T, you can get a status report.

Once done, plug the sdcard, connect HDMI, keyboard then power the raspberry pi.

The next steps are about basic configuration to get started.

  • From the main menu, select expand file system : this is enlarging the file system to the whole sdcard (raspbian per default in 2GB, if your sdcard is larger, this process will allow you to access space over 2GB). Just validate, raspbian will be back to this menu after expending process.
raspi-config main menu
raspi-config main menu
  • From the main menu, configure your keyboard layout (this have to be done if you are not using a standard Qwerty). Select Internationalization Options in the menu
raspi-config - change keybord layout
raspi-config – change keybord layout

Then Change Keyboard layout to match your keyboard entry.

raspi-config : change keyboard layout
raspi-config : change keyboard layout

Select you keyboard type, generally, Generic 105 key is good.

raspi-config : select keyboard layout
raspi-config : select keyboard layout

Select your language (select other for non English)

raspi-config : non english layout
raspi-config : non english layout

Select your language in the list (here french) – you have to adapt to your own language.

raspi-config : select french language
raspi-config : select french language

Now, you have a couple of screens to select specific behavior

raspi-config : select language alternatives
raspi-config : select language alternatives
raspi-config : select AltGR behavior
raspi-config : select AltGR behavior
raspi-config : select Right ALT behavior
raspi-config : select Right ALT behavior
raspi-config : select CTRL+ALT+BSpace behavior
raspi-config : select CTRL+ALT+BSpace behavior

This last step brings you back to the main menu.

 

  • From the main menu, now select Change User Password entry, you will be prompted for a new password.
raspi-config main menu
raspi-config main menu
  • From the main menu, now select Enable Boot to Desktop… entry, to select a console mode only (no need for graphical environment for our purpose)
raspi-conf : configure boot
raspi-conf : configure boot
raspi-config : select Text Console at boot
raspi-config : select Text Console at boot
  • Now, from main menu, select Advanced Options to enable SSH server
raspi-config : Advanced Options
raspi-config : Advanced Options

Then select SSH to activate server

raspi-config : active SSH server
raspi-config : active SSH server

Confirm

raspi-config : confirm SSH server activation
raspi-config : confirm SSH server activation
  • Now, the raspbian is configured, from the main menu, select Finish then reboot.
raspi-config : finishing
raspi-config : finishing
raspi-config : rebooting
raspi-config : rebooting
  •  Once the system have finished reboot, you can see the assigned IP in the console
raspi-config : assigned IP address
raspi-config : assigned IP address
  • Now, you can log to the system in the console or from the network, with default user pi and the password you set.

4 – Install the rfrpi needed libraries

Rfrpi is using wiringPI for accessing GPIO. The installation process is the following, from the raspberry command line:

# ssh -l pi 10.0.0.161
pi@raspberrypi ~ $ git clone git://git.drogon.net/wiringPi
pi@raspberrypi ~ $ cd wiringPi
pi@raspberrypi ~/wiringPi $ ./build

5 – Install the rfrpi software

RfRpi comes with a demonstration program you can fin in this git repository : https://bitbucket.org/disk_91-admin/rfrpi/src

To install it on Pi :

# ssh -l pi 10.0.0.161
pi@raspberrypi ~ $ git clone https://bitbucket.org/disk_91-admin/rfrpi.git
pi@raspberrypi ~ $ cd rfrpi/rfrpi_src

Depending on the type of Rapberry you have, you should modify de file version.h by commenting / uncommenting the needed line.

// For RPI v1
// #define RFRPI_RPI_VERSION       1
// For RPI B+ and RPI 2
#define RFRPI_RPI_VERSION       2

For RPI2 and RPIB+ you also need to compile the kernel driver you will find in the krfrpi folder ; for this, take a look to this post about kernel driver for rf433

If you have a RPI 1 ; you don’t have to care about what it is above.

For all, you need to compile and run !

pi@raspberrypi ~/rfrpi/rfrpi_src $ make

You must run the I/O configuration script on startup by adding the blue line in /etc/rc.local if not doing it, the raspberry will emit continuously noise and disturb other devices.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi

/home/pi/rfrpi/rfrpi_src/rfrpi_hwinit.sh
exit 0

Then run it:

pi@raspberrypi ~/rfrpi/rfrpi_src $ sudo ./rfrpi_test

You should got the following result as an example:

pi@raspberrypi ~/rfrpi/rfrpi_src $ sudo ./rfrpi_test 
Singleton::init() - entering 
Singleton::init() - ledManager created 
Singleton::init() - core_433 created 
Singleton::init() - EventManager created 
Singleton::init() - Singleton is ready 
Version (0.1) Branch (beta) Build date(20140223)
EventManager::enqueue() - enqueue ((null))
EventManager::eventLoop() - proceed INIT 
* Core_433::receptionLoop() - received message [RCSW 123456]
EventManager::enqueue() - enqueue (RCSW 123456)
* Core_433::receptionLoop() - received message [RCSW 123456]
EventManager::enqueue() - enqueue (RCSW 123456)
EventManager::eventLoop() - proceed GETSENSORDATA 
[INFO] Welcome message correctly received, Rx/Tx working fine
EventManager::eventLoop() - proceed GETSENSORDATA 
[INFO] Welcome message correctly received, Rx/Tx working fine
* Core_433::receptionLoop() - received message [OSV2 1A2D1002402000842577]
EventManager::enqueue() - enqueue (OSV2 1A2D1002402000842577)
EventManager::eventLoop() - proceed GETSENSORDATA 
 {"datetime": "2014-02-23 20:11:31", "temperature": "20.400000", "humidity": "40.000000", "channel": "1" } 

The part in green is a shield health check procedure, the INIT event is send to the eventManager, this makes the 3 led blinking then emitting a 123456 message to ensure emitter and receiver are working. This part can be removed from main().

The part in blue is an example of message received from a sensor. The behavior can be modified from the eventManager.cpp class.

6 – Let’s Hack it !

Now, you can start working with the library, a couple of explanations :

  • RCSwitch is the lower end driver  listening RF and decoding signals, it is where you can active some new layer 1 decoding protocol.
  • RcOok is the layer 1 decoding system for miscellaneous protocols. It is where you can add you own layer 1 decoding protocol.
  • Core433 is the associated Thread interpreting RF messages and creating the message to the eventManager once a message is received.
  • EventManager is the state machine receiving the messaging and executing the expected actions like extracting and printing sensors data from a RF message. It is where you can add your custom code.
  • Sensor is the layer 2 decoding protocol, at this level we are extracting the sensor measure from the received data, like temperature, humidity … This is where you can add you own sensors definition.
  • LedManager is the led driver allowing functions like on/off/blinking/fast blinking…
  • Singleton is a really bad way, but efficient one to start all the threads and to allow an object sharing across the Threads.

Have fun with this code, do not hesitate to upgrade it and push modification of this code, particularly if you are implementing new sensors, I’m sure all of us will be happy to use it as you can be happy to use the one already in it !

 

This entry was posted in IoT and tagged , , , . Bookmark the permalink.

36 Responses to Getting start with rfrpi card v1.0 – rf433 for raspberry pi

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.