Bien, estoy mirando ejemplos de la libreria Emonlib, al parecer la entrada de la señal que quiero controlar, tienen que ser directa en una de las entradas analogicas del arduino.
alguien ha conseguido usar la libreria con un ADS1115 que usa protocolo i2c.?
He visto que hay que cambiar algo en la libreria Emonlib, pero parece que no termina de resultar.
Por ejemplo en esta pagina.
Ok, entonces si quisiera usar solo 1 ADS1115, podría usar su código como stock, que es este:
// In this example we will use an ADS1115 breakout board instead of the Arduino's local analog inputs
// This is especially useful for nodemcu/esp8266 users who only have a single analog input
#include <Wire.h>
#include <Adafruit_ADS1015.h>
// EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3
#include <EmonLib_I2C.h> // Include Emon Library
EnergyMonitor emon1; // Create an instance
Adafruit_ADS1115 ads; // Create an instance of the ADS1115 object
// Make a callback method for reading the pin value from the ADS instance
int ads1115PinReader(int _pin){
return ads.readADC_SingleEnded(_pin);
}
void setup()
{
emon1.inputPinReader = ads1115PinReader; // Replace the default pin reader with the customized ads pin reader
emon1.current(1, 111.1); // Current: input pin, calibration.
}
void loop()
{
double Irms = emon1.calcIrms(1480); // Calculate Irms only
Serial.print(Irms*230.0); // Apparent power
Serial.print(" ");
Serial.println(Irms); // Irms
}
Esto se compila muy bien. Aunque estoy un poco confundido en cuanto a cómo seleccionar el "pin" del ADS.
En emonlib.cpp agregó este código:
//--------------------------------------------------------------------------------------
// Constructor. Set the pinReader to the default pin reader method
//--------------------------------------------------------------------------------------
EnergyMonitor::EnergyMonitor()
{
this->inputPinReader = defaultInputPinReader;
}
//--------------------------------------------------------------------------------------
// By default we just call Arduino's analogRead
//--------------------------------------------------------------------------------------
int EnergyMonitor::defaultInputPinReader(int _pin)
{
return analogRead(_pin);
}
Y cambió esto:
startV = analogRead(inPinV);
para:
startV = (this->inputPinReader)(inPinV);
y algunos otros puntos donde hizo el ajuste usando "this->". Y en emonlib.h agregó esto a la sección Pública:
EnergyMonitor();
typedef int (*inputPinReaderMethod) (int _pin);
inputPinReaderMethod inputPinReader;
static int defaultInputPinReader(int _pin);
alguien lo ha intentado y ha tenido exito, gracias