Ci-dessous, les différences entre deux révisions de la page.
Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
documentation:microcontroleurs:arduino:modules:ina219_va_meter:index [2025/05/01 13:56] – [I2C] f1sls | documentation:microcontroleurs:arduino:modules:ina219_va_meter:index [2025/05/04 14:42] (Version actuelle) – f1sls | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | ====== Voltmètre / Ampèremètre INA219 ====== | + | ====== Voltmètre / Ampèremètre INA219/ |
{{: | {{: | ||
\\ | \\ | ||
Ligne 11: | Ligne 11: | ||
===== I2C ===== | ===== I2C ===== | ||
- | I2C Address | ||
- | |||
The INA219 uses the I2C protocol to communicate with microcontrollers, | The INA219 uses the I2C protocol to communicate with microcontrollers, | ||
Ligne 39: | Ligne 37: | ||
So, if you want to have multiple INA219 modules in the same system, you just need to set a unique address for each one by configuring the A0 and A1 pins accordingly. Remember, any time you change the I2C address, you must update the address in your microcontroller’s software so it knows where to find each INA219 on the I2C bus. | So, if you want to have multiple INA219 modules in the same system, you just need to set a unique address for each one by configuring the A0 and A1 pins accordingly. Remember, any time you change the I2C address, you must update the address in your microcontroller’s software so it knows where to find each INA219 on the I2C bus. | ||
- | ===== WIRING | + | ===== REGISTERS & VALUES CALCULATIONS |
+ | |||
+ | The INA219 has a set of internal registers that hold measurement data and control settings. They can be accessed via the I2C interface to configure the chip, initiate measurements, | ||
+ | {{: | ||
+ | |||
+ | ==== Configuration Register (Address = 00h) ==== | ||
+ | This register is used to control various aspects of the INA219, such as the bus voltage range, PGA gain, ADC resolution/ | ||
+ | |||
+ | ==== Shunt Voltage Register (Address = 01h) ==== | ||
+ | This register holds the raw measurement result for the shunt voltage. It can be read to obtain the shunt voltage measurement, | ||
+ | |||
+ | Shunt voltage (in volts) is calculated by taking the raw reading from the Shunt Voltage Register and multiplying it by 10 µV. The formula is: | ||
+ | |||
+ | '' | ||
+ | |||
+ | ==== Bus Voltage Register (Address = 02h) ==== | ||
+ | This register holds the raw measurement result for the bus voltage. It can be read to obtain the bus voltage measurement, | ||
+ | |||
+ | Bus voltage (in volts) is calculated by taking the raw reading from the Bus Voltage Register and multiplying it by 4 mV. The formula is: | ||
+ | |||
+ | '' | ||
+ | |||
+ | ==== Power Register (Address = 03h) ==== | ||
+ | This register holds the calculated power value. It can be read to obtain the power measurement, | ||
+ | |||
+ | Power (in watts) is calculated by taking the raw reading from the Power Register and multiplying it by the Power_LSB value (defined when the calibration register is set). The formula is: | ||
+ | |||
+ | '' | ||
+ | |||
+ | ==== Current Register (Address = 04h) ==== | ||
+ | This register holds the calculated current value. It can be read to obtain the current measurement, | ||
+ | |||
+ | Current (in amperes) is calculated by taking the raw reading from the Current Register and multiplying it by the Current_LSB value (defined when the calibration register is set). The formula is: | ||
+ | |||
+ | '' | ||
+ | |||
+ | ==== Calibration Register (Address = 05h) ==== | ||
+ | This register is used to set the calibration value for the current and power calculations. It can be read or written to set the correct calibration value. | ||
===== PINOUT ===== | ===== PINOUT ===== | ||
Ligne 50: | Ligne 85: | ||
* **Vin+** this pin connects to the positive terminal of the voltage supply that you want to measure. | * **Vin+** this pin connects to the positive terminal of the voltage supply that you want to measure. | ||
+ | ===== WIRING ===== | ||
+ | {{: | ||
+ | {{: | ||
===== Librairie(s) ===== | ===== Librairie(s) ===== | ||
* [[https:// | * [[https:// | ||
Ligne 59: | Ligne 97: | ||
==== ARDUINO CODE ==== | ==== ARDUINO CODE ==== | ||
<code cpp> | <code cpp> | ||
+ | #include < | ||
+ | #include < | ||
+ | |||
+ | Adafruit_INA219 ina219; | ||
+ | |||
+ | void setup(void) | ||
+ | { | ||
+ | Serial.begin(9600); | ||
+ | while (!Serial) | ||
+ | { | ||
+ | delay(1); | ||
+ | } | ||
+ | |||
+ | // Initialize the INA219. | ||
+ | if (! ina219.begin()) | ||
+ | { | ||
+ | Serial.println(" | ||
+ | while (1) | ||
+ | { | ||
+ | delay(10); | ||
+ | } | ||
+ | } | ||
+ | // To use a slightly lower 32V, 1A range (higher precision on amps): | ||
+ | // | ||
+ | // Or to use a lower 16V, 400mA range, call: | ||
+ | // | ||
+ | |||
+ | Serial.println(" | ||
+ | } | ||
+ | |||
+ | 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(" | ||
+ | Serial.print(" | ||
+ | Serial.print(" | ||
+ | Serial.print(" | ||
+ | Serial.print(" | ||
+ | Serial.println("" | ||
+ | |||
+ | delay(1000); | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | <code cpp> | ||
+ | #include " | ||
+ | #include " | ||
+ | |||
+ | Adafruit_INA219 ina219; | ||
+ | |||
+ | void setup() { | ||
+ | // Open serial communications and wait for port to open: | ||
+ | Serial.begin(9600); | ||
+ | while (!Serial) { | ||
+ | ; // wait for serial port to connect. Needed for native USB port only | ||
+ | } | ||
+ | |||
+ | if (! ina219.begin()) { | ||
+ | Serial.println(" | ||
+ | while (1) { delay(10); } | ||
+ | } | ||
+ | |||
+ | Serial.print(" | ||
+ | Serial.print(" | ||
+ | Serial.print(" | ||
+ | Serial.print(" | ||
+ | Serial.println(" | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | 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(busvoltage); | ||
+ | Serial.print(shuntvoltage); | ||
+ | Serial.print(loadvoltage); | ||
+ | Serial.print(current_mA); | ||
+ | Serial.println(power_mW); | ||
+ | |||
+ | delay(1000); | ||
+ | } | ||
</ | </ |