I am trying to use the Arduino IDE to program an ESP8266 (ESP-12F). I am able to upload a simple program that blinks the built-in led. As soon as I put a reference to Serial.begin()
anywhere in the code, my program no longer works. Even code that executes before the call to Serial.begin()
fails to run.
I am using the following code:
const int ledPin = 2;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
digitalWrite(ledPin, LOW);
delay(1000);
digitalWrite(ledPin, HIGH);
delay(2000);
// If this line is present, the led never turns on, not even the first time.
// Removing it makes the led blink, as expected.
Serial.begin(115200);
}
I am connecting the ESP as follows. It is probably not very relevant since I am able to upload and run code successfully as long as it does not attempt to use the serial port. I have also tried replacing the connection to RTS and DTR with push buttons to GND, and the result is the same.
What am I doing wrong ? How do I use the serial port on the ESP8266 ?
PS: I know that Serial.begin()
should not go inside the loop()
. I've only moved it there so that it happens after turning the led on.
Update
I tried to flash the latest firmware using the official tool, but this process always fails with an "Invalid head of packet" error. It seems to occur when writing the last packet, because if I flash a large file, it gives the error only at 99%.
After these attempts, I have been unable to make any program work. Even the simple led blinker without any Serial reference seems to do nothing, although the serial monitor shows the ESP boot messages.