Help

So why not create the lcd object in the same way as in the "hello world" which you know works ?

I’ve decided to start it again…

I’ve got this far with the code.

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

int pin=2;
DHT11 dht11(pin);
LiquidCrystal_I2C lcd(0x27,20,4); 

void setup()
{
  lcd.init();
  lcd.init();
  
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("Temperature:");
  lcd.setCursor(0,2);
  lcd.print("Pressure:");
  lcd.setCursor(0,1);
  lcd.print("Humidity:");
  lcd.setCursor(0,3);
  lcd.print("Altitude:");   
}

void loop()
{
  int err;
  float temp, humi;
  if((err=dht11.read(humi, temp))=0)
{
  lcd.clear();
  delay(500);
  lcd.setCursor(0,0);
  lcd.print("Temperature:");
  lcd.setCursor(0,1);
  lcd.print("Humidity:");
  lcd.setCursor(0,2);
  lcd.print("Pressure:");
  lcd.setCursor(0,3);
  lcd.print("Altitude:");
  lcd.print(temp);
  lcd.print(" C");
  lcd.setCursor(9,0);
  lcd.print(humi);
  lcd.print(" %");
  delay(10000);
}

I haven’t connected the BMP180 yet to this code but it all connected up on the arduino board

  lcd.init();
  lcd.init();

So good that you did it twice.

if((err=dht11.read(humi, temp))=0)

= for assignment, == for comparison. What does that line do?

UKHelibob

That is what i found on the examples that came preloaded on the arduino software so i decided that it was best to leave that in to ensure that i don't prompt future error messages.
I assume that it doesn't make a difference?

groundFungus

I'm not entirely sure but from my understanding if the DHT11 has an error it will display the values for these as 0

Im not the best at coding an arduino :slight_smile:

tangopear:
That is what i found on the examples that came preloaded on the arduino software

I doubt that... In which example did you see this?

tangopear:
I'm not entirely sure but from my understanding if the DHT11 has an error it will display the values for these as 0

Alright, why do you try to assign a value instead of checking it? Read the post again :wink:

tangopear:
Im not the best at coding an arduino :slight_smile:

Not the best? It just doesn't work ::slight_smile: And press Ctrl+t and see how much clearer that looks :wink:

I’m using the DHT sensor library which i think if i’m not mistaken came pre-loaded on the software but it may also be one that i downloaded when i started this project.

This is my up to date code with no errors

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

int pin=2;
DHT11 dht11(pin);
LiquidCrystal_I2C lcd(0x27,20,4); 
SFE_BMP180 Pressure;

 // Altitude of Central Sussex College

void setup()
{

  (Pressure.begin());
  lcd.init();

  lcd.println("BMP180 init success");
  
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("Temp:");
  lcd.setCursor(0,2);
  lcd.print("Pressure:");
  lcd.setCursor(0,1);
  lcd.print("Humidity:");
  lcd.setCursor(0,3);
  lcd.print("Altitude:");   
}

void loop()
{
  int err;
  float temp, humi;
  if((err=dht11.read(humi, temp))=0)
  dht11.read (humi, temp);
  char status;
  double T,P,p0,a;
  
{
  lcd.clear();
  delay(500);
  lcd.setCursor(0,0);
  lcd.print("Humidity:");
  lcd.setCursor(0,1);
  lcd.print("Temperature:");
  lcd.print(temp);
  lcd.print(" C");
  lcd.setCursor(9,0);
  lcd.print(humi);
  lcd.print(" %");

  lcd.println();
  lcd.setCursor(0,2);
  lcd.print("Altitude:");
 // lcd.print();
  lcd.print(" ft");

  status = Pressure.getPressure(P,T);
  
  lcd.setCursor(0,3);
  lcd.print("Pressure:");
  lcd.print(P,2);
  lcd.print(" mb");
 
 
  delay(10000);
}
}

ctrl-t was actually a help thank you!

I would like it to constantly read the values so i’m not sure what i need to tell it to do?
loop or do i lower the delay?

tangopear:
I'm using the DHT sensor library which i think if i'm not mistaken came pre-loaded on the software but it may also be one that i downloaded when i started this project.

Even if you downloaded it I doubt they would run .init() twice...

tangopear:
This is my up to date code with no compilererrors

Fixed it :wink: Because I do see errors.

tangopear:
ctrl-t was actually a help thank you!

Then why post code you didn't use that trick ::slight_smile:

tangopear:
I would like it to constantly read the values so i'm not sure what i need to tell it to do?
loop or do i lower the delay?

The delay determines how often you read. So what do you think?

But I would only write to the screen what changed. The text will stay the same :slight_smile:

Couple of notes on the code:

{
    lcd.clear();

Why the opening bracket there?

(Pressure.begin());

And why the extra set of brackets here?

if ((err = dht11.read(humi, temp)) = 0)

groundFungus already pointed that out. What do you think that bit does? Knowing a = is the assign operator and a == is the comparison operator.

int pin = 2;
int err;
float temp, humi;
double T, P, p0, a;

Stop that bad habit right now :wink: Don't use short variable names. Yes, they are quick to type. But they are hard to remember because you have to know what it is. This makes reading the ode also hard. Use variable names that tell exactly what they are. Even though they are longer, it's easier when writing.

So for example

const byte  DthPin = 2;
float temperature;
float humidity;
float pressure;
double T, P, p0, a;

PS. Symbole for milli bar is mbar :wink: