Read only variable

Hi,

How do I read only the variable Irms, and Vrms or realPower?
I do not need to read all the variables via serial.

Ailton

Robert Wall's picture

Re: Read only variable

I do not understand your question.

I think you are asking: "How to I choose which variables to send through the serial link to display on the computer?"

Look in the sketch and the file "EmonLib.cpp", and you will see statements like

    Serial.print(realPower);
    Serial.print(' ');
    Serial.print(apparentPower);
    Serial.print(' ');
    Serial.print(Vrms);
    Serial.print(' ');
    Serial.print(Irms);
    Serial.print(' ');
    Serial.print(powerFactor);
    Serial.println(' ');

The first prints the value of realPower, the second prints a space, the third prints the value of apparentPower, etc.
The last prints a space and ends the line (println( ) ).

If you do not want some of this lines, make them comments:

    Serial.print(realPower);
  //  Serial.print(' ');
  //   Serial.print(apparentPower);
    Serial.print(' ');
    Serial.print(Vrms);
    Serial.print(' ');
    Serial.print(Irms);
  //   Serial.print(' ');
  //  Serial.print(powerFactor);
    Serial.println(' ');

This will NOT print apparentPower and powerFactor. It WILL print realPower, Vrms and Irms.

 

 

 

 

ailtonfacanha's picture

Re: Read only variable

Hi, Robert

Thanks, Robert for your explanations. I want to use the variables without the use emonx.serialprint ();

Can you help me?

I will not use them in the serial monitor and want to send these variables to an LCD.

Ailton

Robert Wall's picture

Re: Read only variable

Now I understand. Are you using the RFM12B module?

The r.f. module uses a data packet of type "payloadTX" (or a similar name) to send the data. The contents of "payload" must be the same in both the emonTx and the emonGLCD. The definition is similar to:

typedef struct
{
  int powerA, appA;
  int powerB, appB; 
} PayloadTX;
PayloadTX emontx;  

In this example, there are 4 integer values: powerA, appA, powerB, appB.  The particular instance is called "emontx"

The data is written into payload inside loop( ) after it has been calculated:

emontx.powerA = emon1.realPower;
emontx.appA = emon1.apparentPower;
  [etc]

At the GLCD end, you need to define exactly the same data structure (but it need not have the same name) and you extract the data in much the same way (only in reverse):

consuming = emontx.powerA;  
  [etc]  

You can of course put whatever data you want into the payload. (The data elements need not have the same names, but they must correspond exactly in order, type and size - example: {int, float, long} is not the same as {long, int, float} and the information will be corrupted).

If you are not using the serial monitor, you can change all those Serial.print( ) statements into comments.

ailtonfacanha's picture

Re: Read only variable

Hi, Robert

Robert -> Are you using the RFM12B module?

Ailton -> I'm not using. I'll use a 20x4 LCD compatible with HD44780.

Thanks for your help!

Ailton

Robert Wall's picture

Re: Read only variable

I based my explanation on the software for the emonTx and emonGLCD. So, if you are not using those, how are you collecting the data, processing it to calculate rms voltage and current, power, etc, and then transmitting it to the LCD?

ailtonfacanha's picture

Re: Read only variable

Hi, Robert

Something like this: http://openenergymonitor.org/emon/buildingblocks/nokia-3310-lcd . Updated to Emonlib.

Thanks for your help!

Ailton

 

Robert Wall's picture

Re: Read only variable

If you look at the very last few lines of that sketch, you have the Serial.print(  ) statements, then 3 lines to reset the accumulators, then:

//Output Real Power to the LCD
itoa((int)(realPower), chvalue,10);
lcd.LCD_3310_clear();
lcd.LCD_3310_write_string_big(15, 1, chvalue, MENU_NORMAL);
lcd.LCD_3310_write_string(65, 3, "W", MENU_NORMAL);

itoa((int)(realPower), chvalue,10);  converts the integer value to ASCII characters, putting the characters into 'chvalue'

lcd.LCD_3310_write_string_big(15, 1, chvalue, MENU_NORMAL);  does what it says - writes to the display.

You will need to look at the other (Nokia?) documentation to see where the characters are written (That's what the "15,1" is), work out how to arrange the display of the 3 values you want and add 2 more sets of lines (itoa....   and  ...write_string...) to write Vrms and Irms.

 

 

Comment viewing options

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