Skip to content

Instantly share code, notes, and snippets.

@jhorsman jhorsman/main.cpp
Created Jan 26, 2018

Embed
What would you like to do?
Blink for Node MCU; Blinking the builtin led on GPIO pin 2.
/**
* Blink for Node MCU
* also see https://arduino.stackexchange.com/questions/38477/does-the-node-mcu-v3-lolin-not-have-a-builtin-led
*
* Turns on an LED on for one second,
* then off for one second, repeatedly.
*/
#include "Arduino.h"
// On a NodeMCU board the built-in led is on GPIO pin 2
#define LED_BUILTIN 2
void setup()
{
Serial.begin(14400);
// initialize LED digital pin as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
Serial.println("Node MCU blink!");
// turn the LED on (the built-in led on a Node MCU board is active low)
digitalWrite(LED_BUILTIN, LOW);
// wait for a second
delay(1000);
// turn the LED off (the built-in led on a Node MCU board is active low)
digitalWrite(LED_BUILTIN, HIGH);
// wait for a second
delay(1000);
}
@AakashPandey

This comment has been minimized.

Copy link

commented Apr 17, 2018

Do you know how to do this with lua ? I tried pin 2 & pin 0 but it doesn't seem to work.

@Bartvelp

This comment has been minimized.

Copy link

commented May 27, 2018

@AakashPandey
I dont understand why but you should use GPIO 4 (?)
for turning it on:

gpio.mode(4,gpio.OUTPUT)
gpio.write(4, 0)

For turning it off

gpio.mode(4,gpio.OUTPUT)
gpio.write(4, 1)
@flywire

This comment has been minimized.

Copy link

commented Jan 3, 2019

I dont [sic]understand why but you should use GPIO 4 (?)

It's confusing with esp8266 modules because pin numbers on board don't map to GPIO - Pin D4 is actually GPIO2.

Lua must be using board pin numbers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.