Hello all,
Hope you can tell me how to solve this issue. Thanks in advance.
I'm trying to use the BME280 sensor-i2C (from Adafruit) to display the values of Temperature, Pression, Attitude and Humidity on LCD-20x4-i2C.
With the code attached, I can see the values on Serial Monitor [with printValuesOnMonitor() function] but I can not display these values on LCD (with printValuesOnLCD() function) in the same time.
Regards,
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h> // SENSOR-i2C
// Library added for LCD-i2C (20x4)
#include "LCD.h"
#include "LiquidCrystal_I2C.h"
//Set the pins on the i2C chip used for LCD connections
//ADDR,EN,R/W,RS,D4,D5,D6,D7
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7); // 0x27 is the default i2C bus address of LCD
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME280 bme;
unsigned long delayTime;
void setup() {
Serial.begin(9600);
while(!Serial); // time to get serial running
Serial.println(F("BME280 test"));
lcd.begin (20,4); // 20x4 i2C-LCD module
lcd.setBacklightPin(3,POSITIVE); // BL, BL_POL
lcd.setBacklight(HIGH);
unsigned status;
// default settings
status = bme.begin();
// status = bme.begin(0x76); // 0x76 is the default i2C bus address of BME280
if (!status) {
Serial.println("Could not find a valid BME280 sensor, check wiring, address, sensor ID!");
Serial.print("SensorID was: 0x"); Serial.println(bme.sensorID(),16);
Serial.print(" ID of 0xFF probably means a bad address, a BMP 180 or BMP 085\n");
Serial.print(" ID of 0x56-0x58 represents a BMP 280,\n");
Serial.print(" ID of 0x60 represents a BME 280.\n");
Serial.print(" ID of 0x61 represents a BME 680.\n");
while (1) delay(10);
}
Serial.println("-- Default Test --");
delayTime = 1000;
Serial.println();
}
/* Example: Set off LCD module
lcd.begin (20,4); // 20x4 LCD module
lcd.setBacklightPin(3,POSITIVE); // BL, BL_POL
lcd.setBacklight(HIGH);
lcd.print("Hello World !");
lcd.setCursor(0,1);
lcd.print(" Good Day !");
delay(5000);
*/
void loop() {
printValuesOnMonitor();
printValuesOnLCD();
delay(delayTime);
}
void printValuesOnMonitor() {
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println(" *C");
Serial.print("Pressure = ");
Serial.print(bme.readPressure() / 100.0F);
Serial.println(" hPa");
Serial.print("Approx. Altitude = ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println(" m");
Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println(" %");
Serial.println();
}
void printValuesOnLCD(){
// lcd.clear();
// Display Temperature
lcd.setCursor(0,1);
lcd.print("Temp = ");
lcd.setCursor(0,6);
lcd.print(bme.readTemperature());
lcd.println("*C");
// Display Pressure
// Diaplay Attitude
// Display Humidity
}