Using an LCD instead of Serial Monitor with emontx Energy Monitor

Compiler error
By trying to use an lcd instead of the serial monitor i am getting a compiler error

  • ’class energymonitor’ has no member named 'lcdprint’

I have posted this issue on the openergymonitor.org forum with a reply that the moderator ‘did not understand the problem’ and that the 328 may not have enough processing power.

Background of the project
I built the energy monitor using the openenergymonitor.org files “Measuring an AC voltage using an AC-AC power adapter” and “CT sensors - interfacing with an arduino”

The project works beyond expectations - data displays on the serial monitor and is quite accurate for Real Power, Apparent Power, Voltage, Current and Power Factor.

I ran into the compiler error(above) when trying to change to using an LCD instead of the serial monitor.

Using programmers notepad I modified the emonlib.cpp and emonlib.h files adding the lcdprint code.

This is the modified emonlib.h file with the lcd code in bold.

/*
Emon.h - Library for openenergymonitor
Created by Trystan Lea, April 27 2010
GNU GPL
*/

#ifndef EmonLib_h
#define EmonLib_h

#if defined(ARDUINO) && ARDUINO >= 100

#include “Arduino.h”

#else

#include “WProgram.h”

#endif

class EnergyMonitor
{
public:

void voltage(int _inPinV, double _VCAL, double _PHASECAL);
void current(int _inPinI, double _ICAL);

void voltageTX(double _VCAL, double _PHASECAL);
void currentTX(int _channel, double _ICAL);

//void calcVI(int wavelengths, int timeout);
//double calcIrms(int NUMBER_OF_SAMPLES);
//void serialprint();

void calcVI(int wavelengths, int timeout);
** double calcIrms(int NUMBER_OF_SAMPLES);**
** void lcdprint();**

long readVcc();
//Useful value variables
double realPower,
apparentPower,
powerFactor,
Vrms,
Irms;

Here is the modified emonlib.cpp file

The header part…
/*
Emon.cpp - Library for openenergymonitor
Created by Trystan Lea, April 27 2010
GNU GPL
*/

//#include “WProgram.h” un-comment for use on older versions of Arduino IDE
#include “EmonLib.h”

#if defined(ARDUINO) && ARDUINO >= 100

#include “Arduino.h”

#include <LiquidCrystal.h>

#else

#include “WProgram.h”

#endif

LiquidCrystal lcd(8,9,4,5,6,7);

and
The output part at the bottom of the file, with the lcd code segment in bold

/*
void EnergyMonitor::serialprint()
{
Serial.print(realPower);
Serial.print(’ ‘);
Serial.print(apparentPower);
Serial.print(’ ‘);
Serial.print(Vrms);
Serial.print(’ ‘);
Serial.print(Irms);
Serial.print(’ ‘);
Serial.print(powerFactor);
Serial.println(’ ');
delay(100);
}

*/

void EnergyMonitor::lcdprint()
{

** //LCD Output**
** lcd.setCursor(0,0);**
** lcd.print(“KW”);**
** lcd.print(realpower/1000,1);**
** lcd.print(" KVA");**
** lcd.print(apparentPower/1000,1);**

** lcd.setCursor(0,1);**
** lcd.print(“V”);**
** lcd.print(Vrms,0);**
** lcd.print(" I");**
** lcd.print(Irms,0);**
** lcd.print(" PF");**
** lcd.println(powerFactor,2);**
** delay(100);**
}

long EnergyMonitor::readVcc() {
long result;
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
delay(2);
ADCSRA |= _BV(ADSC);
while (bit_is_set(ADCSRA,ADSC));
result = ADCL;
result |= ADCH<<8;
result = 1126400L / result;
return result;
}

The modified sketch

// EmonLibrary examples openenergymonitor.org, Licence GNU GPL V3

#include “EmonLib.h” // Include Emon Library

#include <LiquidCrystal.h>

EnergyMonitor emon1; // Create an instance

LiquidCrystal lcd(8,9,4,5,6,7);

/*
double realPower;
double apparentPower;
double Vrms;
double Irms;
double powerFactor;
*/
void setup()
{
lcd.begin(16,2);
Serial.begin(9600);

emon1.voltage(5, 430, 0); // Voltage: input pin, calibration, phase_shift
emon1.current(1, 990); // Current: input pin, calibration.
}

void loop()
{
/*
emon1.calcVI(20,2000); // Calculate all. No.of wavelengths, time-out
emon1.serialprint(); // Print out all variables
*/
emon1.calcVI(20,2000); //print to LCD
emon1.lcdprint();
delay(1000);

}

Hi, first of all, edit your post and put all the code organized by click on “#” (Insert Code).
So, what’s the LCD you are using for this project ? What arduino compiler version you’re using ?
You have to make sure if all the energy monitor library is full compatible with Arduino IDE and also the LCD library!