Code to upload first?

I recently purchased fully assembled emonTx V3. I downloaded USB to UART Drivers and then installed libraries as given in the instructions on this website. I also downloaded the emonTxFirmware. According to the instructions, i now need to upload emonTx_CT123_Voltage​. However inside the sketchbook, this code is contained within emonTx V2 folder, whereas i purchased emonTx V3. 

Is this the first code that i need to upload? I can't find emonTx_CT123_Voltage inside the folder for emonTx V3.

Eric_AMANN's picture

Re: Code to upload first?

Hi,

For EmonTxV3, follow the instructions here.

The main sketck for EmonTX V3 is emonTxV3_RFM12B_DiscreteSampling.

(I assume you have purchased a V3 with RF)

Eric

 

 

yhabib's picture

Re: Code to upload first?

Yes i purchased fully assembled V3 with 433 Mhz. However at the moment i want to keep it simple and DO NOT want to include any RF. I have purchased:

1) USB to UART cable

2) 2 CTs

3) AC-AC power supply adapter

4) emonTx V3

5) Mini-USB cable

All i want at the moment is to get the Apparent Power and Real Power values at the serial monitor of the Arduino IDE. According to the instructions page that you mentioned above, it says that i do not need to upload any firmware since it is already uploaded. 

If this is the case and keeping in view that i do not want to use RF, how should i proceed?

Appreciate your help.

Robert Wall's picture

Re: Code to upload first?

Unfortunately, the default sketch only gives you real power at the serial monitor, it does not provide you with apparent power. Therefore you will need to add a few lines of code to your sketch and re-load it.

If you look at the sketch, you'll see that, in the main loop you have a section for each CT (inside an "if" block selected by "if (CT1)". I'll only tell you about CT1, you can do the same to all 4. The method "calcVI" actually gets and processes all the data that you require, you just need to extract the values. These are:

double realPower,
       apparentPower,
       powerFactor,
       Vrms,
       Irms;

(Look at emonlib.h to find them.)

Therefore all you have to do is add, inside "if (debug==1) {Serial.print(emontx.power1); Serial.print(" ");}" another Serial.print to give you ct1.apparentPoweremontx.power1 is actually ct1.realPower if an AC adapter is present, otherwise it is apparent power using an assumed value for the voltage.

Having made that change, upload the sketch to your emonTx V3 and monitor the serial output. You will need the AC adapter and a CT connected, and a serial (programmer) connection, to get the sketch to go through the correct branches to print the values.

If you wish to not transmit the data, you can comment out the line "send_rf_data();"

calypso_rae's picture

Re: Code to upload first?

If you just power up the board with the AC adapter, what does it show at the Serial monitor?  If nothing seems to be happening, you could try pressing the reset button while  the Serial Monitor is open.  The standard V3 sketch should identify itself as part of its start-up sequence.  The Baud rate in the Serial Monitor will need to be set to 9600 to match the line:

Serial.begin(9600);

 With the default sketch, RF messages are routinely transmitted, but they're not doing any harm.

yhabib's picture

Re: Code to upload first?

Since i am using serial monitor so my only way of powering the emonTx V3 is through the programmer (USB to UART cable). Before making any modifications for calculating apparent power as suggested by Robert Wall, i thought i should check real power at the serial monitor. When i try to upload the sketch 'emonTxV3_RFM12B_Discrete Sampling', i keep getting the same error which says 'sleepy' has not been declared'. 

I don't know what to do with it. Any suggestions?

pb66's picture

Re: Code to upload first?

does this help at all http://openenergymonitor.org/emon/node/512

Paul

yhabib's picture

Re: Code to upload first?

Thanks pb66.

I resolved the problem since i had made the same mistake of not renaming the files. 

Regards

yhabib's picture

Re: Code to upload first?

void loop()
{
 
  if (CT1) {
  double irms = ct1.calcIrms(no_of_samples);
  Serial.print(irms); Serial.print("  ");
  emontx.power1 = irms*Vrms;                               // Calculate Apparent Power 1  1480 is  number of samples
  if (debug==1) Serial.println(emontx.power1);
  delay(5000);
  }
}

 

I am using the above simple code to calculate the apparent power value. The Vrms is set to default 240 V. Could someone please explain the significance of no_of_samples? Why is it set to 1480 and what happens if i change its value?

Robert Wall's picture

Re: Code to upload first?

