Blog
OpenEnergyMonitor

Pulse counting with the RFM69PI and RaspberryPi EmonBase basestation

The latest version of the RFMPi Adapter board made much of the spare digital and analog IO available for use directly on the RFMPi adapter board. D3 is one of the digital inputs available and can have an interrupt attached (INT 1) which makes it useful for pulse counting.

By connecting a optical pulse sensor directly to the rfm69pi adapter board this can make a relatively low cost solution for internet connected pulse counting (or local logging to emoncms running on the raspberrypi).


Setup

1) The RJ45 connector on the optical pulse counter needs to be removed and individual wires exposed. Connect the red wire to 3.3V, the black wire to GND and the blue wire to D3:


2) To use the rfm69pi adapter with pulse counting the pulse counting firmware needs to be uploaded to the rfm69pi adapter board, the steps to upload this firmware are:
  1. SSH into your raspberrypi running the standard OpenEnergyMonitor image.
  2. Place raspberrypi in write mode:
    $ rpi-rw
  3. Stop emonhub:
    $ sudo service emonhub stop
  4. Pull in latest changes to RFM2Pi git directory:
    $ cd RFM2Pi
    $ git pull
  5. Upload pulse counting firmware:
    $ avrdude -v -c arduino -p ATMEGA328P -P /dev/ttyAMA0 -b 38400 -U flash:w:/home/pi/RFM2Pi/firmware/dev/RFM69CW_RF12_Demo_ATmega328_Pulse/RFM69CW_RF12_Demo_ATmega328_Pulse.cpp.hex
  6. Start emonhub:
    $ sudo service emonhub start
Next login to the local emoncms installation on the raspberrypi and navigate to the emonhub.conf editor. Add the following node definition in the nodes section of emonhub.conf:

[[15]]
    nodename = rfmpi_pulse
    firmware = RFM69CW_RF12_Demo_ATmega328_Pulse
    hardware = rfm69pi
    [[[rx]]]
       names = power,count
       datacodes = h,L
       scales = 1,1
       units = W,Wh 


The pulse count is accumulated on the rfm69pi until the rfm69pi is reset either by an outage or by turning off and on the power.

To record the total accumulated pulse count in emoncms use the wh_accumulator input process which detects resets continuing the total pulse count accumulation from the last value before the reset. To engage in discussion regarding this post, please post on our Community Forum.