I am trying to use emonlib used in Arduino in esp32 ttgo oled v1

Hello, I measured power on Arduino and tried to measure it using the same method on esp32 ttgo oled v1, but the measurement did not work. Maybe emon1.current(0,111.1); I have a question as I wonder if this is an adjustment issue. If anyone knows something, please help :slight_smile: The code is below.

#include "EmonLib.h"
EnergyMonitor emon1;


double Total = 0;
int count = 0;
double TotalPower = 0;
unsigned long t1 = 0;

void setup() {
  Serial.begin(115200);
  emon1.current(0,111.1);

  
 /* for (int i = 0; i <25; i++) {
    double IrmsNock = emon1.calcIrms(1480);       
      if (i >10) {
      Total += IrmsNock;
      count++;
    }
  }
*/
  /*Total /= count;
  Serial.print("평균 IrmsNock: ");        // 0.19
  Serial.println(Total);                                              

  t1 = millis();
  */
}

void loop() {
  unsigned long t2 = millis();
  int nocktime = t2 - t1;
  t1 = t2;

  double Irms = emon1.calcIrms(1480);//- Total;    
    /*
    if(Irms < 0.04)                    
    Irms = 0 ;
     */
       


  double power = Irms * 220.0;                 
  TotalPower += power * nocktime / 3600.0;

  Serial.print(nocktime);
  Serial.print(Irms, 4);
  Serial.print(power, 4);
  Serial.print(TotalPower / 1000, 4);
  Serial.println(" (W)");
  delay(1000);
  //Serial.println("{\"time\":\""+ String(nocktime)+"\",\"I\":\""+String(Irms,4)+"\",\"W\":\""+String(power,4)+"\",\"WH\":\""+String(TotalPower/1000,4)+"\"}");
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.