1

I am trying to connect a nodeMCU to arduino mega using serial communication so that i can read data from firebase.

I have put the following code on the NODEMCU.

#include<SoftwareSerial.h> //Included SoftwareSerial Library
//Started SoftwareSerial at RX and TX pin of ESP8266/NodeMCU
SoftwareSerial s(3,1);

void setup() {
  //Serial S Begin at 9600 Baud
  s.begin(9600);
}

void loop() {
  //Write '123' to Serial
  s.write('h');
  delay(1000);
}

And the following on the MEGA

int data; //Initialized variable to store recieved data

void setup() {
  //Serial Begin at 9600 Baud 
  Serial.begin(9600);
  Serial1.begin(9600);
}

void loop() {
  if(Serial1.available()){
  data = Serial1.read(); //Read the serial data and store it
  delay(1000);
  Serial.print(data);}
}

I have connected TX1(arduino) to RX(nodeMCU) and RX1(arduino) to TX(nodeMCU) yet when ever i upload the code it doesnt work until i press the reset button then some random numbers are passed over then eventually 123 comes accross. I am trying to do 2 way comunication but will worry about that when i finish this.

Any help would be much appreciated as I have spent the last 15 hours trying to solve this problem but to no avail. Cheers, Hamish

  • you did not say how you connected the two controllers together ... please list all wires and all pins – jsotola Jun 25 at 23:17
  • Why not use the standard Serial instead of SoftwareSerial? – Sim Son Jun 26 at 11:50
  • you use old esp8266 SoftwareSerial on hardware Serial pins of the esp8266. and you set the pins swapped in the SoftwareSerial constructor – Juraj Jun 27 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.