Problem with sending and/or recieving data from Mega2560 to esp8266

Hello,
Im using Wemos NodeMCU V3 32mb wifi module with a level converter and arduino mega.
I connected the converter as in this tutorial, under label "Using the BD-LLC for Serial" (I dont really understand this part: " Although you won't be taking advantage of the BD-LCC's bi-directional abilities, it's perfectly fine to use the board to shift serial communication"):

https://learn.sparkfun.com/tutorials/bi-directional-logic-level-converter-hookup-guide

I used exact same level converter and tried to send data from arduino using many different ways. The code for sender(arduino) looks like this:

#include <SoftwareSerial.h>
SoftwareSerial espSerial(19, 18);
String str;
void setup(){
Serial.begin(9600);
Serial1.begin(9600);
espSerial.begin(9600);
delay(2000);
}
void loop()
{
Serial.print("H: ");
Serial.print("% ");
Serial.print(" T: ");
Serial.println("C");
Serial1.print("H: ");
Serial1.print("% ");
Serial1.print(" T: ");
Serial1.println("C");
espSerial.write("H: ");
espSerial.write("% ");
espSerial.write(" T: ");
espSerial.write("C");
espSerial.print("H: ");
espSerial.print("% ");
espSerial.print(" T: ");
espSerial.print("C");
delay(1000);
}

and code for reciever(Wemos wifi) looks like that:

#include <SoftwareSerial.h>

SoftwareSerial espSerial = SoftwareSerial(5, 4);

void setup() {
pinMode(5, INPUT);
pinMode(4, OUTPUT);
espSerial.begin(9600);
Serial.begin(9600);
}

void loop() {

if(Serial.available()){
  Serial.print(espSerial.read());
}
delay(10);
}

I programmed what i wanted the arduino to do in a different program and now i just want to test sending and recieving data. The problems are:

  1. after some edits/rewireing serial on Wemos shows nothing, i suppose because Serial.available() is not true
  2. Serial from Wemos shows only blank squares .

Of course i connected RX to TX and so on, so thats should not be the problem.

The final project is supposed to collect data from sensors(on arduino), and send them to a web server. A part with collecting data is ready and working well, and same for the one sending data to server. I just cant transfer the sensor data from mega to wemos.

any advice would be awesome, as im not experienced, in fact im completly new to recieve/send projects.

Thanks in advance

Hi @marcomur,

Welcome! Do you have your ESP RX and TX pins attached to the Mega's D19 and D18 pins?

Hi, yes i had the pins connected and i think i solved the problem, after 2 days of trying.

So i edited the code for arduino to look like this:

#include <SoftwareSerial.h>

void setup(){

Serial1.begin(9600);

}

void loop()

{

Serial1.write(1);

Serial1.write(2);

Serial1.write(3);

Serial1.write(4);

}

And in my many attempts to make it work i made ports 19 and 18 as software serial, but they were already hardware serial ports, and it made the program to bug.

But now i have another problem my wemos serial looks like that

-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-11234-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-1-11234-1-1-1

do you know how to get rid of these -1s? is there a function that only gets serial when its not empty?

Did you alter your ESP code also? If so could you please post it? You can remove the SoftwareSerial library from your above code. Also try adding a delay in the loop after the serial writes.

Have you changed your esp sketch as follows:

#include <SoftwareSerial.h>

SoftwareSerial espSerial(5, 4);//SRX = 5, STX = 4;

void setup() 
{
    //pinMode(5, INPUT);
    //pinMode(4, OUTPUT);
    espSerial.begin(9600);
    Serial.begin(9600);
}

void loop() 
{
     if(espSerial.available())
     {
          Serial.print(espSerial.read());
     }
     delay(10);
}

I will be able to check the code and send it on monday, because all my work is now stuck at my workplace. I will reply and check your edits, and post wemos code then.
Thanks in advance

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.