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:
- Arduino UNO Sensor Interface is given in attachments
- 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?