1.datasheet
2.好用的代码
用的这个库 在arduino IDE的库管理搜索就行
其中换INA219地址可以用这个语句
INA219 monitor(INA219::I2C_ADDR_40);
/**********************************************
* INA219 library example
* 10 May 2012 by johngineer
*
* 9 January 2016 Flavius Bindea: changed default values and begin()
*
* this code is public domain.
**********************************************/
#include <Wire.h>
#include <INA219.h>
INA219 monitor;
void setup()
{
Serial.begin(9600);
monitor.begin();
// begin calls:
// configure() with default values RANGE_32V, GAIN_8_320MV, ADC_12BIT, ADC_12BIT, CONT_SH_BUS
// calibrate() with default values D_SHUNT=0.1, D_V_BUS_MAX=32, D_V_SHUNT_MAX=0.2, D_I_MAX_EXPECTED=2
// in order to work directly with ADAFruit's INA219B breakout
}
void loop()
{
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() * 1000, 4);
// Serial.println(" mV");
float current=0;
for(int t=1;t<11;t++)
{
current+=monitor.shuntCurrent() *1000;
// Serial.print(monitor.shuntCurrent() * 1000, 4);
delay(10);
}
Serial.println("shunt current: ");
Serial.println(current/10, 4);
Serial.println(" : ");
Serial.print(monitor.shuntCurrent() * 1000, 4);
Serial.println(" mA");
// Serial.print("bus voltage: ");
// Serial.print(monitor.busVoltage(), 4);
// Serial.println(" V");
// Serial.print("bus power: ");
//Serial.print(monitor.busPower() * 1000, 4);
//Serial.println(" mW");
Serial.println(" ");
Serial.println(" "); Serial.println(" ");
Serial.println(" ");
delay(1000);
}
//累加100次求平均值
uint32_t get_ave1(uint8_t times )
{
uint32_t sum = 0;
int t=0;
for( t=0;t<times;t++)
{
sum += monitor.shuntCurrent() ; //读取ADC数据
delay(10);
}
return sum/times;
}