I have a problem with the display and ESP8266

When I have the Arduino board set in the IDE, everything works normally except for network discovery. However, if I switch to the ESP board in the IDE, the display stops working

#include <ESP8266WiFi.h>
#include <U8g2lib.h>

// U8g2 Constructor
U8G2_SSD1306_128X32_UNIVISION_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

void setup() {
  // Initialize the display
  u8g2.begin();

  // Initialize serial communication for debugging
  Serial.begin(9600);
  while (!Serial);

  // Draw initial message
  u8g2.setFont(u8g2_font_ncenB10_tr);
  u8g2.clearBuffer();
  u8g2.drawStr(0, 20, "Scanning WiFi...");
  u8g2.sendBuffer();

  // Start WiFi scan
  int numNetworks = WiFi.scanNetworks();

  // Check if any networks were found
  if (numNetworks == 0) {
    Serial.println("No networks found");
    u8g2.clearBuffer();
    u8g2.drawStr(0, 20, "No networks found");
    u8g2.sendBuffer();
  } else {
    Serial.print(numNetworks);
    Serial.println(" networks found");

    // Print networks to serial and display
    u8g2.clearBuffer();

    u8g2.setFont(u8g2_font_ncenB10_tr);
    for (int i = 0; i < numNetworks; i++) {
      String ssid = WiFi.SSID(i);
      int rssi = WiFi.RSSI(i);
      String msg = ssid + " RSSI: " + String(rssi) + "dBm";
      Serial.println(msg);
      u8g2.drawStr(0, 10 + i * 10, msg.c_str());
    }
    u8g2.sendBuffer();
  }

  // Delay to display the results
  delay(5000);  // 5 seconds delay
}

void loop() {
  // Your main code here
}

https://pl.aliexpress.com/item/1005005281308478.html?spm=a2g0o`Tekst

https://pl.aliexpress.com/item/1005006153737861.html?spm=a2g0o.order_list.order_list_main.10.3b2e1c24gur0yW&gatewayAdapt=glo2pol

arudino


Please read the forum guide in the sticky post, then edit your post able and fix the code tags.

...and give us a better description of the problem, because I honestly admit haven't got much of that statement (and without a clean code it's harder).

When I have the Arduino board set in the IDE, everything works normally except for network discovery. However, if I switch to the ESP board in the IDE, the display stops working

Well, I think it looks like the library has problems with ESP boards.

Have a look to this issue, because it seems to be very similar, hope it helps:

Its not work for me