#include
#include
Adafruit_INA219 ina219;
void setup(void)
{
Serial.begin(115200);
while (!Serial) {
delay(1);
}
uint32_t currentFrequency;
Serial.println("Hello!");
// 初始化会默认使用最大测量范围(32V, 2A),你也可以使用setCalibration指令更改,以获取更高的精度
ina219.begin();
// 用 32V, 1A 范围来测量会获取更高的电流测量精度,如果想使用这个选项就删除下面那行的注释
//ina219.setCalibration_32V_1A();
// 用16V, 400mA 范围来测量会获取更高的电流和电压测量精度,如果想使用这个选项就删除下面那行的注释
//ina219.setCalibration_16V_400mA();
Serial.println("Measuring voltage and current with INA219 ..."); //打印‘正在使用ina219测量电压和电流’
}
void loop(void)
{
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);
Serial.print("Bus Voltage: "); Serial.print(busvoltage); Serial.println(" V"); //打印总线电压
Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage); Serial.println(" mV"); //打印分流电压
Serial.print("Load Voltage: "); Serial.print(loadvoltage); Serial.println(" V"); //打印负载电压
Serial.print("Current: "); Serial.print(current_mA); Serial.println(" mA"); //打印电流
Serial.print("Power: "); Serial.print(power_mW); Serial.println(" mW"); //打印功率
Serial.println("");
delay(2000);
}
All reference designs on this site are sourced from major semiconductor manufacturers or collected online for learning and research. The copyright belongs to the semiconductor manufacturer or the original author. If you believe that the reference design of this site infringes upon your relevant rights and interests, please send us a rights notice. As a neutral platform service provider, we will take measures to delete the relevant content in accordance with relevant laws after receiving the relevant notice from the rights holder. Please send relevant notifications to email: bbs_service@eeworld.com.cn.
It is your responsibility to test the circuit yourself and determine its suitability for you. EEWorld will not be liable for direct, indirect, special, incidental, consequential or punitive damages arising from any cause or anything connected to any reference design used.
Supported by EEWorld Datasheet