I am trying to do Arduino to ESP8266 communication, but I am not able to send data to esp8266. However I can receive data from esp8266.
Here if my Arduino code:
#include <SoftwareSerial.h>
SoftwareSerial ESPserial(0, 1); // RX | TX
void setup()
{
Serial.begin(115200); // communication with the host computer
// Start the software serial for communication with the ESP8266
ESPserial.begin(9600);
Serial.println("Enter 1 to turn led high & 2 to turn led low.");
}
// the loop function runs over and over again forever
void loop() {
// listen for communication from the ESP8266 and then write it to the serial monitor
if ( ESPserial.available() ) {
Serial.write( ESPserial.read() );
}
// listen for user input and send it to the ESP8266
if ( Serial.available() ) {
ESPserial.write( Serial.read() );
}
}
Here is esp8266 code:
void setup()
{
Serial.begin(9600); // communication with the host computer
// Start the software serial for communication with the ESP8266
// initialize digital pin LED_BUILTIN as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
Serial.println("ESP -- Hello");
delay(1000);
// listen for user input and send it to the ESP8266
if ( Serial.available() ) {
int ledState = Serial.parseInt();
if (ledState == 1) {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
Serial.println("ESP Led On\n");
}
if (ledState == 2) {
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
Serial.println("ESP Led Off\n");
}
}
}
Once I upload both sketches, then I can see it terminal " ESP -- Hello " keep printing comming from esp8266 but when I enter 1 or 2, its not sent to esp8266 due to which I never see "ESP led on/off" messages , so correct me guys what mistake I am making.
Serial
for Arduino to PC communication. – Majenko♦ Sep 19 '19 at 19:52