seems o work on CT3 and not CT1

Hi I use this code

#include "EmonLib.h"                   // Include Emon Library
#include "JeeLib.h"
EnergyMonitor ct1;                     // Create an instance

void setup()


  ct1.currentTX(1, 111.1);             // CT channel, calibration

void loop()
  double Irms = ct1.calcIrms(1480);    // Calculate RMS current (1480: no. of samples)
  Serial.print(Irms*240.0);           // Print to serial apparent power
  Serial.print(" ");
  Serial.println(Irms);               // Print to serial Irms


But I receive values look like true when I connect on CT3.  But in the code normaly I used CT1.  It run on leonardo, not yet with ethernetshield.


Any ideas?



Robert Wall's picture

Re: seems o work on CT3 and not CT1

The library EmonLib.cpp contains the conversion from channel to pin number, which is correct only for the emonTx hardware:

   if (_channel == 1) inPinI = 3;
   if (_channel == 2) inPinI = 0;
   if (_channel == 3) inPinI = 1;

If you are using different I/O pins, it will not work. You must use the same I/O pins, or change your library.'s picture

Re: seems o work on CT3 and not CT1

Thanks for your answer, I find on EmonLib.cpp the conversion.  So correct me if I am wrong.  Like it s show on Port Map, I use CT1 ADC1.  With this information, I have to change cpp like this if (_channel ==1) inPinI=1;



Port Map

Function Arduino Port
9V AC sample ADC0
CT 1-4 ADC 1-4
DS18B20 Temperature Dig4
LED Dig9
RFM12B SS Dig10 (recommended) / Dig5
RFM12B INT Dig3 Leonardo / Dig2 Uno


Robert Wall's picture

Re: seems o work on CT3 and not CT1

If you have connected CT1 to ADC1, then yes. Only you know how you have wired it ;-)

Comment viewing options

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