Difference between revisions of "Raspberry Pi"

From OpenEnergyMonitor Wiki
Jump to: navigation, search
(RFM12BPi Setup)
Line 121: Line 121:
 
#* 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.  
 
#* 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] then [Enter]
 
#* To exit minicom  [CTRL+ A] then [X] then [Enter]
 
  
  

Revision as of 17:47, 24 October 2012

RFM12Pi

RFM12Pi Front RFM12Pi installed Raspberry Pi


DOCUMENTATION ON THIS PAGE IS IN DEVELOPMENT AND INCOMPLETE!


Overview

TBC - working with Martin Mharizanov


Design Files & Part List

https://github.com/mharizanov/RFM2Pi

RFM12Pi Setup

RF12PI ASSEMBLY INSTRUCTIONS TO GO HERE

ATtiny84

The ATtiny84 should come pre-loaded with RFM12 Demo sketch. However if you have obtained a blank ATtiny84 you will need to upload the rf12 demo 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:

  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 simple 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:

  1. Setup Arduino 1.x IDE for working with ATtiny's 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 up your AVR programmer to the RF12Pi's ISP header and select your programmer in Arduino IDE tools>Programmer menu
  6. In 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 ATtiny's.


Raspberry Pi Setup

SD card & Raspbian Linux Setup

Note: when working we the Pi we recommend shutting down the Pi properly with $ sudo halt before powering down the Pi or removing the SD card to avoid a corrupted card. We learnt this the hard way!


  1. Download Raspbian 'Wheezy' SD card image This guide was made using 18th September 2012 release.
  2. Copy SD card image on SD card using Linux tool "dd" for any other OS see Raspberry Pi tutorial
    • Insert SD card $ df -h to view mounted partition, make note of SD card device name, for me this was 'sdb'
    • Unmount SD card $ umount /dev/sdb1 you will need to change sdb to match your SD card drive. If the card has more than one partition un mount that also $ umount /dev/sdb2
    • Write the .img to the card $ sudo dd bs=4M if=~/Downloads/2012-09-18-wheezy-raspbian.img of=/dev/sdb again you will need to replace sdb with your SD card device name and modify the location and name of the image as need.
  3. Put SD card into Pi and connect network and power
  4. Find the IP address of the Pi and SSH to it $ SSH [email protected], default password is 'raspberry'
  5. Once successfully logged in run Raspbian setup $ sudo raspi-config
    • Select Expand root partition to fill SD card finish and reboot
    • One rebooted restart SSH connection and run $ sudo raspi-config 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 $ startx.
    • Set locale and timezone as required
    • Finish and reboot, remember to use your new password when SSH'ing back in!
  6. (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 $ sudo nano /etc/hostname [Ctrl+X] then [Y] then [Enter] to save and exit
    • and in the file $ sudo nano /etc/hosts [Ctrl+X] then [Y] then [Enter] to save and exit
    • Reboot the Pi and you should be able to SSH back in with $ ssh [email protected] 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

  1. Install emoncms following this guide up to the end of section 7
  2. Instead of emoncms3 on the OpenEnergyMonitor GitHub use $ git clone git://github.com/emoncms/emoncms.git 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
  3. Navigate to the emoncms modules folder $ cd emoncms/Modules
  4. Download the Raspberry Pi emoncms module into the Modules folder $ git clone https://github.com/emoncms/raspberrypi.git
  5. Now carry on following the 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 $ cd /var/www/emoncms/
  6. 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.


RFM12BPi Setup

Make sure Raspberry Pi’s UART is disconnected from the console and available for programs to use it.

  1. Backup cmdline.txt $ sudo cp /boot/cmdline.txt /boot/cmdline_backup.txt
  2. Edit cmdline.txt to remove references to Pi’s UART (ttyAMA0)
    • $ sudo nano /boot/cmdline.txt
    • edit it from dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait to dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 elevator=deadline rootwait [Ctrl+X] then [y] then [Enter] to save and exit
    • $ sudo nano /etc/inittab comment out the following line at the bottom of the file by adding a '#' at begining of: T0:23:respawn:/sbin/getty -L ttyAMA0 115200 vt100 [Ctrl+X] then [y] then [Enter] to save and exit
  3. Reboot the Pi by $ sudo reboot


Install serial PHP libraries

  1. $ sudo apt-get install php-pear php5-dev
  2. $ sudo pecl install channel://pecl.php.net/dio-0.0.6
  3. $ sudo nano /etc/php5/cli/php.ini add extension=dio.so to file in the beginning of the ;Dynamic Extensions; section on line 843 [Ctrl+X] then [y] then [Enter] to save and exit
  4. Restart apache $ sudo /etc/init.d/apache2 restart
  5. Connect the RFM12Pi on to Pi's GPIO taking care to line up pin 1 as show in photo above
  6. 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.
    • $ sudo apt-get install minicom
    • $ minicom -b 9600 -o -D /dev/ttyAMA0
    • The default RFM12B settings are 868Mhz and network group 210
    • Type 4b into the minicom serial window to change the RFM12B to 433Mhz and xxg to change network group with x 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 received and the raw data packet should come up in the serial window.
    • To exit minicom [CTRL+ A] then [X] then [Enter]


Setup emoncms Raspberry Pi module

  1. Get emoncms to detect the raspberry Pi module by.....to be completed!
  2. $ sudo nano /var/www/emoncms/index.php
  3. db_schema_setup(load_db_schema()); - TO BE COMPLETED!