With the addition of an #RFM12Pi expansion board a Raspberry Pi running emoncms can be used as a powerful emonBase base-station to log, process and visualise energy, temperature and other environmental data.
Data can be logged locally to the Raspberry Pi's SD card and/or to a remote emoncms server. Emoncms graphs and dashboards can be served from the Raspberry Pi's web-server.
The RFM12Pi GPIO expansion board enables the Raspberry Pi to receive or transmit data via RFM12B wireless (433/868/915Mhz) from other OpenEnergyMonitor modules such an an emonTx energy and temperature monitoring node or an emonGLCD display. The RFM12Pi expansion board can be purchased from the OpenEnergyMonitor shop
This page details how to build the RFM12Pi adapter board
The RFM12Pi is uses an ATtiny84 microcontroller running a modified version of JeeLabs RF12Demo to receive wireless data via RFM12B wireless transceiver and spit out the data via serial onto the Pi's internal serial UART port
The RFM12Pi board and much of the software is work of Martin Harizanov. We have worked with Martin on the hardware design and emoncms software integration. We owe a big thank you to Martin for the work he as put into making this solution work well.
Design Files & Part List
|1x||ATtiny84 (RF12B firmware preloaded)|
|2x||10K (brown, black, orange, gold)|
|1 x||100R (brown, black, brown, gold)|
|1x||RFM12B (433/868 Mhz)|
|1x||GPIO 6x2 pin header female socket|
|1x||ISP 3x2 pin header|
The RFM12Pi's Eagle CAD PCB design files, schematic and Arduino based firmware can be downloaded from Martin Mharizanov's GitHub
It's recommended you read through the whole of this guide and familiarise yourself with the steps before you start the actual build.
Step 1 - Identify Components and Kit Contents
Layout and identify the components from the kit.
Ok, we're ready to start. Here is the PCB ready:
Step 2 - 10k Resistors
As a general principle we're going to build up from the shallowest component. Start with the resistors. Bend each leg of the resistor over 90 degrees, right next to the body. The last colour on all of the resistors is brown - it's recommended that you align them all in the same direction and have the brown at the same end. The colours for the 10K resistor are (brown, black, orange, gold).
Step 3 - 100R Resistor
Add the 100R resistor in exactly the same way, its colours are (brown, black, brown, gold)
Step 4 - ATtiny84 DIL Socket
Fit the ATtiny84 DIL Socket as shown in the picture. Note that one end has a small notch in it - this signifies pin 1 and should match up with the notch on the PCB print. Make sure the socket is fitted flat on the board.
Step 5 - Green LED
Add the green LED. Ensure the long leg's (and round edge) go to the + symbol printed on the board.
Step 6 - RFM12B RF
Place the RFM12BRF module on the pads (observe the orientation Crystal on the LEFT) and solder each pad onto the board from above.
Step 7 - 100nF Ceramic Capacitors
Add the two 100nF ceramic capacitors one at either end of the board.
Step 8 - ISP 3x2 pin header
Add the ISP 3x2 pin header long pins point up, short pins go into the board and are soldered.
Step 9 - GPIO 6x2 pin header female socket
The GPIO female socket needs to go onto the bottom of the board.
Step 10 - RF Antenna
Add the Antenna through the hole bottom right and solder in place. The length of the Antenna is dependant on the frequency of your RFM12B module. This is a piece of wire 82mm long for 868Mhz and 165mm for 433Mhz which will act as a quarter wave for the frequency. For more background information on the RFM12B see: 
Step 11 - ATtiny84 Integrated Circuit
Fit the ATtiny84 IC into its sockets. Note the spot next to pin 1 and ensure you insert it the right way round.
IC's usually come with their legs pointing slightly outwards. To get them to fit easily into the socket, you should put the legs flat on a desk and rock the IC slightly to bend the pins inwards - do that at both sides and try again to fit into the socket.
Step 12 - Relax job done
Turn off your soldering iron and go and have a cup of tea :-)
There are two options to setup your Pi with emoncms and RFM12Pi. You can set up the system from scratch or you can quickstart by downloading the ready-to-go SD card image.
(Optional) Bootload the ATtiny84
The ATtiny84 microcontroller should come pre-loaded with the required firmware (RFM12 Demo sketch). If you have bought the RFM12pi from the OpenEnergyMonitor Shop jump ahead to #RaspberryPi Setup. However if you have obtained a blank ATtiny84 you will need to upload the rf12 demo firmware to it yourself:
The 'easy' way to do this is to flash the pre compiled hex file onto the ATtiny, this avoids having to setup the Arduino IDE for ATtiny's and having to get the correct arduino libraries etc:
- Download the pre compiled RF12 demo .hex file from the firmware folder on Mharizanov's RF12Pi Github Repo
- Power the RF12Pi board with 3.3V, this can be done from the Pi
- If you have an AVR ISP MKII programmer simply connect it up to the ISP header and run the following terminal commend:
$ sudo avrdude -c avrispmkII -p t84 -P usb -e -Uefuse:w:0xFF:m -Uhfuse:w:0xD7:m -Ulfuse:w:0xE2:m -U flash:w:ATtiny84_RF12_Demo.cpp.hex
- This avrdude command sets the ATtiny fuses for internal 8Mhz crystal with the BOD disabled and flashes a pre-compiled RF12 Demo sketch
Alternatively you can compile the RF12 Demo sketch yourself using Arduino IDE:
- Setup Arduino 1.x IDE for working with ATtiny's by following our guide
- Download a modified version (to use software serial on the ATtiny) of JeeLabs RF12 Demo from Mharizanov's RF12Pi Github Repo
- Ensure you have the latest JeeLabs JeeLib Arduino library installed
- Power the RF12Pi board with 3.3V, this can be done from the Pi
- Connect up your AVR programmer to the RF12Pi's ISP header and select your programmer in Arduino IDE tools>Programmer menu
- In Arduino IDE select ATtiny84 @ 8Mhz (internal oscillator; BOD disabled) in the Tools>Board menu and click Tools>Burn Bootloader
- You are now ready to upload the RF12 Demo to the ATtiny84 using the Arduino IDE
- Note: if you're having trouble it might be best to go back to basics with the ATtiny on a breadboard and follow this detailed guide to working with ATtiny's.
SD Card Speed & Benchmarking
We have found that emoncms works better on some brands of cards than others, even if the cards have identical class markings. This section is for listing the make, model, capacity and actual speed of your SD card. The speed can be measured using
sudo hdparm -t /dev/sdb assuming your SD card is on sdb.
- Kingston 4GB Class 4: 50 MB in 3.09 seconds = 16.20 MB/sec - emoncms is slow
- SanDisk 4GB Class 4: 50 MB in 3.02 seconds = 16.55 MB/sec - emoncms works well
- SanDisk 8GB Class 10: 54 MB in 3.04 seconds = 17.74 MB/sec
- Samsung SDHC Essential 32GO Class 10: 70 MB in 3.02 seconds = 23.21 MB/sec - emoncms looks fine
If you have followed these instructions and got to the end and it hasn't worked, don't worry, you won't be alone! Try reading through the instructions again. The main cause of errors are typos and missed steps. Use Copy and Paste to enter the command lines into the RaspberryPi terminal window. If you are still having problems, ask a question on our friendly forums.
When posting on the forum, please include as much information as you can, about what you have done, and what you see. Please include information about your monitoring setup.
Updates & Work in Progress
We are currently looking into integrating into the emoncms Raspberry Pi Module the function to allow the RFM12Pi to send the current time to the emonGLCD, see forum thread. This currently creates an issue where the serial string can get corrupted and the ATiny interprets this as a command to change the RFM12B network or node IDE. To solve this Martin has released a firmware update for the ATtiny84 which allows the 'locking' of the RFM12B settings:
Martin Harizanov ATtiny84 firmware update (22/12/12): http://harizanov.com/2012/12/rfm2pi-firmware-updates/
-Ability to lock RFM12B settings
-Fix for ACKS timing