Emonlib variable instead analog pin

Hello,

 

I'm doing an energy monitor with Arduino, a pair of Ciseco RF modules and SCT013-030.

So, the SCT goes in the analog pin of one RF Module and the Arduino gets this value by the other RF module by serial connection. So i have the analog value in a variable.

How can I use this variable instead of the analog input pin in emonlib?

 

Example: The default is something like:

 emon1.current(0, 30);     // Current: input pin, calibration.

I need:

emon1.current(value, 30);     // Current: variable, calibration.

 

thanks

Robert Wall's picture

Re: Emonlib variable instead analog pin

You can't do what you are suggesting. In principle, you will need to rewrite the library method that you want to use - instead of reading the analogue input, you use your variable.

So, for example, sampleV = analogRead(inPinV);  becomes  sampleV = VariableByRadio;

To keep (your version of) the library general and reusable, it would be best to pass in a pointer to the value. 

That will probably only work if the radio output is a continuous analogue signal, which you infer is not the case. If it is discrete samples, you have a jitter and timing problem as the sample rate will be governed by the transmitter; therefore you will need to work out a method of synchronising the main calculation loop to the incoming samples. If you can't do that, you may find you need to use the arrival of a value as an interrupt, with the ISR doing the accumulation part of the maths and the main loop handling the per cycle averaging and scaling - like the example sketches that use interrupts.

Of course, you'll need to work out what the calibration will be, and you'll need to check that you can sample the wave often enough. Bear in mind there are restrictions in the license for the proportion of the time that the radio is allowed to transmit, which varies according to the frequency band that you are using, in the UK the channel occupancy is limited to 10% at 433 MHz, 1% at 868 MHz.

Comment viewing options

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