Project

General

Profile

Thoughts for a Jeenode S0 Pulse counter for multiple (8+) kWh meters

Added by rigolo@gmail.com about 6 years ago

Next week 7 kWh meters will be installed in my metercabinet to monitor energy consumption in the house. One kWh meter will be used to monitor the consumption of the whole house. 4 additional kWh meter will be used for monitoring of the consumption of some specific groups (Koi Pond, downstairs, upstairs, rest of the house). The 2 remaining kWh meters will be used to monitor the generation of solar power of the two inverters will be installed later this month. All kWh meters are rated for max 40A and give 2000 pulses per kWh consumed. Of course the 40A is never reached, not even for the whole house (35A main fuse) and the other and solar groups are limited to 16A. Assuming all the kWh meters are going at full 40A power then you get 5.1 pulse per second for each kWh meter (40A x 230 = 9.2 kW * 2000 = 18400 / 3600s = 5.111)

Of course I would like to measure all those pulses using a JeeNode. Using a commercial Pulse logger is always an option, but in my case it would require 4 Flukso’s (but that is still cheaper that one EMU S0 Impulse-Logger)

As a loyal jeelabs blog reader I have followed JCW’s work he has done in his house as documented here:
http://jeelabs.org/2012/10/21/detecting-pulses/

That hookup is working for 3 pulse inputs limited by the RJ12 6 pins. Using 2 of these setups you can go to 6 inputs. Switching to 2x RJ45 could give you more options but then you run into the limitations of the JeeNode only exposing 8 inputs of the 4 ports.

I also read this page:
http://openenergymonitor.org/emon/buildingblocks/12-input-pulse-counting

Here a seperate Arduino was used to make sure that there were no counting hickups as counting some many individual pulses. But the JeeNode does not expose all the pins like the arduino so this example can not be copied over to a JeeNode. And it would require 2 jeenodes making the whole setup more complex in my mind.

Then there is the InputPlug that gives you 16 inputs. I am not sure if that can count quick enough if combined with a normal JeeNode. With 8 inputs firing away at 5.1 pulses per second you have on average one pulse per 24ms. So speed is important when dealing with multiple inputs. And a missed pulse can never be recovered anymore

On the connection side you can also have various options both on the power side and on the output side.
As each S0 port requires at least 5V and consumes a minimum of 20mA (JCW’s uses 27mA) per pulse you are looking at 160mA for 8 kWh meters per pulse. I am not sure if you can power the JeeNode + kWh meter using USB voltage/current from a RPi without affecting the stable operation of the RPi and/or JeeNode. You could (should?) use a powered USB Hub to connect the JeeNode via USB to the RPi and only use the +5V of an other USB port to power the kWh meters to avoid any influence between the 2.
To make everything tidy on the metercabinet side you could also create a little box with a USB port that provides the 5V power for the S0 meters. A RJ45 plug could be used to connect the 8 outputs to the JeeNode. All the pull-down resistors and 5V~~> 3V resistor could be housed in that box instead of the JeeNode side but that would make things less “standard”.

These are my thoughts … collected of the last couple of days looking at this from various sides. As I am no good with a solder iron I am not in a position just start hooking things up … (or at least .. I could use some hand-holding :-) )

What are the thoughts about this here on the board?

Hein


Replies (22)

RE: Thoughts for a Jeenode S0 Pulse counter for multiple (8+) kWh meters - Added by jcw about 6 years ago

Whoa, serious setup :)

W.r.t. speed - no worries: an ATmega can easily scan 1,000 times per second, probably also 10,000 times or more. I wouldn’t use I/O chips, because I think you have plenty on even a JeeNode: 4x 2 pins on the ports, 1 on the shared IRQ pin, A4 + A5 on the PSIX header, and B0 + B1 on the SPIX header, for a total of 13, and two more on D0/D1 if you also re-use the serial port.

Where is all that data going to? If you use a 3s wireless packet report + one more every 10s from the P1 serial, then you’d be doing almost exactly the same as I am doing here (I’ve also got a Flukso waiting for a upgrade, and then it’ll be added here, just to see how current clamps perform). I’m still using 2 JN’s: one for the pulse counters and 1 for the P1 port, but that’s really only because I haven’t combined the two sketches yet (i.e. “if it works, don’t fix it”).

