Added INA233
Some checks failed
Test compiling project / test (push) Failing after 1m39s

This commit is contained in:
2024-07-28 17:45:49 +02:00
parent ce08e4c211
commit 1d19e23df6
5 changed files with 134 additions and 11 deletions

View File

@@ -13,6 +13,7 @@
#include "INA226.h"
#include "Wire.h"
#include "INA233.h"
#include <Preferences.h>
@@ -83,13 +84,14 @@ WaterData water_data;
int64_t mac_address = ESP.getEfuseMac();
//#define INA226
// #ifdef INA226
//#define USE_INA226
#ifdef USE_INA226
INA226 ina_sensor(0x40);
// #else
// INA233 ina_sensor();
// #endif
#else
INA233 ina_sensor(0x40);
#endif
Preferences prefs;
@@ -173,6 +175,7 @@ void display_task(void* parameter)
if (!is_error()) {
// We have no error, refresh status display and wait half a second
display_percentage(water_data.percentage);
delay(1000);
} else {
Log.verbose("Error detected");
// We have an error, display error code for 3 seconds and then water level for 3 seconds
@@ -210,7 +213,7 @@ void wifi_task(void* parameter)
String old_ssid = prefs.getString(ssid_key, "xxx");
while (prefs.getString(ssid_key, "") == "" || prefs.getString(ssid_key, "") == old_ssid) {
delay(1000);
delay(5000);
}
failed_connection_attempts = 0;
@@ -264,8 +267,10 @@ void read_sensor_task(void* parameter)
{
while (true) {
// Get Values from sensor
float bus_voltage = ina_sensor.getBusVoltage();
float shunt_voltage = ina_sensor.getShuntVoltage_mV() - zero_value;
float shunt_current = shunt_voltage / RESISTOR_VALUE;
// Get values from storage
@@ -348,10 +353,19 @@ void setup()
Log.verbose("Begin INA");
ina_sensor.begin(33, 32);
display_error_code(20);
ina_sensor.setMaxCurrentShunt(0.02, 4, false);
ina_sensor.setBusVoltageConversionTime(7);
ina_sensor.setShuntVoltageConversionTime(7);
ina_sensor.setAverage(4);
#ifdef USE_INA226
ina_sensor.setMaxCurrentShunt(0.02, 4, false);
ina_sensor.setBusVoltageConversionTime(7);
ina_sensor.setShuntVoltageConversionTime(7);
ina_sensor.setAverage(4);
#else
//ina_sensor.setMaxCurrentShunt(0.02, 4, false);
//ina_sensor.setBusVoltageConversionTime(7);
//ina_sensor.setShuntVoltageConversionTime(7);
//ina_sensor.setAverage(4);
#endif
display_error_code(21);
display_error_code(22);