### Complete Power Monitoring Example Source: https://context7.com/adafruit/adafruit_ina219/llms.txt A comprehensive example demonstrating how to initialize the sensor, configure calibration, and calculate load voltage based on bus and shunt voltage readings. ```cpp #include #include Adafruit_INA219 ina219; void setup() { Serial.begin(115200); if (!ina219.begin()) { while (1) { delay(10); } } } void loop() { float shuntvoltage = ina219.getShuntVoltage_mV(); float busvoltage = ina219.getBusVoltage_V(); float current_mA = ina219.getCurrent_mA(); float power_mW = ina219.getPower_mW(); float loadvoltage = busvoltage + (shuntvoltage / 1000); Serial.print("Load Voltage: "); Serial.println(loadvoltage); delay(2000); } ``` -------------------------------- ### Monitor Multiple INA219 Sensors via I2C in C++ Source: https://context7.com/adafruit/adafruit_ina219/llms.txt This example initializes three INA219 sensors with distinct I2C addresses (0x40, 0x41, 0x44). It demonstrates how to apply specific calibration profiles for each sensor and output voltage, current, and power readings to the serial monitor. ```cpp #include #include // Three INA219 sensors with different I2C addresses // Address set by A0 and A1 pin connections: // A0=GND, A1=GND -> 0x40 // A0=V+, A1=GND -> 0x41 // A0=GND, A1=V+ -> 0x44 Adafruit_INA219 ina219_A(0x40); // Main power supply Adafruit_INA219 ina219_B(0x41); // Motor driver Adafruit_INA219 ina219_C(0x44); // LED strip void setup() { Serial.begin(115200); while (!Serial) { delay(1); } Serial.println("Multi-Channel Power Monitor"); // Initialize all sensors if (!ina219_A.begin()) { Serial.println("Failed to find INA219 at 0x40"); } if (!ina219_B.begin()) { Serial.println("Failed to find INA219 at 0x41"); } if (!ina219_C.begin()) { Serial.println("Failed to find INA219 at 0x44"); } // Configure each sensor for its expected range ina219_A.setCalibration_32V_2A(); // Main supply: higher current ina219_B.setCalibration_32V_1A(); // Motor: medium current ina219_C.setCalibration_16V_400mA(); // LEDs: low current, high precision Serial.println("All sensors initialized"); } void loop() { Serial.println("=== Power Readings ==="); // Read main power supply Serial.print("Main Supply - "); Serial.print("V: "); Serial.print(ina219_A.getBusVoltage_V()); Serial.print(" V, I: "); Serial.print(ina219_A.getCurrent_mA()); Serial.print(" mA, P: "); Serial.print(ina219_A.getPower_mW()); Serial.println(" mW"); // Read motor driver Serial.print("Motor - "); Serial.print("V: "); Serial.print(ina219_B.getBusVoltage_V()); Serial.print(" V, I: "); Serial.print(ina219_B.getCurrent_mA()); Serial.print(" mA, P: "); Serial.print(ina219_B.getPower_mW()); Serial.println(" mW"); // Read LED strip Serial.print("LEDs - "); Serial.print("V: "); Serial.print(ina219_C.getBusVoltage_V()); Serial.print(" V, I: "); Serial.print(ina219_C.getCurrent_mA()); Serial.print(" mA, P: "); Serial.print(ina219_C.getPower_mW()); Serial.println(" mW"); Serial.println(""); delay(2000); } ``` -------------------------------- ### Configure INA219 for 32V/1A Range (C++) Source: https://context7.com/adafruit/adafruit_ina219/llms.txt Details how to configure the INA219 sensor for a 32V bus voltage and 1A current range using `setCalibration_32V_1A()`. This setting offers higher precision with 40µA per bit for current and 800µW per bit for power, but has a lower maximum measurable current of 1.3A. The example demonstrates reading voltage and current in the loop. ```cpp #include #include Adafruit_INA219 ina219; void setup() { Serial.begin(115200); while (!Serial) { delay(1); } if (!ina219.begin()) { Serial.println("Failed to find INA219 chip"); while (1) { delay(10); } } // Configure for 32V, 1A range (higher precision than 32V_2A) ina219.setCalibration_32V_1A(); Serial.println("Configured for 32V, 1A range"); Serial.println("Current resolution: 40uA per bit"); Serial.println("Power resolution: 800uW per bit"); Serial.println("Max measurable current: 1.3A"); } void loop() { float current = ina219.getCurrent_mA(); float voltage = ina219.getBusVoltage_V(); Serial.print("Bus Voltage: "); Serial.print(voltage); Serial.println(" V"); Serial.print("Current: "); Serial.print(current); Serial.println(" mA"); delay(1000); } ``` -------------------------------- ### Configure INA219 for 32V/2A Range (C++) Source: https://context7.com/adafruit/adafruit_ina219/llms.txt Explains how to explicitly set the INA219 sensor's calibration for a 32V bus voltage and 2A current range using `setCalibration_32V_2A()`. This method provides a current resolution of 100µA per bit and a power resolution of 2mW per bit, with a maximum measurable current of 3.2A. The example also shows how to read current and power in the loop. ```cpp #include #include Adafruit_INA219 ina219; void setup() { Serial.begin(115200); while (!Serial) { delay(1); } if (!ina219.begin()) { Serial.println("Failed to find INA219 chip"); while (1) { delay(10); } } // Configure for 32V, 2A range (default, but explicit call shown) ina219.setCalibration_32V_2A(); Serial.println("Configured for 32V, 2A range"); Serial.println("Current resolution: 100uA per bit"); Serial.println("Power resolution: 2mW per bit"); Serial.println("Max measurable current: 3.2A"); } void loop() { float current = ina219.getCurrent_mA(); float power = ina219.getPower_mW(); Serial.print("Current: "); Serial.print(current); Serial.println(" mA"); Serial.print("Power: "); Serial.print(power); Serial.println(" mW"); delay(1000); } ``` -------------------------------- ### begin() Source: https://context7.com/adafruit/adafruit_ina219/llms.txt Initializes the INA219 sensor and establishes I2C communication. By default, configures the sensor for 32V/2A range. Returns true on success, false if the sensor is not found. ```APIDOC ## begin() Initializes the INA219 sensor and establishes I2C communication. By default, configures the sensor for 32V/2A range. Returns true on success, false if the sensor is not found. ### Parameters #### Path Parameters *None* #### Query Parameters *None* #### Request Body *None* ### Request Example ```cpp #include #include Adafruit_INA219 ina219; void setup() { Serial.begin(115200); while (!Serial) { delay(1); } // Initialize with default Wire interface if (!ina219.begin()) { Serial.println("Failed to find INA219 chip"); while (1) { delay(10); } } Serial.println("INA219 initialized successfully"); // Alternative: Use a different Wire interface (e.g., Wire1) // if (!ina219.begin(&Wire1)) { ... } } void loop() {} ``` ### Response #### Success Response (true) * **bool**: true if the sensor was initialized successfully. #### Error Response (false) * **bool**: false if the sensor was not found. ### Response Example *Success* ``` INA219 initialized successfully ``` *Error* ``` Failed to find INA219 chip ``` ``` -------------------------------- ### Initialize INA219 Sensor and I2C Communication (C++) Source: https://context7.com/adafruit/adafruit_ina219/llms.txt Shows how to initialize the INA219 sensor and establish I2C communication using the `begin()` method. It includes error handling for sensor detection and demonstrates using the default Wire interface or an alternative one like Wire1. The sensor is configured for a 32V/2A range by default. ```cpp #include #include Adafruit_INA219 ina219; void setup() { Serial.begin(115200); while (!Serial) { delay(1); } // Initialize with default Wire interface if (!ina219.begin()) { Serial.println("Failed to find INA219 chip"); while (1) { delay(10); } } Serial.println("INA219 initialized successfully"); // Alternative: Use a different Wire interface (e.g., Wire1) // if (!ina219.begin(&Wire1)) { ... } } void loop() {} ``` -------------------------------- ### Constructor Source: https://context7.com/adafruit/adafruit_ina219/llms.txt Creates a new INA219 sensor instance with a specified I2C address. The default address is 0x40. Custom addresses can be calculated using the INA219_CALC_ADDRESS macro. ```APIDOC ## Constructor Creates a new INA219 sensor instance with a specified I2C address. The default address is 0x40 when both A0 and A1 pins are connected to GND. Use the `INA219_CALC_ADDRESS` macro to calculate addresses for other configurations. ### Parameters #### Path Parameters *None* #### Query Parameters *None* #### Request Body *None* ### Request Example ```cpp #include #include // Default address (A0=GND, A1=GND) -> 0x40 Adafruit_INA219 ina219; // Custom address (A0=V+, A1=GND) -> 0x41 Adafruit_INA219 ina219_alt(0x41); // Calculate address using macro (A0=GND, A1=V+) -> 0x44 Adafruit_INA219 ina219_calc(INA219_CALC_ADDRESS(0, 1)); ``` ### Response *None* ### Response Example *None* ``` -------------------------------- ### Instantiate INA219 Sensor with I2C Address (C++) Source: https://context7.com/adafruit/adafruit_ina219/llms.txt Demonstrates how to create new INA219 sensor instances using default and custom I2C addresses. It utilizes the Wire library for I2C communication and the Adafruit_INA219 library. The default address is 0x40, but custom addresses can be set or calculated using the INA219_CALC_ADDRESS macro. ```cpp #include #include // Default address (A0=GND, A1=GND) -> 0x40 Adafruit_INA219 ina219; // Custom address (A0=V+, A1=GND) -> 0x41 Adafruit_INA219 ina219_alt(0x41); // Calculate address using macro (A0=GND, A1=V+) -> 0x44 Adafruit_INA219 ina219_calc(INA219_CALC_ADDRESS(0, 1)); ``` -------------------------------- ### Retrieve Power Consumption from INA219 Source: https://context7.com/adafruit/adafruit_ina219/llms.txt Returns the calculated power consumption in milliwatts based on the current bus voltage and current measurements. ```cpp float power_mW = ina219.getPower_mW(); Serial.print("Power: "); Serial.print(power_mW); Serial.println(" mW"); ``` -------------------------------- ### Configure INA219 Calibration for High Precision Source: https://context7.com/adafruit/adafruit_ina219/llms.txt Sets the sensor to a 16V, 400mA range for maximum measurement precision. This configuration provides a current resolution of 50µA per bit and a power resolution of 1mW per bit. ```cpp #include #include Adafruit_INA219 ina219; void setup() { Serial.begin(115200); while (!Serial) { delay(1); } if (!ina219.begin()) { Serial.println("Failed to find INA219 chip"); while (1) { delay(10); } } // Configure for 16V, 400mA range (highest precision) ina219.setCalibration_16V_400mA(); Serial.println("Configured for 16V, 400mA range"); } ``` -------------------------------- ### Retrieve Current Measurement from INA219 Source: https://context7.com/adafruit/adafruit_ina219/llms.txt Returns the measured current in milliamps. The library automatically refreshes the calibration register before reading to ensure accuracy. ```cpp float current_mA = ina219.getCurrent_mA(); Serial.print("Current: "); Serial.print(current_mA); Serial.println(" mA"); ``` -------------------------------- ### Retrieve Bus Voltage from INA219 Source: https://context7.com/adafruit/adafruit_ina219/llms.txt Reads the voltage at the V- terminal, representing the load side of the shunt resistor. Returns the value in volts. ```cpp float busvoltage = ina219.getBusVoltage_V(); Serial.print("Bus Voltage: "); Serial.print(busvoltage); Serial.println(" V"); ``` -------------------------------- ### Verify I2C Operation Success Source: https://context7.com/adafruit/adafruit_ina219/llms.txt Checks the status of the last I2C operation to detect communication errors. Returns true if successful, allowing for robust error handling in sensor-based projects. ```cpp if (ina219.success()) { Serial.println("Operation successful"); } else { Serial.println("I2C communication failed"); } ``` -------------------------------- ### setCalibration_32V_2A() Source: https://context7.com/adafruit/adafruit_ina219/llms.txt Configures the sensor for measuring up to 32V bus voltage and 2A current. This is the default calibration with 100µA per bit resolution for current and 2mW per bit for power. Counter overflow occurs at 3.2A. ```APIDOC ## setCalibration_32V_2A() Configures the sensor for measuring up to 32V bus voltage and 2A current. This is the default calibration with 100µA per bit resolution for current and 2mW per bit for power. Counter overflow occurs at 3.2A. ### Parameters #### Path Parameters *None* #### Query Parameters *None* #### Request Body *None* ### Request Example ```cpp #include #include Adafruit_INA219 ina219; void setup() { Serial.begin(115200); while (!Serial) { delay(1); } if (!ina219.begin()) { Serial.println("Failed to find INA219 chip"); while (1) { delay(10); } } // Configure for 32V, 2A range (default, but explicit call shown) ina219.setCalibration_32V_2A(); Serial.println("Configured for 32V, 2A range"); Serial.println("Current resolution: 100uA per bit"); Serial.println("Power resolution: 2mW per bit"); Serial.println("Max measurable current: 3.2A"); } void loop() { float current = ina219.getCurrent_mA(); float power = ina219.getPower_mW(); Serial.print("Current: "); Serial.print(current); Serial.println(" mA"); Serial.print("Power: "); Serial.print(power); Serial.println(" mW"); delay(1000); } ``` ### Response *None* ### Response Example *None* ``` -------------------------------- ### setCalibration_32V_1A() Source: https://context7.com/adafruit/adafruit_ina219/llms.txt Configures the sensor for measuring up to 32V bus voltage and 1A current with higher precision (40µA per bit for current, 800µW per bit for power). Counter overflow occurs at 1.3A. ```APIDOC ## setCalibration_32V_1A() Configures the sensor for measuring up to 32V bus voltage and 1A current with higher precision (40µA per bit for current, 800µW per bit for power). Counter overflow occurs at 1.3A. ### Parameters #### Path Parameters *None* #### Query Parameters *None* #### Request Body *None* ### Request Example ```cpp #include #include Adafruit_INA219 ina219; void setup() { Serial.begin(115200); while (!Serial) { delay(1); } if (!ina219.begin()) { Serial.println("Failed to find INA219 chip"); while (1) { delay(10); } } // Configure for 32V, 1A range (higher precision than 32V_2A) ina219.setCalibration_32V_1A(); Serial.println("Configured for 32V, 1A range"); Serial.println("Current resolution: 40uA per bit"); Serial.println("Power resolution: 800uW per bit"); Serial.println("Max measurable current: 1.3A"); } void loop() { float current = ina219.getCurrent_mA(); float voltage = ina219.getBusVoltage_V(); Serial.print("Bus Voltage: "); Serial.print(voltage); Serial.println(" V"); Serial.print("Current: "); Serial.print(current); Serial.println(" mA"); delay(1000); } ``` ### Response *None* ### Response Example *None* ``` -------------------------------- ### Retrieve Shunt Voltage from INA219 Source: https://context7.com/adafruit/adafruit_ina219/llms.txt Reads the voltage drop across the shunt resistor in millivolts. This value is used to calculate current flow based on the resistor's resistance. ```cpp float shuntvoltage = ina219.getShuntVoltage_mV(); Serial.print("Shunt Voltage: "); Serial.print(shuntvoltage); Serial.println(" mV"); ``` -------------------------------- ### Manage Power-Save Mode for INA219 Source: https://context7.com/adafruit/adafruit_ina219/llms.txt Enables or disables the INA219 power-down mode to minimize current consumption. When enabled, the sensor stops measurements; when disabled, continuous monitoring resumes. ```cpp ina219.powerSave(true); // Enter power-save mode delay(5000); ina219.powerSave(false); // Exit power-save mode ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.