It is the number of samples over which the average is calculated. That should be very obvious from the code, if you look into the workings of emonLib. What might not be so obvious is that you should have an integer number of cycles over which you calculate the average. Unfortunately, as you are not measuring voltage, you have no means of knowing when a cycle starts and ends, so you have to make a guess at how long a cycle is in terms of the number of samples. Then you need a reasonably long sampling period so that 'end effects', if you include part of a cycle because your guess was wrong, are minimised. But the sampling period should be short enough to keep the power drain to an acceptable level if you are running on batteries. Knowing the approximate sampling rate and bearing in mind that the sketch must be suitable for both 50 Hz and 60 Hz systems, 1480 seemed to be a good choice. If you wish, you are free to change it.

yhabib's picture

Re: Code to upload first?

I am using the programmer to power the emontx V3 since i require values at serial monitor.

Based on the code pasted above, i got the following values at the serial monitor:

0.14  34.60
0.14  33.79
0.14  33.87
0.14  34.04
0.14  34.06
0.14  33.99
0.14  34.18
0.14  33.79

The values in the left column are for irms current and those in the second column are for apparent power. My question is that why do i keep getting different values for apparent power for the same current value? The Vrms value is fixed at 240 V and based on the multiplication i should keep getting the constant value:

0.14 (A) * 240 (V) = 33.6 VA

 

calypso_rae's picture

Re: Code to upload first?

I think this is just an effect of the precision with which the value for Irms is being displayed.  0.15 (A) * 240 (V) = 36 VA, so any power value between 33.6 and 36 could reasonably be displayed alongside the 0.14 value.  If you were to display the Irms value to more precision, this effect would probably disappear. 

Serial.println(Irms, 4);  // to display four decimal places rather than the normal two

If you can monitor voltage as well as current, your value for power will be much more accurate.

yhabib's picture

Re: Code to upload first?

Thank you.

I am facing another problem too. I keep getting the 0.14 A value irrespective of the connection of the Current Transformer. 

When the Current Transformer is not connected to any wire, i get the same value of 0.14 A and when i connect it across a t.v powering cable, i still get the same value. 

From what i think, i should get 0 A when CT is not connected across a cable and 0.14 A value only when it is clipped across a cable.

pb66's picture

Re: Code to upload first?

Unless you are clipping the CT around one core only, of the TV's power lead you will not get a reading as you are effectively measuring in 2 places in 2 directions which will cancel each other out.

A TV is not the best load to use for testing, a short extn lead with a short length of the outer sheath removed will allow you to clip ct on one core and test on a steady resistive load like a incandescent lamp or a kettle.

There may also be some "noise" present when working correctly but no load present, it is unlikely to read exactly 0.

Paul

calypso_rae's picture

Re: Code to upload first?

From what i think, i should get 0 A when CT is not connected across a cable and 0.14 A value only when it is clipped across a cable.

If no current is flowing through your test cable, it should not matter whether the CT is clipped around the cable or not.  You should be seeing 0 A in both cases

When using the  "current-only" sketch (which involves squaring the measured value), all signal from the CT is seen as positive, so the calculated value is always greater than zero.  But when you measure voltage as well (which is negative for 50% of the time), nearly all of that calculated power goes away.

On the systems that I build, the background power value is never greater that a Watt, and usually much less.  That's 35 times lower than you are seeing.

yhabib's picture

Re: Code to upload first?

I am still a little confused about the values of calibration for CT. Sometimes its 111.1 and other times its 90.9.

1) Can someone briefly explain which one of them is correct since both give different values of Irms. 

I need to know this so that i can get on with my work rather than spend time worrying about calibration values.

Robert Wall's picture

Re: Code to upload first?

They are both correct - in different circumstances. Of course they will give different values, that is what calibration is all about. Look for the page about "CT and AC power adaptor installation and calibration theory" in Building Blocks.  You can read all about it there.

You will also find it very instructive to read the page "Calibration".

yhabib's picture

Re: Code to upload first?

The UK mains supply 230 V RMS. If that's the case then i don't understand the logic of calculating Vrms based on the following code:

double V_RATIO = VCAL *((SUPPLYVOLTAGE/1000.0) / (ADC_COUNTS));
Vrms = V_RATIO * sqrt(sumV / numberOfSamples);

Why can't we just put a constant value of 230 V instead of calculation above?

 

jpbrigg's picture

Re: Code to upload first?

BS 7671 Appendix 2 section 14.
The UK supply 230 V +10% - 6%

yhabib's picture

Re: Code to upload first?

