hi I'm doing a school project where i use a Solar Panel that send data to an ESP8266 using INA219 and F031-06 Voltage Sensor; then everything get sent to an database.
the problem is that ESP can't find the INA.
Can someone help me?
thanks.
I' ve used this image as an example:
in LOAD i used a led;
instead of using arduino I've used ESP8266;
instead of using INA169 I've used INA219.
HERE'S THE CODE
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <Wire.h>
#include <Adafruit_INA219.h>
Adafruit_INA219 ina219;
#define LED_RED 5
int contatore = 0;
const char* ssid = "zubir's_wify";
const char* password = "zubir567891011";
const char* web_server = "192.168.115.105";
String postData = "";
String payload = "";
String send_Status_Read_INA219 = "";
float shuntvoltage = 0;
float busvoltage = 0;
float current_mA = 0;
float loadvoltage = 0;
float power_mW = 0;
void setup() {
pinMode(LED_RED, OUTPUT);
digitalWrite(LED_RED, HIGH);
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println();
Serial.println("--------");
Serial.print("Connecting");
int connecting_process_timed_out = 20;
while (WiFi.status() != WL_CONNECTED && connecting_process_timed_out > 0) {
Serial.print(".");
digitalWrite(LED_RED, HIGH);
delay(500);
digitalWrite(LED_RED, LOW);
delay(500);
connecting_process_timed_out--;
}
if (connecting_process_timed_out == 0) {
ESP.restart();
}
digitalWrite(LED_RED, HIGH);
Serial.println();
Serial.print("Successfully connected to: ");
Serial.println(ssid);
Serial.println("--------");
if (!ina219.begin()) {
Serial.println("Failed to find INA219 chip");
while (1) { delay(10); }
} else {
Serial.println("INA219 sensor initialized");
}
ina219.setCalibration_32V_2A();
}
void loop() {
WiFiClient Client;
HTTPClient http;
int httpCode;
contatore = contatore + 1;
Serial.print("primo invio: ");
Serial.println(contatore);
Serial.println();
Serial.println("----------getdata.php");
postData = "id=Progetto";
http.begin(Client, "http://" + (String(web_server)) + "/esp8266/getdata.php");
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
httpCode = http.POST(postData);
payload = http.getString();
Serial.print("httpCode: ");
Serial.println(httpCode);
Serial.print("payload : ");
Serial.println(payload);
http.end();
Serial.println("-----------");
shuntvoltage = ina219.getShuntVoltage_mV();
busvoltage = ina219.getBusVoltage_V();
current_mA = ina219.getCurrent_mA();
power_mW = ina219.getPower_mW();
loadvoltage = busvoltage + (shuntvoltage / 1000);
Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage); Serial.println(" mV");
Serial.print("Bus Voltage: "); Serial.print(busvoltage); Serial.println(" V");
Serial.print("Current: "); Serial.print(current_mA); Serial.println(" mA");
Serial.print("Power: "); Serial.print(power_mW); Serial.println(" mW");
Serial.print("Load Voltage: "); Serial.print(loadvoltage); Serial.println(" V");
send_Status_Read_INA219 = "SUCCEED";
postData = "id=Progetto";
postData += "&busvoltage=" + String(busvoltage);
postData += "&shuntvoltage=" + String(shuntvoltage);
postData += "¤t_mA=" + String(current_mA);
postData += "&loadvoltage=" + String(loadvoltage);
postData += "&power_mW=" + String(power_mW);
postData += "&status_read_sensor_ina219=" + send_Status_Read_INA219;
Serial.print("postData: ");
Serial.println(postData);
http.begin(Client, "http://" + (String(web_server)) + "/esp8266/getdata.php");
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
httpCode = http.POST(postData);
payload = http.getString();
Serial.print("httpCode: ");
Serial.println(httpCode);
Serial.print("payload : ");
Serial.println(payload);
http.end();
Serial.println("-----------");
delay(2000);
}