|(176 intermediate revisions by 29 users not shown)|
File:Front_rfm12pi.png|200 px|RFM12Pi Front]] [[ File: Onpi_rfm12pi. png|200 px|RFM12Pi installed Raspberry Pi]]
'''DOCUMENTATION ON THIS PAGE IS IN DEVELOPMENT AND INCOMPLETE!'''
===Design Files & Part List===
===Design Files & Part List===
===Raspberry Pi Setup ===
====SD card & Raspbian Linux Setup====
'Note: when working we the Pi we recommend shutting down the Pi properly with <code> $ sudo halt</code> before powering down the Pi or removing the SD card to avoid a corrupted card. We learnt this the hard way!''
to a .this
#Download [http: //www. raspberrypi. org/ downloads Raspbian 'Wheezy' SD card image ] ''This guide was made using 18th September 2012 release.''
#Copy SD card image on SD card using Linux tool "dd" for any other OS see [http: //elinux. org/ RPi_Easy_SD_Card_Setup Raspberry Pi tutorial]
#* Insert SD card <code>$ df - h</code> to view mounted partition, make note of SD card device name, for me this was 'sdb'
#* Unmount SD card <code>$ umount /dev/sdb1</code> you will need to change sdb to match your SD card drive. If the card has more than one partition un mount that also <code>$ umount /dev/ sdb2</code>
#* Write the .img to the card <code>$ sudo dd bs=4M if=~/ Downloads/ 2012-09-18-wheezy-raspbian. img of=/ dev/ sdb</ code> again you will need to replace sdb with your SD card device name and modify the location and name of the image as need.
# Put SD card into Pi and connect network and power
# Find the IP address of the Pi and SSH to
<code>$ SSH [email protected]<
code>, default password is 'raspberry'
# Once successfully logged in run Raspbian setup <code>$ sudo raspi- config</ code>
#* Select ''Expand root partition to fill SD card'' finish and reboot
#* One rebooted restart SSH connection and run <code>$ sudo raspi-config</ code> again
#* Check for updates
#* Change password for user Pi to something of your choice, make it secure it will be storing your home energy data!
#* If you plan to run the Pi as a headless dataloggin emoncms server as we do then select ''memory- split'' and choose the first setting a ''240/ 16'' split, the gives the CPU more memory at the expense of graphics which we're not using
#* We also recommend selecting ''boot behaviour'' and disabling booting straight into a desktop since this increases boot time and wastes system resources. If required a desktop can be loaded with <code>$ startx</code>.
#* Set ''locale'' and ''timezone'' as required
#* Finish and reboot, remember to use your new password when SSH'ing back in!
# (optional) set a host name for the Pi to enable host name to be used instead of IP address when connection to the Pi
#* Change the default ''raspberrypi'' host name to that of your choice eg.emoncms in the file <code>$ sudo nano / etc/hostname</code> [Ctrl+X] then [Y] then [Enter] to save and exit
#*and in the file <code>$ sudo nano /etc/hosts</code> [Ctrl+X] then [Y] then [Enter] to save and exit
#* Reboot the Pi and you should be able to SSH back in with <code>$ ssh [email protected]</code> if '
' was your chosen host name. ''Note: this won't work with all routers, you might need to set the Pi as a 'Fixed Host' in the router config''
#Install emoncms following [http://openenergymonitor.org/emon/emoncms/installing-ubuntu-debian-pi this guide] up to the end of section 7
# Instead of emoncms3 on the OpenEnergyMonitor GitHub use <code> $ git clone git://github.com/emoncms/emoncms.git</code> as the GtiHub emoncms repo. This is a new 'modular' version of emoncms. Alternatively you could download the zip file from github an extract into /var/www
# Navigate to the emoncms modules folder <code>$ cd emoncms/Modules</code>
# Download the Raspberry Pi emoncms module into the Modules folder <code>$ git clone https://github.com/emoncms/raspberrypi.git</code>
# Now carry on following the [http://openenergymonitor.org/emon/emoncms/installing-ubuntu-debian-pi emoncms install guide] section 8-10.
#* Note: since we're using the new modular version of emoncms the first bit of step 9 should be <code>$ cd /var/www/emoncms/</code>
# When you've finished you should be able to browse to Http://Pi IP address or Host/emoncms, create and account and test posting data with the 'try me' button in the API section.
Make sure Raspberry Pi’s UART is disconnected from the console and available for programs to use it.
# Backup cmdline.txt <code> $ sudo cp /boot/cmdline.txt /boot/cmdline_backup.txt</code>
<code>sudo nano ///.</code> and the file by and the
# Edit cmdline.txt to remove references to Pi’s UART (ttyAMA0)
#* <code>$ sudo nano / boot/ cmdline.txt</code>
#* edit it from <code>dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait </ code> to <code>dwc_otg. lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait</code> [Ctrl+X] then [y] then [Enter] to save and exit
#* <code>$ sudo nano /etc/inittab</code> comment out the following line at the bottom of the file by adding a '#' at begining of: <code>T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100</code> [Ctrl+X] then [y] then [Enter] to save and exit
#Reboot the Pi by <code>$ sudo reboot</code>
Install serial PHP libraries
# <code>$ sudo apt-get install php-pear php5-dev</code>
://..///this ] to and -.
# <code>$ sudo pecl install channel:// pecl.php.net/dio-0. 0. 6</code>
# <code> $ sudo nano /etc/php5/cli/ php.ini</ code> add <code>extension=dio.so</ code> to the ''end of the file - is this the correct location?''. [Ctrl+X] then [y] then [Enter] to save and exit
# Restart apache <code>$ sudo /etc/init.d/apache2 restart</code>
# Connect the RFM12Pi on to Pi's GPIO taking care to line up pin 1 as show in photo above
# Test the RFM12Pi is working and receiving RFM12 data by viewing it's serial output
#* <code>$ sudo apt-get install minicom</code>
#* <code>$ minicom -b 9600 -o - D /dev/ttyAMA0</code>
#* The LED on the RFM12Pi should flash to indicate a data packet received and the raw data packet should come up in the serial window.
#* To exit minicom [CTRL+ A] then [X]
Setup emoncms Raspberry Pi module
# Get emoncms to detect the raspberry Pi module by.. ...to be completed!
the . .
# <code>$ sudo nano /var/www/emoncms/index.php</code>
# db_schema_setup(load_db_schema()); - '''TO BE COMPLETED!'''
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
The RFM12Pi is uses an ATtiny84 microcontroller running a modified version of JeeLabs RF12Demo to receive wireless data via an RFM12B wireless transceiver and transmit data via the Pi's internal serial port
The RFM12Pi board and much of the software is the work of Martin Harizanov. We worked with Martin on the hardware design and emoncms software integration. We owe Martin a big thank you for the effort put into making this solution work well.
Design Files & Part List
||ATtiny84 (RF12B firmware preloaded)
||10K (brown, black, orange, gold)
||100R (brown, black, brown, gold)
||RFM12B (433/868 Mhz)
||GPIO 6x2 pin header female socket
||ISP 3x2 pin header
The RFM12Pi's Eagle CAD PCB design files, schematic and Arduino based firmware can be downloaded from Martin Harizanov's GitHub
1) RFM12Pi Assembly
It's recommended you read this guide and familiarise yourself with the steps before you start the build.
Step 1 - Identify Components and Kit Contents
Lay out, and identify, the components from the kit.
Ok, we're ready to start. Here is the PCB:
Step 2 - 10k Resistors
As a general principle we're going to build up from the lowest-profile component.
Start with the resistors. Bend each leg of the resistor 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 silkscreen. Make sure the socket is fitted flat on the board.
Step 5 - Green LED
Add the green LED. Ensure the long leg (and round edge) are facing 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 to the board.
Step 7 - 100nF Ceramic Capacitors
Add the two 100nF ceramic capacitors one at either end of the board.
Step 8 - 3x2 pin ISP header
Add the 3x2 pin ISP header. Long pins point up, short pins are soldered to the board.
Step 9 - 6x2 pin GPIO header female socket
The GPIO socket needs to go on the bottom of the board.
Step 10 - RF Antenna
Add the Antenna through the bottom-right hole, and solder it 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 antenna. For more information on the RFM12B see: 
Step 11 - ATtiny84 Integrated Circuit
Fit the ATtiny84 IC into its socket. Note the spot next to pin 1 and ensure you insert it the right way round.
ICs usually come with their legs pointing slightly outwards. To get them to fit easily into the socket, put the legs flat on a desk and rock the IC slightly to bend the pins inwards - do that to both sides and try to fit it into the socket again.
Step 12 - Relax job done
Turn off your soldering iron and go and have a cup of tea :-)
2) Prepare SD Card
There are two options to set up your Pi with emoncms and RFM12Pi. You can set up the system from scratch, or you can quickstart it by downloading the ready-to-go SD card image.
Using ready-to-go image Recommended
Build from scratch
(Optional) Bootload the ATtiny84
The ATtiny84 microcontroller should come pre-loaded with the required firmware (RFM12 Demo sketch). If you bought the RFM12pi from the OpenEnergyMonitor Shop jump ahead to #RaspberryPi Setup. However, if you have obtained a blank ATtiny84 you'll need to upload the rf12 demo firmware to it:
The 'easy' way to do this is to flash the pre compiled hex file onto the ATtiny, this avoids the need to set up the Arduino IDE for an ATtiny, getting 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 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 operation with an ATtiny 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 your AVR programmer to the RF12Pi's ISP header and select your programmer in the Arduino IDE tools>Programmer menu
- In the 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 an ATtiny.
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
Using WiFi on a Raspberry Pi
Update: The Edimax EW-7811 UN has adapter been reported to work well on the Pi. See OEM forum thread and setup instructions
If you can't get your Pi close to an Ethernet connection, it's possible to use WiFi with a USB WiFi adapter. Setup is quite easy, as the drivers are built into Raspbian on which the pre-built emoncms SD card image is based. I used a USB WiFi adapter based on the RTL8188CUS chipset. Performance was fine, but noticeably slower than Ethernet.
Plug the adapter into the Pi and run
$ lsusb and
$ lsmod to verify the adapter and the driver 9182cu are listed. As a final check, run
$ iwconfig to see if the adapter driver is loaded.
To set up your WiFi connection, edit the config file by running
$ sudo nano /etc/network/interfaces and checking that the following is in the file:
iface wlan0 inet dhcp
close and save, then run
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf and edit the file by entering your SSID and WPA key in the correct locations
Save, close and finally run
$ sudo ifup wlan0 to reboot the module and connect to the network. WiFi should now be up and running. You can double check by running
If you find the WiFi drops off, you might want to use this script to periodically check for a connection and re-connect.
The script needs to be added to the crontab to run periodically,
$ crontab -e to edit or add a new cron tab or '-l' (lower case L) to list existing (if any) crontabs.
If you have followed these instructions and your WiFi still doesn't work, 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're still having problems, ask a question on our friendly forum.
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.