(You’re welcome to drop by and see the setup, if you’re anywhere near Utrecht/Houten…)

-jcw

RE: Thoughts for a Jeenode S0 Pulse counter for multiple (8+) kWh meters - Added by rigolo@gmail.com about 6 years ago

>Whoa, serious setup :)

Thanks … but it still needs wiring and hookup .. :-) so still things to do before it works.
>W.r.t. speed~~ no worries: an ATmega can easily scan 1,000 times per second, probably also 10,000 times or more.

If speed is not an option .. then why did they run into issues in that setup on openenergymonitor.org? Apparently their code for sending out data was not fast enough? Or did they try to do too much? (they were experimenting with 54kW loads on a 1000/kWh pulse meter)

>I wouldn’t use I/O chips, because I think you have plenty on even a JeeNode: 4x 2 pins on the ports, 1 on the shared
>IRQ pin, A4 + A5 on the PSIX header, and B0 + B1 on the SPIX header, for a total of 13, and two more on D0/D1 if you
>also re-use the serial port.

For now 8 ports would be enough I think … but once you know you can measure things .. you always want more :-)
>Where is all that data going to?
I was hoping to HouseMon :-) .. that is why I was wondering what you were planning on using for long term storage :-)
In the mean time I think one or more online sites .. just to check them out (OpenEnergyMonitor, PVOutput etc etc)
And local storage also … in a simple MySQL database I think .. just to start with.
>If you use a 3s wireless packet report + one more every 10s from the P1 serial, then you’d be doing almost exactly the same as I am doing here
>(I’ve also got a Flukso waiting for a upgrade, and then it’ll be added here, just to see how current clamps perform).
Your hookup + other internet sites gave the basis for this setup. I think it is good to exactly know what you are using as a whole and that you can “zoom in” on the various parts behind that. Those 4 additional kWh meters are for those groups that have multiple wall outlets. The washing machine, dryer, over etc are now monitored with PlugWise plugs that were gathering dust here. Using python-plugwise (https://bitbucket.org/hadara/python-plugwise/wiki/Home) and plugwiser (https://github.com/infernix/plugwiser) to read their details (but I suspect there is a memory leak somewhere .. my RPi keeps on freezing after some time)
Did you know about these pages btw:
http://www.onezerozeroone.com/javascript/plugwise-espresso-machines-and-nodejs/
http://www.onezerozeroone.com/javascript/plugwisejs/
http://www.24hr.se/controlling-the-world-with-nodejs/
Looks interesting enough to investigate … reading plugwise modules with node.js :-)

>I’m still using 2 JN’s: one for the pulse counters and 1 for the P1 port, but that’s really only because I haven’t combined the two sketches
>yet (i.e. “if it works, don’t fix it”).

No P1 port here … we would like to keep our Ferraris Counter for a while …

>(You’re welcome to drop by and see the setup, if you’re anywhere near Utrecht/Houten…)

I will keep that in mind … not nearby .. but I always like to drive :-)

RE: Thoughts for a Jeenode S0 Pulse counter for multiple (8+) kWh meters - Added by jcw about 6 years ago

> If speed is not an option .. then why did they run into issues in that setup on openenergymonitor.org?

Might be latency. You have to make sure that nothing is preventing the main polling loop from running. With the RF12, EtherCard, or (the current) Serial driver it should all be feasible. Note that I don’t send each pulse, I just send counts every 3s, and time between the last pulses in milliseconds. The latter gives me 0.1 W resolution in the low range. Sending each pulse when say 7.2 KW is being drawn in total, generates 4 pulses per second on average. I didn’t want to clog the airwaves to that extent.

Hm… did I get the calculation right? Not sure.

RE: Thoughts for a Jeenode S0 Pulse counter for multiple (8+) kWh meters - Added by jcw about 6 years ago

> that is why I was wondering what you were planning on using for long term storage :-)

I’m saving all data as daily log files with raw RF12demo output. No decision yet on an intermediate format for quick data access, but I’ll be switching from my old JeeMon setup to HouseMon for central data collection this evening, using exactly the same file format.

RE: Thoughts for a Jeenode S0 Pulse counter for multiple (8+) kWh meters - Added by rigolo@gmail.com about 6 years ago

jcw wrote:
> Hm… did I get the calculation right? Not sure.

