Difference between revisions of "Raspberry Pi"

From OpenEnergyMonitor Wiki
Jump to: navigation, search
(RFM12Pi)
(Troubleshooting)
 
(36 intermediate revisions by 5 users not shown)
Line 1: Line 1:
 
=Raspberry Pi=
 
=Raspberry Pi=
  
With the addition of an [[#RFM12Pi]] expansion board a Raspberry Pi running [http://openenergymonitor.org/emon/emoncms emoncms] can be used as a powerful [http://openenergymonitor.org/emon/emonbase emonBase] base-station to log, process and visualise energy, temperature and other environmental data.
+
With the addition of an [[#RFM12Pi]] expansion board, a Raspberry Pi running [http://emoncms.org emoncms] can be used as a powerful [http://openenergymonitor.org/emon/emonbase 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.  
 
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.  
Line 9: Line 9:
 
===RFM12Pi===
 
===RFM12Pi===
  
The RFM12Pi GPIO expansion board enables the Raspberry Pi to receive or transmit data via RFM12B wireless (433/868/915Mhz) from other [http://openenergymonitor.org/emon/Modules/ OpenEnergyMonitor modules] such an an [http://openenergymonitor.org/emon/emontx emonTx] energy and temperature monitoring node or an [http://openenergymonitor.org/emon/emonglcd emonGLCD] display.The RFM12Pi expansion board can be purchased from the [http://shop.openenergymonitor.com/raspberry-pi/ OpenEnergyMonitor shop]
+
The RFM12Pi GPIO expansion board enables the Raspberry Pi to receive or transmit data via RFM12B wireless (433/868/915MHz) from other [http://openenergymonitor.org/emon/Modules/ OpenEnergyMonitor modules] such an an [http://openenergymonitor.org/emon/emontx emonTx] energy and temperature monitoring node, or an [http://openenergymonitor.org/emon/emonglcd emonGLCD] display. The RFM12Pi expansion board can be purchased from the [http://shop.openenergymonitor.com/raspberry-pi/ OpenEnergyMonitor shop]
  
 
[[File:Front_rfm12pi.png|200 px|RFM12Pi Front]]
 
[[File:Front_rfm12pi.png|200 px|RFM12Pi Front]]
 +
 +
==For the new pre-assembled RFM12Pi V2 [[RFM12Pi_V2 | see new documentation]]==
  
 
=== Technical Overview===
 
=== Technical Overview===
The RFM12Pi is uses an ATtiny84 microcontroller running a modified version of [https://github.com/jcw/jeelib/tree/master/examples/RF12/RF12demo 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 is uses an ATtiny84 microcontroller running a modified version of [https://github.com/jcw/jeelib/tree/master/examples/RF12/RF12demo 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 work of [http://harizanov.com/wiki/wiki-home/rfm2pi-board/ 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.
+
The RFM12Pi board and much of the software is the work of [http://harizanov.com/wiki/wiki-home/rfm2pi-board/ 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===
 
===Design Files & Part List===
Line 49: Line 51:
 
|}
 
|}
  
The RFM12Pi's Eagle CAD PCB design files, schematic and Arduino based firmware can be downloaded from [https://github.com/mharizanov/RFM2Pi Martin Mharizanov's GitHub]
+
The RFM12Pi's Eagle CAD PCB design files, schematic and Arduino based firmware can be downloaded from [https://github.com/mharizanov/RFM2Pi Martin Harizanov's GitHub]
  
==RFM12Pi Assembly==
+
==1) RFM12Pi Assembly==
  
'''It's recommended you read through the whole of this guide and familiarise yourself with the steps before you start the actual build.'''
+
'''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'''
 
'''Step 1 - Identify Components and Kit Contents'''
  
Layout and identify the components from the kit.
+
Lay out, and identify, the components from the kit.
  
 
[[File:Rasppi.JPG|200 px]]
 
[[File:Rasppi.JPG|200 px]]
  
  
Ok, we're ready to start. Here is the PCB ready:
+
Ok, we're ready to start. Here is the PCB:
  
 
[[File:Rasppirfm1.jpg|200 px]]
 
[[File:Rasppirfm1.jpg|200 px]]
Line 68: Line 70:
 
'''Step 2 -  10k Resistors'''
 
'''Step 2 -  10k Resistors'''
  
As a general principle we're going to build up from the shallowest component.
+
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 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).  
+
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).  
  
 
[[File:Rasppirfm2.jpg|100 px]]  
 
[[File:Rasppirfm2.jpg|100 px]]  
Line 82: Line 84:
  
 
Fit the ATtiny84 DIL Socket as shown in the picture.  
 
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.
+
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.
  
  
Line 89: Line 91:
 
'''Step 5 - Green LED'''
 
'''Step 5 - Green LED'''
  
Add the green LED.  Ensure the long leg's (and round edge) go to the + symbol printed on the board.
+
Add the green LED.  Ensure the long leg (and round edge) are facing the + symbol printed on the board.
  
 
[[File:Rasppirfm5.jpg|100 px]]
 
[[File:Rasppirfm5.jpg|100 px]]
Line 97: Line 99:
 
'''Step 6 - RFM12B RF'''
 
'''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.
+
Place the RFM12BRF module on the pads (observe the orientation - Crystal on the LEFT) and solder each pad to the board.
  
 
[[File:Rasppirfm6.jpg|100 px]]
 
[[File:Rasppirfm6.jpg|100 px]]
Line 107: Line 109:
 
[[File:Rasppirfm7.jpg|100 px]]
 
[[File:Rasppirfm7.jpg|100 px]]
  
'''Step 8 - ISP 3x2 pin header'''
+
'''Step 8 - 3x2 pin ISP header'''
  
Add the ISP 3x2 pin header long pins point up, short pins go into the board and are soldered.
+
Add the 3x2 pin ISP header. Long pins point up, short pins are soldered to the board.
  
 
[[File:Rasppirfm8.jpg|100 px]]
 
[[File:Rasppirfm8.jpg|100 px]]
  
'''Step 9 - GPIO 6x2 pin header female socket'''
+
'''Step 9 - 6x2 pin GPIO header female socket'''
  
The GPIO female socket needs to go onto the bottom of the board.
+
The GPIO socket needs to go on the bottom of the board.
  
 
[[File:Rasppirfm9.jpg|100 px]]
 
[[File:Rasppirfm9.jpg|100 px]]
Line 121: Line 123:
 
'''Step 10 - RF Antenna'''
 
'''Step 10 - RF Antenna'''
  
Add the Antenna through the hole bottom right and solder in place.
+
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 for the frequency. For more background information on the RFM12B see: [http://openenergymonitor.org/emon/buildingblocks/rfm12b-wireless]
+
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: [http://openenergymonitor.org/emon/buildingblocks/rfm12b-wireless]
  
 
[[File:Rasppirfm10.jpg|100 px]]
 
[[File:Rasppirfm10.jpg|100 px]]
Line 128: Line 130:
 
'''Step 11 - ATtiny84 Integrated Circuit'''
 
'''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.
+
Fit the ATtiny84 IC into its socket. 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.
+
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.
  
 
[[File:Rasppirfm11.jpg|100 px]]
 
[[File:Rasppirfm11.jpg|100 px]]
Line 138: Line 140:
 
Turn off your soldering iron and go and have a cup of tea :-)
 
