Skip to main content
added 32 characters in body
Source Link
Ikbel
  • 620
  • 4
  • 13

First, you need a SoftwareSerial interface, since the hardware serial is already used for debugging. To setup a SoftwareSerial this is an example:

#include <SoftwareSerial.h>

const byte rxPin = 6; // Wire this to Tx Pin of ESP8266
const byte txPin = 7; // Wire this to Rx Pin of ESP8266

// We'll use a software serial interface to connect to ESP8266
SoftwareSerial ESP8266 (rxPin, txPin);

void setup() {
  Serial.begin(115200);
  ESP8266.begin(115200); // Change this to the baudrate used by ESP8266
  delay(1000); // Let the module self-initialize
}

void loop() {
  while (ESP8266.available()){
     String inData = ESP8266.readStringUntil('\n');
     Serial.println("Got Data from ESP8266: " + inData);
     // The rest of your code...
  }  
}

To send data from ESP8266 back to Arduino try something like this:

uart.setup(0, 115200, 8, 0, 1, 1 ) -- Change the baudrate to 115200
-- A simple http server
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
    conn:on("receive",function(conn,payload)
        payload = payload + "\n"
        uart.write(0, payload) -- send it back to Arduino via Serial interface
    end)
      conn:on("sent",function(conn) conn:close() end)
    end)
    
uart.on("data", function(data) 
    -- When ESP8266 receives data from Arduino, it will trigger this event
end, 0)

First, you need a SoftwareSerial interface, since the hardware serial is already used for debugging. To setup a SoftwareSerial this is an example:

#include <SoftwareSerial.h>

const byte rxPin = 6; // Wire this to Tx Pin of ESP8266
const byte txPin = 7; // Wire this to Rx Pin of ESP8266

// We'll use a software serial interface to connect to ESP8266
SoftwareSerial ESP8266 (rxPin, txPin);

void setup() {
  Serial.begin(115200);
  ESP8266.begin(115200); // Change this to the baudrate used by ESP8266
  delay(1000); // Let the module self-initialize
}

void loop() {
  while (ESP8266.available()){
     String inData = ESP8266.readStringUntil('\n');
     Serial.println("Got Data from ESP8266: " + inData);
     // The rest of your code...
  }  
}

To send data from ESP8266 back to Arduino try something like this:

uart.setup(0, 115200, 8, 0, 1, 1 ) -- Change the baudrate to 115200
-- A simple http server
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
    conn:on("receive",function(conn,payload)
        uart.write(0, payload) -- send it back to Arduino via Serial interface
    end)
      conn:on("sent",function(conn) conn:close() end)
    end)
    
uart.on("data", function(data) 
    -- When ESP8266 receives data from Arduino, it will trigger this event
end, 0)

First, you need a SoftwareSerial interface, since the hardware serial is already used for debugging. To setup a SoftwareSerial this is an example:

#include <SoftwareSerial.h>

const byte rxPin = 6; // Wire this to Tx Pin of ESP8266
const byte txPin = 7; // Wire this to Rx Pin of ESP8266

// We'll use a software serial interface to connect to ESP8266
SoftwareSerial ESP8266 (rxPin, txPin);

void setup() {
  Serial.begin(115200);
  ESP8266.begin(115200); // Change this to the baudrate used by ESP8266
  delay(1000); // Let the module self-initialize
}

void loop() {
  while (ESP8266.available()){
     String inData = ESP8266.readStringUntil('\n');
     Serial.println("Got Data from ESP8266: " + inData);
     // The rest of your code...
  }  
}

To send data from ESP8266 back to Arduino try something like this:

uart.setup(0, 115200, 8, 0, 1, 1 ) -- Change the baudrate to 115200
-- A simple http server
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
    conn:on("receive",function(conn,payload)
        payload = payload + "\n"
        uart.write(0, payload) -- send it back to Arduino via Serial interface
    end)
      conn:on("sent",function(conn) conn:close() end)
    end)
    
uart.on("data", function(data) 
    -- When ESP8266 receives data from Arduino, it will trigger this event
end, 0)
Source Link
Ikbel
  • 620
  • 4
  • 13

First, you need a SoftwareSerial interface, since the hardware serial is already used for debugging. To setup a SoftwareSerial this is an example:

#include <SoftwareSerial.h>

const byte rxPin = 6; // Wire this to Tx Pin of ESP8266
const byte txPin = 7; // Wire this to Rx Pin of ESP8266

// We'll use a software serial interface to connect to ESP8266
SoftwareSerial ESP8266 (rxPin, txPin);

void setup() {
  Serial.begin(115200);
  ESP8266.begin(115200); // Change this to the baudrate used by ESP8266
  delay(1000); // Let the module self-initialize
}

void loop() {
  while (ESP8266.available()){
     String inData = ESP8266.readStringUntil('\n');
     Serial.println("Got Data from ESP8266: " + inData);
     // The rest of your code...
  }  
}

To send data from ESP8266 back to Arduino try something like this:

uart.setup(0, 115200, 8, 0, 1, 1 ) -- Change the baudrate to 115200
-- A simple http server
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
    conn:on("receive",function(conn,payload)
        uart.write(0, payload) -- send it back to Arduino via Serial interface
    end)
      conn:on("sent",function(conn) conn:close() end)
    end)
    
uart.on("data", function(data) 
    -- When ESP8266 receives data from Arduino, it will trigger this event
end, 0)