Weather Station - No Pressure reading on LCD ?

Hi all.

I have been trying for days now to get my code/sketch to display the current Air Pressure on my LCD.

I am using a Arduino UNO R3 + a DHT22 Temperature & Humidity sensor, and a BMP180 air pressure sensor, with an i2c 20,4 LCD, the Temp, & Humidity indicators are spot on,but no Pressure Reading.

I have used a Test sketch to check out the BMP180 sensor, the sensor is ok, it shows very accurate readings on the Serial Monitor screen.

I am not idle, but after surfing for days on the internet, and studying my C++ for Dummies instruction book, and countless changes to my sketch, i am still no further on to getting it to read out, hence my cry for help.

Here's my sketch, i bet i have done something silly.

//Libraries

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

LiquidCrystal_I2C lcd(0x27, 20, 4);  // Set the LCD address to 0x27 for a 20 chars and a 4 line display
#include <DHT.h>  //Including DHT 22 library

int analogPin = A0; // UV Sensor (middle pin) connected to analog pin A0

//Constants

#define ALTITUDE  123.0  //Altitude of Parsons Close Weather Station.
#define DHTPIN 4  // what UNO pin we're connected to
#define DHTTYPE DHT22  // DHT 22  (AM2302)

DHT dht(DHTPIN, DHTTYPE);  // Initialize DHT sensor for normal 16mhz Arduino

int chk;
float hum;  //Stores humidity value
float temp; //Stores temperature value
float pres; //Stores pressure value.

void setup(){
  
  
  lcd.init();   // initialize the LCD
  lcd.begin(20,4);
  lcd.backlight();
  
  hum = dht.readHumidity();
  temp = dht.readTemperature();
  
double T, P, p0; //Creating variables for temp, pressure and relative pressure

}

void loop(){
  
  lcd.begin(20,4);
  lcd.setBacklight(HIGH);
  lcd.clear();

//Reading Temperature.
  lcd.setCursor(0, 0); //First column, first row
  lcd.print("Temp. : ");
  lcd.print(temp);
  lcd.print(" ");
  lcd.print((char)223);
  lcd.print("C");

//Reading Humidity.
  lcd.setCursor(0, 1); // First column, Second row
  lcd.print("Humidity : ");
  lcd.print(hum);
  lcd.print(" %");

//Reading Air Pressure.  
  lcd.setCursor(0, 2); // First column, Second row
  lcd.print("Press. :");
  lcd.setCursor(16, 2);  //Seventeenth column, Second row
  lcd.print("mbar");

           
  delay(5000);

}
  lcd.setCursor(0, 2); // First column, Second row
  lcd.print("Press. :");
  lcd.setCursor(16, 2);  //Seventeenth column, Second row
  lcd.print("mbar");

I'm going with "not doing anything at all"

What is the name of the variable that holds the value of the pressure ?
Whereabouts in the program do you print it to the LCD ?

gresleyman:
Here's my sketch, i bet i have done something silly.

//Libraries

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

LiquidCrystal_I2C lcd(0x27, 20, 4);  // Set the LCD address to 0x27 for a 20 chars and a 4 line display
#include <DHT.h>  //Including DHT 22 library

int analogPin = A0; // UV Sensor (middle pin) connected to analog pin A0

//Constants

#define ALTITUDE  123.0  //Altitude of Parsons Close Weather Station.
#define DHTPIN 4  // what UNO pin we're connected to
#define DHTTYPE DHT22  // DHT 22  (AM2302)

DHT dht(DHTPIN, DHTTYPE);  // Initialize DHT sensor for normal 16mhz Arduino

int chk;
float hum;  //Stores humidity value
float temp; //Stores temperature value
float pres; //Stores pressure value.

void setup(){
 
 
  lcd.init();  // initialize the LCD
  lcd.begin(20,4);
  lcd.backlight();
 
  hum = dht.readHumidity();
  temp = dht.readTemperature();
 
double T, P, p0; //Creating variables for temp, pressure and relative pressure

}

void loop(){
 
  lcd.begin(20,4);
  lcd.setBacklight(HIGH);
  lcd.clear();

//Reading Temperature.
  lcd.setCursor(0, 0); //First column, first row
  lcd.print("Temp. : ");
  lcd.print(temp);
  lcd.print(" ");
  lcd.print((char)223);
  lcd.print("C");

//Reading Humidity.
  lcd.setCursor(0, 1); // First column, Second row
  lcd.print("Humidity : ");
  lcd.print(hum);
  lcd.print(" %");

//Reading Air Pressure. 
  lcd.setCursor(0, 2); // First column, Second row
  lcd.print("Press. :");
  lcd.setCursor(16, 2);  //Seventeenth column, Second row
  lcd.print("mbar");

delay(5000);

}

