Hi, I'll try to be brief; I'm a noob but 2.0; -Been testing and coding 'couple of weeks now. I've managed to isolate some issues, and solved the calibration problems on ADC-ESP32 Wroom.
I had already combined code, from a page and from blynk, to make this work and send to the cloud and the blynk app. It works, not working when combined, and I totally suspect it's a code -location- issue. Or an extra/ or missing float line, or 'int' code (yes I've tried many combiations, comm out, etc.). So;
-I've moved the volt-specific code to just below the "#include" section, and also below the 'ACS712' section/.
-Can get amperage, current data with the most recent code uploaded, but not voltage.
-Can get serial feebdack from each sensor when the code is separated for each, and now have them calibrated to maybe 5%. (posting screenshots). Solved by changing the source volt level in the code, and using one ground line per sensor.
-Not getting any erros on loading the code.
-Sensors are the simple Volt divider >25v, and the ACS712, using the library from GitHub - RobTillaart/ACS712: Arduino library for ACS Current Sensor - 5A, 20A, 30A
-I tested disconnecting the ESP from USB and the sensors from source power, then reconnecting. That seemed to work when testing the ACS712 alone.
-I've changed the location several times, of the section "define SIGNAL_PIN 27" and its 7 lines, but not the lines inside 'void loop'
Apreciate any feedback!, including to go read more foum posts... I'm killing plants just reading for weeks. Thanks!
#define BLYNK_TEMPLATE_ID "TMP....."
#define BLYNK_DEVICE_NAME "test ..."
#define BLYNK_AUTH_TOKEN "RU....."
#define BLYNK_PRINT Serial
//code mixing test v1,2.27 print this to LCD
#define SIGNAL_PIN 27 //esp32 pin input analog syntax?
float adc_voltage = 0.0;
float in_voltage = 0.0;
float R1 = 30000.0;
float R2 = 7500.0;
float ref_voltage = 3.6; //power source, chg to calibrate if divider not <1v
int adc_value = 0;
// float input_voltage = 0; // test this outside void loop, there's another instance line 82
#include <ACS712.h>
#include <Blynk.h>
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
#include <LiquidCrystal_I2C.h>
ACS712 ACS(34, 3.1, 4095, 100);
LiquidCrystal_I2C lcd(0x27, 16, 2);
BlynkTimer timer;
char auth[] = "RU.....; //might be repeated
char ssid[] = "t.....";
char pass[] = "I.....";
unsigned long lastmillis = millis(); //changed loc. from line 26
void myTimerEvent() { // what does this do and del'd a '}' broke the void s.
}
void setup() {
Serial.begin(115200);
ACS.autoMidPoint();
int sensorVal; //right location? -edit to make Voltsensor work.
Blynk.begin(auth, ssid, pass);
timer.setInterval(5000L, myTimerEvent);
lcd.begin(16, 2);
lcd.init();
lcd.backlight();
lcd.setCursor(3, 0);
lcd.print("Barbosa Worlds");
lcd.setCursor(0, 1);
lcd.print("Solar to Cloud");
delay(1500);
lcd.clear(); //review if necess
}
void loop() {
// adc_value = analogRead(27); //changed
adc_value = analogRead(SIGNAL_PIN);
adc_voltage = (adc_value * ref_voltage) / 4096.0; //esp32 resolution is 4096
in_voltage = adc_voltage / (R2 / (R1 + R2));
Serial.print("BattVolts = ");
Serial.println(in_voltage, 2);
{
int mA = ACS.mA_DC();
Serial.print("mA: ");
Serial.println(mA);
if (Serial.available() > 0) // needs a ; ?
{
char c = Serial.read();
if (c == '+') ACS.incMidPoint();
if (c == '-') ACS.decMidPoint();
if (c == '0') ACS.setMidPoint(512);
Serial.println(ACS.getMidPoint());
if (c == '*') ACS.setmVperAmp(ACS.getmVperAmp() * 1.05);
if (c == '/') ACS.setmVperAmp(ACS.getmVperAmp() / 1.05);
Serial.println(ACS.getmVperAmp());
}
delay(1000);
float input_voltage = 0; // test this!! location?
lcd.begin(16, 2);
lcd.init();
//lcd.clear(); test this
lcd.setCursor(0, 0); //added these two up
lcd.print("BV=");
lcd.print(in_voltage, 2);
// NOW EDITING SERIAL, LCD FOR ACS AMPS
lcd.setCursor(9, 0);
lcd.print(mA);
lcd.print(" mAmp");
lcd.setCursor(0, 1); //2nd line lcd ident code v.
lcd.print("Code mix1, V2.27");
Blynk.run();
timer.run();
}
}