Difference between revisions of "RFM12Pi V2"
|Line 128:||Line 128:|
[[File:RFM12Pi V1.6 sch.png]]
[[File:RFM12Pi V1.6 sch.png]]
Revision as of 14:37, 24 January 2014
The RFM12Pi allows the Raspberry Pi to receive wireless data from RFM12B wireless module.
Development of the RFM12Pi has been a team effort between Martin Harizanov and Glyn Hudson.
The RFM12Pi V2 consists of an RFM12B wireless module and an ATmega328 microprocessor running OptiBoot serial bootloader (modified for 8mhz internal oscillator) which is Arduino compatible.
The ATmega328 runs a slightly modified version of JeeLabs's RF12Demo. Raw wireless packets are passed to the Pi via serial using the Pi's internal UART serial port. The raw packets are processed by the [ https://github.com/emoncms/raspberrypi emoncms Raspberry Pi module] or python emoncms gateway See emoncms documentation on emoncms.org for detailed documentation regarding setting up and running emoncms on a Raspberry Pi with an RFM12Pi.
- ATmega328 based, has more memory and hardware serial support
- Runs on the internal 8Mhz oscillator (to save unnecessary components)
- SMT used, board layout is optimized for pick-and-place assembly
- Lower profile to fit inside most Raspberry Pi enclosures
- The new RFM2Pi with ATmega328 allows programming directly from Raspberry Pi using avrdude (..and OptiBoot)
RFM12Pi V2 Setup
The RFM12Pi V2 can be purchased pre-assembled and ready flashed with firmware from the [shop.openenergymonitor.com/raspberry-pi/ OpenEnergyMonitor shop]. No assembly or setup is needed to the RFM12Pi itself.
See Raspberry Pi documentation on emoncms.org for pre-built emoncms Raspberry Pi read-to-go SD card & Pi setup instructions.
If you have assembled the RFM12Pi yourself or wish to re-flash the firmware this can be done using the ISP header and a ISP programmer. See #Flashing the Bootloader
Upgrading RFM12Pi Firmware Direct from the Pi
- These instructions were written for the original/older Raspberry Pi SD card image based on Raspbian. They probably won't work (we've yet to try) using the newer emoncms forwarding gateway images based on IPE image. We recommend running Raspbian to upgrade change the firmware. Please post if you get this working under IPE. *
If you're running the pre-built emoncms Raspberry Pi SD card image then uploading firmware to the Pi is a simple as grabbing the latest firmware build from github, stopping the rfm12piphp service (to free up the hardware serial port) then upload the .hex file via serial using avrdude:
$ cd RFM2Pi/firmware/RF12_Demo_atmega328 $ git pull $ sudo service rfm12piphp stop $ sudo avrdude -v -c arduino -p ATMEGA328P -P /dev/ttyAMA0 -b 38400 -U flash:w:RF12_Demo_atmega328.cpp.hex $ sudo service rfm12piphp start
If you're not running the pre-built emoncms SD card image then you will need to setup the following:
Since the Raspberry Pi lacks a DTR pin that makes it oh-so-easy to upload your hex files into the avr, we need this hack to make it just as easy. Thanks to JCW from JeLabs for working this out and Martin Harizanov for implementing it for the RFM12Pi.
$ sudo apt-get update $ sudo apt-get install arduino $ sudo apt-get install python-dev&&python-rpi.gpio $ git clone https://github.com/mharizanov/avrdude-rpi.git $ cd avrdude-rpi $ sudo cp autoreset /usr/bin $ sudo cp avrdude-autoreset /usr/bin $ sudo mv /usr/bin/avrdude /usr/bin/avrdude-original $ sudo ln -s /usr/bin/avrdude-autoreset /usr/bin/avrdude $ cd /home/pi $ git clone https://github.com/mharizanov/RFM2Pi.git $ cd RFM2Pi/firmware/RF12_Demo_atmega328 $ sudo service rfm12piphp stop $ avrdude -v -c arduino -p ATMEGA328P -P /dev/ttyAMA0 -b 38400 -U flash:w:RF12_Demo_atmega328.cpp.hex $ sudo service rfm12piphp start
Flashing the Bootloader
The ATmega328 on the RFM12Pi should come pre-loaded with the Optiboot bootloader and RFM12Pi firmware, this step should not be required unless you have assembled the RFM12Pi yourself and used a blank ATmega328.
Note: the RFM12Pi is a 3.3V only therefore it should not be powered by a 5V ISP programmer.
To avoid accidental connection of 5V the VCC pin on the ISP header by default is disconnected. A jumper connection between the two adjacent pads must be made to connect the ISP VCC the VCC on the board. On some ISP programmers (such as the AVR MKII that I use) the VCC pin needs to be connected to initialise the programmer even though the programmer itself does not power the board. An easy way to power the board with 3.3V for programming is to connect it onto the Pi's GPIO taking care to align pin 1.
The stock RFM12Pi firmware can be downloaded in pre-compiled .hex form from github here. This pre-compiled .hex file contains both the optiboot bootloader and the modified RF12Demo Sketch.
The .hex can be flashed and the fuses set on the ATmega328 using the following avrdude command:
$ sudo avrdude -v -p atmega328p -c avrispmkII -P usb -e -Ulock:w:0x3F:m -Uefuse:w:0x05:m -Uhfuse:w:0xDE:m -Ulfuse:w:0xE2:m -U flash:w:Optiboot328_8mhz_RF12_Demo.hex -B 10
Alternatively you could flash the modified Optiboot bootloader then upload the RF12_Demo_atmega328.cpp.hex to RFM12Pi direct from the Pi, see instructions below for how to modify the OptiBoot bootloader and instructions above for how to upload direct from the Pi once the bootloader is in place.
Modified OptiBoot Bootloader
The ATmega328 on the RFM12Pi runs off the internal 8Mhz oscillator. This requires a special version of Optiboot optimised for 38.4kbps baud. The modified and compiled version can be downloaded from Martin's github.
The full guide of how to modify and re-compile Optboot is detailed on the Arduino forums here.
In order to compile Arduino sketches to work for this modified bootloder we need to add a new entry in arduino-1.0.2\hardware\arduino\boards.txt.
atmega328_384_8.name=ATmega328 Optiboot @ 38,400baud w/ 8MHz Int. RC Osc. atmega328_384_8.upload.protocol=arduino atmega328_384_8.upload.maximum_size=30720 atmega328_384_8.upload.speed=38400 atmega328_384_8.bootloader.low_fuses=0xE2 atmega328_384_8.bootloader.high_fuses=0xDE atmega328_384_8.bootloader.extended_fuses=0x05 atmega328_384_8.bootloader.path=optiboot atmega328_384_8.bootloader.file=optiboot_atmega328_384_8.hex atmega328_384_8.bootloader.unlock_bits=0x3F atmega328_384_8.bootloader.lock_bits=0x0F atmega328_384_8.build.mcu=atmega328p atmega328_384_8.build.f_cpu=8000000L atmega328_384_8.build.core=arduino atmega328_384_8.build.variant=standard
Now we just need to select board > ATmega328 Optiboot @ 38,400baud w/ 8MHz Int. RC Osc in Arduino IDE when compiling sketches.
Design Files & Referance
The board schematic, layout and firmware (in Eagle CAD format) are available on Martin Harizanov's github
Minicom can be used to view the serial output of the RFM12Pi on the Pi's internal serial
Fist stop any progress that's using the serial port either
$ sudo service rfm12piphp stop
if your using the rfm21piphp service or if your using the OEM gateway on the rock-solid read-only gateway
$ ps -ef | grep python
$ kill -9 xxxx
replacing xxxx with the PID of your python script process.
$ sudo apt-get install minicom
$ minicom -b9600 -D/dev/AMA0
[CTRL + A] then [X] to exit minicom
If all is working well you should see the following when the RFM12pi is connected to the Pi's GPIO. Not the packets being received from Node 10 (emonTx).
The default Frequency of the RFM12pi is 868Mhz, group 210 and node ID 15.
These parameters can be changed in software by issuing the correct serial commands and illustrated below
Hacks, Modifications & Extensions
Controlling RF Plugs
Thanks to Paul Tanner the RFM12Pi V2 has successfully been used to control (switch on/off) KAKU mains plugs via wireless OOK protocol.
The KAKU protocol is built into the RF12 demo, however the default firmware (currently as of July 2013) on the RFM12Pi uses a cut down version of the RF12 demo. In order to use the full functionality of the RF12 demo including the OOK KAKU protocol the firmware on the ATmega328 needs to be upgraded. We have released a version of the full RF12 demo which as been slightly customised for the RF12Pi (baud rate, turn off bad packet reporting and "OK" printing). This firmware is available on github here.
The firmware can be updated direct from the pi by following the instructions above but specifying the Full_RF12demo_atmega328.cpp.hex in the avrdude commandline.
See the original forum thread with full upgrading instructions from Paul if you're not running the pre-built emoncmspi SD card.