Cleanweb UK

Last Thursday Glyn and I attended the Ignite Cleanweb UK event in London, an event exploring the power and potential of the web to help us solve our environmental challenges.

The format of the talks where all 5 minute, 20 slides, 15 seconds per slide which was a challenge to create but makes for a really fascinating event where you here about a lot of different projects in a short space of time. Videos of all the presentations talks are up on the web here:

Here's a video of our presentation on OpenEnergyMonitor:

The slides on their own can be viewed on slideshare:

Thanks a lot to James Smith (@floppy) for organising the event and inspiring us with the cleanweb uk manifesto at the end.

EmonTx and NanodeRF Code guides

These EmonTx and NanodeRF code guides go through the main components required to put a full EmonTx and NanodeRF (or ENC28J60 based OpenKontrolGateway) firmware together.

If your just starting out, you might find going through these guide examples first better than starting straight in with the fully fledged firmware examples.

Cleanweb UK - Ignite Evening - London 13th Sep

Thursday, September 13, 2012

7:00pm, at Forward Technology in London

Trystan and I are looking forward to attending and speaking at the first Cleanweb UK Ignite evening in London. It looks like it will be a great event, there will be 12 short (5min) fast paced talks to do with sustainability and the internet. 

Please come along and joins us, registration and full event details here:

Reading Watt-hour data from an Elster A100C electricity meter using IrDA by Dave Berkeley part 2

As mentioned before if you have an Elster meter this is a fantastic way to read the exact accumulated watt hours that you have generated or used and can compliment and cross check a CT based measurement.

Dave Berkeley has now packaged the code into a nice library which makes it really easy to use. We have uploaded the library to a repository on github here:

How to build it

1) To build the TSL261R based sensor for use with the emontx, follow the jack plug connection diagram on the emontx reference page here:

We've put together a small kit available in the shop of all the components needed to connect it to an emontx including the TSL261R a male 3.5mm jack, 1m of cable and heat-shrink.

2) Plug the sensor into the pulse input on the emontx (digital pin 3, interrupt pin 1)

3) Download the ElsterMeterReader library and place in the arduino libraries folder.

4) Open the Arduino IDE and run the following example:

#include "elster.h"

void meter_reading(unsigned long r)

ElsterA100C meter(meter_reading);

void setup()
  Serial.println("IRDA Meter reader");
void loop()
  // Decode the meter stream
  const int byte_data = meter.decode_bit_stream();
  if (byte_data != -1) {

5) If you now go to the serial window and place the sensor over the IrDA port (bottom-left of the meter) you should see the Watt-hours elapsed printed out to the serial window:

Thanks a lot to Dave Berkeley for this, for more information see his project page:

Open Kontrol Gateway - emonBase

For a while now we have been using the NanodeRF as our emonBase web-connected base station. The NanodeRF is great and has met our needs well. However using the ENC28J60 Ethernet chip does have some limitations.

We have through about having an emonBase option which supports the Wiznet Ethernet chip. This is the chip that is used in the official Arduino Ethernet. On the Wiznet chip the TCP/IP stack is implemented on the chip as opposed to on the ATmega328 as in the case of the ENC28J60, this means ATmega328 has a greatly reduced load, more application memory is freed up and the code is much simpler and brought in line with the Arduino Ethernet code examples.

In testing we have found the Wiznet chip to be more stable at holding a connection over a long period.

However the Wiznet chip is more expensive than the ENC28J60, what we need is a flexible emonBase unit which is interchangeable between the two Ethernet chips, enter the Open Kontrol Gateway (OKG)!

The OKG is a very flexible web-connected base station based on the ATmega328 which is totally Arduino IDE compatible (Arduino UNO bootloader). The OKG has been designed and manufactured by our friend Miles who runs Ciseco Plc.

The OKG PCB supports multiple wireless options such as RFM12B, XBEE, XRF, RN-XV Wifi. There is also PCB footprints for expansions like a RTC, SD card and SRAM. Finally what attracted us to the OKG was the ability to easily choose between the ENC28J60 or Wiznet Ethernet chips:

OKG ENC28J60 module

OKG Wiznet W5200 module 
We now have stock of the OKG in kit form in the OpenEnergyMonitor shop. The kits will come with an RFM12B wireless radio (choice of frequency) and a choice of ENC28J60 or Wiznet Ethernet chips.

The OKG with the ENC28J60 is almost hardware identical to the NanodeRF. NanodeRF emonBase sketches will run on the OKG with a couple of little changes.

See the OKG OpenEnergyMonitor wiki page for the changes required to make the OKG work with the RFM12B and OpenEnergyMonitor emonBase examples:

Note: The wiki is still in beta, we will blog more about it once it's been a bit more polished. It's our hope that by using a Media Wiki for our more technical documentation people will be more inclined to contribute corrections and additions and the documentations should be easier to organise and maintain. The OpenEnergyMonitor login should automatically log you in to the wiki. Just make sure your logged into the OpenEnergyMonitor website before opening up the wiki page. Try clearing your browsers cookies if this doesn't work first time.

We are now stocking the OKG in the OpenEnergyMonitor shop:

What about the Raspberry Pi!? 
Don't worry we haven't overlooked the Raspberry Pi! We have successfully had emoncms running on a Pi receiving RFM12B data from a USB JeeLink, we plan to blog more about this soon. We're currently with Martin Harizanov to make a RFM12B to Raspberry Pi GPIO expansion board. The Raspberry Pi will make a very powerful emonbase/home energy server however it's quite a complicated little beast for beginners who have limited linux knowledge. We think there is still a need to also have a simpler Arduino based emonBase option such as the NanodeRF or OKG.

emonTx SMT - Progress Update

Hello Everyone,

Here's another progress update on the emonTx SMT design.

