I connected an INA219 sensor via I2C pins SDA (GPIO#21)& SCL(GPIO#22). The I2C address of the INA219 is 0x40. The following code works great. As soon as I add the SSD1306 OLED display code (I2C address 0x3C), the INA219 reading is no longer valid. The OLED display still works fine. Here is the code:
#include <Wire.h>
#include <Adafruit_INA219.h>
#include “heltec.h”
Adafruit_INA219 ina219;
void setup(void)
{
Serial.begin(115200);
while (!Serial) {
delay(1);
}
// Initialize the INA219.
if (! ina219.begin()) {
Serial.println(“Failed to find INA219 chip”);
while (1) { delay(10); }
}
// Initialize OLED display SSD1306
Heltec.begin(true /DisplayEnable Enable/, false /LoRa Disable/, true /Serial Enable/);
Heltec.display->init();
Heltec.display->flipScreenVertically();
Heltec.display->setFont(ArialMT_Plain_16);
Heltec.display->clear();
Heltec.display->drawString(8, 0, “INA219 integration”);
Heltec.display->display();
}
void loop(void)
{
float current_mA = 0;
float loadvoltage = 0;
current_mA = ina219.getCurrent_mA();
loadvoltage = busvoltage + (shuntvoltage / 1000);
Serial.print(“Load Voltage: “); Serial.print(loadvoltage); Serial.println(” V”);
Serial.print(“Current: “); Serial.print(current_mA); Serial.println(” mA”);
delay(5000);
}
I came across a similar problem when trying to integrate the SCD41 CO2 sensor via I2C interface. I am not sure how to setup the I2C correctly to interface both the SSD1306 and INA219 simultaneously. Can you suggest a solution?
PeterHsi75