Returning data from EmonLib functions

When running the standard "Voltage and Current" sketch, several parameters including 'real power' are calculated and displayed to the screen.  This activity takes place in functions within the library file, EmonLib.cpp.

In order to control the power to my immersion heater, my sketch needs to know how much power is available.  It therefore needs access to the displayed variable, realPower.  On examination of the file EmonLib.h, I was pleased to discover that realPower is a public member of class EnergyMonitor so can therefore be accessed from my sketch using the construct, emon1.realPower. 

OK, so what's the point I'm making.  Well, it's basically one of inconsistency.  The first sketch that I looked at was the "Current Only" one.  This calls the library function calcIrms() which returns the calculated value of Irms.  This calculated value is then assigned to a similarly named local variable for use in the sketch.   To the casual observer, it may not be apparent that the same value could have been properly obtained in a more direct way.

The loop() function in the 'Current Only' sketch is at present like this:

void loop()
{
  double Irms = emon1.calcIrms(1480);  // Calculate Irms only
  
  Serial.print(Irms*230.0);	       // Apparent power
  Serial.print(" ");
  Serial.println(Irms);		       // Irms
}

If it were to be re-written as below, I think it would be more clear as to what it going on. 

void loop()
{
  double dummy = emon1.calcIrms(1480);  // Calculate Irms only

  Serial.print(emon1.Irms*230.0);	       // Apparent power
  Serial.print(" ");
  Serial.println(emon1.Irms);		       // Irms
}

The same approach could then be used for assessing relevant values from calcVI() in the Current and Voltage sketch, as I am intending to do.

Robin
 

 

TrystanLea's picture

Re: Returning data from EmonLib functions

Hello Robin

Sorry for the slow reply, yes your right, I was wondering when writing it what would be best, I thought that as Irms is the only one calculated in the case of calcIrms I might as well pass it. But yes maybe it would best for consistency as you say to just reference the public variable: emon1.Irms

calypso_rae's picture

Re: Returning data from EmonLib functions

Hi Tristan,

My readings thus far of Irms are not particularly consistent, but when using calcVI() to determine realPower, the results are very much better.  Dither in the I and V readings appear to be cancelling each other out, or something like that.  Robert Wall and I have been exchanging ideas about this.

I wonder whether this aspect has already been raised on the forum, i.e. that power can be more accurately determined by measuring voltage and current, rather than just current. 

Hope your Euro-tour went well,

Cheers, Robin

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.