Feedback on new Energy Monitoring Hardware System

Hey guys, I’m new here so hopefully this is the correct place for this.

I’m currently trying to make my own custom Energy Monitoring hardware in order to meet my own needs & requirements as well as make a potential product. The entire design will be open source (I’ll only sell assembled and tested hardware if it works) and I plan to use EmonCMS as the web application backend (I’m an embedded hardware guy - not a web dev). I’ve already got a fair amount of the design in the works but I’m running into feature paralysis - I’m not sure what others want and/or don’t want at this point. So, basically I’m asking for feedback on my planned system design, recommendations for additional features, or advice on removing unwanted features.

I’m comparing my design somewhat to this product.

My design currently:

  • Two MCU’s - an ESP32 for wifi web connectivity/user interface and a STM32 for power measurement and calculations
  • Capability to measure current on 20 independent channels - 20 CT’s total
  • 15 of 20 CT’s will be fixed at 30 amps (designed for YHDC SCT-006 CT’s ).
  • 5 of 20 CT’s will be adjustable for high current circuits - up to 80A
  • Line voltage measurement through 12VAC XFMR but possibly direct line voltage measurement (like an oscilloscope) using certified scope probes - allowing future non-invasive load monitoring features
  • Li-ion backup battery capable of powering system for several hours without mains connection
  • OLED display & buttons for on-board user interface
  • SD card for data storage
  • Fully broken-out programming & debug headers for both MCU’s
  • Onboard temp,pressure,humidity sensor
  • approximately 10cm x 10cm size

Some possibilities in question:

  • Circuitry to drive external relays?
  • Circuitry to interface with RS485,ModBus, or other industrial protocols?

Here’s the system diagram as it stands now:

And a picture of the hardware as it stands currently:

This is actually not my first attempt at an energy monitoring system. I’ve documented a previous system on my website here. Anyway, please let me know any thoughts, ideas, or criticisms that you may have. Thanks!

2 Likes

You should be able to post more pictures now.

Making the inputs suitable for a particular c.t. ties you down. I suggest, if it’s at all possible, to make the input suit, or capable of accepting, as many different c.t’s as reasonably possible, both in terms of the value of the burden, and the voltage you need to develop across it. E.g. there is a wide choice of “economical” c.t’s that are only capable of 0.333 V ( ~1 V p-p input), and almost any c.t. is more accurate the closer the burden is to a short circuit.

Beware ground loops if you go down this path. You might find you need full isolation on every output connector (programming, wired network, etc) if you go that route.

I’m guessing those analog muxes are external to the stm32? There are some big performance gains to be had if you can use on-chip muxes, i.e. choose an stm32 with a lot more pins. With that approach you can configure the ADCs and DMA controllers so that they continuously step through all their analog inputs with no cpu involvement at all. Configured and started once at boot-time, the conversions then run continuously with the results dumped straight into your C array (by the thousands if you make the array big enough). The cpu then gets an interrupt when the array is half full and the conversions continue in the other half.

With that model, the ARM core is totally dedicated to doing the power maths on values that have been magically delivered into your array. It doesn’t have to spend any cycles dealing with ADC completions, MUX configuring, SPI bus transactions etc. etc.

There’s some sample stm32 code that uses that technique to implement a basic energy monitor in this thread: https://community.openenergymonitor.org/t/stm32-development/6815

Looks really nice @iamatesla! thanks for sharing, its great to see other hardware designs, ideas and hear your commitment to making it open source. The Li-ion backup battery is a nice feature.

We are working slowly on an STM32 design here too, Im currently refreshing on the work we did earlier this year exploring the platform. It will be great to compare notes and progress better open designs.

Hi Coyt,

This is one of those FWIW observations…

I read your whitepaper describing your original monitoring device.

In your paper, you mentioned The majority of household circuit breakers are rated at 30A.

In a typical US load center, most of the breakers are rated at 20A, vice 30A.

Because of cost considerations, most of the wiring in US homes is AWG12 which has a max
rating at 20A. Large load circuits, e.g. dryer, oven, stove, etc will use AWG10 or larger wiring,
but the typical US residence has many more 20A circuits than 30A circuits.

One other item that’s not outwardly obvious is the fact a 20A breaker installed in an enlosure
that lacks air circulation, (the vast majority of US residential load centers) is derated to 16A.

But in the UK, 32 A mcb’s are common (every house will have at least one), and you’ll also find higher rated ones - up to 50 A.

Didn’t mean to imply that 30A breakers were rare. US houses use a 30A double pole breaker
for an appliance such as a clothes dryer or water heater and a 50A DP breaker on electric stoves and ovens, but there’s usually only one or two 50A circuits in the typical US household. A larger house might have 2 water heaters and/or central heat/aircon units plus other large loads, and thus more than one or two 50A circuits. There are exceptions of course. e.g. I have ten 50A DP breakers in my load center.