I understand the logic of calculating RMS voltage and RMS current since the product of these two quantities gives us the apparent power. However what confuses me the most is the calculation of real power.

From my understanding, the real power is simply the average of the instantaneous power (product of instantaneous current and instantaneous voltage).  The code uses the following lines to calculate the real power (or average power)

1) (calculates the instantaneous power)      
    instP = phaseShiftedV * filteredI;  

2) (Takes the average)
sumP +=instP;  
sumP / numberOfSamples;    

Now my question simply is that how can we assume phaseshiftedV is the instantaneous voltage when it simply is the RMS voltage measured by the AC-AC adapter.

Robert Wall's picture

Re: Code to upload first?

"Now my question simply is that how can we assume phaseshiftedV is the instantaneous voltage when it simply is the RMS voltage measured by the AC-AC adapter."

That is totally wrong, and where your misunderstanding lies. It is not the rms value (the ac-ac adapter does no calculation of its own, it is only a transformer in a case), phaseshiftedV is indeed the instantaneous voltage - but "phaseshifted" is probably the wrong word, it would be more accurate (but a lot harder to write) to call it the interpolated/extrapolated time-shifted instantaneous approximation. You can read up about it in Building Blocks (of course) in "Explanation of the phase correction algorithm".

You can read why the UK voltage has asymmetrical tolerances in the appendix to my test reports on the AC adapters.

yhabib's picture

Re: Code to upload first?

Thanks Robert.

From my understanding based on your explanation in Ideal Power 9V AC-AC Adaptor (Voltage Transformer), i assume that the adapter exhibits a phase lead in the input voltage to the arduino processor. Now in order to overcome this error, we pass on the calibration constant (1.7) in the code to determine the phaseShiftedV which we utilize to measure the realPower (please correct me if i am wrong)

My question is that can we use phaseShiftedV instead of filteredV​ to determine the Vrms?

Robert Wall's picture

Re: Code to upload first?

Phase is vitally important when calculating real power. That is why the correction is applied. Note the correction is not because of the phase lead in the VT, it is because of the phase difference between the ct and vt, plus the time difference between the two samples. Phase does not matter when calculating rms voltage (or rms current). You could make the change, but why should you want to? The only reason that I can see is to account for the small amplitude difference that the interpolation/extrapolation algorithm introduces.

yhabib's picture

Re: Code to upload first?

Thank you Robert

yhabib's picture

Re: Code to upload first?

I have started to get the following error while uploading the sketches:

Found programmer: Id = ""; type =

          Software Version =   .; Hardware Version = .a

avrdude: error: buffered memory access not supported. Maybe it isn't
a butterfly/AVR109 but a AVR910 device?

 

Can someone help?

truzzman's picture

Re: Code to upload first?

I'm a real dummy....

I try ti set some print.serial line to show also apparent power Irms and power factor but I am unable to have some code that works.

Could you write the exact code? thanks

I use emontx 3 and "emonTxV3_RFM12B_DiscreteSampling.ino"

Robert Wall's picture

Re: Code to upload first?

Yes, I could. But instead I will tell you how to find what you want to print.

Look at your sketch. How is Real Power printed? It comes from ct1.RealPower

So what is ct1? It's an instance of the class EnergyMonitor. What's that? Just above where you find the definition of ct1, you see "#include "EmonLib.h"" Find that file. That's where the class EnergyMonitor is declared. Look down it and you'll see a list of names that are "public". Amongst them you'll find realPower, plus the ones that you are looking for.

Now does that tell you what you need to do to print apparentPower and powerFactor? - It should do.
For ct1, the variables you want are ct1.apparentPower and ct1.powerFactor.

truzzman's picture

Re: Code to upload first?

Thanks, some work (after a night of study) and this code seems to work:

 if (debug==1) {
      
      Serial.print("CT1 REAL POWER= ");
      Serial.print(ct1.realPower);
      Serial.print(" ");  
      Serial.print("CT1 APPARENT POWER= ");
      Serial.print(ct1.apparentPower);
      Serial.println(" ");
      Serial.print("CT1 Power Factor= ");
      Serial.print(ct1.powerFactor);
      Serial.println(" ");
      Serial.print("Irms CT1= ");
      Serial.print(ct1.Irms);
      Serial.print(" ");
      Serial.println(" ");

 

Robert Wall's picture

Re: Code to upload first?

That's all correct. Learning is always hard work, I hope it was worth the effort. Now you understand a little about object oriented programming and how classes work.

Comment viewing options

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