I am interest in I2C devices, so I Hope you don’t mind my feedback even if I don’t directly answer the question “Where is the I2C LCD program”.
I used EmonPi for an ADE9000 using SPI MISO, MOSI, SCK, CS and IRQ1. SPI is similar to I2C.
In summary, what I did was:
- enable SPI on the RPI, or in your case I2C.
- Write the code to read the SPI data.
- Put it in the proper format for the EmonPI, or should I say EmonCMS to read.
Following is my C++ code to read SPI. I excluded spiComm.h, and spiComm.cpp files to keep it brief. If needed, let me know and I will post.
There is also influx & grafana for this, but Emoncms contains more features and more detailed analysis tools.
#include "spiComm.h"
#include <unistd.h>
#include <stdint.h>
#include <iostream>
#include <string>
using namespace std;
unsigned long interval = 50;
unsigned long dccount = 1;
char postcmd[1024];
//char postcmd[256];
int main() {
spiComm commObj;
double avrmsaccum, airmsaccum, awattaccum, avaaccum, apfaccum, bvrmsaccum, birmsaccum;
double bwattaccum, bvaaccum, bpfaccum;
string result;
cout << "Start Data\n";
avrmsaccum = 0;
airmsaccum = 0;
awattaccum = 0;
avaaccum = 0;
apfaccum = 0;
bvrmsaccum = 0;
birmsaccum = 0;
bwattaccum = 0;
bvaaccum = 0;
bpfaccum = 0;
while(1) {
avrmsaccum += commObj.readVoltage(R_AVRMS_REGISTER);
airmsaccum += commObj.readCurrent(R_AIRMS_REGISTER);
awattaccum += commObj.readPower(R_AWATT_REGISTER);
avaaccum += commObj.readEnergy(R_AVA_REGISTER);
apfaccum += commObj.readPowerFactor(R_APF_REGISTER);
bvrmsaccum += commObj.readVoltage(R_BVRMS_REGISTER);
birmsaccum += commObj.readCurrent(R_BIRMS_REGISTER);
bwattaccum += commObj.readPower(R_BWATT_REGISTER);
bvaaccum += commObj.readEnergy(R_BVA_REGISTER);
bpfaccum += commObj.readPowerFactor(R_BPF_REGISTER);
if(dccount >= interval)
{
double avrms, airms, awatt, avarms, apfrms, bvrms, birms, bwatt, bvarms, bpfrms, abwatt, abirms, abvrms;
avrms = avrmsaccum/dccount;
airms = airmsaccum/dccount;
awatt = awattaccum/dccount;
avarms = avaaccum/dccount;
apfrms = apfaccum/dccount;
bvrms = bvrmsaccum/dccount;
birms = birmsaccum/dccount;
bwatt = bwattaccum/dccount;
bvarms = bvaaccum/dccount;
bpfrms = bpfaccum/dccount;
abwatt = (awattaccum + bwattaccum)/dccount;
abirms = (airmsaccum + birmsaccum)/dccount;
abvrms = ((avrmsaccum + bvrmsaccum)/2)/dccount;
printf("avrms: %.2f\n", (avrms));
printf("airms: %.2f\n", (airms));
printf("awatt: %.2f\n", (awatt));
printf("ava %.2f\n", (avarms));
printf("apf %.2f\n", (apfrms));
printf("bvrms: %.2f\n", (bvrms));
printf("birms: %.2f\n", (birms));
printf("bwatt: %.2f\n", (bwatt));
printf("bva %.2f\n", (bvarms));
printf("bpf %.2f\n", (bpfrms));
printf("bpf %.2f\n", (abwatt));
printf("Number of Samples Averaged: %ld\n", dccount);
snprintf( postcmd, 1024, "/usr/bin/curl --data \"node=13&data={L1V:%.2f,L1A:%.2f,L1W:%.2f,L1VA:%.2f,L1pf:%.2f,L2V:%.2f,L2A:%.2f,L2W:%.2f,L2VA:%.2f,L2pf:%.2f,L12W:%.2f,L12A:%.2f,L12V:%.2f,L12W2:%.2f}&apikey=6bd2aa3ad1970a8fafafb9c32d26838e\" \"http://192.168.1.77/emoncms/input/post\"", avrms, airms, awatt, avarms, apfrms, bvrms, birms, bwatt, bvarms, bpfrms, abwatt, abirms, abvrms, abwatt );
system(postcmd);
dccount = 0;
avrmsaccum = 0;
airmsaccum = 0;
awattaccum = 0;
avaaccum = 0;
apfaccum = 0;
bvrmsaccum = 0;
birmsaccum = 0;
bwattaccum = 0;
bvaaccum = 0;
bpfaccum = 0;
}
dccount++;
//sleep(5);
usleep(250000);
//usleep(40000);
//sleep(1);
}
}