@iamatesla Im writing up my notes here if its of interest: GitHub - openenergymonitor/STM32: STM32 Energy Monitoring

Explanation: The MCB operates both on instantaneous and long-term overloads. The instantaneous trip is by an electro-magnetic release mechanism (commonly referred to as “magnetic”) and the long-term overload trip is by a heating element and a bi-metallic release mechanism (commonly referred to as "thermal "). It is the latter which will respond at a lower than rated value at an elevated ambient temperature, or when there is insufficient ventilation to allow heat from the heating element - including those in adjacent MCBs - to dissipate.

Awesome feedback guys! I really appreciate it!

Sorry I’ve been MIA after my initial post - the day after I made it I got inundated with work from my day job. Such is life though.

Let me tackle thoughts in order of your posts so far…

  • I agree the CT connections should be as universal as possible. I’ll explore some ways to do this (and it’s feasibility in general) over the weekend.

  • Good point with the o-scope probe ground loops. Careful design will be needed here. Maybe some sort of two probe differential setup? This is already a future stretch goal for the project but may allow cool stuff like FFT’s to get very accurate phase info to compensate for the CT’s and whatnot. My reason for the scope probes specifically was to avoid having to do high voltage “certifications” myself :wink: my board would only see the low voltage output of the probe.

  • Good point with the ARM processor. I planned to get the external analog mux control lines all on the same ARM MCU port pin groupings (I.E. PORTA) so sequencing through the muxs could be made very fast. Just getting an arm chip with more analog IO probably will be faster and better - I’ll explore this over weekend as well.

  • Additional positive point of on-board battery: entire system can be switched to battery power during the voltage measurement on the 12VAC line. This will lead to a more accurate measurement because the 12VAC XFMR will have zero loading. I read this has been an issue with previous energy monitoring hardware in the past.

  • You’re correct - 30A is more than normal for regular household circuits in the US. I’m well aware that real breaker boxes contain 15A or 20A breakers. I sized the original CT’s to 30A for flexibility, because they were easily available from yhdc, and to provide headroom. There’s no downside to using 30A CT’s on a 0 to 15A circuit except (the potential for improved) resolution as far as I’m aware. Looking back I do admit I used the 30A figure incorrectly in my paper.

  • I specifically have 5 of my 20 CT circuits setup to handle 80A CT’s for the higher current loads (maybe 240VAC 50A or whatever going to your stovetop or HVAC). The voltage used (120VAC vs 240VAC) in the US split phase system would be configurable in software.

  • awesome references for STM32 software. I’ll review this and see how/what I can integrate with my project and what I can contribute back. I likely won’t have much software to contribute until I have the hardware a bit more solidified.

Anyway, thanks again! I’m welcome to more feedback / discussion and I’ll definitely keep you all posted on progress as it happens.

2 Likes

I wondered if that was the intent when I saw that solid state switch in there. I believe you’re right about the DC supplies having a tendency to put a big divot in the 12VAC sinewave as their caps start conducting. Others here have more experience than I do with that.

The downside is it’s not immediately obvious how to fit that in with continuous sampling. The model used in that example stm32 code I referenced above sets the ADCs running at init time and never goes near them again. All I and V input pins will be sampled continuously at their configured sampling frequency forever, with no cpu involvement. The cpu is responsible for processing the results in a timely fashion, and since they’re magically loaded into your C data structures that’s pretty easy. Effectively, there’s a separate engine co-ordinating all the conversions, continuously, forever and ever.

I’m a big advocate of true continuous sampling rather than some round-robin or stop/start approach. That’s probably just the purist in me because that’s how the energy ICs work once you set them running, and I’ve tried to emulate them in that example code. In your case, avoiding the divots in the 12VAC signal is probably way more important than continuous sampling so that’s a design trade-off for you to ponder.

Consider choosing one with a decent DSP/FPU in that case. I did some tests ages ago on the 72 MHz M4 in the F303 and found it could do an FFT on 1024 floating point values in 1.3 msecs. That’ll get you to the 512 complex pairs and it takes another 284 usecs to calculate their magnitudes. I think I also timed how long to calculate the phase, but don’t have access to that currently.

I’ve also recently picked up a STM32H743ZI, it’s got a 400MHz M7 core with an FPU that will do double precision. That oughta’ have mind blowing performance, but I’ve not found time to do much with it as yet.

I was thinking exactly about the same project with STM32.

In my opinion this system is extremely valuable while it is able to monitor all sorts of energy consumption, and how it translate to temperature and humidity. The data base is stable, the web interface is very nice.

It lacks the ability to trigger events.

For example at certain temperatures to trigger different events. This way it will start perform not only a sensor role, but active management role in a smart home.

Now I created a smart system in my home to manage couple of sources of heat with different efficiency in different conditions. But I cannot make it speak to my emoncms and thus cannot trigger events in my system on the base of different conditions.

