Category Archives: Internet of Things

NodeMCU: ESP8266 Arduino JSON parsing example

In this tutorial we learn How to encode and decode json on NodeMCU using Arduino IDE? we will be using the ArduinoJson library for the ESP8266 to help us parse JSON data and extract values based on keys. The ArduinoJson library is also capable of serializing JSON, meaning you could generate your own JSON data using data from sensors connected to your ESP8266 or Arduino.

ESP8266 JSON Example

Continue reading NodeMCU: ESP8266 Arduino JSON parsing example

RFID Reader MFRC522 interface with NodeMCU using Arduino IDE

In this tutorial we will learn How to interface NodeMCU with RC522 RF ID Reader using Arduino library for MFRC522 and other RFID RC522 based modules.

This library read and write different types of Radio-Frequency IDentification (RFID) cards on your Arduino or NodeMCU using a RC522 based reader connected via the Serial Peripheral Interface (SPI) interface. Before we move to actual code lets know more about RF ID.

RF ID Reader MFRC-522
RF ID Reader

Continue reading RFID Reader MFRC522 interface with NodeMCU using Arduino IDE

Arduino NodeMCU (ESP8266) Spiffs File System Uploading and Reading

In this tutorial we upload a text file and read it in serial monitor.

Steps to Upload a file in NodeMCU SPIFFS file system

ESP8266FS is a tool which integrates into the Arduino IDE. It adds a menu item to Tools menu for uploading the contents of sketch data directory into ESP8266 flash file system.

  • Restart Arduino IDE
  • Open a sketch (or create a new one and save it)
  • Go to sketch directory (choose Sketch > Show Sketch Folder)
  • data older next to your .ino file
  • Create a directory named data and put your files you want in the file system there

  • Make sure you have selected a board, port, and closed Serial Monitor
  • Select Tools > ESP8266 Sketch Data Upload. This should start uploading the files into ESP8266 flash file system. When done, IDE status bar will display SPIFFS Image Uploaded message. Note during upload it takes longer time.

 

Reading Uploaded File

In above process we uploaded notes.txt file in ESP flash. In this program we read it and display its contents in serial monitor. Uploading of sketch will not affect sketch data. i.e. uploaded notes.txt file.

/*
 *  ESP8266 Communication and Protocols
 *  SPIFFS Direct File Upload Example
 *  -Manoj R. Thkuar
 */

#include <ESP8266WiFi.h>
#include <FS.h>   //Include File System Headers

const char* file = "/notes.txt";   //Enter your file name

void setup() {
  delay(1000);
  Serial.begin(115200);
  Serial.println();

  //Initialize File System
  SPIFFS.begin();
  Serial.println("File System Initialized");

  File dataFile = SPIFFS.open(file, "r");   //Open File for reading
  Serial.println("Reading Data from File:");
  //Data from file
  for(int i=0;i<dataFile.size();i++) //Read upto complete file size
  {
    Serial.print((char)dataFile.read());    //Read file
  }
  dataFile.close();
}

void loop() {
}

 

Results


In serial monitor you will get File contents, you can upload images, html and javascript files. examples can be found here

  1. Image upload and display
  2. JavaScript Gauges

Add NodeMCU ESP8266 to Arduino IDE

In this tutorial, we’ll learn how to program your NodeMCU or ESP8266 using an Arduino IDE. NodeMCU board is not available by default.

The NodeMCU ESP8266 is a low-cost WiFi module built by Espressif Systems. Its popularity has been growing among the hardware community thanks to its nice features and stability, to the point that it can be easily programmed using your Arduino IDE.

Requirements

  1. Arduino IDE version 1.7 or higher
  2. Active Internet connection
  3. NodeMCU or ESP8266 board (for testing only)

Step 1: Adding ESP8266 URL to Arduino IDE Board Manger

  1. Make sure you are using Arduino IDE version 1.7 or higher.
  2. Add additional URL for board manager. Go to File >> Preferences and paste below url in Additional Board Manager URLs.                                                               http://arduino.esp8266.com/stable/package_esp8266com_index.json

JSON URL for ESP8266 in Arduino IDE

Note: Sometimes pakage_esp8266com_index.json link is down due to heavy download try again after few hours.

Step 2: Open Board Manager

  1. Go to Tools >> Boards >> Board Manager

Board Mnanger Link

Step 3: Search and Installing Node MCU (ESP8266) in Arduino IDE

  1. Type “ESP8266” in search box.
  2. Select ESP8266 Community. (If internet is not available then you will not find ESP8266)
  3. Click on Install Button. Download progress starts. wait for finish.
Install NodeMCU
Installing ESP8266

Step 4: Verify installation of ESP8266

  1. Go to Tools>>Boards>> select NodeMCU (If you don’t find NodeMCU, check your installation is ok)
  2. Select proper Com port
  3. Upload blink example and check is it working. on board LED uses GPIO2
NodeMCU board in Arduino IDE
NodeMCU board is visible

Additional Resources

  1. Installing ESP32 in Arduino IDE
  2. Getting Started with ESP8266
  3. ESP8266 IOs
  4. NodeMCU Pin Numbers and Confusions (Must read)