Arduino to esp8266-12 serial.read not working on ESP8266
Posted: Mon Dec 25, 2017 11:30 am
Hi i have have created a few Serial communication sketches in the past for Arduinos but never for a ESP8266,s and so i tried to use the Arduino library that allows me to use Arduino code and such on a ESP8266.
I have connected the Arduinos RX,TX pins to the ESP,s TX,RX pins and the ESP receives the data i am sending but it seems to print it directly to the Serial monitor over the usb connection instead of the coding reading it ?
I have tried using if (Serial.available) and while(Serial.available) to listen to the Serial data and Serial.read to record but neither work again it just prints the data as if it is passing directly through, why is it doing this ?
I have connected the Arduinos RX,TX pins to the ESP,s TX,RX pins and the ESP receives the data i am sending but it seems to print it directly to the Serial monitor over the usb connection instead of the coding reading it ?
I have tried using if (Serial.available) and while(Serial.available) to listen to the Serial data and Serial.read to record but neither work again it just prints the data as if it is passing directly through, why is it doing this ?
Code: Select all
#include <SoftwareSerial.h>
#include <Arduino.h>
#include <ESP8266WiFi.h> //https://github.com/esp8266/Arduino
#define USE_SERIAL Serial
char x = {0};
void setup() {
delay(2000);
USE_SERIAL.begin(9600);
USE_SERIAL.println();
USE_SERIAL.println();
USE_SERIAL.println(); // idk why you need to run this 3 times, but that what i read ?
USE_SERIAL.println("\n Starting");
}
void loop() {
if (USE_SERIAL.available()) {
while (USE_SERIAL.available()) {
x = USE_SERIAL.read(); // read one character from the Serial
USE_SERIAL.print("\n recived");
USE_SERIAL.println(x);
}
}
}