-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsensors.h
56 lines (50 loc) · 1.44 KB
/
sensors.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <Wire.h>
#include "Adafruit_INA219.h"
#include <WebSerial.h>
Adafruit_INA219 ina219;
TwoWire I2CINA = TwoWire(0);
void ina219Setup(int sdaPin, int sdcPin)
{
Serial.println("** [INA219 Sensor] Init **");
I2CINA.begin(sdaPin, sdcPin, 100000);
if (!ina219.begin(&I2CINA))
{
Serial.println("Failed to find INA219 chip");
while (1)
{
delay(10);
}
}
// WebSerial.print("BV");
// WebSerial.print("\t"); // Bus Voltage
// WebSerial.print("SV");
// WebSerial.print("\t"); // Shunt Voltage
// WebSerial.print("LV");
// WebSerial.print("\t"); // Load Voltage
// WebSerial.print("C");
// WebSerial.print("\t"); // Current
// WebSerial.println("P"); // Power
}
void ina219DisplayValues()
{
float shuntvoltage = 0;
float busvoltage = 0;
float current_mA = 0;
float loadvoltage = 0;
float power_mW = 0;
shuntvoltage = ina219.getShuntVoltage_mV();
busvoltage = ina219.getBusVoltage_V();
current_mA = ina219.getCurrent_mA();
power_mW = ina219.getPower_mW();
loadvoltage = busvoltage + (shuntvoltage / 1000);
// WebSerial.print(busvoltage);
// WebSerial.print("\t");
// WebSerial.print(shuntvoltage);
// WebSerial.print("\t");
WebSerial.print(loadvoltage);
WebSerial.print("V\t");
WebSerial.print(current_mA);
WebSerial.println("mA");
// WebSerial.print("\t");
// WebSerial.println(power_mW);
}