Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By edwin martin
#72693 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 ?

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);
        }
      }
    }
User avatar
By edwin martin
#72718 Never mind I have the serial from the arduino going to the esp and my code reading it perfectly, i found no tutorials on it though and it took me the good part of xmas night :roll:

Any how use the software serial on pins 13,15 for and go from there. my code is for company use so i cant share it all but its not hard, i am just sending 12 ints or floats and some strings so i used start and stop chars no libraries are needed except software serial.

Please close this post. thank you

#include <SoftwareSerial.h>
SoftwareSerial mySerial(13, 15); // RX, TX nodemcu

void setup() {
Serial.begin(9600);
mySerial.begin(9600);
pinMode(13, OUTPUT);
delay(2000);
Serial.println("started");
}

loop() {
char e = mySerial.read();
if (e == '#') {
Serial.println("hash");
}
}
User avatar
By mrburnette
#72893
edwin martin wrote:Never mind I have the serial from the arduino going to the esp and my code reading it perfectly, i found no tutorials on it though and it took me the good part of xmas night :roll:

Any how use the software serial on pins 13,15 for and go from there.
}


Well, that is one way to "make" it work, but I would suggest you read:
https://arduino-esp8266.readthedocs.io/en/latest/reference.html#serial

There is no reason you cannot utilize the hardware serial. If you were using a NodeMCU or similar with USB, then the primary serial is generally consumed by the USB interface on the composite board.

Ray
My stuff