Below is a quick review of the NodeMCU v1.0 Dev Kit board microcontroller that can be picked up for under $10. NodeMCU is an open-source IoT platform based on the ESP8266 Wi-Fi SoC.
Specs:
I ordered 1x Node MCU v1.0 with Free delivery from eBay seller 19star-au for $10.94.
I have played with Arduinos and having Wifi in a small microcontroller by default is appealing.
How to program your NodeMCU
- Goto www.arduino.cc and download the Arduino IDE (1.8.x or higher).
- Open the Arduino IDE and find the Preferences Menu
- Paste the following in the “Additional Boards Manager” textbbox: http://arduino.esp8266.com/stable/package_esp8266com_index.json
- Goto Tools, Boards*, Boards manager and search for “esp8266” and install it.
- Close your Arduino IDE and reopen it.
- Now choose your board type in the Arduino IDE (Tools, Board, Node MCU, 1.0 ESP-12E..)
You will not be able to select a sample script (e.g Blink) by navigating to File, Examples, ESP8266, Blink.
The Blink code will look like this:
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 active 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 now plug the ESP8266 in and try compile and upload the new sketch to the device.
Mac Troubleshooting: If the Arduino IDE says you do not have a serial port you may need to download the USB-Serial driver from silabs.
If all goes well you will have a blinking light on your ESP8266.
Now lets try the web server sketch
#include <ESP8266WiFi.h> #include <WiFiClient.h> #include <ESP8266WebServer.h> #include <ESP8266mDNS.h> const char* ssid = "yourwifinetwork"; const char* password = "yourwifipassword"; ESP8266WebServer server(80); const int led = 13; void handleRoot() { digitalWrite(led, 1); server.send(200, "text/plain", "hello from esp8266!"); digitalWrite(led, 0); } void handleNotFound(){ digitalWrite(led, 1); String message = "File Not Found\n\n"; message += "URI: "; message += server.uri(); message += "\nMethod: "; message += (server.method() == HTTP_GET)?"GET":"POST"; message += "\nArguments: "; message += server.args(); message += "\n"; for (uint8_t i=0; i<server.args(); i++){ message += " " + server.argName(i) + ": " + server.arg(i) + "\n"; } server.send(404, "text/plain", message); digitalWrite(led, 0); } void setup(void){ pinMode(led, OUTPUT); digitalWrite(led, 0); Serial.begin(115200); WiFi.begin(ssid, password); Serial.println(""); // Wait for connection while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.print("Connected to "); Serial.println(ssid); Serial.print("IP address: "); Serial.println(WiFi.localIP()); if (MDNS.begin("esp8266")) { Serial.println("MDNS responder started"); } server.on("/", handleRoot); server.on("/inline", [](){ server.send(200, "text/plain", "this works as well"); }); server.onNotFound(handleNotFound); server.begin(); Serial.println("HTTP server started"); } void loop(void){ server.handleClient(); }
A quick check of my routers DHCP list and I found the ESP8266 listening for web requests at 192.168.1.110.
More to come….
Donate and make this blog better
Ask a question or recommend an article
[contact-form-7 id=”30″ title=”Ask a Question”]