Kendziorra - Arduino NodeMCU v2 ESP8266-12E Shield - BOOST up your Arduino!
Print
Category: Arduino and ESP8266
Hits: 8039

User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active
 


BOOST your Arduino with this Shield

(click thumbnail)
Wiring, information and demo output

 Amica NodeMCU V2 DEVKIT with ESP8266-12E


NodeNCU v2 Shield:
Boost up your Arduino with this cheap ESP8266-12E Shield.
Use the 32 bit RISC CPU with 4 Mb memory, WiFi STA and/or AP, 2-32 GB micro SD card, 7 free GPIO and 1 Analog ports, 2 LEDs and 1 button. Then you can use your Arduino for important things like reading sensors, controlling stepper motors, ... .

Hardware Serial/USB:
Total unhindered to use for firmware flash and the debug monitors. No fiddling with jumpers and buttons.

SoftwareSerial 3.3V ↔ 5V:
Using a 5V Arduino? Use a 3.3V↔5V (Bi-Directional) 'Level Converter' to save your ESP8266.

Pull-up resistor:
Use a 10 kΩ pull-up resistor on te SS (Chip Select) line.

SD Filesystem:

 Demo sketches with Serial and Arduino SD library on the next two pages.


ESP8266:

/*  DEMO Arduino + NodeMCU Shield
 *   With softwareSerial and micro SD
 *   Edited SD and SoftwareSerial examples
 *****************************************/

#include <SPI.h>             // https://github.com/esp8266/Arduino
#include <SD.h>              // https://github.com/esp8266/Arduino
#include <SoftwareSerial.h>  // https://github.com/esp8266/Arduino
#include <Streaming.h>       // http://arduiniana.org/libraries/streaming

File root;
SoftwareSerial serial(D1, D2, false, 128);  // RX-D1->UNO-TX, TX-D2->UNO-RX

void listFiles();
void printDirectory(File, int);
void show(String);

void setup() {
  Serial.begin(115200);  // to monitor (DEBUG)
  serial.begin(38400);   // to Arduino
  while (!Serial) {};    // wait for serial port to connect. Needed for native USB port only
  for (uint8_t t = 5; t > 0; t--) { 
    Serial.println();
    Serial.flush();
    delay(1000);
  }

  show("\n\nESP8266 Software serial test started\n");
  listFiles();
  show("\nType text to send...\n");
}

void loop() {
  while (serial.available()) Serial << serial.readString();  // from Arduino
  while (Serial.available()) serial << Serial.readString();  // from ESP8266 Monitor to Arduino
}

void listFiles() {
  show("_______________________\nInitializing SD card...\n");
  if (!SD.begin(D4)) {
    show("initialization failed!\n");
    return;
  }
  show("initialization done.\n");
  root = SD.open("/");
  printDirectory(root, 0);
  show("SD card done!\n_______________________\n\n");
}

void printDirectory(File dir, int numTabs) {  // get a list of SD files 
   while(true) {
     File entry =  dir.openNextFile();
     if (! entry) {
       // no more files
       break;
     }
     for (uint8_t i=0; i<numTabs; i++) {
       show("\t");
     }
     show(entry.name());
     if (entry.isDirectory()) {
       show("/\n");
       printDirectory(entry, numTabs+1);
     } else {
       // files have sizes, directories do not
       show("\t\t");
       show(String(entry.size(), DEC) + "\n");
     }
     entry.close();
   }
}

void show(String s) {  // show it on Arduino and ESP8266 monitors
  Serial << s;
  serial << s;
}


Arduino:

/*  DEMO Arduino + NodeMCU Shield
 *   With softwareSerial and micro SD
 *   Edited SoftwareSerial example
 ************************************/

#include <SoftwareSerial.h>
// using serial.read(): If lost characters then try AltSoftSerial
//              =====
//#include <AltSoftSerial.h>  // http://www.pjrc.com/teensy/td_libs_AltSoftSerial.html 
#include <Streaming.h>  // http://arduiniana.org/libraries/streaming

SoftwareSerial serial(8, 9); //  RX-D8->ESP-TX, TX-D9->ESP-RX
//AltSoftSerial serial; //  RX-D8->ESP-TX, TX-D9->ESP-RX

String inBuf = "";

void setup() {
  Serial.begin(115200);
  serial.begin(38400);
  while (!Serial) {}  // wait for serial port to connect. Needed for native USB port only
  char s[] = "\n\nArduino Software serial test started\n";
  Serial << s;
  serial << s;
  Serial << "Wait for ESP8266 message...\n";
}

void loop() {
  while (serial.available()) Serial << (serial.readString());  // from ESP8266
  while (Serial.available()) serial << (Serial.readString());  // from Arduino Monitor to ESP8266

}