Open Energy Monitor Port

@phec I’m glad you got this all up and running before I attempted this! Now when I start playing around with the Open Energy Monitor I know you figured out alot of settings to get the Spark Core working correctly.

Thanks for sharing, I’ll do the same thing when I get going on this.

So if I wanted to measure Voltage and Current flowing out of a DC to AC inverter with the Spark Core what would you recommend? I just want to show AC wattage and Current on a LCD display and total up power output over time. AC output no more than 2.5kw

I have not attempted this yet but I was thinking a CT clamp and AC adapter brick to get correct readings like the Open Energy Monitor project is doing?

@RWB I’d have thought that you could measure the voltage and current exactly the way I have. The SCT-013-030 handles more current than you need but given the resolution of the Spark ADC that shouldn’t be a problem. You could always loop the cable twice through the clamp giving you the full 1v signal with 15 amps. I much prefer to use this model of clamp rather than the ones with an external burden resistor because of the large back EMF you can get if you disconnect an unburdened clamp.
There are some posts in this forum where people have connected up an LCD display eg.
https://community.spark.io/t/liquid-crystal-library/1048/3

There are plenty of spare digital pins so you could use either a serial or parallel display.
My Pi software does the totalling up and averaging but it is just as easy to do it in the Spark. If you want to store the total (so it is still there after a reset or power outage) you should be able to put it in the Spark’s non-volatile memory. I’ve not used this on the Spark but I’ve done it on an Arduino and it is quite easy to do. I suggest that you only update the non volatile memory every hour or so as it has a limited life.
I use an adaptor brick as you suggest. It does a good job. If you are prototyping on a breadboard watch where the 9v ac goes from the brick goes - I ruined a Spark core by slipping and putting 9v on the ground line. For breadboard work I now have a brick with the output divided down external to the circuit board. It is not pretty but it is less risky.
Is your power always flowing out of the inverter? Is it always at nominal mains voltage? Is the load mainly resistive? If the answer to all three is yes you don’t really need the OpenEnergyMonitor stuff - you could just measure the current.
I look forward to hearing how you get on.

Annotated Graph of Outputs

The minute by minute data are from the Spark. It was sunny in the UK today. The monthly average data combine the old Arduino numbers from last year as well as the current Spark data since the format I use is identical.

@phec

These will be use on portable solar generator systems so yes it will be DC to AC inverters so the output voltage will be pretty stable since I’m using hi quality inverters. The loads will be different depending on who is using the system and for what. It doesn’t have to be super accurate, 10% accuracy would be good enough.

I have the digital Displays worked out, I’m using Digole displays for now via SPI and they are working just fine.

So I just need a CT Sensor and a 9v power adapter and the correct code to begin reading AC voltage and Current? What other data can be provided with that setup? Power Factor? Its all new to me so all info is appreciated.

@RWB yes, just those two sensors. If you wire them as I did then all you need to do is set up the scale factors and tell SemonLib which ADC channels you are using with calls to voltage() and current() in setup(). Then a call to calcVI() inside your loop() makes a series of measurements and calculates real power, apparent power (i.e V x I ignoring any phase shift), rms voltage and current and the power factor. These are available as public variables accessible directly from your own code. The names of the variables are in the SemonLib.h file.

Adding cumulative power is easy(ish) depending on whether you follow the non-volatile route. Rolling 24h average power needs quite a bit of RAM if you want fine granularity - just keep an eye on how much you have available or you will get a pretty red flash from the Spark.

Another thing you might like to add to the project, since you have a graphical display and without any additional hardware, is a display of the waveform that the inverter produces. If yours was designed for a UPS it is probably quite smooth but some are not. Since the Spark grabs about 180 ADC V and I samples per mains cycle (150 in the USA) you could save about one cycle’s worth of samples and display them on your Digole. You could see the effect of connecting a switch mode power supply or a triac power regulator. Again keep an eye on RAM but 2 off 128 element integer arrays for the waveform and a 240 element float array for a 24 hr rolling average power in 6min buckets should be fine.
The Open Energy Monitor web site has quite a lot of background information on real vs apparent power, power factors and how the library code works. I’m afraid that I’m no expert.

Thanks @phec for the advice.

So should I just buy the CT sensor and 9v Adapter from Open Energy Montior’s web store? I’ll order it up and give all this a shot in the near future.

Displaying the AC waveform on the LCD sounds pretty cool. I’d like to try it. How its done is over my head right now but I’ll come back once this is setup and we can work though it.

I’m interested in pushing this data to a Web Based graph also and the Spark can help with that.

I don’t think the Open Energy Monitor guys do the model I suggested (sct-013-030). Theirs is the 100a model and needs a burden resistor - they have the details on how to size the resistor on their site. Alternatively you can get the 30a one from Amazon or on ebay. Ditto the power block though my local hardware store had good quality 9v ac supplies cheaper even than ebay.

Ok so this should be good then http://www.amazon.com/013-030-Output-Non-invasive-Current-Transformer/dp/B005CTWE8A Ordered.

Now what exactly does the AC to 9v DC power adapter actually do? How does it help get the voltage of the AC power line?