Turn off your soldering iron and go and have a cup of tea :-)
  
===ATtiny84===
+
==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.
  
'''The ATtiny84 microcontroller should come pre-loaded with the required firmware (RFM12 Demo sketch). If you have bought the RFM12pi from the  [http://shop.openenergymonitor.com 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:'''
+
[http://emoncms.org/site/docs/raspberrypibuild Using ready-to-go image] '''Recommended'''
  
 +
[http://emoncms.org/site/docs/raspberrypibuild Build from scratch]
  
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:
+
==(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 [http://shop.openenergymonitor.com 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 [https://github.com/mharizanov/RFM2Pi Mharizanov's RF12Pi Github Repo]  
 
# Download the pre compiled RF12 demo .hex file from the firmware folder on [https://github.com/mharizanov/RFM2Pi Mharizanov's RF12Pi Github Repo]  
 
# Power the RF12Pi board with 3.3V, this can be done from the Pi
 
# 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:   
+
# If you have an AVR ISP MKII programmer simply connect it to the ISP header and run the following terminal commend:   
 
#* <code>$ 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</code>
 
#* <code>$ 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</code>
 
#* This avrdude command sets the ATtiny fuses for internal 8Mhz crystal with the BOD disabled and flashes a pre-compiled RF12 Demo sketch
 
#* 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:
 
Alternatively you can compile the RF12 Demo sketch yourself using Arduino IDE:
  
# Setup Arduino 1.x IDE for working with ATtiny's by following [http://openenergymonitor.org/emon/buildingblocks/attiny our guide]
+
# Setup Arduino 1.x IDE for operation with an ATtiny by following [http://openenergymonitor.org/emon/buildingblocks/attiny our guide]
 
# Download a modified version (to use software serial on the ATtiny) of JeeLabs RF12 Demo from [https://github.com/mharizanov/RFM2Pi Mharizanov's RF12Pi Github Repo]
 
# Download a modified version (to use software serial on the ATtiny) of JeeLabs RF12 Demo from [https://github.com/mharizanov/RFM2Pi Mharizanov's RF12Pi Github Repo]
 
# Ensure you have the latest JeeLabs [https://github.com/jcw/jeelib JeeLib Arduino library] installed  
 
# Ensure you have the latest JeeLabs [https://github.com/jcw/jeelib JeeLib Arduino library] installed  
 
# Power the RF12Pi board with 3.3V, this can be done from the Pi
 
# 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  
+
# Connect your AVR programmer to the RF12Pi's ISP header and select your programmer in the 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''  
+
# 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
 
# 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 [http://hlt.media.mit.edu/?p=1695 this detailed guide to working with ATtiny's].
+
# Note: if you're having trouble it might be best to go back to basics with the ATtiny on a breadboard and follow [http://hlt.media.mit.edu/?p=1695 this detailed guide to working with an ATtiny].
  
==Raspberry Pi Setup==
+
==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 <code>sudo hdparm -t /dev/sdb</code> assuming your SD card is on sdb.
  
There are two options to setup your Pi with emoncms and RFM12Pi. You can set up the system from scratch following all the steps in the section below, or you can quickstart by downloading our ready-to-go SD card image.
+
*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
 +
*[http://www.samsung.com/fr/consumer/it/memory-card/sd/MB-SSBGA/EU Samsung SDHC Essential 32GO Class 10]: 70 MB in  3.02 seconds =  23.21 MB/sec - emoncms looks fine
  
===Using the ready-to-go SD card image===
+
==Using WiFi on a Raspberry Pi==
  
''Documentation for this section is in progress....may be incomplete or incorrect''
+
'''Update: The [http://uk.rs-online.com/web/p/wireless-adapters/7603621/?searchTerm=760-3621&relevancy-data=636F3D3126696E3D4931384E525353746F636B4E756D6265724D504E266C753D656E266D6D3D6D61746368616C6C26706D3D5E5C647B337D5B5C732D2F255C2E2C5D5C647B332C347D2426706F3D313426736E3D592673743D52535F53544F434B5F4E554D424552267573743D3736302D333632312677633D4E4F4E4526 Edimax EW-7811 UN] has adapter been reported to work well on the Pi. See [http://openenergymonitor.org/emon/node/2941 OEM forum thread] and [http://svay.com/blog/setting-up-a-wifi-connection-on-the-raspberrypi/ setup instructions]'''  
  
This 'ready-to-go' SD card image is designed for a 2GB SD card. It's based on Raspbian 'Wheezy' (Sep 2012 release), and has all the needed server components and emoncms installed and configured to receive wireless data from OpenEnergyMonitor and JeeNode modules using the RFM12Pi hardware connected to the GPIO header on the Pi. A few additional setup steps are required/recommended:
 
  
''We recommend using SSH to access the Pi terminal window remotely. That way, you won't need a monitor connected to the Pi''
+
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. 
  
'''Note: when working with the Pi, we recommend shutting down the Pi properly with <code>$ sudo halt</code> before powering down or removing the SD card. (to avoid a corrupted card) We learnt this the hard way!'''
+
Plug the adapter into the Pi and run <code>$ lsusb</code> and <code>$ lsmod</code> to verify the adapter and the driver ''9182cu'' are listed. As a final check, run <code>$ iwconfig</code> to see if the adapter driver is loaded.
  
#'''Download the ready-to-go SD card image [https://www.dropbox.com/s/5odwpcrgpsqoxso/emoncmspi.zip here]''' (514Mb
+
To set up your WiFi connection, edit the config file by running <code>$ sudo nano /etc/network/interfaces</code> and checking that the following is in the file:
# Extract .img from .zip file, the emoncmspi.img uncompressed image size is 2GB
+
# Write image to 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 to SD card using <code>sudo dd bs=4M if=emoncmspi.img of=/dev/sdb</code>
+
# Insert card into the Pi and connect Ethernet and power
+
# ssh to the Pi using <code>ssh [email protected]</code> and password '''raspberry'''. You will need to replace the IP address with the local IP address of your Pi. This can be found by looking at the DHCP table in your router. Alternatively, you can use a network scanning app such as [https://play.google.com/store/apps/details?id=com.overlook.android.fing Fing (android)], [https://itunes.apple.com/us/app/inet/id403304796?mt=12 iNet (Mac)], [https://itunes.apple.com/us/app/inet-network-scanner/id340793353?mt=8 iNet (iPhone)] to scan your network.
+
# Optional but recommended: run <code>sudo raspi-config</code> and set a number of options:
+
#* If you card >2Gb Expand the root partition to fill SD card, this will give you more space to log data
+
#* Set your timezone
+
#* Optional: set a 'Modest' over clock setting to improve performance
+
#* Optional: run update raspi - caution this may break things!
+
#* Save and reboot
+
# From another computer on the same local network navigate to the Pi's IP address
+
# If all is working well you should see the emoncms login screen
+
# Login to emoncms using username '''raspi''' and password '''raspberry'''
+
# Once logged in navigate the the Raspberry Pi config section (top left tab)
+
# If you see an error message stating that the script is not running you will need to restart cron, this seems to be needed when loading up a fresh SD card.
+
#* ssh to the Pi (instructions above)
+
#* once logged in via ssh enter <code>$ ps -A | grep cron</code> to view the current process list
+
#* To kill the cron process, enter <code>$ sudo kill xxx</code> replacing xxx with the cron process number from the list above. There might be more than one cron process running. Repeat this step until all cron processes have been killed. <code>$ ps -A</code> can be ran again to check.
+
#* The PHP script must be killed within 1 minute before it gets re-spawned. To do this, enter <code>$ sudo top</code> then <code>kill xxx</code> where x is the php process number (usually at the bottom of the list, press 'down key' to scroll down).
+
#* reboot the pi <code>& sudo reboot</code>
+
# Once the Pi restarts log back into emoncms using a web browser and navigate the the Rasbperry Pi section, if all has gone well you should see a message stating that the script is running.   
+
# Enter in your RFM12B wireless frequency and network group for your module and network. We recommend you use 15 as the Pi's node ID. See recommended node ID allocation table at bottom of [http://openenergymonitor.org/emon/buildingblocks/rfm12b2 this page].
+
# Enter in your remote emoncms login details if you want you data to be mirrored to a remote sever
+
# After clicking save, head over to the Inputs section. You should now see your wireless nodes appear
+
# Map the Inputs through to Feeds using the input processes of your choice. See [http://openenergymonitor.org/emon/emoncms/using-emoncms using emoncms documentation] for info.
+
  
 +
<code><pre>
 +
auto wlan0
 +
allow-hotplug wlan0
 +
iface wlan0 inet dhcp
 +
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf 
 +
</pre></code> 
  
# Note: all passwords on the pre-configured system (eg. MYSQL,SSH should be '''raspberry''')
+
close and save, then run <code>sudo nano /etc/wpa_supplicant/wpa_supplicant.conf</code> and edit the file by entering your SSID and WPA key in the correct locations
  
 +
<code><pre>
 +
network={
 +
ssid="YOURSSID"
 +
proto=RSN
 +
key_mgmt=WPA-PSK
 +
pairwise=CCMP TKIP
 +
group=CCMP TKIP
 +
psk="WIFIPASSWORD"
 +
}
 +
</pre></code>
  
''If you're a Linux guru, and know how we can make the above 'pre-built SD card' setup easier, (ideally plug and play), please get in touch with us!''
+
Save, close and finally run <code>$ sudo ifup wlan0</code> to reboot the module and connect to the network. WiFi should now be up and running. You can double check by running <code>$ iwconfig</code>.
  
===Configuring from scratch===
+
If you find the WiFi drops off, you might want to use [http://rpi.tnet.com/project/scripts/wifi_check this script] to periodically check for a connection and re-connect.
  
In this section, we will install the operating software onto the RaspberryPi and configure it remotely.  To do this we will use SSH. You will need to have an SSH client program. Linux and Mac OS X already have this installed (on a mac use the Terminal App  - Applications/Utilities/Terminal, for Windows get [http://www.chiark.greenend.org.uk/~sgtatham/putty/ Putty] or an alternative. 
+
The script needs to be added to the crontab to run periodically, <code> $ crontab -e</code> to edit or add a new cron tab or '-l' (lower case L) to list existing (if any) crontabs.
 
+
''Note: when working we the Pi we recommend shutting down the Pi properly with <code>$ sudo halt</code> before powering down or removing the SD card. (to avoid a corrupted card) We learnt this the hard way!''
+
 
+
 
+
#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 it <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  (sudo reboot) and you should be able to SSH back in with <code>$ ssh [email protected]</code> if 'emoncms' 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''
+
 
+
====Emoncms Setup====
+
 
+
Now that you have your RaspberryPi up and working, we are now going to install the Emonncms software.  To do this we need to install the webserver software (Apache), the database (MySQL) as well as the Emoncms scripts (written in a programming language called php).
+
 
+
'''It is highly recommended that you copy and paste the command line code to avoid making mistakes''' (the most common cause of most errors).
+
 
+
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 if you prefer not to setup GitHub on the Pi you can download the .tar file directly from github and extract into /var/www:
+
 
+
 
+
'''Be aware that installing Emoncms to any directory other than /var/www/ will break the data import scripts. (see http://openenergymonitor.org/emon/node/1329#comment-7526).'''
+
 
+
 
+
# <code>cd /var/www/<br>
+
# sudo wget -O emoncms.tar.gz https://github.com/emoncms/emoncms/tarball/master<br>
+
# sudo tar xvfz emoncms.tar.gz<br>
+
# sudo mv -i emoncms-emoncms-96885fe emoncms</code><br>
+
 
+
'''NOTE''' that the commit part of the name (the alphanumeric code) will change with every new version on github so you'll need to replace that part of the name with the correct value when renaming the folder
+
 
+
'''Install the raspberrypi module'''<br>
+
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>
+
 
+
Or if not using git:
+
 
+
# <code>cd /var/www/emoncms/Modules<br>
+
# sudo wget -O raspberrypi.tar.gz https://github.com/emoncms/raspberrypi/tarball/master<br>
+
# sudo tar xvfz raspberrypi.tar.gz<br>
+
# sudo mv -i emoncms-raspberrypi-b9703b5 raspberrypi</code><br>
+
 
+
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> instead of ''emoncms3''
+
 
+
When you have finished you should be able to browse to Http://Pi IP address or Host/emoncms and the emoncms login/register screen should appear:
+
 
+
[[File:raspberrypi_emoncms.png|400 px]]
+
 
+
====RFM12BPi Setup====
+
 
+
 
+
Make sure your Raspberry Pi’s UART is disconnected from the console and available for programs to use.
+
 
+
# Backup cmdline.txt <code>$ sudo cp /boot/cmdline.txt /boot/cmdline_backup.txt</code>
+
# 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
+
# Edit inittab
+
#* <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>
+
# <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 file in the beginning of the '';Dynamic Extensions;'' section on line 843 [Ctrl+X] then [y] then [Enter] to save and exit
+
# Restart apache <code>$ sudo /etc/init.d/apache2 restart</code>
+
 
+
 
+
 
+
Test the RFM12Pi is receiving data
+
 
+
# Connect the RFM12Pi to your 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. You will need a transmitting RFM12B node to see received transmissions.
+
#* <code>$ sudo apt-get install minicom</code>
+
#* <code>$ minicom -b 9600 -o -D /dev/ttyAMA0</code>
+
#* The default RFM12B settings are 868Mhz and network group 210
+
#* Type <code>4b</code> into the minicom serial window to change the RFM12B to 433Mhz and <code>xxxg</code> to change network group with <code>x</code> being the desired network group.
+
#* With the serial window open, un-plug the RFM12Pi, then plug it in to see the full list of available RF12 demo commands 
+
#* The LED on the RFM12Pi should flash to indicate a data packet was received and the raw data packet should show up in the serial window.
+
#* To exit minicom  [CTRL+ A] then [X] then [Enter]
+
 
+
 
+
'''Important info from M. Harizanov if you want to use Minicom for debugging purposes:'''
+
 
+
''Regarding minicom, I suspect you have the PHP cron job that emoncms starts running in the background. you can't use both emoncms's cron and minicom at the same time, or you'll see gibberish. To stop the cron job, edit the crontab and comment out the line that runs every minute, then reboot. Glyn and I have had that same issue before, it was easily resolved by stopping the cron job - the serial port can't be accessed both by emoncms and minicom at the same time.
+
 
+
====Setup emoncms Raspberry Pi module====
+
 
+
'''Config module:'''
+
 
+
# When you login to emoncms you should see Raspberry PI in the top menu bar, click to open the raspberry pi config page.
+
# Set your RFM12b frequency, group and RFM12BPi nodeid.
+
# Click Save so save settings and connect the RFM12BPi to the emoncms account your logged in as. One of the neat things with the module is that you dont have to manually enter the apikey to point to your account as the module does this for you.
+
 
+
At this stage you will see that the message box says: 'The RFM12 to PI interface script is not running, you may need to configure cron'.
+
 
+
[[File:raspberrypi_module2.png|400 px]]
+
 
+
Follow the following steps to run the script:
+
 
+
Open crontab:
+
<code>$ sudo nano /etc/crontab</code>
+
 
+
Add this line to the end:
+
<code>*/1 * * * * root cd /var/www/emoncms/Modules/raspberrypi && php raspberrypi_run.php</code>
+
 
+
Reboot the pi with <code>$ sudo reboot</code>
+
 
+
With the script running you should now see the message box at the top of the raspberry pi module page turn green
+
 
+
[[File:raspberrypi_module1.png|400 px]]
+
 
+
You should now see nodes appear in your input list, setup feeds and dashboards from here as normal.
+
 
+
===SD Card Speed & Benchmarking===
+
We have found that emoncms works better on some SD card than others even if the SD cards are both marked as class 4. This section is for listing the make, model, capacity and actual speed of your SD card. The speed can be measured using <code>sudo hdparm -t /dev/sdb</code> assuming your SD card is on sdb.
+
 
+
*Kingston 4GB Class 4:  50 MB in  3.09 seconds =  16.20 MB/sec - emoncms is slow
+
*ScanDisk 4GB Class 4:  50 MB in  3.02 seconds =  16.55 MB/sec - emoncms works well
+
*ScanDisk 8GB Class 10: 54 MB in  3.04 seconds =  17.74 MB/sec
+
*[http://www.samsung.com/fr/consumer/it/memory-card/sd/MB-SSBGA/EU Samsung SDHC Essential 32GO Class 10]: 70 MB in  3.02 seconds =  23.21 MB/sec - emoncms looks fine
+
  
 
==Troubleshooting==
 
==Troubleshooting==
  
If you have followed these instructions and got to the end and it hasn't worked, don't worry, you won't be alone!
+
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 carefully again, the main reason for errors are typo's and missed steps. Try to Copy and Paste the command lines into the RaspberryPi terminal window to avoid these.
+
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 [http://openenergymonitor.org/emon/forum forums]. 
+
If you're still having problems, ask a question on our friendly [https://community.openenergymonitor.org/ forum].
 
+
When posting on the forum please give as much information about what you have done and what you see as you can.  Please also include information about what your monitoring setup is.
+
 
+
==Updates & Work in Progress==
+
 
+
We are currently looking into integrating into the [https://github.com/emoncms/raspberrypi emoncms Raspberry Pi Module] the function to allow the RFM12Pi to send the current time to the emonGLCD, see [http://openenergymonitor.org/emon/node/1348 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/ http://harizanov.com/2012/12/rfm2pi-firmware-updates/]
+
 
+
-Ability to lock RFM12B settings
+
  
-Fix for ACKS timing
+
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.

Latest revision as of 17:31, 14 March 2017

Raspberry Pi

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.

RFM12Pi installed Raspberry Pi

RFM12Pi

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

RFM12Pi Front

For the new pre-assembled RFM12Pi V2 see new documentation

Technical Overview

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

Quantity Part
1x ATtiny84 (RF12B firmware preloaded)
2x 100nF
1x 5mm LED
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 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.

Rasppi.JPG


Ok, we're ready to start. Here is the PCB:

Rasppirfm1.jpg

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).

Rasppirfm2.jpg

Step 3 - 100R Resistor

Add the 100R resistor in exactly the same way, its colours are (brown, black, brown, gold)

Rasppirfm3.jpg

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.


Rasppirfm4.jpg

Step 5 - Green LED

Add the green LED. Ensure the long leg (and round edge) are facing the + symbol printed on the board.

Rasppirfm5.jpg


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.

Rasppirfm6.jpg

Step 7 - 100nF Ceramic Capacitors

Add the two 100nF ceramic capacitors one at either end of the board.

Rasppirfm7.jpg

Step 8 - 3x2 pin ISP header

Add the 3x2 pin ISP header. Long pins point up, short pins are soldered to the board.

Rasppirfm8.jpg

Step 9 - 6x2 pin GPIO header female socket

The GPIO socket needs to go on the bottom of the board.

Rasppirfm9.jpg

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: [1]

Rasppirfm10.jpg

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.

Rasppirfm11.jpg

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:

  1. Download the pre compiled RF12 demo .hex file from the firmware folder on Mharizanov's RF12Pi Github Repo
  2. Power the RF12Pi board with 3.3V, this can be done from the Pi
  3. 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:

  1. Setup Arduino 1.x IDE for operation with an ATtiny by following our guide
  2. Download a modified version (to use software serial on the ATtiny) of JeeLabs RF12 Demo from Mharizanov's RF12Pi Github Repo
  3. Ensure you have the latest JeeLabs JeeLib Arduino library installed
  4. Power the RF12Pi board with 3.3V, this can be done from the Pi
  5. Connect your AVR programmer to the RF12Pi's ISP header and select your programmer in the Arduino IDE tools>Programmer menu
  6. In the Arduino IDE, select ATtiny84 @ 8Mhz (internal oscillator; BOD disabled) in the Tools>Board menu and click Tools>Burn Bootloader
  7. You are now ready to upload the RF12 Demo to the ATtiny84 using the Arduino IDE
  8. 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:

auto wlan0
allow-hotplug wlan0
iface wlan0 inet dhcp
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf  

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

network={
ssid="YOURSSID"
proto=RSN
key_mgmt=WPA-PSK
pairwise=CCMP TKIP
group=CCMP TKIP
psk="WIFIPASSWORD"
}

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 $ iwconfig.

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.

Troubleshooting

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.