Adding an LCD to emonlib

i want to add an lcd to my emon project but get this error on compile

'class Energy Monitor' has no member named 'lcdprint'

Using programmers notepad i modified the cpp and h files.

emonlib.h was modified to 

class EnergyMonitor

    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);// added code segment
    double calcIrms(int NUMBER_OF_SAMPLES);
void lcdprint();

    long readVcc();
    //Useful value variables
    double realPower,


emonlib.cpp was modified with these additions;

In the header...#include <LiquidCrystal.h>

and in the body...i converted watts to KW as below and confined the number of decimal places as shown eg as either one(realpower/1000,1) or none (Irms,0) or two (powerFactor,2)

void EnergyMonitor::lcdprint()

//LCD Output
lcd.print(" KVA");

lcd.print(" I");
lcd.print(" PF");


The sketch was modified with the addition - in the loop;

emon1.calcVI(20,2000); //print to LCD


Still getting the error on compile - can anyone offer a 

fix to add an lcd

Many thanks.

Robert Wall's picture

Re: Adding an LCD to emonlib

I don't understand your problem. The emonlib library is only intended for the emonTx. Are you trying to add an LCD to the emonTx? I think you might struggle to add a display as there won't be enough processor power to do anything.

platypus's picture

Re: Adding an LCD to emonlib

Not sure what happened there - my reply cant be seen so here goes again.

Yes I want to use an LCD to display data as this makes this device portable with the benefit of real time data updates.

I would like to access the calculated data variables for further processing.

I feel that the 328 should manage the processing - the added lcd code segment is just not recognized.

Just my limited understanding of the program which is causing this compiler error.

09540's picture

Re: Adding an LCD to emonlib

You have to initialize the LCD library by putting this somewhere before void setup();

LiquidCrystal lcd(6, 7, 0, 1, 2, 4); // RS, Enable, D0, D1, D2, D3

...replacing the numbers in parenthesis with the pins on your processor that connect to the corresponding data lines in the comment. (This is for 4 bit mode, for 8 bit mode, include all 10 pin numbers.)

platypus's picture

Re: Adding an LCD to emonlib

Thanks Fronius but all sorted out.


Aoun_46271's picture

Re: Adding an LCD to emonlib

'((EnergyMonitor*)this)->EnergyMonitor::lcd' does not have class type

I was trying to display the calculated values on LCD but came across the above problem. Do you have any idea how to remove this sort of error or kindly explain the method for displaying the values of EmonLib on LCD. I have made the changes in emonilb.h and cpp files as mentioned you. Kindly help me out it would be so nice of you.

coldpenguin's picture

Re: Adding an LCD to emonlib

I don't think you need to be casting like the code above.
The problem would appear (unless you have modified the .h since it was posted), that you haven't defined the member lcd, unless you are using it as a global variable as 09540 suggests. In addition, your error at the beginning would suggest you are referencing your new function as a member instead of a function (which I would have expected an undefined reference error, if it was a linker problem).
I think that you have made other changes above the ones that you have posted, and it would be impossible to debug further without complete details.

Comment viewing options

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