So I would say yes it should be able to connect to external modules. Like Sensibo (control of AC, they have API) or just pure relay module that could be used as interface to other utility systems.

For the STM32 there are different Possix ROS options. The ROS is needed in case there are control or trigger functions incorporated.

my 2 cents.

I use these guys relays in my setup.

Their architecture is very open and diverse in terms of control options. SNMP, CLI, WEB.

What they lack is nice interface, they cannot fit it on their chips. And better feature set. Like sheduling, triggering events in a flexible way, flexible sensor infrastructure.

Their system provide no way to connect the way OpenEM is connected to the sensors. Their system cannot measure electricity or other utility consumption.

Accept it as flexible and reliable relay for control with good interface.

@dBC

Interesting trade-off you bring up with the sampling architectures. I understand and agree continuous sampling is the “ideal”. Getting there while having other system limitations in place seems to be the hard part.

Random thought i just had typing this - maybe continuous sample the 12VAC line as you propose but also interrupt the 12VAC load connection frequently with solid state switch. Then, have a filter in software which drops all voltage readings during the time a load was connected? I may be crazy - just trying to think of ways to reconcile your continuous sampling with the no load XFMR sampling architecture. Actually more I think about this… system hysteresis (i.e. caps recharging, etc…) may prevent the ability to do this fast enough…but idk.

That STM32 you propose looks epic. I may buy the nucleo board just to play with it as well. Unfortunately the cheapest raw chip on mouser is $21 that’s my second biggest concern with using it. If I did, that would add up to over $30 per PCB just for MCU’s when you factor in the ESP32 I plan to use.

My growing first concern with this project is over complicating it trying to get to some ideal immediately. I’m realizing this more through the discussion here. I may just make a quick and simple version of this board without worrying about perfect power calculations and measurement and just see if I can get it to work reliably.

@tubeme

Thanks for the recommendations. I’ll most likely add connections for external IO (I.E. relays) to my board for this purpose. Unfortunately it’s another matter altogether to have relay drivers for 12V relays on my board -doing so will add a lot of circuitry (I don’t mind if it’s a critical needed feature by the community). I’ll have to review the capability of those wifi relay boards in more detail tomorrow - they look pretty cool.

You might not be able to do that. The amount of voltage drop you experience depends on the impedance of the source. Adding anything in series (a transformer) increases that and worsens the voltage drop. In my opinion, the only way to get the “best” sample to monitor the voltage is to do it as independently as possible of the power supply. A power supply that draws current over as much of the cycle as possible, and not just before the voltage peak, will help enormously.

One other thing I forgot to mention earlier, the US ‘split-phase’ mains is, as far as I know, unique to you. Most of the rest of the world has a three-phase system at the final distribution level. In the UK, most homes get only one phase at 240 V line-neutral, and I believe it’s much the same in countries that were the former British Empire. In Europe, homes get all three phases, but most loads are single-phase at 230 V. Some parts of Europe have 230 V line-line and loads are single phase but connected line-line, so both lines are 132 V to earth and there’s no neutral. Where there’s a 3-phase supply available, large loads, and especially rotating machines, will normally be 3-phase. And of course you should really measure all three voltages with a 3-phase system.

Because I run a solar setup with a DIY 12.2 Kw lifepo4 battery, a additional DC voltage and bi-directional current sensor would be ideal, even at individual voltage level for each battery in series in my DIY battery bank 16s as there is little on the market.

Have you considered an actual power measurement IC?
I have been looking at the ATM90E26
http://www.microchip.com/mymicrochip/filehandler.aspx?ddocname=en590041

It looks very capable and does all the math, but maybe that takes the fun out of it for you :smiley:
At about $1/channel, it seems fairly priced. The current channel has a PGA, so it will work well with just about any current transformer.

You might also want to look at iotawatt and learn what you can from that.
You will likely find out how flakey sd cards can be and how hard it is to get very reliable software.

For control stuff MQTT is a popular transport which can then be consumed by my things to enable actions.

While I still use emoncms, I find the speed, visualizations, and ease of use of grafana and influxdb to be better for some things.

If you are doing this for fun, that is great have fun. If the goal is a saleable product, be aware that it is a long road with a lot of curves and hills and sometimes the bridge is out so you have to make a detour :wink:

1 Like

@Ross
Just a note on the DC side of things… You’re probably aware of the need for isolation in general?
CTs and VTs make monitoring AC energy very safe, which is the route taken here.

A separate safe DC voltage or current measuring device which outputs up to something like 3.3 or 5V could possibly be used but…
Fifteen of the inputs are planned to make use of a CT requiring a burden resistor, which mark those inputs out for accepting a simple voltage input.
@iamatesla The remaining 5 planned adjustable inputs, there are some interesting questions here. Voltage output CTs, current output CTs, burden resistor configuration… There are going to be simple ways of making those inputs flexible for both DC and AC, with an input type selectable in software.