Problem with programmed via Arduino IDeESP8266 rst cause : 4 boot mode (3,7)-I'm driving crazy already

Hello, currently I am working on some small project which i want to unite in one thing and I have spend too much time lurking throuh the internet so I want to ask here what the problem is and how to solve it maybe someone will help.

#include <ESP8266WiFi.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
#define OLED_RESET     -1
#define SCREEN_ADDRESS 0x7B
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void temperatura_wewnetrzna (void);
void temperatura_zewnetrzna (void);

uint8_t temp_wewn;
uint8_t temp_zewn;

#define Pin_D1  5 //d5/gpio14
#define Pin_D2  6 // d6/gpio12

// Enter your wifi network name and Wifi Password
const char* ssid = "Grzechuu";
const char* password = "grzegorz2137";

// Set web server port number to 80
WiFiServer server(80);

// Variable to store the HTTP request
String header;

// Assign output variables to GPIO pins
#define swiatlo_1 0//d0 gpio16
#define swiatlo_2 3//d3 gpio0

// These variables store current output state of LED
String swiatlo1_stan = "Wyl";
String swiatlo2_stan = "Wyl";

void setup() {
  //while (1){ESP.wdtFeed();};
  //ESP.wdtDisable();
  Serial.begin(115200);
  // Initialize the output variables as outputs
  pinMode(swiatlo_1, OUTPUT);
  pinMode(swiatlo_2, OUTPUT);
  pinMode(Pin_D1, OUTPUT);
  pinMode(Pin_D2, OUTPUT);
  pinMode(A0, INPUT);
  
   // Set outputs to LOW
  digitalWrite(swiatlo_1, LOW);
  digitalWrite(swiatlo_2, LOW);
  
   if(!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) {
    Serial.println(F("SSD1306 allocation failed"));
    for(;;); // Don't proceed, loop forever
   }
   
  // Connect to Wi-Fi network with SSID and password
  Serial.print("Łączenie z :  ");
  Serial.println(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(200);
    Serial.println("Łączę...");
  }
  // Print local IP address and start web server
  Serial.println("");
  Serial.println("Połączono");
  Serial.println("Lokalny adres IP: : ");
  Serial.println(WiFi.localIP());
  server.begin();
}
void temperatura_wewnetrzna() {
  temp_wewn=(analogRead(A0) / 1024.0) * 100;
  digitalWrite(Pin_D1,HIGH);
  digitalWrite(Pin_D2,LOW);
}
void temperatura_zewnetrzna() {
  temp_wewn=(analogRead(A0) / 1024.0) * 100;
  digitalWrite(Pin_D1,LOW);
  digitalWrite(Pin_D2,HIGH);
}
void loop() {
  WiFiClient client = server.available(); // Listen for incoming clients
  if (client) { // If a new client connects,
    Serial.println("Nowy użytkownik"); // print a message out in the serial port
    String currentLine = ""; // make a String to hold incoming data from the client
    while (client.connected()) { // loop while the client's connected
      if (client.available()) { // if there's bytes to read from the client,
        char c = client.read(); // read a byte, then
        Serial.write(c); // print it out the serial monitor
        header += c;
        if (c == '\n') { // if the byte is a newline character
          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println("Connection: close");
            client.println();

            // turns the GPIOs on and off
            if (header.indexOf("GET /0/on") >= 0) {
              Serial.println("Światło dla ptaków włączone");
              swiatlo1_stan = "on";
              digitalWrite(swiatlo_1, HIGH);
            } else if (header.indexOf("GET /0/off") >= 0) {
              Serial.println("Światło dla ptaków wyłączone");
              swiatlo1_stan = "off";
              digitalWrite(swiatlo_1, LOW);
            } else if (header.indexOf("GET /3/on") >= 0) {
              Serial.println("Green LED is on");
              swiatlo2_stan = "on";
              digitalWrite(swiatlo_2, HIGH);
            } else if (header.indexOf("GET /3/off") >= 0) {
              Serial.println("Green LED is off");
              swiatlo2_stan = "off";
              digitalWrite(swiatlo_2, LOW);
            }

            // Display the HTML web page
            client.println("<!DOCTYPE html><html>");
            client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
            client.println("<link rel=\"icon\" href=\"data:,\">");
            // CSS to style the on/off buttons
            client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}");
            client.println(".buttonRed { background-color: #ff0000; border: none; color: white; padding: 16px 40px; border-radius: 60%;");
            client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}");
            client.println(".buttonGreen { background-color: #00ff00; border: none; color: white; padding: 16px 40px; border-radius: 60%;");
            client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}");
            client.println(".buttonYellow { background-color: #feeb36; border: none; color: white; padding: 16px 40px; border-radius: 60%;");
            client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}");
            client.println(".buttonOff { background-color: #77878A; border: none; color: white; padding: 16px 40px; border-radius: 70%;");
            client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}</style></head>");

            // Web Page Heading
            client.println("<body><h1>Grzeszne IoT Prot.v.1.2</h1>");

            // Display current state, and ON/OFF buttons for GPIO 2 Red LED
            client.println("<p>Swiatlo1 " + swiatlo1_stan + "</p>");
            // If the outputRedState is off, it displays the OFF button
            if (swiatlo1_stan == "off") {
              client.println("<p><a href=\"/0/on\"><button class=\"button buttonOff\">Wyl</button></a></p>");
            } else {
              client.println("<p><a href=\"/0/off\"><button class=\"button buttonRed\">Wlaczone</button></a></p>");
            }

            // Display current state, and ON/OFF buttons for GPIO 4 Green LED
            client.println("<p>Swiatlo2 " + swiatlo2_stan + "</p>");
            // If the outputGreenState is off, it displays the OFF button
            if (swiatlo2_stan == "off") {
              client.println("<p><a href=\"/3/on\"><button class=\"button buttonOff\">Wyl</button></a></p>");
            } else {
              client.println("<p><a href=\"/3/off\"><button class=\"button buttonGreen\">Wlaczone</button></a></p>");
            }
            client.println("</body></html>");


            // The HTTP response ends with another blank line
            client.println();
            // Break out of the while loop
            break;
          } else { // if you got a newline, then clear currentLine
            currentLine = "";
          }
        } else if (c != '\r') { // if you got anything else but a carriage return character,
          currentLine += c; // add it to the end of the currentLine
        }
      }
    }
    // Clear the header variable
    header = "";
    // Close the connection
    client.stop();
    Serial.println("Client disconnected.");
    Serial.println("");
  }
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(4, 4);
  temperatura_wewnetrzna();
  Serial.println("temp.w.: ");
  Serial.println(temp_wewn);
  delay(300);
  temperatura_zewnetrzna();
  Serial.println("temp.z.: ");
  Serial.println(temp_zewn);
  delay(300);
}

