Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
SOTM
Published © CC BY-NC-SA

Using NodeMCU ESP2866 Boards with Arduino IDE Sketches

We love NodeMCU ESP8266 and Lua, but sometimes we want to take advantage of the Arduino IDE. This tip shows how to.

BeginnerProtip1 hour3,304
Using NodeMCU ESP2866 Boards with Arduino IDE Sketches

Things used in this project

Hardware components

NodeMCU ESP8266
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

Our NodeMCU ESP8266 Test Sketch

Arduino
/*
 *  Test sketch to validate NodeMCU ESP8266 is working
 *  
 *  Server On The Move
 */
#include "ESP8266WiFi.h"
 
void setup() {
  Serial.begin(115200);
 
  // Enable station mode and - just in case - disconnect from previous Wifi
  WiFi.mode(WIFI_STA);
  WiFi.disconnect();
  delay(100);
 
  Serial.println("Setup complete");

  // Set Built-in LED to output
  pinMode(LED_BUILTIN, OUTPUT);
}
 
void loop() {
  Serial.println("Start Scanning - please stand-by");
 
  int n = WiFi.scanNetworks(); // how many did we find ?
  
  Serial.println("Scanning complete");

  // nothing found :-(
  if (n == 0)
    Serial.println("No Networks found.");
  else
  // found something
  {
    Serial.print("Networks found: ");
    Serial.println(n);
    for (int i = 0; i < n; ++i)
    {
      // Show each SSID and its RSSI (quality of network).
      // Mark encrypted networks with a "*"
      Serial.print(i + 1);
      Serial.print(": ");
      Serial.print(WiFi.SSID(i));
      Serial.print(" (");
      Serial.print(WiFi.RSSI(i));
      Serial.print(")");
      Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*");
      delay(10);
    }
  }
  Serial.println("Performing Flash of BUILTIN LED");

  // Do LED blink
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(250);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(150);                       // wait for a second
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(250);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(150);                       // wait for a second
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(500);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  
  // Wait a bit before scanning again
  delay(5000);
}

Credits

SOTM
7 projects • 4 followers
Contact

Comments

Please log in or sign up to comment.