Enable Javascript


Last Arduino/ESP8266 project (click to open)

User Rating: 5 / 5

Star ActiveStar ActiveStar ActiveStar ActiveStar Active
 

Article Index

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

}