ESP8266 keeps restarting

When I try to execute my file, the ESP8266 always restarts with the following message on the Serial Monitor:

 ets Jan  8 2013,rst cause:4, boot mode:(3,6)

wdt reset
load 0x4010f000, len 3460, room 16 
tail 4
chksum 0xcc
load 0x3fff20b8, len 40, room 4 
tail 4
chksum 0xc9
csum 0xc9
v00041700
~ld

This is my code. I commented out most of it, so it only should cause the LED to blink, but it is still causing the crashes. I tried the LED_BLINK example for the ESP8266 which worked just fine:

#include "Arduino.h"
//#include "ESP8266TimerInterrupt.h"
//#include "testImage.cpp"



const int PCLK = 16; // D0
const int HSYNC = 5; // D1
const int VSYNC = 4; // D2
const int DATEN_CMD = 0; // D3
const int DATA = 2; //D4
const int HOST_PRESENTZ = 14; //D5


int pclk_counter = 0;
int line_counter = 0;
int hsync_counter = 0;

#define LINE_CYCLES 652
#define HSYNC_CYLCLES 360
#define VSYNC_LINES 2
//#define FRAME_LINES 525

//#define HSYNC_HIGH (GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, 1<<HSYNC-1))


#define TIMER_INTERVAL_MS 0.1//0.00125
// Init ESP8266 timer 0
//ESP8266Timer ITimer;

/*void ICACHE_RAM_ATTR TimerHandler()
{
  ++pclk_counter;
  if(hsync_counter++ == 4-1){
    digitalWrite(HSYNC,LOW);
    hsync_counter == 0;
  }
  
  if(line_counter == 0 and pclk_counter == 0){
    digitalWrite(VSYNC,HIGH);
    digitalWrite(HSYNC,HIGH);
  }else if(pclk_counter > 3 and pclk_counter < 3+HSYNC_CYLCLES+1){
    //Serial.println("Send Meessage");
   digitalWrite(VSYNC,LOW);
   if(pclk_counter > 4 and pclk_counter < 652){
    digitalWrite(HSYNC,LOW);
    digitalWrite(DATEN_CMD,HIGH);
    sendPixel(pclk_counter,line_counter);
    digitalWrite(DATEN_CMD,LOW);
    digitalWrite(DATA,LOW); //Set data pin to low
   }
  }

  //One line finished
  if(pclk_counter == 652-1){
    line_counter++;
    pclk_counter = 0;
    digitalWrite(HSYNC,HIGH);
    //Serial.println("RESET");
   }

    if(line_counter == 3+HSYNC_CYLCLES+1-1){
    line_counter = 0; 
   }
 
 
}*/

void setup() {
  //pinMode(PCLK,OUTPUT);
  pinMode(HSYNC,OUTPUT);
  //pinMode(VSYNC,OUTPUT);
  //pinMode(DATEN_CMD,OUTPUT);
  //pinMode(DATA,OUTPUT);
  //pinMode(HOST_PRESENTZ,OUTPUT);
  //digitalWrite(HOST_PRESENTZ,HIGH);
  
  pinMode(8,INPUT);
  pinMode(LED_BUILTIN, OUTPUT);  

  /*
  Serial.begin(115200);
  //while (!Serial);

  delay(200);
  Serial.print("PIN TEST");
  Serial.println( (1<<HSYNC-1));
  */
  /* Interval in microsecs
  if (ITimer.attachInterruptInterval(TIMER_INTERVAL_MS * 1000, TimerHandler))
  {
    int lastMillis = millis();
    Serial.print("Starting ITimer OK, millis() = "); 
    Serial.println(lastMillis);
  }
  else
    Serial.println("Can't set ITimer correctly. Select another freq. or interval");
  */
}

/*
void sendPixel(int pclk_counter,int line_counter){
  pgm_read_word_near(image + 640*line_counter+pclk_counter) == 0 ? digitalWrite(DATA,HIGH) : digitalWrite(DATA,LOW);
}*/

//=======================================================================
//                MAIN LOOP
//=======================================================================
void loop()
{
  /*
  Serial.println("ALIVE");
  //HSYNC_HIGH;
  if(digitalRead(8)==HIGH){
   Serial.println("HIGH");
  }else if(digitalRead(8)==LOW){
    Serial.println("LOW");
  }*/
  digitalWrite(LED_BUILTIN, LOW);   // Turn the LED on (Note that LOW is the voltage level
  // but actually the LED is on; this is because
  // it is active low on the ESP-01)
  delay(1000);    
  //Serial.println("ALIVE");// Wait for a second
  digitalWrite(LED_BUILTIN, HIGH);  // Turn the LED off by making the voltage HIGH
  delay(2000); 
}

Can someone tell me why the ESP8266 keeps crashing?

Your post was MOVED to its current location as it is more suitable.

Have you considered that this :

#include "Arduino.h"

does not belong in an ESP sketch ?

It seems the main problem was that I used pin 8. This one is already used by the LED and I tried using it as an input. Once I switched the pin it was working fine

const int DATEN_CMD = 0; // D3
const int DATA = 2; //D4

The problem is not so much that you want to use them as an input, but you have to make sure that neither of these 2 pins (as well as pin GPIO 1) can be pulled 'LOW' at boot. That means that also if you use them as an output, you will need to make them 'active LOW'.

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