This week I've sent the PCB CAD design files off to get a few prototype PCB's made. It's a very exciting moment, quite a milestone but also nerve wrecking! These prototypes will be assembled by hand and tested extensively. Eventually we plan to get the board ready assembled using factory SMT pick-and-place machines, selling the emonTX SMT as a kit is not an option! We don't plan to discontinue the current through-hole emonTx, we believe there is value in having a simpler through-hole kit version as an option. 

It will be sometime before emonTx SMT's are rolling off the production line, there are many hoops which need to be jumped through before then, but getting the first prototype off the ground is a good step forward! 

As a quick re-cap the main features of the emonTx SMT are:
  • Improved accuracy when monitoring low power levels with a programmable gain op-amp input stage on the CT inputs..see blog post
  • Single power supply - Half-wave rectifier AC-DC circuit to power the unit (under basic operation) and monitor mains voltage (enabling real power readings) from a single AC-AC PSU..see blog post
  • Direct USB programming - No USB to UART or FTDI cable required - built in USB host using the ATmega32u4 building on Arduino Leonardo design.
  • On-board Ethernet and multiple wireless radio options – RFM12B will remain the default option.
  • Pluggable-terminal block - Pulse-counting input, 2 x one-wire temperature inputs and other spare I/O broken out on a pluggable-terminal block.
  • Casing - designed to fit in a nice wall-mountable extruded aluminium case with laser cut fascias and external SMA antenna.

For more info, design notes and my general ramblings see my forum post...

Overload Protection of Mains Electrical Circuits by Robert Wall

A new guide by Robert Wall on overload protection of mains electrical circuits.

Robert Wall writes:

The fundamentals.

All electrical circuits must have some means of protecting against overload. This may be done by including a fuse or circuit breaker in the circuit, or the protection may be designed in to the supply that is feeding the circuit. We will only consider fuses and circuit breakers, as these are most likely the device that will be encountered in a normal environment.

How to determine the ratings.

First, you need to know the current that the load demands, under all conditions. You then need to choose a fuse or circuit breaker that will not blow (or trip) when carrying that current, but with only the smallest safety margin under worst-case conditions. Finally, you must choose everything in between – cable, switches, plug & sockets, etc – so that each will safely carry the current that will guarantee that the fuse will blow, or the circuit breaker will trip, under all conditions (paying particular regard to ambient temperature and the ability of the cable expecially to stay cool, i.e. it must not be buried in insulation).

Read the full guide here: Overload Protection of Mains Electrical Circuits

Plug and play sensor nodes

At the moment to get a system up and running you need to do quite a bit of manual firmware configuration, setting unique node-id's selecting different emontx sketches for different functionality, hard coding the emonglcd to get different screens. To add a second emontx you need to add several lines of code to the emonbase and the basestation needs to know the data structure of the sensor nodes.

What if you could upload a standard sketch to each of these nodes, plug your base station into your router, power up an emontx and see emontx 1 appear in a node list in emoncms. Then as you add more nodes they automatically appear in emoncms, no additional base station configuration needed. In time the software could develop to allow remote configuration of nodes such as emontx config and emonGLCD pages: beginning with page template functions as described in the last blog post: emonglcd template based displays

Continue reading the forum post here.

Low-level ADC control: ADMUX

While discussing the 3 phase sketch implementation here: by Pcunha which makes use of the AVR analog read commands rather than the arduino analog_read function which is a wrapping for these commands JBecker suggested that the analog reference voltage was not being selected correctly, so I had to do some reading up on this on ADMUX and bitwise operators.

So for anyone interested, this is how it works first ADMUX is an 8-bit byte that holds the settings for the analog reference voltage and the analog pin to select:

ADMUX is 8-bit:

 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit 

 REFS1REFS0 Voltage Reference Selection 
 0AREF, Internal Vref turned off 
 0AVcc with external capacitor on AREF pin 
 1Internal 1.1V (ATmega168/328) or  2.56V on (ATmega8)

MUX 3...0Single Ended Input

So if we want to use AVcc with external capacitor on AREF pin as our voltage reference (which is the default arduino voltage reference) and we want to select ADC2 for example, we would need to set ADMUX to:

 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 bit 

We can use bitwise operations to get there:

This is how its done in wiring_analog.c found in Arduino-1.0/hardware/arduino/cores/arduino

ADMUX = (analog_reference << 6) | (pin & 0x07);

Starting with (analog_reference << 6). The variable analog_reference is set to 1 as default for the atmega328 so 1 << 6 means bitshift 1 left 6 places where 1 in binary is 00000001 and shifting the bits left 6 places moves the 1 to 01000000. The desirable result for setting the 6th bit REFS0 to 1.

If you dont need to select different analog_reference values then we can get 01000000 directly by specifying its hexadecimal: 0x40.

Next looking at the  (pin & 0x07) part.

  • The & 0x07 is actually just for validation, it essentially says only allow selection of ADC0 to ADC5. 
  • The & bitwise operator is the AND operation.
  • 0x07 is hexadecimal whose binary representation is 00000111
  • Selecting ADC2 which is pin = 2 or in binary 00000010
  • The result of 2 & 0x07 = 00000010 AND 00000111 = 00000010.

The last part is the | bitwise operator: OR

(analog_reference << 6) | (pin & 0x07) becomes in our example here 01000000 OR 00000010. Which is equall to: 01000010 the result we where looking for above.

If you would like to read more on the AVR ADC commands see these helpful articles:

Configurable single to 3-phase interrupt based EmonTX code by Pcunha

Some great work I'd like to flag up by Pcunha, who has developed a super configurable single to 3-phase interrupt based firmware for the EmonTX.

Its up on github here:

and there is more about it in the forum thread here: