Sunday, March 20, 2016

Blink NodeMCU on-board LED using Arduino IDE with ESP8266 core for Arduino, and more examples


To program NodeMCU in Arduino IDE, we have to install esp8266 board (ESP8266 core for Arduino) to Arduino IDE.

Add Additional Board Manager URL for ESP8266 board:
> File > Preference

Add "http://arduino.esp8266.com/stable/package_esp8266com_index.json" in Additional Board Manager URLs.


Add ESP8266 board to Arduino IDE:
- Open Boards Manager in Arduino IDE
- Search "esp8266" or "NodeMCU", you will find "esp8266 by ESP8266 Community". Install it.


Test:
Once esp8266 board installed, you can find an example to blink the on-board LED.
File > Examples > ESP8266 > Blink

/*
 ESP8266 Blink by Simon Peter
 Blink the blue LED on the ESP-01 module
 This example code is in the public domain
 
 The blue LED on the ESP-01 module is connected to GPIO1 
 (which is also the TXD pin; so we cannot use Serial.print() at the same time)
 
 Note that this sketch uses LED_BUILTIN to find the pin with the internal LED
*/

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);     // Initialize the LED_BUILTIN pin as an output
}

// the loop function runs over and over again forever
void loop() {
  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 acive low on the ESP-01)
  delay(1000);                      // Wait for a second
  digitalWrite(LED_BUILTIN, HIGH);  // Turn the LED off by making the voltage HIGH
  delay(2000);                      // Wait for two seconds (to demonstrate the active low LED)
}

You can upload it to NodeMCU, to toggle the on-board LED.


notice:
- Once the ModeMCU programmed, the original firmware will be erased. To restore the original firmware with Lua shell, you have to flash the firmware again.

Control GPIO (external IO pins) of NodeMCU (ESP8266) with ESP8266 core for Arduino

Next:
Read NodeMCU MAC address using Arduino IDE with esp8266 library
Get my IP address
Run diagnosis
NodeMCU to read analog input, A0
NodeMCU act as WiFi client to update dweet.io
Display on 128x64 I2C OLED, using Adafruit SSD1306 and GFX libraries
esp8266-OLED, another esp8266-Arduino library for I2C-OLED displays
NodeMCU/ESP8266 act as AP (Access Point) and simplest Web Server
NodeMCU/ESP8266 act as AP (Access Point) and web server to control GPIO
NodeMCU/ESP8266 implement WebSocketsServer to control RGB LED
NodeMCU/ESP8266 WebSocketsServer, load html from separate file in flash file system
Read Buttons and write LEDs
NodeMCU/ESP8266 Arduino Core analog output PWM
Simple http server to output PWM, to set color/brightness of RGB LED
Install Arduino IDE on Raspberry Pi/Raspbian Jessie with PIXEL and Add Arduino core for ESP8266 to Arduino IDE (run on Raspberry Pi/Raspbian Jessie with PIXEL)

1 comment:

  1. Hi, good sample! It used by default in arduino esp8266 board sketch examples.
    Could you point me how I should use GPIO5 which is D1 in nodemcu board. What is pin name?

    ReplyDelete