Unable to get data in right format when sending data from Arduino Uno to NodeMCU

I’m trying to interface BMP-180 sensor (Barometric Sensor) to Arduino Uno and Send the Sensor data to NodeMCU. I’m trying to see the data received in the Serial Monitor of NodeMCU and find that the data is not in the right format which I’m seeing in the Serial Monitor of Arduino Uno.

Can you please help me in understanding what I’m doing wrong? And how I can correct this?

Connections:

  1. Arduino UNO Sensor Interface is given in attachments
  2. Arduino Pins 5 → NodeMCU D5; Arduino Pins 6 → NodeMCU D6; Common Ground

[Arduino UNO: Pins 5,6 (Rx, Tx); NodeMCU: Pins D6,D5 (Rx,Tx)

Arduino Uno Code:

#include <Wire.h>
#include <SFE_BMP180.h>
#include <SoftwareSerial.h>

SoftwareSerial s(5,6); //(Rx,Tx)

SFE_BMP180 bmp180;

char status;
double T, P;
String P_T;
bool success = false;
int test = true;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  s.begin(115200);
  
  bool success = bmp180.begin();
  
  if (success) {
    Serial.println("BMP180 init success");
  }

  else{
    Serial.println("BMP180 init failure");
  }
}

void bmp_Print_Sensor_Data_Test()
{
  Serial.print("Pressure: ");
  Serial.print(P);
  Serial.println(" hPa");

  Serial.print("Temperature: ");
  Serial.print(T);
  Serial.println(" C");
}

void bmp_Send_Sensor_Data()
{
   
    s.write ("Pressure: ");
    s.write (P);
    s.write (" hPa");
    s.write ("Temperature: ");
    s.write (T);
    s.write ("C");
   
}

void bmp_Get_Sensor_Data()
{
  status = bmp180.startTemperature();
  if (status != 0) 
  {
    delay(1000);
    status = bmp180.getTemperature(T);

    if (status != 0) 
    {
      status = bmp180.startPressure(3);

      if (status != 0) 
      {
        delay(status);
        status = bmp180.getPressure(P, T);
        //if (test == true)
        {
          bmp_Print_Sensor_Data_Test();
        }

        //else 
        {
          bmp_Send_Sensor_Data();
        }
        
      }
    }
  }
}

bool check_nodemcu_for_uno_flag()
{
  bool f = false;
  char c = s.read();
  if (c == 'u')
  f = true;
  
  return f;
}

void loop() 
{
  // put your main code here, to run repeatedly:
  //Serial.begin("Exec loop");
  bool flag = false;
  if (s.available()>0)
  {
      flag = check_nodemcu_for_uno_flag();
      //flag = true;

      if (flag == true)
      {
        delay(500);
        bmp_Get_Sensor_Data();
      }
  }

}

NodeMCU Code:

#include <Wire.h>
#include <SFE_BMP180.h>
#include <SoftwareSerial.h>
SoftwareSerial s(D6,D5); //(RX,TX)

int data;

void setup() 
{
  // put your setup code here, to run once:
  s.begin(115200);
  Serial.begin(115200);
}

void loop() 
{
  // put your main code here, to run repeatedly:

  s.write("u");
  if(s.available()>0)
  {
    data = s.read();
    //char val[] = 
    Serial.println(data);
  }
  delay(1000);
}

PS: I’ve attached the responses in the Serial Monitors of Arduino UNO & NodeMCU

PPS: I guess the problem is someway related to the type of the data being sent. If it is, Not really sure how to solve this issue?

SoftwareSerial doesn't receive reliable at 115200 baud. use 9600 baud.

and in this code

  if(s.available()>0)
  {
    data = s.read();
    //char val[] =
    Serial.println(data);
  }

you print the ascii codes of the recieved characters one at a line with println

change type of data to char
and use write() to copy a character read by read() to Serial Monitor

  if(s.available()>0)
  {
    data = s.read();
    Serial.write(data);
  }

@Juraj, Can you please elaborate? I couldn't understand.

Nandan007:
@Juraj, Can you please elaborate? I couldn't understand.

I edited the previous comment

Juraj:
I edited the previous comment

Thanks a ton for the suggestion!!

I’ve done the change with the NodeMCU code and it’s working out now!

NodeMCU changes:

String data;
.
.
.
.
  if(s.available()>0)
  {
    data = s.readString();
    
    Serial.println(data);
  }

In Arduino UNO, I’ve used s.print instead of s.write and it’s woking out!!

void bmp_Send_Sensor_Data()
{

    s.print("{\"Temperature\":");
    s.print(T);//sensor id
    s.print(" C");
    s.print(",");
    s.print("\"Pressure\":");
    s.print(P);//offset
    s.print(" hPa");
    s.print("}");
 
}

PS: I’ve attached the Serial Monitor responses of Arduino UNO & NodeMCU