Need help for Watchdog timer gets active on ESP8266 with oled display using u2g8 library

Hi all!
im new to ESP and i want to display current value on display of oled display. code is working fine but when i use display library like (u2g8 or SSD1306) it will trigger software watchdog timer.

here is code:

#define BLYNK_TEMPLATE_ID "xxxxxxxx"
#define BLYNK_TEMPLATE_NAME "xxxxxx"
#define BLYNK_AUTH_TOKEN "xxxxxxxxxxxxxx"

#include "Arduino.h"
#include <Wire.h>
#include <Adafruit_ADS1X15.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SSD1306Wire.h> 

// Wi-Fi credentials
const char* ssid = "xxxxx"; 
const char* pass = "xxxxx"; 

// Initialize SSD1306 for 128x64 OLED
#define OLED_SDA 14  // D2
#define OLED_SCL 12  // D1
SSD1306Wire display(OLED_SDA, OLED_SCL);

Adafruit_ADS1115 ads;

// Variables
float Battery_A_Voltage, Battery_B_Voltage, Total_Battery_Voltage, OFFSET, Current, average;
float blynk_offset = 0.000f;
int16_t adc0, adc1, adc2, adc3;
float volts0, volts1, volts2, volts3;

const int numSamples = 20;

// Calibration Constants
const float BATT_B_MULTIPLIER = 4.8297;
const float TOTAL_V_MULTIPLIER = 9.4615;
const float Current_MULTIPLIER = 0.020f;

// Functions
void connectWiFi();
void readADCValues();

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

  // Initialize ADS1115
  if (!ads.begin()) {
    Serial.println("Failed to initialize ADS1115!");
    while (1);
  }

  // Initialize SSD1306
  display.init();
  display.clear();
  display.display();

  // Connect to Wi-Fi
  connectWiFi();
  Blynk.begin(BLYNK_AUTH_TOKEN, ssid, pass);
}

BLYNK_WRITE(V4) {
  blynk_offset = param.asFloat();
}

void connectWiFi() {
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("Connected to WiFi");
}

void readADCValues() {
  adc0 = ads.readADC_SingleEnded(0);
  adc1 = ads.readADC_SingleEnded(1);
  adc2 = ads.readADC_SingleEnded(2);
  adc3 = ads.readADC_SingleEnded(3);

  volts0 = ads.computeVolts(adc0);
  volts1 = ads.computeVolts(adc1);
  volts2 = ads.computeVolts(adc2);
  volts3 = ads.computeVolts(adc3);

  OFFSET = 1.808 - volts1 + blynk_offset;
  Current = (OFFSET / Current_MULTIPLIER) * 1.3916;

  // Compute average current over numSamples
  float sum = 0;
  for (int i = 0; i < numSamples; i++) {
    sum += Current;
    delay(10);
  }
  average = sum / (float)numSamples;

  Battery_B_Voltage = volts2 * BATT_B_MULTIPLIER;
  Total_Battery_Voltage = volts3 * TOTAL_V_MULTIPLIER;
  Battery_A_Voltage = Total_Battery_Voltage - Battery_B_Voltage;
}

void loop() {
  if (WiFi.status() != WL_CONNECTED) connectWiFi();

  static unsigned long lastTime = 0;
  const unsigned long interval = 500; 

  if (millis() - lastTime >= interval) {
    lastTime = millis();
    readADCValues();

    // Update Blynk
    Blynk.virtualWrite(V0, Total_Battery_Voltage);
    Blynk.virtualWrite(V1, Battery_A_Voltage);
    Blynk.virtualWrite(V2, Battery_B_Voltage);
    Blynk.virtualWrite(V3, average);
    
    // Prepare the current value with a sign
    char currentString[10];
    snprintf(currentString, sizeof(currentString), "%.2f", Current);
    
    // Display current value on OLED
    display.clear();
    display.drawString(0, 0, "Current: ");
    display.drawString(0, 10, currentString);
    display.display();
    
    Blynk.run();
  }
}

IMG_20240922_203227_532

can anyone help me in it thanks!

Your topic has been moved. Please do not post in "Uncategorized"; see the sticky topics in Uncategorized - Arduino Forum.

It appears that some of the code in the library is blocking. On the ESP8266, your code runs as a task within its multitasking environment. The ESP8266 has two watchdog timers: one implemented in hardware and another in software. The following links will help you understand what is happening:

https://sigmdel.ca/michel/program/esp8266/arduino/watchdogs_en.html

yea it might causing problem , is there any way out i can try

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.