CT Example

This commit is contained in:
Siwat Sirichai 2024-02-10 16:29:40 +07:00
parent 8244ad1c8a
commit 6c418115ec
1 changed files with 32 additions and 0 deletions

View File

@ -4,6 +4,8 @@
#include <ClimateCard.hpp>
#include <ESPMegaDisplayOTA.hpp>
#include <RemoteVariable.hpp>
#include <CurrentTransformer.hpp>
#include <AnalogCard.hpp>
// #define FRAM_DEBUG
// #define MQTT_DEBUG
@ -14,6 +16,7 @@
#define WEB_SERVER_ENABLE
#define LCD_OTA_ENABLE
#define REMOTE_VARIABLE_ENABLE
#define CT_ENABLE
// Demo PLC firmware using the ESPMegaPRO OOP library
@ -28,6 +31,16 @@ RemoteVariable testVar = RemoteVariable();
ESPMegaDisplayOTA internalDisplayOTA = ESPMegaDisplayOTA();
#endif
#ifdef CT_ENABLE
float adc2current(uint16_t adcValue)
{
return (adcValue - 2048) * 0.0005;
}
AnalogCard analogCard = AnalogCard();
float voltage = 220.0;
CurrentTransformer ct = CurrentTransformer(&analogCard, 0, &voltage, adc2current, 1000);
#endif
#ifdef CLIMATE_CARD_ENABLE
// Climate Card
const char *mode_names[] = {"off", "fan_only", "cool"};
@ -202,6 +215,15 @@ void setup()
ESP_LOGI("Initializer", "Initializing testvar");
testVar.begin(32, "/testvar", espmega.iot, true,"/testvar/request");
testVar.enableSetValue("/testvar/set");
#endif
#ifdef CT_ENABLE
ESP_LOGI("Initializer", "Initializing analog card");
analogCard.begin();
ESP_LOGI("Initializer", "Initializing current transformer");
ct.begin();
ct.bindFRAM(&espmega.fram, 7000);
ct.loadEnergy();
ct.setEnergyAutoSave(true);
#endif
ESP_LOGI("Initializer", "Setup complete");
}
@ -249,4 +271,14 @@ void loop()
testVar.setValue("Hello World");
}
#endif
#ifdef CT_ENABLE
ct.loop();
static uint32_t last_ct_print = 0;
if (millis() - last_ct_print >= 1000)
{
last_ct_print = millis();
Serial.print("Current: ");
Serial.println(ct.getCurrent());
}
#endif
}