@RWB It must be an ac power adapter. All it is doing is reducing the mains voltage down to a safe level for the Spark. Unfortunately neither I nor the Open Energy guys could source a mains to 1 volt adapter so we use a 9 volt one and then further reduce the voltage using a pair of resistors. See:
http://openenergymonitor.org/emon/buildingblocks
The current clamp gives you the current, the power block gives you the voltage the phase difference between the two gives you the power factor. There is a good description in the reference. Happy reading! My circuit is very similar to theirs but I’ve simplified it a bit by using a common 1.65 volt supply.

V and I waveform added to Energy Monitor display

Adding these plots really pushes the Spark RAM. The first plot is where I was using about 3kW, the second I was exporting about 3 (I changed the scaling and added a caption between plots).There was not enough space to store the data as ints so I have scaled V and I to be in the range 0 - 255 and used char arrays.
The UDP communication remains the same - I’ve just tacked two 128 element char arrays after the string containing the power data.

The current clamp you recommended arrived!

@phec Now how in the hell do I get this working on the Spark Core without spending a week trying to figure it out?

1 Like

I’m following this closely. I’m spending all my spare time working on my spark monitoring web service. It’s perfect for all the graphing I want from this.

I’m going to jump on this in the spring… after @RWB is done being the guinea pig. :slight_smile:

1 Like

Start with the Open Energy Monitor web site - their intorduction to voltage an current monitoring then see how that relates to the pictures of the Spark hardware and the Spark version of the emon library and how I’ve used it.
You can test the library with your hardware without all the rest of the software by writing a small application like this - (which I’ve just typed in so I leave bug fixing as an excercise … )

// test SemonLib20
// I've not tested this snippet!
// 

#include "SemonLib20.h"
#include "application.h"

EnergyMonitor emon1; // make an instance of the EnergyMonitor class
char output[128];    // somewhere to store the output

setup(){
    emon1.voltage(0, 250.0, 1.12); // initialise emon with pin, Vcal and phase
    emon1.current(1, 30);          // pin, Ical correct at 1kW
    Spark.variable("results", &output, STRING);
}
loop(){
  emon1.calcVI(20,1600); // I have timing problems if I increase the 1600 timeout
  sprintf(output, "%.1f, %.1f", emon1.Vrms, emon1.Irms);
  delay(1000);
}

I guess I’m wanting to know if there is any special modifications that I will need to make to Open Energy Monitors Code to get this working on the Spark Core based on the current web IDE build. Know what changes to make should save me a lot of trouble.

Is the code you posted above specific to the Spark Core with any changes that are needed for proper operation?

I have a new Spark Core sitting here waiting to be put to use.

1 Like

I’m afraid I can’t answer the part of your question about what changes are needed for the web IDE. I’ve compiled locally - depending on the version of the core software on the web IDE it may struggle with the two channel ADC or with listening for the next software flash while it is busy UDPing or in its tight read ADC loop. I certainly had problems with both of these before going local. Compiling locally is also a good deal quicker. If these two issues have been fixed, the only change to the ported software for web IDE is to omit the #include “application.h”

Within your software, if you are borrowing from the Open Energy project, you need to replace the Open Energy library emonLib.cpp and its header with the one I’ve ported to Spark, SemonLib.cpp.

The software I’ve posted is exactly what I am currently using to monitor my solar panels and switch on my immersion heater. It seems pretty stable so it should form a reasonable basis for what you want to do.

Thanks! I’ll dig in soon and report back.

Trying to put together the parts list of this to make sure I have everything.

  1. Current sensor: SCT 013-030
  2. Reed switch: COM-10601
  3. Photoresitor: ???

Any other major parts besides resistors and capacitors?

Hi @kareem613
You need a low voltage ac power supply too otherwise that’s it. The lowest voltage ac supply I could find was 9v so as described in the Open Energy Monitor website I divided it down with a pair of resistors so it was within the range of the Spark ADC.
I don’t have a part number for the photoresistors. You don’t have to use photoresistors if you are measuring the power with the current clamp. I got mine from Hobbytronics in the UK together with a shrouded 5x2 header box and matching ribbon cable and connector. I also used their decoupling capacitors but don’t recommend them if you are using strip board as they have rigid pins. Very neat for a PCB though. The exact photoresistor doesn’t matter. The ones I used have a HUGE drop in resistance when they are illuminated so it is very easy to use them to pull down a digital pin to earth and trigger an interrupt. I don’t think the results are very sensitive - you just need something that goes from a value well above the 100k pull up resistor in the dark to well below it when the meter flashes. The main thing to watch with the photoresistors is to keep out extraneous light. You can see in the photo near the top of this topic that I have put the photoresistor in a black ballpoint tube and attached it to the meter with blutack.
I hope the project goes well.
I’ve been tweeking the software a little so when you are ready to code make sure you check the Gist for the latest version - though I imagine that you will modify it quite a bit to suit your web based graphing.

Do you think this AC/AC adapter will do the trick?
http://www.jameco.com/webapp/wcs/stores/servlet/Product_10001_10001_100061_-1

I’m assuming 500mA is enough.

@kareem613 From what I understand all the AC adapter is for is to power the Spark Core. So you could just use a USB AC Charger and a USB cord and keep the Spark powered via USB if you want to.