EmonPi

From OpenEnergyMonitor Wiki
Jump to: navigation, search

Raspberry Pi Energy Monitoring Shield

Hardware Technical Wiki Documentation

Technical Overview

caption emonPi V1.6 PCB


  • 2 x CT Current Sensor Inputs - designed for 100A max YHDC clip-on SCT-013-000
  • RJ45 connector for connecting DS18B20 temperature sensors, IRQ pulse counting sensor, and access to power and spare I/O including analog and PWM
  • I2C LCD (16 x 2) with control push button
  • Raspberry Pi Shutdown Button

Hands-on overview video of emonPi hardware:


emonTx / emonPi Comparison Table

' emonPi V1.5 emonTx V3.4
Integrated Raspberry Pi web-connected base-station YES NO
Number of current CT sensor inputs 2 4 (1 high sensitivity)
Number of AC voltage sensor inputs 1 1
Powered by AC-AC adapter NO YES
Requires DC 5V power adapter YES NO
Status LCD display YES NO
Powered by batteries NO YES
Firmware remotely updatable YES NO
Remote IRQ/AUX/PWM/DS18B20 connection via RJ45 YES YES

System Diagram

EmonPi System Diagram.png

Port Map

emonPi ATmega328

Arduino Pin AVR Special Function emonPi V1.6 Atmega 328 Raspberry Pi
Analog 0 (D14) AC Voltage
Analog 1 (D15) CT1
Analog 2 (D16) CT2
Analog 3 (D17)
Analog 4 (D18) (SDA)
Analog 5 (D19) (SCL)
Analog 6 (D20) RJ45 pin 8 – ADC6 / Dig20
Analog 7 (D21)
Digital 0 (RXD) FTDI Tx GPIO 14 / pin 8
Digital 1 (TXD) FTDI Rx GPIO 15 / pin 10
Digital 2 (int0) PWM RFM12B/69CW INT / (JP5 – RJ45 pin 7)
Digital 3 (int1) PWM RJ45 pin 6 – Pulse counter
Digital 4 RJ45 pin 4 – one-wire DS18B20
Digital 5 PWM Raspi GPIO 17 / Pin 11 GPIO 17 / Pin 11
Digital 6 PWM OOK Tx / (GPIO 18 -Pin 12) V1.6
Digital 7
Digital 8 Shutdown PTM Button
Digital 9 PWM emonPi PCB LED
Digital 10 (SS) PWM RFM69CW SEL
Digital 11 (MOSI) PWM RFM69CW SDI
Digital 12 (MISO) RFM69CW SDO
Digital 13 (SCK) RFM69CW SCK

Raspberry Pi GPIO

Raspberry Pi GPIO RasPi Function emonPi V1.6 ATmega328
2 (0 REV1) I2C SDA I2C LCD
3 (1 REV 1) I2C SCL I2C LCD
4 (pin 7) ATmega328 reset
7 SPI CS
8 SPI CS
9 SPI
10 SPI
11 SPI
14 UART Tx Dig 0 /Rx
15 UART Rx Dig 1 / Tx
17 (pin 11) Atmega Dig 5 – shutdown signal
18 (pin 12) OOK Tx (V1.6)
22
23 (pin 16) LCD push button
24
25
27 (21 REV 1)

Red dots mark GPIO used by the emonPi:

EmonPi GPIO.png

All unused Raspberry Pi GPIO ports can be used to connect additional peripherals using the double header on the emonPi PCB, make sure to take account of additional current requirements.

Raspberry Pi Compatibility

The emonPi has been designed to operate with the Raspberry Pi Model B+ and Pi2.

The emonPi will also work with the older Model B, although due to physical differences it won't fit inside the emonPi aluminium case. To use the emonPi on the Model B, a 13-pin GPIO extender is required instead of the 20-pin extender included. Please leave a note at checkout when ordering.

Power Supply

The emonPi is powered by 5V DC via a mini-B USB socket. The Raspberry Pi is powered by the emonPi via the GPIO pins. The emonPi board runs at 3.3V provided by on on-board voltage regulator. The Raspberry Pi's 3.3V rail is not used by the emonPi.

We recommend a USB power supply capable of supplying at least 1.2A

SD Card Image

Based on Raspbian

Download

Build

Run the emonPi install script. See script for details

$ git clone https://github.com/openenergymonitor/emonpi.git $ cd emonpi $ sudo ./install

Uploading Arduino Firmware

.hex file upload command:

$ avrdude -v -c arduino -p ATMEGA328P -P /dev/ttyAMA0 -b 115200 -U flash:w:sketch_name.hex