Yes .. you did … you just passed the Math exam :-)
Thinking a bit futher on the path to a 8 port S0 JeeNode I am now thinking about the following:
I would think you should also power the S0 connection from the JeeNode it self using the PWR pin from the Port connector. I’ve been thinking about hooking up the JeeNode to my doorbell transformer as a power source. It is rated at 8V/1A. Not sure what happens to the stability of the power when somebody rings the bell though. But it would be a good source of power, close the meter cabinet, always on, and 8V is not a problem for the JeeNode it self, and more then the 5V minimum needed to power the S0 port. I noticed that you can also get 0.5A doorbell transformers …. so maybe even getting a separate doorbell transformer for the S0 JeeNode might be an option.
Then I think a separate “PulsePlug” could be created that has an RJ11 connector on it for 2S0 pulse inputs. Not sure of the RJ11 connetor should face left, right up or down :-)

pin1: not connected
pin2: S01+ -> connected to the PWR pin of JeeNode Port
pin3: S01- -> connected to the DIO pin of JeeNode Port (via PullDown Resistor to GND and a 8V -> 3.3V Resistor)
pin4: S02- -> connected to the AIO pin of JeeNode Port (via PullDown Resistor to GND and a 8V -> 3.3V Resistor)
pin5: S02+ -> connected to the PWR pin of JeeNode Port
pin6: not connected

(I placed the PWR pins on the outside, not sure why … )

If you would take 4 of these plugs to occupy all the JeeNode ports you can monitor up to 8 S0 inputs

The only thing that might be difficult to make “generic” is the conversion of the voltage maybe you can make it such that it takes somewhere between 5V and 12V as the input of the JeeNode.

What do you think about that solution?

s.
Looking through the long list of JeeNode plugs I notice the Opto-coupler Plug … maybe that can be used as the “PulsePlug”. It already allows for 2 inputs, and is separated from the JeeNode it self. Then you can just power the JeeNode via a USB power connection from the router or any other power source.

RE: Thoughts for a Jeenode S0 Pulse counter for multiple (8+) kWh meters - Added by o_cee about 6 years ago

Excellent thread, very timely :)

I’m about to do pretty much the same thing, monitoring five DIN mounted meters (1x house, 1x apartment, 2x heatpump, 1x stables). My plan is to monitor them with two JeeNodes (which will hopefully be delivered this week :) since the meters will be at two locations.

I will try to use pin change interrupts to get correct timing, to be able to calculate momentary power use with the micro second timer, averaged with a running average function. The problem with this is that, as far as I’ve been able to tell, you can’t sleep the CPU since it looses track of time.

> If speed is not an option .. then why did they run into issues in that setup on openenergymonitor.org?
I think the problem was that the Ethernet library blocked during sending, and missing pulses (it wasn’t using interrupts).

> Where is all that data going to?
I will be pushing the data to emoncms, which I think is pretty nice.

RE: Thoughts for a Jeenode S0 Pulse counter for multiple (8+) kWh meters - Added by martynj about 6 years ago

Are these impulse generators cleanly debounced?

RE: Thoughts for a Jeenode S0 Pulse counter for multiple (8+) kWh meters - Added by o_cee about 6 years ago

No clue, haven’t been able to run any tests yet. Hopefully I will be able to handle that in software though, otherwise I’m a bit screwed since I don’t know much about electronics :)

RE: Thoughts for a Jeenode S0 Pulse counter for multiple (8+) kWh meters - Added by martynj about 6 years ago

IMHO, bouncy inputs and pin change interrupts are incompatible.   Strobing the I/O register  and software debouncing is fine with a regular polling loop that can be driven off one of the timers.

RE: Thoughts for a Jeenode S0 Pulse counter for multiple (8+) kWh meters - Added by o_cee about 6 years ago

Will need to do some experimenting, using pin change interrupts might not be necessary (sleep not possible anyway for instance). Why wouldn’t it be possible to filter bounces in software in the ISR? (Yeah I’m new to µC’s, I’m used to programming powerful PLCs).

The alternative would be an Arduino Mega with more real interrupts maybe?

RE: Thoughts for a Jeenode S0 Pulse counter for multiple (8+) kWh meters - Added by martynj about 6 years ago

