I can't load simple code to NodeMCU

Hi, I’ve just bought a NodeMCU v2 and I’m trying to test it with a simple program. The problem is that I can’t load it, I always receive one of the two errors in the attachments. How can I fix them?

This is the code:

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
Serial.println("Ciao Ciao");
delay(1000);
}

These are the errors:

Arduino: 1.8.9 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled, All SSL ciphers (most compatible), 4M (no SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

Sketch uses 262308 bytes (25%) of program storage space. Maximum is 1044464 bytes.
Global variables use 26660 bytes (32%) of dynamic memory, leaving 55260 bytes for local variables. Maximum is 81920 bytes.
esptool.py v2.6
2.6
esptool.py v2.6
Serial port COM3
Connecting........_____....._____....._____....._____....._____....._____....._____
Traceback (most recent call last):
  File "C:\Users\luigi\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2/tools/upload.py", line 25, in <module>
    esptool.main(fakeargs)
  File "C:/Users/luigi/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool\esptool.py", line 2653, in main
    esp.connect(args.before)
  File "C:/Users/luigi/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool\esptool.py", line 468, in connect
    raise FatalError('Failed to connect to %s: %s' % (self.CHIP_NAME, last_error))
esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Arduino: 1.8.9 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, Flash, Disabled, All SSL ciphers (most compatible), 4M (no SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

Sketch uses 262308 bytes (25%) of program storage space. Maximum is 1044464 bytes.
Global variables use 26660 bytes (32%) of dynamic memory, leaving 55260 bytes for local variables. Maximum is 81920 bytes.
esptool.py v2.6
2.6
esptool.py v2.6
Serial port COM3
Connecting........_____....._____....._____....._____....._____....._____.....____Traceback (most recent call last):
  File "C:\Users\luigi\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.5.2/tools/upload.py", line 25, in <module>
    esptool.main(fakeargs)
  File "C:/Users/luigi/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool\esptool.py", line 2653, in main
    esp.connect(args.before)
  File "C:/Users/luigi/AppData/Local/Arduino15/packages/esp8266/hardware/esp8266/2.5.2/tools/esptool\esptool.py", line 468, in connect
    raise FatalError('Failed to connect to %s: %s' % (self.CHIP_NAME, last_error))
esptool.FatalError: Failed to connect to ESP8266: Timed out waiting for packet header
_
the selected serial port _
 does not exist or your board is not connected

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Don't ever post pictures of text. Copy the text and paste it into your message.

That's the generic error you get when "something went wrong" and it's not getting any response from the ESP8266. I'm not sure what the troubleshooting steps are though, since the nodemcu doesn't have any room for wiring problems. Does the NodeMCU v2 have the thing that automatically resets the chip into upload mode, or is that one of the boards where you have to hold a button and press reset to put it into upload mode? I don't know which version of the NodeMCU added that, but I know most of the ones now are v3. You would probably have a better response on the forums dedicated to ESP8266 on Arduino - the ESP8266 on Arduino people mostly hang out there, not here.

did you select the right COM port?

DrAzzy:
Don't ever post pictures of text. Copy the text and paste it into your message.

That's the generic error you get when "something went wrong" and it's not getting any response from the ESP8266. I'm not sure what the troubleshooting steps are though, since the nodemcu doesn't have any room for wiring problems. Does the NodeMCU v2 have the thing that automatically resets the chip into upload mode, or is that one of the boards where you have to hold a button and press reset to put it into upload mode? I don't know which version of the NodeMCU added that, but I know most of the ones now are v3. You would probably have a better response on the forums dedicated to ESP8266 on Arduino - the ESP8266 on Arduino people mostly hang out there, not here.

There is a little rst button and I tried to press it but nothing changes

Juraj:
did you select the right COM port?

I selected the COM port that appears as Silicon Labs CP210x USB to UART Bridge into the Device Manager

Update: seems like the only way I have of loading the code is by keeping the button flash pressed during upload. That's weird, this is never mentioned anywhere. Do I have a faulty card?

This is what appears if I press flash while loading:

Sketch uses 257096 bytes (24%) of program storage space. Maximum is 1044464 bytes.
Global variables use 26540 bytes (32%) of dynamic memory, leaving 55380 bytes for local variables. Maximum is 81920 bytes.
esptool.py v2.6
2.6
esptool.py v2.6
Serial port COM3
Connecting....
Chip is ESP8266EX
Features: WiFi
MAC: 3c:71:bf:28:ec:b7
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Auto-detected Flash size: 4MB
Compressed 261248 bytes to 190910...

Writing at 0x00000000... (8 %)
Writing at 0x00004000... (16 %)
Writing at 0x00008000... (25 %)
Writing at 0x0000c000... (33 %)
Writing at 0x00010000... (41 %)
Writing at 0x00014000... (50 %)
Writing at 0x00018000... (58 %)
Writing at 0x0001c000... (66 %)
Writing at 0x00020000... (75 %)
Writing at 0x00024000... (83 %)
Writing at 0x00028000... (91 %)
Writing at 0x0002c000... (100 %)
Wrote 261248 bytes (190910 compressed) at 0x00000000 in 17.1 seconds (effective 122.5 kbit/s)...
Hash of data verified.

Leaving...
Hard resetting via RTS pin...

I have the same problem.

I think I have tried holding the reset button down while flashing, and it doesn't work for me.

I used to be able to flash them easily.

I am suspicious someone has changed the software to upload the flow and it doesn't work now.

I am not going to try with the one working one which I know works. But I can't use it for other reasons.

I tried another one which I had flashed before it also doesn't work.
Then I got a brand new one "out of the box, unopened". Doesn't work.

I am really suspicious of the software.

Did you put the "needed line" in the settings of the IDE?
(Control ,) (comma)

You scroll down towards the bottom and there is a part:
addition boards manager URL

You should have this in there.

http://arduino.esp8266.com/stable/package_esp8266com_index.json

But that doesn't fix the problem.

I'd say more but I seem to be not liked here when I post things.

Slight update:

I updated the board driver to one before the latest.

Set the baud rate to 57600 (you can try faster ones, but....)
I didn't use 115200.

Plugged it in, pressed (and held) the FLASH button.

Sketches can be uploaded.

Not the best solution, but it works at time of posting.

NOTE!

I have 2.5.0 installed for the esp8266.

Good luck and I hope you get it working.

P.S.
If you update to 2.5.1 you get the "problem" that it uploads but at the end it attempts to reset with a signal.
I don't know what is happening, but I can't get the sketch to work.