And the serial monitor:
image
Thank you in advance

You didn't say much about your project. We need to know a lot more.

For example, can you upload a simple example sketch and run it? What board you have? Did you write this code?

Well it's my engineering project that i fully want to move from arduino to esp8266. I want it to measure temperature from 2 points via one analog input (in previous version of program it worked) it comunnicates with local network (same here), but problems start when I want to use the OLED screen then the program crashes mainly rst cause:4 boot mode (3,7) previos it showe boot mode (3,6)

Does it print "SSD1306 allocation failed" ?

Also you posted in "Installation and Troubleshooting". This category is not for projects.

It doesn't print anything I launched it earlier without having anything connected to the microcontroller and it went without issues. When i prepared the circuit it showed me this message.
With everything commented connecting to display it shows me this:
image
As I know from the internet it has to do something with watchdog. It is possible that I damaged somehow the controller?

Are you sure of the i2c address of the SSD1306 ?

I think that this would make the watchdog very unhappy.
It would reset, and you would not see the "SSD1306 allocation failed" message.

Start with working example.
Add in your logic & requirements one at a time.
Always keep copy of successes as backup. Disk space is cheap. If you are "disk storage challenged, invest in a 64G USB flash (pen) drive.

ESP32/ESP8266: DHT Temperature and Humidity Readings in OLED Display | Random Nerd Tutorials

similar problem in post esp8266-not-running-oled-properly ??

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