It is a general issue that affects many families of MPU.  In brief, with an unbounced input, the chip internal setup times may easily be violated and without any latching, the interrupt service routine can get in the state of  ’someone knocked, but who was it??’.

Since you know the fastest that events can occur and the minimum incoming pulse width, a judicious choice of polling time much less than 0.5*pulse width will catch them all.

Something along the lines of -

  Event_ISR_routine {
    Wakeup based on fast timer tick
     Clear the timer interrupt
     Global interrupts back on
     Strobe the I/O register(s)
     XOR with last_known_register_state(s)
     Zero?  Restart timer. Go back to base level
     Something happening, strobe again and start filtering the changed bit(s)
     All stable? Increment the volatile event counter(s), save state, restart timer. Go back to base level
     }
  Base_routine {
    Kick off long timer
    Sleep
    any counters moved?
    stuff the RFM12B packet
    send update to remote
    loop
    }

It is important to allow nested interrupts in the Event_ISR_routine to allow INT0 from the RFM12B module to come in and pre-empt processing. Since INT0 has priority over the timers, this allows the time critical RFM12 driver to get service when required.

The design takes some thinking through - e.g. by chance, there may be several impulses arrive around the same time, but not of course synchronised. So you may be busy debouncing more than one impulse smeared out in time, spending a relatively long time in a minor loop in the interrupt service routine. This is usually said to be bad practise, but here the baseline code is not time critical and the RFM12B can get pre-emptive service when required.

Debugging ISR’s is fun. The only trace ability is to turn on LED’s, and have debug prints at base level only.

RE: Thoughts for a Jeenode S0 Pulse counter for multiple (8+) kWh meters - Added by o_cee about 6 years ago

Thanks Martyn, much appreciated. I will hopefully start experimenting with this soon. Might need to bring the stuff to work and see if I can get an oscilloscope running, and see what the signal looks like. Of course, I have no idea what’s inside of it, but I’m guessing it’s some kind of optocoupler.

RE: Thoughts for a Jeenode S0 Pulse counter for multiple (8+) kWh meters - Added by martynj about 6 years ago

An optocoupler would be good.  Especially if there are not some other components tacked on for “protection” (often a series blocking diode and/or a zener across the output terminals are present). If it is a ‘straight’ opto, it may well function fine in a ‘starved’ mode i.e. just enough current to see the input side IR diode turn on, instead of that industrial strength ~20mA spec’d.  Also, a well-behaved opto is effectively bounceless.

I’d be tempted to get the drill and hobby knife out …    ;-)

RE: Thoughts for a Jeenode S0 Pulse counter for multiple (8+) kWh meters - Added by o_cee about 6 years ago

> I’d be tempted to get the drill and hobby knife out … ;-)

Yeah thanks a lot for that Martyn, now i had to open it up :)

I can’t determine what components are on the S0 line, since there are two PCBs sandwiched together. What I can see is C46, R30 and Q1 (but as far as I can see, there is nothing at C46). Then there’s a bigger component which says ICIO on the silkscreen, quite big four-legged thing (6x3x3mm).

The other interesting thing I found is a 6 pin data connection of some sort. If I connect a FTDI cable, the LCD comes on! A bit dim, but it comes on. No RS232 data coming through though it seems.

Tried e-mailing the manufacturer, but I’m not sure they’ll want to respond.

The meter is a Yong Tai Long DTS-353.

RE: Thoughts for a Jeenode S0 Pulse counter for multiple (8+) kWh meters - Added by martynj about 6 years ago

Please be very cautious if you apply power - it almost certainly derives logic power directly from the mains WITHOUT ISOLATION. Depending on your L1/L2 or L1/N setup, ALL TRACES CAN BE AT FULL MAINS POTENTIAL.

Any pictures? The 4-leg device sounds like an optocoupler - the size is to ensure to provide enough in/out “creep” protection at the rated isolation voltage.

RE: Thoughts for a Jeenode S0 Pulse counter for multiple (8+) kWh meters - Added by o_cee about 6 years ago

I took some pictures before rushing of to work: https://www.dropbox.com/sh/dg124lqef81ozaj/G5QPEqA3Wr

Sorry for the shadow, the lens is a bit too big for the built in flash. I don’t have a good macro lens, but you can see some things here I think. The S0-output is the blue and red cables. If you click “View original” down in the right corner you can see the components a bit clearer on picture 5 and 6 for instance.

