Understanding the EmonLib sampling rate

Hello everybody,

I have installed this simple monitor in my house on an arduino uno.

I am right now trying to experiment with the sampling rates.

I could see on this topic and in others that I am supposed to take around 500 samples during the default 10 cycles, however if I print them inside the Emonlib.cpp, I can see only 35 of them during the 10 cycles of voltage.

 

Code is here:

    sampleV = analogRead(inPinV);                 //Read in raw voltage signal
    sampleI = analogRead(inPinI);                 //Read in raw current signal
    Serial.print(millis());
    Serial.print(",");
    Serial.print(sampleV);
    Serial.print(",");
    Serial.println(sampleI);
 (...)
   realPower = V_RATIO * I_RATIO * sumP / numberOfSamples;
   apparentPower = Vrms * Irms;
   powerFactor=realPower / apparentPower;
   Serial.println("yo");

 

And I get this :

27890,486,492
27933,847,515
27981,380,502
28027,218,483
28075,877,524
28120,489,498
28167,168,473
28213,848,502
28260,555,510
28306,120,467
28353,792,510
28399,567,510
28446,120,464
28492,731,505
28537,791,519
28583,160,485
28631,525,493
28677,842,528
28724,167,484
28771,509,491
28817,820,524
28864,136,481
28910,500,492
28966,143,470
29014,816,512
29073,777,509
29120,526,509
29193,722,504
29238,780,517
29285,123,479
29331,553,495
29387,166,473
29434,827,50
yo

 

So what I really don't know is how I can see these 500 samples - just for checking not forever. I know that by printing them I cause a delay but getting only around 35 samples is too much, no?

 

Thanks everyone in advance :D

Robert Wall's picture

Re: Understanding the EmonLib sampling rate

Printing from within the loop will create a huge delay, and that will slow the loop greatly, as you have found. First, what is your mains frequency? If you are on a 60 Hz system, you should get around 44 sample pairs per cycle. The way to check how many samples you are getting is to start the timer before you enter the loop to read the 500 samples, then read it again after exiting the loop. Anything you add inside the loop will slow the sample rate. Even saving the values in an array, whilst a lot faster than printing, will slow the loop.

ioannamirto's picture

Re: Understanding the EmonLib sampling rate

I'm on a 50 Hz system. Ok I read it before and after

33856,34068
34336,34548
34796,35008
35257,35468
35717,35928

and we can see its almost 20ms*10 cycles.

Then i made it count how many samples it takes and here it is

81948,82159,556
82448,82668,555
83027,83239,554
83497,83708,555
83968,84178,554
84457,84669,555
84927,85138,555

:)

yeih thanks a lot I couldn't imagine that much of a delay for printing.

Robert Wall's picture

Re: Understanding the EmonLib sampling rate

If you think about it - printing at 9600 bits/s - how many characters, how many bits....

Comment viewing options

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