First, your code only takes one temp and humidity reading with the do the reading code being in setup; which only runs one time.

Nest where, in your code, does it take the pressure measurement?

The code seems to be doing exactly what you asked. You've set up a variable pres to hold the pressure but you never read anything into it and you never attempt to display it anywhere.

Steve

You have forgotten:

SFE_BMP180 pressure;

And:

if (pressure.begin())
    Serial.println("BMP180 init success");
  else
  {
    // Oops, something went wrong, this is usually a connection problem,
    // see the comments at the top of this sketch for the proper connections.

    Serial.println("BMP180 init fail\n\n");
    while(1); // Pause forever.
}

And:

#define ALTITUDE 1655.0 // Altitude of SparkFun's HQ in Boulder, CO. in meters

Read through the examples in the library.

Hi all, many thanks for your replies, though they have left me confused somewhat.

AWOL, i have corrected the line of construction from seventeenth to sixteenth column, but as you know it's made no difference to the sketch working.

outsider, i have been through the example sketches in the IDE, they all work with my BMP180 sensor, but all are for reading the results in the Serial Monitor, i am trying to get the results on the LCD.

slipstick, i just do not understand your answer?

idahowalker, "Nest where, in your code, does it take the pressure measurement?" what does "nest" mean?

ukhelibob, this is what i am asking, what do i nuse, and where do i put it?

Regards

Ray

AWOL, i have corrected the line of construction from seventeenth to sixteenth column, but as you know it's made no difference to the sketch working.

You are neither taking a pressure reading, nor printing the reading you're not taking, so it isn't really surprising you're not seeing anything.

