NodeMCU/ESP8266 - Can't get blink to work. Upload seems to work?

I have a NodeMCU and I struggled for a long while getting "espcomm_sync failed" but I found that I should hold the flash button, then reset, then release flash, and it seems to have made it accept my uploads.

However, the sketch doesn't seem to run. All I have is the NodeMCU connected via USB. When I press upload, the "writing flash" shows for a long time, and the LED blinks for maybe 20 seconds, but then when it's ready, nothing blinks.

I'm using the Arduino IDE, but I tried using Deviot too, but I still get the "espcomm_sync failed" in there.

The brand of the NodeMCU is Hysiry, looks a little bit larger than AI-Thinker which seems to be the more common one. Not sure if it's broken or something.

Here's my sketch and build output:

Blink.ino

void setup() {
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}

Build output

Build options changed, rebuilding all
Archiving built core (caching) in: /var/folders/48/59_lz30x1sz9qdxt5db0qj4c0000gn/T/arduino_cache_409699/core/core_esp8266_esp8266_generic_CpuFrequency_80,FlashFreq_40,FlashMode_dio,UploadSpeed_115200,FlashSize_512K64,ResetMethod_nodemcu,Debug_Disabled,DebugLevel_None_____1484efb33042dc08697d88ee21bc3886.a
Sketch uses 219443 bytes (50%) of program storage space. Maximum is 434160 bytes.
Global variables use 31136 bytes (38%) of dynamic memory, leaving 50784 bytes for local variables. Maximum is 81920 bytes.
/Users/niclas/Library/Arduino15/packages/esp8266/tools/esptool/0.4.8/esptool -vv -cd nodemcu -cb 115200 -cp /dev/cu.wchusbserial1460 -ca 0x00000 -cf /var/folders/48/59_lz30x1sz9qdxt5db0qj4c0000gn/T/arduino_build_694141/Blink.ino.bin 
esptool v0.4.8 - (c) 2014 Ch. Klippel <ck@atelier-klippel.de>
	setting board to nodemcu
	setting baudrate from 115200 to 115200
	setting port from /dev/tty.usbserial to /dev/cu.wchusbserial1460
	setting address from 0x00000000 to 0x00000000
	espcomm_upload_file
	espcomm_upload_mem
opening port /dev/cu.wchusbserial1460 at 115200
	tcgetattr
	tcsetattr
	serial open
opening bootloader
resetting board
trying to connect
	setting character timeout 0
	done
	setting character timeout 1
	done
	espcomm_send_command: sending command header
	espcomm_send_command: sending command payload
trying to connect
	setting character timeout 0
	done
	setting character timeout 1
	done
	espcomm_send_command: sending command header
	espcomm_send_command: sending command payload
	espcomm_send_command: receiving 2 bytes of data
	espcomm_send_command: receiving 2 bytes of data
	espcomm_send_command: receiving 2 bytes of data
	espcomm_send_command: receiving 2 bytes of data
	espcomm_send_command: receiving 2 bytes of data
	espcomm_send_command: receiving 2 bytes of data
	espcomm_send_command: receiving 2 bytes of data
	espcomm_send_command: receiving 2 bytes of data
Uploading 223584 bytes from to flash at 0x00000000
	erasing flash
	size: 036960 address: 000000
	first_sector_index: 0
	total_sector_count: 55
	head_sector_count: 16
	adjusted_sector_count: 39
	erase_size: 027000
	espcomm_send_command: sending command header
	espcomm_send_command: sending command payload
	setting timeout 15000
	setting character timeout 150
	done
	setting timeout 1
	setting character timeout 1
	done
	espcomm_send_command: receiving 2 bytes of data
	writing flash
...
starting app without reboot
	espcomm_send_command: sending command header
	espcomm_send_command: sending command payload
	espcomm_send_command: receiving 2 bytes of data
closing bootloader

I appreciate any ideas to get it working! :slight_smile:

I remember someone saying that there is a variant of the NodeMCU board that has the LED connected to a different pin than normal. Try it with a specific pin and connect an external LED or a multimeter to that pin to verify that it's blinking. If so you will either need to do some research or just trial and error to figure out which pin the onboard LED is connected to.

hmm! I connected a LED to D2, and used pinMode(4, OUTPUT); according to some schematics, this is GPIO4, and it blinks! Amazing!

So I guess LED_BUILTIN just doesn't work as it should.

Thanks for the help :slight_smile:

The NodeMCU variant defines LED_BUILTIN as 16, which is also known as D0.

A tricky thing about the ESP8266 core is they use the Dn pin name scheme. Sometimes you will see references to pins on other Arduino boards with this syntax but when they say D13 they actually mean pin 13 used in the digital mode. With the ESP8266 this is not the case. If it says D2 on the silkscreen you have to use D2 in your code, not 2. Or in this case you can use 4 because that's the value defined for D2 in the NodeMCU variant but that's kind of confusing. This definitely had me stumped for a while when I first used an ESP8266. I thought I had gotten a weird board with a non-standard PCB design.