Greetings,
So my objective was to make or find a working code appropriate for my basic needs to achieve simple stuff like displaying temperature and pressure on the I2C LCD screen and displaying as well altitude on an Android App that I made and it worked quite well with the help of this community forum users as well as some YouTube channels, still, I have some ambiguity with some specific lines in the code.
The first one is what are the 2,1,0,4,5,6,7,3 and ,POSITIVE); do?
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
2nd, Literally what is everything about it especially what the F between println and "Arduino does?
Serial.println(F("Arduino + BMP280"));
3rd, pretty sure these ones are about calculating pressure and temperature but still don't know we didn't do one as well for the altitude or simply because it doesn't require this kind of line, also what sprintf and "%d.%02u% do specifically .
sprintf(text, "%u.%02u hPa ", (int)(pressure/100), (int)((uint32_t)pressure % 100));
sprintf(text, "%d.%02u%cC ", (int)temperature, (int)(temperature * 100)%100, 223);
here is the full code :
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#include <LiquidCrystal_I2C.h>
#define BMP280_I2C_ADDRESS 0x76
Adafruit_BMP280 bmp280;
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
void setup() {
Serial.begin(9600);
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];
void loop()
{
float temperature = bmp280.readTemperature();
float pressure = bmp280.readPressure();
float altitude_ = bmp280.readAltitude(1013.25);
sprintf(text, "%d.%02u%cC ", (int)temperature, (int)(temperature * 100)%100, 223);
lcd.setCursor(5, 0);
lcd.print(text);
sprintf(text, "%u.%02u hPa ", (int)(pressure/100), (int)((uint32_t)pressure % 100));
lcd.setCursor(5, 1);
lcd.print(text);
Serial.print("Temperature = ");
Serial.print(temperature);
Serial.println(" °C");
Serial.print("Pressure = ");
Serial.print(pressure/100);
Serial.println(" hPa");
Serial.print("Approx Altitude = ");
Serial.print(altitude_);
Serial.println(" m");
Serial.println();
delay(2000);
}