[Solved]Need help to send data via Rx/Tx from ESP8266 ESP01 to Arduino Nano

Hello,

I am unsuccessfully trying to send specific data (temperature), from an ESP8266 ESP-01S WLAN WiFi Modul to an Arduino Nano using Rx/Tx pins on both ends. The ESP is separately supplied with 3.3V. Connection is the folloing;
Rx/Tx Tx/Rx

Here is the code I use for the sender (= ESP8266 ESP01):

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>  // http web access library
#include <ArduinoJson.h>        // JSON decoding library
#include <SoftwareSerial.h>
#include <TimeLib.h>

SoftwareSerial toUno(3, 1); //Rx, Tx partie NEW
 byte pinState = 0;
 
const char *ssid     = "xxx";
const char *password = "xxx-xxxx";
 
void setup() {

 toUno.begin(9600); //partie NEW
  Serial.begin(115200);
 
  delay(500);
  Serial.print("Connecting.");
 
  WiFi.begin(ssid, password);   // access Wi-FI point
 
  while ( WiFi.status() != WL_CONNECTED ) {
    delay(500);
    Serial.print(".");
  }
  
  Serial.println("connected\r\n");

internet();

toUno.print("From the ESP8266 OLAA"); //partie NEW
 
}
 
void loop() 
{
  internet();
  
  
  }

void internet()
{
 
  if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
 
    HTTPClient http;  //Declare an object of class HTTPClient
 
    // specify request destination
    http.begin("http://api.openweathermap.org/data/2.5/weather?q=Bt,pt&APPID=8b996a0dd66af5a4ada85678e81b013");
 
    int httpCode = http.GET();  // send the request
 
    if (httpCode > 0) { // check the returning code
 
      String payload = http.getString();   //Get the request response payload
 
    DynamicJsonBuffer jsonBuffer(512);
 
      // Parse JSON object
      JsonObject& root = jsonBuffer.parseObject(payload);
      if (!root.success()) {
        Serial.println(F("Parsing failed!"));
        return;
      }
 
      float temp = (float)(root["main"]["temp"]) - 273.15;        // get temperature
      int   humidity = root["main"]["humidity"];                  // get humidity
      float pressure = (float)(root["main"]["pressure"]) / 1000;  // get pressure
      float wind_speed = root["wind"]["speed"];                   // get wind speed
      int  wind_degree = root["wind"]["deg"];                     // get wind degree
 
      // print data
      Serial.printf("Temperature = %.2f°C\r\n", temp);
      Serial.printf("Humidity    = %d %%\r\n", humidity);
      Serial.printf("Pressure    = %.3f bar\r\n", pressure);
      Serial.printf("Wind speed  = %.1f m/s\r\n", wind_speed);
      Serial.printf("Wind degree = %d°\r\n\r\n", wind_degree);

toUno.write(toUno.read()); //partie NEW
delay(2000); //partie NEW

 
    http.end();   //Close connection
 
    }    }  
 
 delay(60000);   // wait 1 minute
 }

My questions:

  1. How do I tell ESP01 to send the data through the TX pin (Pin 1) to the Arduino? I use SoftwareSerial toUno(3, 1);
    but it seems not to work.

  2. How do I specify what data is to send, I only want to send temperature.

  3. Now, on the Arduino Nano, how do I tell Arduino to read the data on its Rx port coming from ESP and to print it ( here the temperature) in a Led matrix?

Thanks in advance for all information

before trying temperature, i would just try to send a string

if the esp is at 3.3V and the arduino is at 5V, won't you need something so that they transmit data at a voltage both can receive?

Thank you for the advice. It looks complicated to set a common voltage between both modules.

rs-485 interface chips make work because they use a balance signal (no ground)

Level shifters are not necessary. You can simply put 2K series resistors on the Rx and Tx lines between the two chips. That will limit the current to a safe level for the ESP chip.

Eureka!, but it is still not perfect.
I followed the recommendation to place a 2k resistance on each Rx/Tx connection. Finally I also connected the GND-cable coming from the 3.3V power supply to the Arduino GND pin, and it worked.
It’s not perfect, because the data coming from the ESP is incomplete and corrupted:

Temperature = 1.45°C
Humidity    = 93 %
Pressure    = 1.015 bar
Wind n=⸮T
emperature = 1.45°C
Humidity    = 93 %
Pressure    = 1.015 bar
Winp4

g6

Could it be that to much data is trying to flow through the Tx port at the same time? I tried to slow the flow by usind delay(20) after each value in the ESP code, but it did not help.

Thanks in advance for all suggestion to solve this.

Update: it is solved, I had to lower the BAUD to 9600 on ESP.

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