Hi everyone, this is my first time posting in this community forum,
To start off with I'm fairly new to Arduinos even when it comes to electronics, recently I've been trying to make some simple mini projects such as making and using an android app to text and display it on the LCD screen and I've had quite a success with it and it showed that the LCD is working perfectly, so in this topic, as the title says I'm trying to figure out why my LCD is not displaying the Temperature and Pressure even though the sensor is displaying values in the serial monitor from the computer.
I'm using an Arduino Uno, with the following connections :
BMP 280:
VCC with 3.3V
GND with GND
SCL with A5
SDA with A4
As for 16x2 LCD I2C screen :
VCC with 5V
GND with GND
SCL with GPIO 19 ( SCL I2C )
SDA with GPIO 18 ( SCL I2C )
Edit* (code) :
/*
* Interfacing Arduino with BMP280 temperature and pressure sensor.
* Temperature and pressure values are displayed on 16x2 LCD.
* This is a free software with NO WARRANTY.
* https://simple-circuit.com/
*/
#include <Wire.h> // include Wire library, required for I2C devices
#include <Adafruit_Sensor.h> // include Adafruit sensor library
#include <Adafruit_BMP280.h> // include adafruit library for BMP280 sensor
#include <LiquidCrystal.h> // include LCD library
// define device I2C address: 0x76 or 0x77 (0x77 is library default address)
#define BMP280_I2C_ADDRESS 0x76
Adafruit_BMP280 bmp280;
// LCD module connections (RS, E, D4, D5, D6, D7)
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
void setup() {
Serial.begin(9600);
// set up the LCD's number of columns and rows
lcd.begin(16, 2);
Serial.println(F("Arduino + BMP280"));
if (!bmp280.begin(BMP280_I2C_ADDRESS))
{
Serial.println("Could not find a valid BMP280 sensor, check wiring!");
while (1);
}
lcd.setCursor(0, 0);
lcd.print("Temp:");
lcd.setCursor(0, 1);
lcd.print("Pres:");
}
char text[14];
// main loop
void loop()
{
// get temperature, pressure and altitude from library
float temperature = bmp280.readTemperature(); // get temperature
float pressure = bmp280.readPressure(); // get pressure
float altitude_ = bmp280.readAltitude(1013.25); // get altitude (this should be adjusted to your local forecast)
// print data on the LCD screen
// 1: print temperature
sprintf(text, "%d.%02u%cC ", (int)temperature, (int)(temperature * 100)%100, 223);
lcd.setCursor(5, 0);
lcd.print(text);
// 2: print pressure
sprintf(text, "%u.%02u hPa ", (int)(pressure/100), (int)((uint32_t)pressure % 100));
lcd.setCursor(5, 1);
lcd.print(text);
// print data on the serial monitor software
// 1: print temperature
Serial.print("Temperature = ");
Serial.print(temperature);
Serial.println(" °C");
// 2: print pressure
Serial.print("Pressure = ");
Serial.print(pressure/100);
Serial.println(" hPa");
// 3: print altitude
Serial.print("Approx Altitude = ");
Serial.print(altitude_);
Serial.println(" m");
Serial.println(); // start a new line
delay(2000); // wait 2 seconds
}
// end of code.