UART Communication ESP8266 - ArduinoUNO

Hello , again !
I think I’ve run into a problem with my project and I need a bit of guidance .
Im using an Arduino UNO to read data from some sensors and I’m sending that data to an ESP8266 through UART .
So something like :

#include <Arduino.h>

#include <SoftwareSerial.h>

SoftwareSerial espSerial(5, 6); // I made the pin 5 = Rx , 6 =Tx .

espSerial.begin(9600);

void loop() {

    espSerial.println(data);

}

And on the ESP side, Im using the Rx/Tx pins and Im just reading from the serial :

Serial.readStringUntil('\n');

This is just an example , not exactly my code .
Anyway , my problem is that I need to receive data on my esp AND send some other data back to Arduino , at the same time .

Can I achieve this with UART ? Or do I need to change my aproach to I2C ?

I’m not quite sure what the actual question is - do you just want the ESP8266 and the Uno to have bi-directional communication - i.e. two-way communications? As if so, well, you do have transmit and receive lines for each (which are buffered) so it’s just a matter of sending data from one device to the other, and each device periodically it’s buffer ( i.e. if (Serial.available() > 0) ) to see if there is a message waiting from the other device.

If it’s more a question of sending data to the Uno whilst the ESP8266 is receiving… that could be interesting… and would probably work. I don’t think I2C will fix that problem, as AFAIK it would still require only one device to talk at a time. i.e. first in best dressed. But because of the serial buffers, I don’t see why you couldn’t send messages to the Uno whilst it was sending to the ESP8266, as it would simply collect in the hardware buffer until the Uno was finished sending.

Sorry for replaying so late .
Yes, the question is how to send data from Arduino to ESP , and also receive , at the same time . Basically, I’ve tried but it didnt work , so im asking for some code on how to do it, and what connections should I make , hardware .

Since you’re connecting Serial RX of the first device to TX of the other, and TX of the first to the RX of the other, either device should be able to talk to and AND listen to each other. I hope you have kept in mind that the ESP8266 is a 3v3 logic-level part, and that the Arduino Uno is a 5v logic-level part, so you need to use a level shifter of some description - where it be a voltage divider or a dedicated level shifter breakout/IC.

And really, since this is a crossover, they should actually be able to talk at the same time - it is just a matter of structuring the code so it can handle that - you don’t don’t the code to block - just keep sucking in the message from the other side until it hits the \n or whatever ‘end of message’ delimiter you use.

The other problem you might face is that of debugging - since if you use the hardware serial port on each device, how do you do any debugging of what is happening with the device, without interfering with the two devices talking together. The solution is to use software serial on both devices, leaving the hardware serial free on both for debugging messages. This post from the Arduino forum might help… serial communication between esp8266 and arduino - Programming Questions - Arduino Forum