For further info see avrdude-rpi readme

Connectivity

RFM69CW

RFM69CW RF module (default 433Mhz) is used to receive (and transmit) data from other OpenEnergyMonitor sensor nodes such as emonTx and emonTH temperature & humidity. The JeeLabs JeeLib Arduino library is used as the driver for the RFM69CW module. The ATmega328 on the emonPi runs a modified version of RF12 demo, printing data received by the RFM69CW to the serial port in JeeLabs packet format.

LightWaveRF OOK

OOK (On-Off-Keying) is a simple RF modulation commonly used by RF remote plugs. With the addition of an [1] module the emonPi can be used to control RF plugs. This documentation is focused on controlling LightWaveRF plugs & dimmers however it would possible to control other OOK plugs with the correct protocol e.g FS20. The LightWaveRF OOK protocol has been reverse engineered and open-sourced, there is an active LightWaveRF development community. Big thanks to Lawrie Griffiths / Geek Grandad blog for creating LightWaveRF Arduino library and porting to Raspberry Pi with MQTT service.

The OOK transmitter footprint is (from left to right): ANT, 5V, D6 + (on emonPi V1.6 GPIO18 / Pin 12), GND.

The OOK transmitter data line is connected to Dig 6 of ATmega328 and on current rev of emonPi (V1.6 - sold since Nov 2015) the OOK is also be connected directly to to GPIO 18 (pin 12) and the antenna connection of the OOK module can be jumpered to share the main SMA emonPi antenna.

OOK Tx module footprint on emonPi V1.6:

EmonPi V1 6 OOK Tx.png

OOK Tx module hacked onto the older emonPi V1.5 (sold pre Nov 2015), the white wire connects to OOK RF antenna to the SMA antenna. A separate antenna could be used. The red wire connects the OOK Data pin to GPIO 18 (labeled G18) :

Emonpi ook.jpg



LightWaveRF

The emonPi + OOK can be used to control Lightwave RF plugs via MQTT using Lawrie Griffiths LightWaveRF Pi library. To install and setup on emonPi follow instructions below. We are looking to include LWRF MQTT OOK control on the next release of the emonPi pre-built SD card image, (emoncms V9) due Dec 2015. Assuming installing on emonPi, if installing on stock Raspberry Pi local mosquitto MQTT server will need to be installed and set up:

rpi-rw

sudo apt-get update

sudo apt-get install wiringpi

sudo apt-get install mosquitto-client

git clone http://git.eclipse.org/gitroot/paho/org.eclipse.paho.mqtt.c.git

cd org.eclipse.paho.mqtt.c

make

sudo make install

git clone https://github.com/lawrie/lightwaverf-pi.git

cd lightwaverf-pi

make

sudo make install

sudo service lwrfd start

To view log:

tail /var/log/daemon.log -f


To make service run at startup:

sudo update-rc.d lwrfd defaults


Once installed, LWRF plugs can be controlled by publishing to 'lwrf' MQTT topic.

The message format is “<channel> <command> [<level>]”, where channel is 1-16, command is 0-2 (2 means mood), and level is 0-31 (used for dimmers).

E.g publishing “1 1” to 'lwrf' topic turns channel 1 on and “1 0” turns it off.

Plugs can be paired with the emonPi in the usual LightwaveRF way: Either press and hold pairing button (if button exists) or turn on the plug from main power and send 'on' command. Most LightWaveRF plugs allow multiple (up to 6) control devices to be paired.