(Hint: I'm guessing "nest" was meant to be "next")

I have used a Test sketch to check out the BMP180 sensor, the sensor is ok, it shows very accurate readings on the Serial Monitor screen.

Revisit this sketch. It apparently has the code you need to read the pressure, which is missing from your current sketch, so add it in. Then all you have to do is add something else that prints it on the LCD.

@OP

1. Have you connected your BM180 (I2C Bus Sensor) Sensor with the Arduino? If not, connect it now.

2. Read the following example (taken from the Example of the IDE) and learn how to measure pressure from BMP180 Sensor using SFE_BM180.h Library. Then pick up the necessary codes from this example and add them in your program. This way, you will be able to respect the recommendations/suggestions made in the previous posts.

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

// You will need to create an SFE_BMP180 object, here called "pressure":

SFE_BMP180 pressure;

#define ALTITUDE 1655.0 // Altitude of SparkFun's HQ in Boulder, CO. in meters

void setup()
{
  Serial.begin(9600);
  Serial.println("REBOOT");

  // Initialize the sensor (it is important to get calibration values stored on the device).

  if (pressure.begin())
    Serial.println("BMP180 init success");
  else
  {
    // Oops, something went wrong, this is usually a connection problem,
    // see the comments at the top of this sketch for the proper connections.

    Serial.println("BMP180 init fail\n\n");
    while(1); // Pause forever.
  }
}

void loop()
{
  char status;
  double T,P,p0,a;

  // Loop here getting pressure readings every 10 seconds.

  // If you want sea-level-compensated pressure, as used in weather reports,
  // you will need to know the altitude at which your measurements are taken.
  // We're using a constant called ALTITUDE in this sketch:
  
  Serial.println();
  Serial.print("provided altitude: ");
  Serial.print(ALTITUDE,0);
  Serial.print(" meters, ");
  Serial.print(ALTITUDE*3.28084,0);
  Serial.println(" feet");
  
  // If you want to measure altitude, and not pressure, you will instead need
  // to provide a known baseline pressure. This is shown at the end of the sketch.

  // You must first get a temperature measurement to perform a pressure reading.
  
  // Start a temperature measurement:
  // If request is successful, the number of ms to wait is returned.
  // If request is unsuccessful, 0 is returned.

  status = pressure.startTemperature();
  if (status != 0)
  {
    // Wait for the measurement to complete:
    delay(status);

    // Retrieve the completed temperature measurement:
    // Note that the measurement is stored in the variable T.
    // Function returns 1 if successful, 0 if failure.

    status = pressure.getTemperature(T);
    if (status != 0)
    {
      // Print out the measurement:
      Serial.print("temperature: ");
      Serial.print(T,2);
      Serial.print(" deg C, ");
      Serial.print((9.0/5.0)*T+32.0,2);
      Serial.println(" deg F");
      
      // Start a pressure measurement:
      // The parameter is the oversampling setting, from 0 to 3 (highest res, longest wait).
      // If request is successful, the number of ms to wait is returned.
      // If request is unsuccessful, 0 is returned.

      status = pressure.startPressure(3);
      if (status != 0)
      {
        // Wait for the measurement to complete:
        delay(status);

        // Retrieve the completed pressure measurement:
        // Note that the measurement is stored in the variable P.
        // Note also that the function requires the previous temperature measurement (T).
        // (If temperature is stable, you can do one temperature measurement for a number of pressure measurements.)
        // Function returns 1 if successful, 0 if failure.

        status = pressure.getPressure(P,T);
        if (status != 0)
        {
          // Print out the measurement:
          Serial.print("absolute pressure: ");
          Serial.print(P,2);
          Serial.print(" mb, ");
          Serial.print(P*0.0295333727,2);
          Serial.println(" inHg");

          // The pressure sensor returns abolute pressure, which varies with altitude.
          // To remove the effects of altitude, use the sealevel function and your current altitude.
          // This number is commonly used in weather reports.
          // Parameters: P = absolute pressure in mb, ALTITUDE = current altitude in m.
          // Result: p0 = sea-level compensated pressure in mb

          p0 = pressure.sealevel(P,ALTITUDE); // we're at 1655 meters (Boulder, CO)
          Serial.print("relative (sea-level) pressure: ");
          Serial.print(p0,2);
          Serial.print(" mb, ");
          Serial.print(p0*0.0295333727,2);
          Serial.println(" inHg");

          // On the other hand, if you want to determine your altitude from the pressure reading,
          // use the altitude function along with a baseline pressure (sea-level or other).
          // Parameters: P = absolute pressure in mb, p0 = baseline pressure in mb.
          // Result: a = altitude in m.

          a = pressure.altitude(P,p0);
          Serial.print("computed altitude: ");
          Serial.print(a,0);
          Serial.print(" meters, ");
          Serial.print(a*3.28084,0);
          Serial.println(" feet");
        }
        else Serial.println("error retrieving pressure measurement\n");
      }
      else Serial.println("error starting pressure measurement\n");
    }
    else Serial.println("error retrieving temperature measurement\n");
  }
  else Serial.println("error starting temperature measurement\n");

  delay(5000);  // Pause for 5 seconds.
}

3. I have made a test run of my BMP180 Sensor using just minimum codes from Step-2. This is the screenshot of the response of the sensor.
scr-8.png

scr-8.png

@Golam Mostafa :

gresleyman:
I have used a Test sketch to check out the BMP180 sensor, the sensor is ok, it shows very accurate readings on the Serial Monitor screen.

AWOL:
@Golam Mostafa :

I had a slight doubt in OP's statement; because, I expected to see in his sketch (at least) the object to be created from the class SFE_BMP180.

GolamMostafa:
I had a slight doubt in OP's statement; because, I expected to see in his sketch (at least) the object to be created from the class SFE_BMP180.

We haven't seen the OP's test sketch.

AWOL:
We haven't seen the OP's test sketch.

I am talking about the sketch of his original post where he is looking for the pressure reading and not of the test sketch used for the stand-alone test of BM180 Sensor.

I hope that you (@AWOL) will let me go to bed; I am sick with flue!

Please, if you are sick of chimneys, please go to bed.

AWOL:
Please, if you are sick of chimneys, please go to bed.

You man is are wanting one more thing from me before I go to bed and that is flu and not flue. That's why, in my country, some of us (excluding me) have the titles: British. (wit and humor)

GolamMostafa:
You man is wanting one more thing from me before I go to bed and that is flu and not flue. That's why, in my country, some of us (excluding me) have the titles: British.

Please, go to bed - you appear to be delerious.
You're probably running a temperature.

Hi again, many thanks for your replies.

@op, I have used the same sketch you have uploaded, my sensor works fine, but this sketch is for Serial Monitor read out, i have been trying (without much look) to convert it to display on my 20,4 i2c LCD.

I appreciate the answers so far, but none seem to be leading me anywhere, i have scoured Google for what seems weeks now, and i cannot get it, i am still learning my Variables from my Constants, if you see a problem with my sketch can you please outline the problem, i will try and work on it from there.

Regards

Ray

but none seem to be leading me anywhere

You are not reading the pressure.
You are not printing the pressure that you are not reading.

The test sketch that you didn't post, but which you said was working, presumably read the pressure (otherwise it couldn't be said to be working) - why don't you look at that, and see how the pressure is read?

@op, I have used the same sketch you have uploaded,

You are the OP.

Can you answer the questions in reply #2 ?