"EmonLib.h" - reading SCT on mega 2560

Hello!

I'm working on my project with use 9 x SCT 013-030 and 3 x AC/AC three phase on arduino mega 2560 with EmonLib.h library, but only eight analog inputs working.

Power and all working OK but only in pin A0-A7 in arduino mega 2560. I check a lot off forums but noting with same problem,... 

I check analog port and are OK.

Anyone already use analog input (8,9,10, 11, ..) with EmonLib.h is any limitation on EmonLib.h or is a problem with Mega 2560.

thanks for any suggestion.

Alex

     

 

Robert Wall's picture

Re: "EmonLib.h" - reading SCT on mega 2560

Do you have available the correct version of  the standard header file  pins_arduino.h  in .....\hardware\arduino\variants\mega

Different methods in emonLib handle the input ports differently. "Channel" to the number on the emonTx printed circuit, which is not the same as the Arduino input number. The translation is done when the class instance is initialised, with

EnergyMonitor::currentTX(int _channel, double _ICAL)

whereas

EnergyMonitor::voltage(int _inPinV, double _VCAL, double _PHASECAL)

EnergyMonitor::current(int _inPinI, double _ICAL)

both use the Arduino input pin. Therefore, if you use the first, you must extend you copy of currentTX( ) to have the mapping for the inputs for the Mega2560. If you use voltage( ) or current( ), you should be able to use the input pin with no changes.

Then you can use EnergyMonitor::calcVI(int wavelengths, int timeout) or EnergyMonitor::calcIrms(int NUMBER_OF_SAMPLES) as normal.

You should be able to define the pins as "A0" - "A15"  If you cannot, I think there is a problem with pins_arduino.h

alesz's picture

Re: "EmonLib.h" - reading SCT on mega 2560

thank you very much for quick response.

....\hardware\arduino\variants\mega - $Id: wiring.h 249 2007-02-03 16:52:51Z mellis $ : not found any newer on net

 

Could you explain where need  I define  A0- A15 in EmonLib.h or in main program ? , because I a little confuse and not sure if I understand you correctly.

Do I need define A0.. A11 in main program?

 

Strange is that A0, A1, A2 - Voltage, A3, A4, A5, A6, A7, A8 - SCT OK,  A9, A10 A11 -only zero

 

thank  you 

// Sets the pins to be used for voltage and current sensors
//--------------------------------------------------------------------------------------
void EnergyMonitor::voltage(int _inPinV, double _VCAL, double _PHASECAL)
{
   inPinV = _inPinV;
   VCAL = _VCAL;
   PHASECAL = _PHASECAL;
}
void EnergyMonitor::current(int _inPinI, double _ICAL)
{
   inPinI = _inPinI;
   ICAL = _ICAL;
}
//--------------------------------------------------------------------------------------
// Sets the pins to be used for voltage and current sensors based on emontx pin map
//--------------------------------------------------------------------------------------
void EnergyMonitor::voltageTX(double _VCAL, double _PHASECAL)
{
   inPinV = 2;
   VCAL = _VCAL;
   PHASECAL = _PHASECAL;
}
void EnergyMonitor::currentTX(int _channel, double _ICAL)
{
   if (_channel == 1) inPinI = 3;
   if (_channel == 2) inPinI = 0;
   if (_channel == 3) inPinI = 1;
   ICAL = _ICAL;
}
//--------------------------------------------------------------------------------------
// emon_calc procedureis only  
Robert Wall's picture

Re: "EmonLib.h" - reading SCT on mega 2560

You should not have to define these. The header file that defines them should have been picked up by the Arduino IDE automatically. Do you have the correct Board specified?

If you have, you should be able to use the names "A9" etc in your sketch, e.g. current(A9, 111.1)

If you do that and the compiler complains, then that probably indicates that the correct header file is not being found.

 

Comment viewing options

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