To reset the plug and delete all pairing, press and hold the pairing button to enter pairing mode, then press and hold again to erase memory. Then press (don't hold) once to confirm. For plugs without a pairing button, turn on the plug from the mains power, then in the first few seconds, press the 'all off' button on the RF remote.


Emulate Remote

The LightWaveRF Pi MQTT emulates 'someone's' LightWaveRF remote with the following default ID: byte id[ = {0x6f,0xed,0xbb,0xdb,0x7b,0xee};]. If you want to be able to control your plugs with either YOUR LightWaveRF remote or the emonPi you will need to capture the unique ID of your remote. To do this you will need an OOK receiver module and an Arduino running the lwrf receive sketch. The ID is the last 6 bytes of the transmission. Once captured replace the ID in mqrfmqtt.c with your remote's ID then recompile (make, sudo make install).

RJ45 Socket

This is not an Ethernet socket! Do not connect it to an Ethernet router. Doing so will cause the emonPi power rail to be shorted to ground. This will be fixed in next revision of the emonPi. As a precaution, the emonPi V1.5 will be shipped with a protective cap on this RJ45 socket.


The emonPi RJ45 socket can be used to connect multiple DS18B20 temperature sensors, an optical pulse counting sensor or access the power rails and auxillary I/O. An RJ45 breakout sold in our shop allows connection of multiple sensors and/or an optical pulse counting sensor to the emonPi. E.g. 5 x ds18b20 temperature sensors and an optical pulse sensor can be connected simultaneously to the RJ45 port on the emonpi.


The RJ45 uses standard pinout used by other manufacturers of DS18B20 temperate sensing hardware such as Sheep Walker Electronics


RJ45 Pinout


DS18B20 Temperature

A DS18B20 digital temperature sensors can easily be connected to the emonPi by connecting the sensors to the emonPi's RJ45 connector. The default firmware (discrete sampling) supports auto-detecting and reading from of up to six DS18B20 sensors.


RJ45 Pinout


DS18B20 sensor on RJ45


RJ45 to Terminal Block Breakout

Encapsulated DS18B20 temperature sensor


Additional RJ45 breakouts are available from Sheep Walk Electronics


Pulse Counting

Many meters have pulse outputs, including electricity meters (single phase, 3-phase, import and export), gas meters, water flow meters etc. The pulse output may be a flashing LED or a switching relay (usually solid state) or both. We recommend using the optical interface where available as this decouples the monitoring equipment from any high/mains voltages.


In the case of an electricity meter, a pulse output corresponds to a certain amount of energy passing through the meter (kWh/Wh). For single-phase domestic electricity meters (eg. Elster A100c), each pulse usually corresponds to 1 Wh (1000 pulses per kWh). Water and gas meters are usually marked to show the quantity of water (litres/gallons) or gas (cubic meters/cubic feet) that each pulse represents.


The standard emonPi has one spare interrupt input (IRQ 1, Dig3) which can be used for pulse counting. This is accessible on the RJ45 socket


The second interrupt IRQ0 is usually used by the RFM69CW module on the emonPi. If the RF module is not present, this interrupt can be jumpered on the PCB (JP5) to be accessible on the RJ45, see below for the pin out:


Optical pulse sensor RJ45 pinout


Pin 2 = VCC

Pin 5 = GND

Pin 6 = IRQ1

Pin 7 = IRQ0 (Usually used by RFM. Can be jumpered via JP5)


A ready made pulse counting sensor is available in the OpenEnergyMonitor shop, this sensor comes with an RJ45 connector and will work plug-and-play with emonPi:

See Optical Pulse Sensor Documentation Page for more info


Optical Pulse Sensor connected to emonPi

The raw pulse count will need to be multiplied by a scalar to convert to wh in Emoncms. E.g. for a meter which outputs 800 pulses per Kwh, the raw pulse count should be multipled by (1000/800 = 1.25) before logging to a Wh accumulator feed in emoncms. If the meter outputs 1000 pulses per Kwh, that is equivalent to one pulse pulse per Wh. Therefore, no scalar multiplier is required.

Adding a Real Time Clock (RTC)

The emonPi updates its internal linux time via NTP when connected to the internet. However, if the emonPi is used in an offline network, or an accurate time stamp is essential, a hardware Real Time Clock (RTC) can easily be added to the Pi's GPIO. We have tested using a DS3231 based RTC module. This RTC module communicates with the emonPi via I2C, it can be easily connected as follows by soldering a four-pin header onto the emonPi aux GPIO pins:

DS3231rtc.jpg

EmonPi RTC.JPG

Once connected, check it's detected on the I2C bus by running:

$ sudo i2cdetect -y 1

If the RTC is successfully detected it should return the following:

Emonpi rtc i2c.png

0x27 is the emonPi's I2C LCD display and 0x68 is the RTC module.

To test the module is working we can temporally load up the RTC module by running

$ sudo modprobe rtc-ds1307

$ sudo bash

$ echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device

$ hwclock -r

$ exit

The final command should read the hardware clock and read the current time. If this is the first time the module is used you may need to set the time with $ hwclock -w first ensuring the Pi's time is correct, check by running $ date. Now we have tested the module is working we can add the RTC kernal module and I2C device creation at boot time to ensure the hardware RTC is used each time the Pi boots:

$ sudo nano /etc/modules

add rtc-ds1307 to the end of the file

$ sudo nano /etc/rc.local

add the following lines before exit 0

echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device

sudo hwclock -s

date

To test this, shut down your Pi, unplug any ethernet cable or wifi dongle, then power up the Pi. Use the following command in a terminal window to check the date is still set. Run $ date to read the time from the hardware RTC.

Aux I/O

Unused input/output ADC 6/Digital 20 is available on the RJ45 connector for general purpose.

Electrical Characteristics

emonPi Datasheet
Function Parameter Min Recommended

Max / typical

Absolute Max


Notes
CT 1-2 Monitoring Power @ 240V 23kW 60kW Using 22R burden and YHDC SCT-013-00 with 22 turns
3.3V Rail current output When powering with 5V USB 150mA 168mA Limitation SOT22 MCP1700 Ta=40C Vi=5.25V
5V Input Voltage USB +3.4V +6V +6.5V (see note 1) See note 1
3.3V Supply Voltage on 3.3V supply rail 2.6V * 3.3V 3.9V * *ADC readings will be incorrect if Vcc!=3.3V
Power Consumption with Raspberry Pi 2 @3.3V 7mA no RasPi - 14mA RasPi Halted 300mA RasPi idle 500mA+ RasPi Load With ATmega328, RFM69CW, Edimax WIFI + RasPi2

Open-Hardware Design Files

See emonPi hardware GitHub repo


EmonP V1.5 sch white.png EmonP V1.5 brd track blacks.png

Hardware Change Log

  • V1.5 - First release KickStarter rewards May-Nov 2015
  • V1.6 - Nov 15 onwards
  • Pull back tracks and GND place around mount holes
  • Connect OOK to GPIO 18
  • Move OOK to top of board to avoid Pi2 connector shorting issue
  • Disconnect RJ45 pin 1 and 3 from GND to stop short when Ethernet is inserted
  • Add to silkscreen that the diode Cathode (flat line - negative) points upward) on the PCB and the Anode goes to GND (downward)
  • Add double side silkscreen for LCD I2C & switch header
  • Fix 'designed by' typo on rear silkscreen :-)

