появились еще вопросы ,как правильно выставить параметры чтоб более-менее правильно считывало,
вот такой шунт в авто поставил:
monitor.configure(0, 3, 11, 11, 7);
// (range, gain, bus_adc, shunt_adc, mode)
// range = 1 (0-32V bus voltage range)
// gain = 3 (1/8 gain - 320mV range)
// bus adc = 3 (12-bit, single sample, 532uS conversion time)
// shunt adc = 3 (12-bit, single sample, 532uS conversion time)
// mode = 7 (continuous conversion)
// test shunt = 115mm of 22AWG solid copper = 0.3 Ohms
monitor.calibrate(0.15, 0.075, 16, 50);
//R_шунта, напряж_шунта, макcнапряж, максток
вот с горем пополам переделал скетч который был выше:
PHP код:
#include <OneWire.h>
#include <DallasTemperature.h>
#include <Wire.h>
#include <INA219.h>
INA219 monitor;
char incomingByte;
int analogInput = 0;
float vout = 0.0;
float vin = 0.0;
float R1 = 100000.0;
float R2 = 10000.0;
int value = 0;
OneWire OW_tempa(9);
OneWire OW_tempb(10);
OneWire OW_tempc(11);
DallasTemperature tempa(&OW_tempa);
DallasTemperature tempb(&OW_tempb);
DallasTemperature tempc(&OW_tempc);
DeviceAddress tempaAddress, tempbAddress, tempcAddress;
void setup(void){
Serial.begin(9600);
monitor.begin(64); //i2c address
monitor.configure(0, 3, 11, 11, 7);
// (range, gain, bus_adc, shunt_adc, mode)
// range = 1 (0-32V bus voltage range)
// gain = 3 (1/8 gain - 320mV range)
// bus adc = 3 (12-bit, single sample, 532uS conversion time)
// shunt adc = 3 (12-bit, single sample, 532uS conversion time)
// mode = 7 (continuous conversion)
// test shunt = 115mm of 22AWG solid copper = 0.3 Ohms
monitor.calibrate(0.15, 0.075, 16, 50);
//R_шунта, напряж_шунта, макcнапряж, максток
pinMode(analogInput,INPUT);
tempa.begin();
tempb.begin();
tempc.begin();
}
void loop(void){
{
Serial.println("******************");
Serial.print("raw shunt voltage: ");
Serial.println(monitor.shuntVoltageRaw());
Serial.print("raw bus voltage: ");
Serial.println(monitor.busVoltageRaw());
Serial.println("--");
Serial.print("shunt voltage: ");
Serial.print(monitor.shuntVoltage(), 4);
Serial.println(" mV");
Serial.print("shunt current: ");
Serial.print(monitor.shuntCurrent() * 1000, 4);
Serial.println(" mA");
Serial.print("bus power: ");
Serial.print(monitor.busPower() * 1000, 4);
Serial.println(" mW");
Serial.println(" ");
Serial.println(" ");
}
value = analogRead(analogInput);
vout = (value*5.0)/1024.0;
vin = vout/(R2/(R1+R2));
if(vin<0.09){
vin = 0.0;
}
tempa.requestTemperatures();
delay(700);
Serial.print("<InDoor:");
if ( !tempa.getAddress(tempaAddress,0)){
Serial.print("0");
}else{
Serial.print(tempa.getTempCByIndex(0),1);
}
Serial.println(">");
tempb.requestTemperatures();
delay(700);
Serial.print("<OutDoor:");
if ( !tempb.getAddress(tempbAddress,0)){
Serial.print("0");
}else{
Serial.print(tempb.getTempCByIndex(0),1);
}
Serial.println(">");
tempc.requestTemperatures();
delay(700);
Serial.print("<Engine:");
if ( !tempc.getAddress(tempcAddress,0)){
Serial.print("0");
}else{
Serial.print(tempc.getTempCByIndex(0),1);
}
Serial.println(">");
delay(700);
Serial.print("<busvoltage:");
Serial.print(monitor.busVoltage(), 4);
Serial.println(">");
Serial.print("<Voltage:");
Serial.print(vin,2);
Serial.println(">");
for(int i = 0; i < 100; i++);
}
пока на планшет выводятся показания 3-х датчиков напряжение борт. сети через делитель и с собственно с INA.
вот так монитор порта выводит:
<InDoor:0>
<OutDoor:0>
<Engine:0>
<busvoltage:-0.0040>
<Voltage:15.79>
******************
raw shunt voltage: -1
raw bus voltage: -1
--
shunt voltage: -0.0000 mV
shunt current: -0.2152 mA
bus power: -4.3042 mW
SerialManager их видит )
наблюдаю интересный момент ,пока мотор не запущен все показывает боле-менее правильно,стоит завестись показания тока
уходят в минус и почему-то скачут в больших пределах ,напряжение норм показывает ,что может быть не так ?
может кто поправит в нужном направлении ,в скетче я там явно лишнего
много
и еще вопрос - зачем в изначальном скетче была библиотека
#include <SPI.h> ?
я ее убрал ... может зря...