Also note the mysterious 6-pin header :)

RE: Thoughts for a Jeenode S0 Pulse counter for multiple (8+) kWh meters - Added by martynj about 6 years ago

Interesting. Yes, that is an optcoupler on the board connecting to the red/blue. Not easy to see if there are other components involved - it may well be just the collector/emitter output which will give a “closure” detection with just say ~1mA flowing. There are two sense resistors so it may well measure power flow in both L1 and L2 (the LED’s are probably anti-fraud that will trigger and latch if L1/L2 power is not equal and/or power flow is detected in the wrong direction).

There is no sign of an isolation transformer, so as I warned before, the traces will sit at ~L1 or L2 potential (not too bad when it is a L/N supply, very hazardous for L1/L2 or a reversed L/N). The header may well be an ISP/JTAG position for loading up/debugging the firmware. Some meters from the same vendor have an RS485 option which would presumably provide a dumps of several parameters.

RE: Thoughts for a Jeenode S0 Pulse counter for multiple (8+) kWh meters - Added by o_cee about 6 years ago

First test was a success! The signals seems clean, no bouncing, and it worked with 5V (spec says 12-27V). Only used a 1kΩ pull-down, and no pin-change interrupts so far, just polling. Not much jitter, but I didn’t test with the RFM12b active.

I asked the manufacturer about changing the pulse counts, but they said it wasn’t possible (of course) and mentioned that the meter would need recalibration if you upload a new firmware.

Not a big problem anyway, for normal loads. It gets a bit slugish when below 100W (~30s between pulses) but I have an idea about that. The problem is to detect a rapid decline to low consumption, which will take extra time to detect because of the long time between pulses (worst case scenario is that it drops to 0W and it isn’t detected at all, “freezing” the power at the previous reading). But, we also know for instance that if there hasn’t been a pulse for 10s, the consumption can’t be more than 360W (1000 imp/kWh), and 30s = 120W. That way, I should be able to lower the measured consumption before the next pulse comes.

RE: Thoughts for a Jeenode S0 Pulse counter for multiple (8+) kWh meters - Added by martynj about 6 years ago

Good results, confirms the eyeball test that you are seeing the ‘contacts’ as the output of an opto, which should be ‘bounceless’ on a short cable. You could try starving the output transistor much further,  the transistor action will continue into the uA region, though eventually noise/leakage will fuzz the decision point. To save components, turning on the DIO pin pull-up resistor will probably work.

Interesting idea on the predictive display - even though the true data is badly quantised at low levels, you still can make valid assumptions about its maximum value before the next ‘tick’.

RE: Thoughts for a Jeenode S0 Pulse counter for multiple (8+) kWh meters - Added by o_cee about 6 years ago

I decided to put my code on GitHub, for everyone’s amusement :)

https://github.com/oscarcarlsson/sensors/tree/master/PulsesEnergyMeter

The code is based on jcw’s pulse counting. It hasn’t been battle tested yet, only light bench testing so far.

RE: Thoughts for a Jeenode S0 Pulse counter for multiple (8+) kWh meters - Added by rigolo@gmail.com about 6 years ago

Update from my side ….

I have create 4 “pulseNode’s” using some help from others to compensate for my (lack of) soldering skills. (I managed to create one my self …. and it was working)
I have attached them to the 4 ports of a JeeNode USB, and linked them to 7 kWh meters that were installed here.

I have updated the homepower sketch to have 8 inputs, and now there are 8 sets of kWh meter data flying through the air here.

I have installed HouseMon and I create my own “driver” to handle the pulseNode format.

S0 now I have a status page that is updating with my readings …
I see some room for improvements, but that is for an other thread I guess.

Hein

RE: Thoughts for a Jeenode S0 Pulse counter for multiple (8+) kWh meters - Added by ltickett over 5 years ago

Hi Hein, great thread- i’ve just started something similar: http://jeelabs.net/boards/6/topics/2701 then stumbled across this during a search!

I don’t suppose you have any pictures of your consumer unit with the meters wired in? The image you shared from dropbox makes me think you might be using the “huge” meters- i’m curious how you’d fit 7 of them in your CU. I was looking at the single width meters.

Do you have any update on the project?

Thanks!

Lee

    (1-22/22)