Open Development

The emonPi has been developed with input from the OpenEnergyMonitor community. See origional development OpenEnergyMonitor.org forum thread.

[emonPi Development Photos Album

Physical Dimensions & Fixtures

PCB: 99.2mm x 76.1mm

Enclosure: 103mm x 85mm x 99mm

Enclosure Screws: Torx T20

Raspberry Pi fixing kit (Rapid Rapid numbers):

  • 4 x 15mm spacer: 33-2040
  • 4 x M3 screw: 33-2300

LCD fixing kit (Rapid Rapid numbers):

  • 4 x 6mm spacer: 33-2034
  • 4 x M3 lock Nut: 33-4402
  • 4 x M3 12mm countersunk screw: 33-2955

Enclosure CAD Design :

EmonPi case CAD drawing.png

License

The emonPi is part of the OpenEnergyMonitor.org project

The hardware designs (schematics and CAD files) are licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

The firmware is released under the GNU GPL V3 license

The documentation is subject to GNU Free Documentation License

The hardware designs follow the terms of the OSHW (Open-source hardware) Statement of Principles 1.0

Media

emonPi Stock Photos

Development Photos

Environmental & Life Cycle

https://blog.openenergymonitor.org/2015/06/investigating-embodied-energy-of-emonpi/

https://blog.openenergymonitor.org/2015/07/open-source-circular-economy-oscedays/

https://blog.openenergymonitor.org/categories/sustainability/

Disclaimer

OUR PRODUCTS AND ASSEMBLY KITS MAY BE USED BY EXPERIENCED, SKILLED USERS, AT THEIR OWN RISK. TO THE FULLEST EXTENT PERMISSIBLE BY THE APPLICABLE LAW, WE HEREBY DISCLAIM ANY AND ALL RESPONSIBILITY, RISK, LIABILITY AND DAMAGES ARISING OUT OF DEATH OR PERSONAL INJURY RESULTING FROM ASSEMBLY OR OPERATION OF OUR PRODUCTS.

The OpenEnergyMonitor system is sold as a development kit to empower members of the openenergymonitor community to to get involved with the OpenEnergyMonitor open-source energy monitoring development project.

Your safety is your own responsibility, including proper use of equipment and safety gear, and determining whether you have adequate skill and experience. OpenEnergyMonitor and Megni registered partnership disclaims all responsibility for any resulting damage, injury, or expense. It is your responsibility to make sure that your activities comply with applicable laws, including copyright. Always check the webpage associated with each unit before you get started. There may be important updates or corrections. All use of the instructions, kits, projects and suggestions given both by megni.co.uk, openenergymonitor.org, shop.openenergymonitor.org and wiki.openenergymonitor.org are to be used at your own risk. The technology (hardware , firmware and software) are constantly changing, documentation (including build guide and instructions) may not be complete or correct.

If you feel uncomfortable with assembling or using any part of the kit / unit, please return it to us, we will happy to give a full refund.