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 emoncms Raspberry Pi module, specifically the raspberrypi_run.php script. 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 OpenEnergyMonitor shop [LINK]. No assembly or setup is needed to the RFM12Pi itself.
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
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 then upload the .hex file via serial using avrdude
$cd /RFM2Pi $ git pull https://github.com/mharizanov/RFM2Pi.git $cd /RFM2Pi/firmware/RF12_Demo_atmega328 $ sudo avrdude -v -c arduino -p ATMEGA328P -P /dev/ttyAMA0 -b 38400 -U flash:w:RF12_Demo_atmega328.cpp.hex
If your 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 $avrdude -v -c arduino -p ATMEGA328P -P /dev/ttyAMA0 -b 38400 -U flash:w:RF12_Demo_atmega328.cpp.hex
Flashing the Bootloader
The RFM12Pi should come pre-loaded with the bootloader and 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: https://github.com/mharizanov/RFM2Pi/blob/master/firmware/RF12_Demo_atmega328/Optiboot328_8mhz_RF12_Demo.hex. 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 </code>
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.
Modified OptiBoot Bootloader
The ATmega328 on the RFM12Pi runs of 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 </code>
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 are available on Martin Mharizanov's github