0

ESP32 OLED interfering with INA260 Readings
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

ESP32 OLED interfering with INA260 Readings

by jdix918 on Wed Jun 09, 2021 1:21 pm

Hello,

I am currently working on a project that calls for reading the power draw on a motor and displaying other information on an OLED, with the Heltec ESP32 Wifi Kit. I have ran into the

problem that when my OLED display is running that the INA 260 outputs in the serial a maximum number that is not a correct reading (Serial Print output: 4294967296.00,mW

5368709120.00,mV -1.25,mA), but the OLED displays the information perfectly fine. However, when I comment out the code for the OLED the INA 260 output is correct.

I am curious if the OLED library I am using may be causing issues with the INA 260's readings (the heltec.h library :

https://github.com/HelTecAutomation/Hel ... r/examples) or if there is something I need to add to my code in order to make the INA 260 work with the OLED on

the Heltec ESP32 Wifi Kit. Below will be the rewritten code showing only the OLED and INA 260 code, in order to get a better understanding of just that problem.

Code: Select all | TOGGLE FULL SIZE
#include "sensorModule.h"
 #include "oledDisplay.h"
 #include "oledNewFonts.h"


 int testCycleCounter = 0;

//Object pointers
SensorModule *sensorModule;
OledDisplay *thisDisplay;

void setup()   
{               
  Serial.begin(115200);

  /**********************
   * Set up sensors
   *********************/
   sensorModule = new SensorModule();
   thisDisplay = new OledDisplay();

  //Initialize the display
  thisDisplay->DisplaySetup();
  delay(1000);
 
}

void loop()
{
 

    thisDisplay->TestDisplayMode();   //Update the display of the oled
 
   
    sensorModule->Update();          //Update INA260 sensor (timer is internal to SensorModule object)
     
    delay(100);
    testCycleCounter++;
}




Below is the OLED library that I wrote myself and will hopefully add some clarity.

Code: Select all | TOGGLE FULL SIZE
#include "oledDisplay.h"

String _cycleCount;
String _currentMode;
String _cycleTiming;
String _sensorData;

extern int testCycleCounter;

//The global variables for ongoing test data

OledDisplay::OledDisplay()
{

  this->_maxTime = 10;

}

OledDisplay::~OledDisplay()
{
 
}

void OledDisplay::DisplaySetup()
{
    Heltec.begin(true, false, false);
    Heltec.display->flipScreenVertically();
    Heltec.display->setFont(ArialMT_Plain_10);


    this->ScreenClear();

}


void OledDisplay::DefaultDisplayWrite()
{

    Heltec.display->setTextAlignment(TEXT_ALIGN_LEFT);    //Align Text to the left
    Heltec.display->drawString (0, 0, "Cycle Default:  " + String(DEFAULT_TARGET_TEST_CYCLE_COUNT));
    Heltec.display->drawString (0, 10, "Start Delay Default: " + String(DEFAULT_TEST_START_DELAY_TIME));
    Heltec.display->drawString (0, 20, "Raise Time Default: " + String(DEFAULT_TEST_RAISE_TIME));
    Heltec.display->drawString (0, 30, "Pause1 Time Default: " + String(DEFAULT_TEST_PAUSE_1_TIME));
    Heltec.display->drawString (0, 40, "Lower Time Default: " + String(DEFAULT_TEST_LOWER_TIME));
    Heltec.display->display();
}

void OledDisplay::TestDisplayWrite()
{
        Heltec.display->setFont(ArialMT_Plain_16);
        Heltec.display->setTextAlignment(TEXT_ALIGN_LEFT);    //Align Text to the left
        Heltec.display->drawString (0, 33, "Cyc: " + String(testCycleCounter));
     
        Heltec.display->display();
}

void OledDisplay::ScreenClear()
{

     Heltec.display->clear();
}

void OledDisplay::TestDisplayMode()
{
 
  ScreenClear();
  TestDisplayWrite();
}


Last is the library for the Adafruit INA 260 senor.

Code: Select all | TOGGLE FULL SIZE
#include "sensorModule.h"

SensorModule::SensorModule()
{
    this->_delayTime = INA260_DELAY_TIME;
    this->_lastVoltage = 0;
    this->_lastCurrent = 0;
    this->_lastPower = 0;
   
   
    // Set up INA260 sensor
    this->ina260 = new Adafruit_INA260();
    this->ina260->begin();
    this->ina260->setAveragingCount(INA260_COUNT_4);            // Set the number of samples to average
    this->ina260->setVoltageConversionTime(INA260_TIME_140_us); // Set the time over which to measure the current and bus voltage
    this->ina260->setCurrentConversionTime(INA260_TIME_140_us); // Set the time over which to measure the current and bus voltage
    this->ina260->setMode(INA260_MODE_CONTINUOUS);
    this->ina260PreviousReadTime = 0;
}

SensorModule::~SensorModule() {}

void SensorModule::Update()
{
    unsigned long currentTime = millis();

    if ((currentTime - this->ina260PreviousReadTime) >= INA260_DELAY_TIME)
    {
        this->UpdateCurrent();
        this->UpdateVoltage();
        this->UpdatePower();
        this->ina260PreviousReadTime = currentTime;
        this->PublishCurrentValues();
    }
}

void SensorModule::UpdateCurrent()
{
    this->_lastCurrent = this->ina260->readCurrent();
}

void SensorModule::UpdateVoltage()
{
    this->_lastVoltage = this->ina260->readBusVoltage();
}

void SensorModule::UpdatePower()
{
    this->_lastPower = this->ina260->readPower();
}

void SensorModule::PublishCurrentValues()
{
    if (Serial)
    {
     

          Serial.println("ComboCVP:" + String(this->_lastPower)   + ",mW,"
                                     + String(this->_lastVoltage) + ",mV,"
                                     + String(this->_lastCurrent) + ",mA,");
                                 
    }
}

jdix918
 
Posts: 1
Joined: Wed Jun 09, 2021 12:56 pm

Please be positive and constructive with your questions and comments.