RFM69Pi V3

From OpenEnergyMonitor Wiki
Revision as of 17:19, 9 February 2015 by Glyn (Talk | contribs) (RFM69Pi V2)

Jump to: navigation, search

RFM69Pi V3


Development of the RFM69Pi has been a team effort between Martin Harizanov, Glyn Hudson and Ken Boak.

The RFM69Pi allows the Raspberry Pi to receive wireless data from other RFM69CW modules or RFM12B (backwards compatible) wireless modules

The RFM69Pi V3 consists of an RFM69CW wireless module and an ATmega328 microprocessor running OptiBoot serial bootloader (modified for 8mhz internal oscillator) which is Arduino compatible. See our blog post introducing the new RFM69CW module.

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.

Technical Overview

  • 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)
  • Communicates with Raspberry Pi via /dev/ttyAMA0 @ 38400 baud

Communicating with the RFM69Pi

The RFM69Pi communicates with Raspberry Pi via /dev/ttyAMA0 @ 38400 baud. The Raspberry Pi's serial console must be disabled to enable the RFM69Pi serial communication:

$ sudo wget https://raw.github.com/lurch/rpi-serial-console/master/rpi-serial-console -O /usr/bin/rpi-serial-console && sudo chmod +x /usr/bin/rpi-serial-console

$ sudo rpi-serial-console disable

$ sudo reboot

$ rpi-serial-console status

You should see the message Serial console on /dev/ttyAMA0 is disabled, the serial port is now free for communication with the ATMega328 on the RFM69Pi

Minicom can be used to view the serial output of the RFM69Pi direcly:

$ sudo apt-get install minicom

$ minicom -b38400 -D/dev/ttyAMA0

[CTRL + A] then [X] to exit minicom

To post data to emoncms:

Communication with the RFM69Pi is handled by emonHub service. Using emonHub received RF data can be posted to one or more Emoncms server or another internet service.

See emoncms documentation on [1] for detailed documentation regarding setting up and running emoncms on a Raspberry Pi with an RFM69Pi.

RFM69Pi V3 Setup

The RFM69Pi V3 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 RFM69Pi itself.

See main OpenEnergyMonitor Build guide

If you have assembled the RFM69Pi 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 RFM69Pi Firmware Direct from the Pi

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

$ sudo apt-get install avrdude
$ sudo service emonhub stop
$ git clone https://github.com/openenergymonitor/avrdude-rpi.git ~/avrdude-rpi && ~/avrdude-rpi/install -u
$ avrdude -v -c arduino -p ATMEGA328P -P /dev/ttyAMA0 -b 115200 -U flash:w:sketch_name.hex
$ sudo service emonhub start


Flashing the Bootloader

The ATmega328 on the RFM69Pi should come pre-loaded with the Optiboot bootloader and RFM69Pi firmware, this step should not be required unless you have assembled the RFM69Pi yourself and used a blank ATmega328.

Note: the RFM69Pi is a 3.3V only therefore it should not be powered by a 5V ISP programmer.

The stock RFM69Pi 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 file 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_RFM69CW_RF12_Demo_ATmega328.cpp.hex:i -B 10

If, for any reason (e.g to make a backup) you want to read the data back from the ATmega328 this can be done with:

 $ avrdude -v -p atmega328p -c avrispmkII -P usb -U flash:r:test_intel.hex:i

Alternatively, you could flash the modified Optiboot bootloader, then upload the RF12_Demo_atmega328.cpp.hex to RFM69Pi direct from the Pi, see below for instructions on how to modify the OptiBoot bootloader, and above, for instructions on how to upload direct from the Pi once the bootloader is in place.

Modified OptiBoot Bootloader

The ATmega328 on the RFM69Pi gets its clock from the the internal 8Mhz oscillator. This requires a special version of Optiboot optimised for 38.4 kbps. The modified and compiled version can be obtained at: downloaded from Martin's github.

The full guide on how to modify and re-compile Optboot is detailed on the Arduino forum here.

In order to compile Arduino sketches to work for this modified bootloader, 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.




Now we just need to select board > ATmega328 Optiboot @ 38,400baud w/ 8MHz Int. RC Osc in the Arduino IDE when compiling sketches.

Design Files & Reference

The board schematic, layout (in Eagle CAD format) are available on theOpenEnergyMonitor Hardware GitHub

The Arduino compatiable firmware is available on the OpenEnergyMonitor Github:

RFm69PiV3.1 brd.jpg

RFm69PiV3.1 sch.png


Minicom can be used to view the RFM69Pi serial output via the Pi's internal serial port. If your running a stock Raspbien image you will need to open access to ttyACM0 the internal UART serial port which the RFM69Pi uses. To do this see instruction here:


$ sudo apt-get install minicom

$ minicom -b38400 -D/dev/ttyAMA0

[CTRL + A] then [X] to exit minicom

If all is working well, you should see the following when the RFM69Pi is connected to the Pi's GPIO. Note the packets being received from Node 10 (emonTx).

The default Frequency of the RFM69Pi is 433Mhz, group 210 and node ID 15.

These parameters can be changed in software by issuing the correct serial commands e.g b4 for 433Mhz, 210g for 210 network group.