Difference between revisions of "EmonPi"

From OpenEnergyMonitor Wiki
Jump to: navigation, search
(Adding a Real Time Clock (RTC))
(Adding a Real Time Clock (RTC))
 
(30 intermediate revisions by 3 users not shown)
Line 5: Line 5:
 
==Technical Overview==
 
==Technical Overview==
  
[[file:Emonpibare_(1).png|500px]]
+
[[file:Emonpi_v1_6.png|500px|frameless|caption]]
 +
emonPi V1.6 PCB
 +
               
  
  
* 2 x CT Current Sensor Inputs - designed for 100A max YHDC clip-on SCT-013-000
+
* 2 x CT Current Sensor Inputs - designed for the 100A max YHDC clip-on SCT-013-000
  
* 1 x AC Voltage Input - [http://shop.openenergymonitor.com/components/ designed for 9V AC power adapter]
+
* 1 x AC Voltage Input - [http://shop.openenergymonitor.com/components/ designed for a 9V AC power adapter]
  
 
* Arduino compatible ATmega328P - [https://github.com/openenergymonitor/avrdude-rpi sketch upload direct from the Pi via GPIO serial]
 
* Arduino compatible ATmega328P - [https://github.com/openenergymonitor/avrdude-rpi sketch upload direct from the Pi via GPIO serial]
Line 16: Line 18:
 
* RJ45 connector for connecting DS18B20 temperature sensors, IRQ pulse counting sensor, and access to power and spare I/O including analog and PWM
 
* RJ45 connector for connecting DS18B20 temperature sensors, IRQ pulse counting sensor, and access to power and spare I/O including analog and PWM
  
* [http://openenergymonitor.org/emon/buildingblocks/rfm69cwRFM69CW 433Mhz RF Radio]
+
* [http://openenergymonitor.org/emon/buildingblocks/rfm69cwRFM69CW 433 MHz Radio]
  
 
* I2C LCD (16 x 2) with control push button
 
* I2C LCD (16 x 2) with control push button
Line 26: Line 28:
  
 
<embedvideo service="youtube">https://youtu.be/lc2LzCZnySo?list=PL75IPdF39mFJzFpxumaSGeIs7oD2EOC8i</embedvideo>
 
<embedvideo service="youtube">https://youtu.be/lc2LzCZnySo?list=PL75IPdF39mFJzFpxumaSGeIs7oD2EOC8i</embedvideo>
 
  
 
==emonTx / emonPi Comparison Table==
 
==emonTx / emonPi Comparison Table==
Line 38: Line 39:
 
| Integrated Raspberry Pi web-connected base-station||YES||NO
 
| Integrated Raspberry Pi web-connected base-station||YES||NO
 
|-
 
|-
| Number of current CT sensor inputs||2||4 (1 high sensitivity)
+
| Number of CT sensor inputs||2||4 (1 high sensitivity)
 
|-
 
|-
 
| Number of AC voltage sensor inputs||1||1
 
| Number of AC voltage sensor inputs||1||1
Line 46: Line 47:
 
| Requires DC 5V power adapter||YES||NO
 
| Requires DC 5V power adapter||YES||NO
 
|-
 
|-
| Status LCD display||YES||NO
+
| LCD status display||YES||NO
 
|-
 
|-
 
| Powered by batteries||NO||YES
 
| Powered by batteries||NO||YES
Line 143: Line 144:
 
| 17 (pin 11)||||Atmega Dig 5 – shutdown signal
 
| 17 (pin 11)||||Atmega Dig 5 – shutdown signal
 
|-
 
|-
| 18 (pin 12)||||''OKK Tx (V1.6)''
+
| 18 (pin 12)||||''OOK Tx (V1.6)''
 
|-
 
|-
 
| 22||||
 
| 22||||
 
|-
 
|-
| 23 (pin 16)||||LCD push button  
+
| 23 (pin 16)||||LCD PTM push button (High when pressed)
 
|-
 
|-
 
| 24||||
 
| 24||||
Line 160: Line 161:
 
[[File:EmonPi_GPIO.png]]
 
[[File: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.
+
All unused Raspberry Pi GPIO ports can be connected to additional peripherals using the double header on the emonPi PCB.
 +
 
 +
N.B. ''Be sure to take account of additional current requirements.''
  
 
==Raspberry Pi Compatibility==  
 
==Raspberry Pi Compatibility==  
  
The emonPi has been designed to with the Raspberry Pi Model B+ and Pi2.
+
The emonPi has been designed to operate with the Raspberry Pi Model B+ and Pi2.
  
The emonPi will also work on 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.
+
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 with an older 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==
 
==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 itself runs at 3.3V provided by on on-board voltage regulator. The Raspberry Pi's 3.3V rail is left un-touched by the emonPi.  
+
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 at least a 1.2A 5V USB power supply''
+
''We recommend a USB power supply capable of supplying at least 1.2A''
  
 
==SD Card Image==
 
==SD Card Image==
  
Based on Raspbien
+
Based on Raspbian
  
 
===Download===
 
===Download===
Line 182: Line 185:
 
===Build===
 
===Build===
  
Run emonPi install script. See script for details
+
Run the emonPi install script. See script for details
  
 
<code>
 
<code>
Line 192: Line 195:
 
==Uploading Arduino Firmware==
 
==Uploading Arduino Firmware==
  
.hex file can be uploaded:  
+
.hex file upload command:  
  
 
<code>
 
<code>
Line 203: Line 206:
 
===RFM69CW===
 
===RFM69CW===
  
[http://openenergymonitor.org/emon/buildingblocks/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 [https://github.com/jcw/jeelib JeeLib Arduino library ] is used as the driver for the RFM69CW module. The ATmega328 on the emonPi runs a modified version of [https://github.com/jcw/jeelib/tree/master/examples/RF12/RF12demo/ RF12 demo], printing data received by the RFM69CW to the serial port in JeeLabs packet format.
+
[http://openenergymonitor.org/emon/buildingblocks/rfm69cw RFM69CW RF module] (default 433 MHz) is used to receive (and transmit) data from other OpenEnergyMonitor sensor nodes such as the emonTx and emonTH. (temperature & humidity) The JeeLabs [https://github.com/jcw/jeelib JeeLib Arduino library ] is used as the driver for the RFM69CW module. The ATmega328 on the emonPi runs a modified version of [https://github.com/jcw/jeelib/tree/master/examples/RF12/RF12demo/RF12 demo], printing data received by the RFM69CW to the serial port in JeeLabs packet format.
  
===OOK===
+
===LightWaveRF OOK===
  
[http://en.wikipedia.org/wiki/On-off_keying OKK (On-Off-Keying)] is a simple RF modulation commonly used by RF remote plugs. With the addition of an [http://uk.rs-online.com/web/p/lower-power-rf-modules/6172072/ OKK transmitter] module the emonPi can be used to control RF plugs.  
+
[http://en.wikipedia.org/wiki/On-off_keying OOK (On-Off-Keying)] is a simple RF modulation commonly used by RF controled remote plugs. With the addition of a [http://shop.openenergymonitor.com/ook-on-off-keying-transmitter-433mhz 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 development comunity at [http://lightwaverfcommunity.org.uk/ http://lightwaverfcommunity.org.uk/]. Big thanks to [https://github.com/lawrie Lawrie Griffiths] / [https://geekgrandad.wordpress.com Geek Grandad blog] for creating [https://github.com/lawrie/LightwaveRF LightWaveRF Arduino library] and porting it to [https://github.com/openenergymonitor/lightwaverf-pi/ Raspberry Pi with MQTT service]. 
  
See here from an [http://www.rs-online.com/designspark/electronics/eng/blog/home-automation-with-raspberry-pi-2-and-node-red example controlling a lightwave RF plug]
+
The OOK transmitter footprint is (from left to right): ANT, 5V, D6 + (on emonPi V1.6 GPIO18 / Pin 12), GND.
  
The OKK transmitter footprint is (from left to right): ANT, 5V, D6, 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.
  
The OKK transmitter data line is connected to Dig 6 of ATmega328 and on the next rev of emonPi V1.6 (yet to be released) the OKK will also be connected directly to to GPIO 18 (pin 12) and the antenna connection of the OOK moudule will be able to be jumpered to share the main SMA emonPi antenna.
+
OOK Tx module footprint on emonPi V1.6:
  
This photo shows a OOK module hacked onto the older emonPi V1.5, the white wire connects to OOK RF antenna to the SMA antenna. A separate antenna could be used. :
+
[[file: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) :
  
 
[[file:Emonpi_ook.jpg]]
 
[[file:Emonpi_ook.jpg]]
 +
 +
 +
 +
 +
'''LightWaveRF'''
 +
 +
The emonPi + OOK can be used to control Lightwave RF plugs via MQTT using Lawrie Griffiths [https://github.com/lawrie/lightwaverf-pi 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:
 +
 +
<code>
 +
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
 +
 +
</code>
 +
 +
To view log:
 +
 +
<code>tail /var/log/daemon.log -f</code>
 +
 +
 +
To make service run at startup:
 +
 +
<code>sudo update-rc.d lwrfd defaults </code>
 +
 +
 +
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 [https://github.com/lawrie/lightwaverf-pi/blob/master/lwrfmqtt.c#L24 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 [http://uk.rs-online.com/web/p/lower-power-rf-modules/6172044/ OOK receiver module] and an Arduino running the [https://github.com/lawrie/LightwaveRF/tree/master/examples/lwreceive lwrf receive sketch]. The ID is the last 6 bytes of the transmission. Once captured replace the ID in [https://github.com/lawrie/LightwaveRF/tree/master/examples/lwreceive mqrfmqtt.c] with your remote's ID then recompile (make, sudo make install).
  
 
===RJ45 Socket===
 
===RJ45 Socket===
  
'''This is not an Ethernet socket! Do not plug into an Ethernet router, this will cause the emonPi power rail to be shorted. This will be fixed in next rev of emonPi. As a precaution the emonPi V1.5 will be shipped with a protector cap on this 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 [http://shop.openenergymonitor.com/optical-utility-meter-led-pulse-sensor/?page_context=category&faceted_search=0ptical optical pulse counting sensor] or access power rails and aux I/O. An RJ45 breakout sold in our shop allows connection of multiple sensors and or 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 emonPi RJ45 socket can be used to connect multiple DS18B20 temperature sensors, an [http://shop.openenergymonitor.com/optical-utility-meter-led-pulse-sensor/?page_context=category&faceted_search=0ptical 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.  
  
  
Line 237: Line 303:
  
  
A DS18B20 digital temperature sensors can easily be connected by the emonPi by connecting the sensors into the emonPi's RJ45 connector. '''The default firmware (discrete sampling) supports auto-detecting and reading from of up to six DS18B20 sensors'''.  
+
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'''.  
  
  
Line 251: Line 317:
  
  
Further RJ45 breakouts are available from [http://www.sheepwalkelectronics.co.uk/index.php?cPath=23 Sheep Walk Electronics]  
+
Additional RJ45 breakouts are available from [http://www.sheepwalkelectronics.co.uk/index.php?cPath=23 Sheep Walk Electronics]  
  
  
Line 260: Line 326:
  
  
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).  For water and gas meters they will usually be marked to show the quantity of water (litres/gallons) or of gas (cubic meters/cubic feet) that each pulse represents.
+
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.
  
  
Line 266: Line 332:
  
  
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 jumped on the PCB (JP5) to be accessible on RJ45, see below for pin out:  
+
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:  
  
  
Line 272: Line 338:
  
  
Pin 2 = VCC
+
Pin 2 = V<sub>CC</sub>
  
 
Pin 5 = GND  
 
Pin 5 = GND  
Line 278: Line 344:
 
Pin 6 = IRQ1
 
Pin 6 = IRQ1
  
Pin 7 = IRQ0 (usually used by RFM can be jumpered via JP5)
+
Pin 7 = IRQ0 (Usually used by RFM. Can be jumpered via JP5)
  
 +
There is an input pull-up inside the pulse (IRQ) input that is enabled in the standard sketch. Therefore, you can connect a volt-free contact or an SO output between Pin 6 (IRQ input, SO+) and Pin 5 (GND, SO-) without the need for an additional resistor. If you must connect your contacts between VCC (Pin 2) and Pin 6, then you must add a pull-down resistor of resistance low enough to overcome the internal pull-up resistor, or you can use a higher-value resistor and modify the sketch to disable the internal pull-up.
  
A [http://shop.openenergymonitor.com/optical-utility-meter-led-pulse-sensor/ ready made pulse counting sensor is available in the OpenEnergyMonitor shop] , this sensor comes with an RJ45 connector and will work plug-and-play out of the box with emonPi:
+
A [http://shop.openenergymonitor.com/optical-utility-meter-led-pulse-sensor/ 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:
  
 
[http://openenergymonitor.org/emon/buildingblocks/opticalpulsesensor See Optical Pulse Sensor Documentation Page for more info]
 
[http://openenergymonitor.org/emon/buildingblocks/opticalpulsesensor See Optical Pulse Sensor Documentation Page for more info]
Line 288: Line 355:
 
[[File:2015-05-28 09.21.45.jpg|400 px|Optical Pulse Sensor connected to emonPi]]
 
[[File:2015-05-28 09.21.45.jpg|400 px|Optical Pulse Sensor connected to emonPi]]
  
The raw pulse count will need to be multiplied by a scalar to convert to wh in Emoncms. Eg 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 meter outputs 1000 pulses per Kwh this is already one pulse pulse per wh therefore no scalar multiplier is required.
+
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)====
 
====Adding a Real Time Clock (RTC)====
  
The emonPi updates its internal linux time from NTP when connected to the internet. However if the emonPi is used in an offline network or for an application when 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 [http://thepihut.com/products/mini-rtc-module-for-raspberry-pi 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:  
+
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 [http://thepihut.com/products/mini-rtc-module-for-raspberry-pi DS3231 based RTC module]. This RTC module communicates with the emonPi via I<sup>2</sup>C, it can be easily connected as follows by soldering a four-pin header onto the emonPi aux GPIO pins:  
 +
 
 +
[[file:DS3231rtc.jpg]]
  
 
[[file:EmonPi RTC.JPG]]
 
[[file:EmonPi RTC.JPG]]
  
Once connected check it's detected on the I2C bus by running:
+
Once connected, check it's detected on the I<sup>2</sup>C bus by running:
  
 
<code> $ sudo i2cdetect -y 1 </code>
 
<code> $ sudo i2cdetect -y 1 </code>
Line 304: Line 373:
 
[[file:Emonpi_rtc_i2c.png]]
 
[[file:Emonpi_rtc_i2c.png]]
  
0x27 is the emonPi's I2C LCD display and 0x68 is the RTC module.
+
0x27 is the emonPi's I<sup>2</sup>C LCD display and 0x68 is the RTC module.
  
To test the module is working we can temporally load up the RTC module by running
+
See instructions here on how to setup RTC with RaspberryPi / emonPi: https://www.raspberrypi.org/forums/viewtopic.php?t=209700
 
+
<code>
+
$ sudo modprobe rtc-ds1307
+
 
+
$ sudo bash
+
 
+
$ echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
+
 
+
$ hwclock -r
+
 
+
$ exit
+
</code>
+
 
+
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:
+
 
+
<code>
+
$ sudo nano /etc/modules
+
</code>
+
 
+
add ''rtc-ds1307'' to the end of the file
+
 
+
<code>
+
$ sudo nano /etc/rc.local
+
</code>
+
 
+
add the following lines before ''exit 0''
+
 
+
<code>
+
echo ds1307 0x68 > /sys/class/i2c-adapter/i2c-1/new_device
+
 
+
sudo hwclock -s
+
 
+
date
+
</code>
+
 
+
To test this out, shutdown your Pi, unplug any ethernet cable or wifi dongle and then turn the Pi back on. 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====
 
====Aux I/O====
  
Unused input / output ADC 6 / Digital 20 is available on RJ45 connector for general purpose.
+
Unused input/output ADC 6/Digital 20 is available on the RJ45 connector for general purpose.
  
 
==Electrical Characteristics==
 
==Electrical Characteristics==
Line 410: Line 443:
  
 
===Hardware Change Log===
 
===Hardware Change Log===
*'''V1.5''' - First release KickStarter rewards May-Aug 2015
+
*'''V1.5''' - First release KickStarter rewards May-Nov 2015
  
*'''V.16''' - (prototype July 15)
+
*'''V1.6''' - Nov 15 onwards
 
::*Pull back tracks and GND place around mount holes  
 
::*Pull back tracks and GND place around mount holes  
::*Connect OOK to GPIO 18
+
::*Connect OOK to GPIO 18  
 
::*Move OOK to top of board to avoid Pi2 connector shorting issue
 
::*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  
 
::*Disconnect RJ45 pin 1 and 3 from GND to stop short when Ethernet is inserted  
Line 469: Line 502:
  
 
==Environmental & Life Cycle==
 
==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==
 
==Disclaimer==
  

Latest revision as of 17:58, 16 April 2019

Raspberry Pi Energy Monitoring Shield

Hardware Technical Wiki Documentation

Technical Overview

caption emonPi V1.6 PCB


  • 2 x CT Current Sensor Inputs - designed for the 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 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
LCD status 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 PTM push button (High when pressed)
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 connected to additional peripherals using the double header on the emonPi PCB.

N.B. Be 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 with an older 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 433 MHz) is used to receive (and transmit) data from other OpenEnergyMonitor sensor nodes such as the 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 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 controled remote plugs. With the addition of a 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 development comunity at http://lightwaverfcommunity.org.uk/. Big thanks to Lawrie Griffiths / Geek Grandad blog for creating LightWaveRF Arduino library and porting it 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)

There is an input pull-up inside the pulse (IRQ) input that is enabled in the standard sketch. Therefore, you can connect a volt-free contact or an SO output between Pin 6 (IRQ input, SO+) and Pin 5 (GND, SO-) without the need for an additional resistor. If you must connect your contacts between VCC (Pin 2) and Pin 6, then you must add a pull-down resistor of resistance low enough to overcome the internal pull-up resistor, or you can use a higher-value resistor and modify the sketch to disable the internal pull-up.

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.

See instructions here on how to setup RTC with RaspberryPi / emonPi: https://www.raspberrypi.org/forums/viewtopic.php?t=209700

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.