This shows you the differences between two versions of the page.
| en:iot-open:practical:hardware:rtu:esp32:scenarios:bmp280 [2025/07/31 17:18] – created kivilands6 | en:iot-open:practical:hardware:rtu:esp32:scenarios:bmp280 [2025/07/31 17:18] (current) – [ESP32 BMP280] kivilands6 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| + | ====== ESP32 BMP280 ===== | ||
| + | This is an example of the BMP280 reading and displaying on screen. | ||
| + | ===== Prequisits ==== | ||
| + | There is no necessary prequisits, the wire library will be pulled in automatically. | ||
| + | ===== Example ==== | ||
| + | < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | /* BMP280 */ | ||
| + | Adafruit_BMP280 bmp; // I2C | ||
| + | |||
| + | #define SDA_PIN 17 | ||
| + | #define SCL_PIN 16 | ||
| + | |||
| + | #define LCD_RS 48 | ||
| + | #define LCD_ENABLE 47 | ||
| + | #define LCD_D4 34 | ||
| + | #define LCD_D5 33 | ||
| + | #define LCD_D6 26 | ||
| + | #define LCD_D7 21 | ||
| + | |||
| + | static Adafruit_LiquidCrystal lcd(LCD_RS, LCD_ENABLE, LCD_D4, LCD_D5, LCD_D6, LCD_D7); | ||
| + | |||
| + | void setup() { | ||
| + | Serial.begin(152000); | ||
| + | |||
| + | // Initialize I2C on custom pins | ||
| + | Wire.begin(SDA_PIN, | ||
| + | |||
| + | // Initialize LCD | ||
| + | if (!lcd.begin(16, | ||
| + | Serial.println(" | ||
| + | while (1); | ||
| + | } | ||
| + | Serial.println(" | ||
| + | lcd.print(" | ||
| + | |||
| + | // Initialize BMP280 with custom I2C (Wire) instance | ||
| + | if (!bmp.begin(0x76)) { | ||
| + | Serial.println(F(" | ||
| + | while (1) delay(10); | ||
| + | } | ||
| + | |||
| + | bmp.setSampling(Adafruit_BMP280:: | ||
| + | Adafruit_BMP280:: | ||
| + | Adafruit_BMP280:: | ||
| + | Adafruit_BMP280:: | ||
| + | Adafruit_BMP280:: | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | float h = bmp.readPressure(); | ||
| + | float t = bmp.readTemperature(); | ||
| + | |||
| + | if (bmp.takeForcedMeasurement()) { | ||
| + | Serial.print(F(" | ||
| + | Serial.print(bmp.readTemperature()); | ||
| + | Serial.println(" | ||
| + | |||
| + | Serial.print(F(" | ||
| + | Serial.print(bmp.readPressure()); | ||
| + | Serial.println(" | ||
| + | |||
| + | Serial.print(F(" | ||
| + | Serial.print(bmp.readAltitude(1013.25)); | ||
| + | Serial.println(" | ||
| + | } | ||
| + | |||
| + | lcd.setCursor(0, | ||
| + | lcd.print(" | ||
| + | lcd.print(h / 100.0); // Convert Pa to hPa | ||
| + | lcd.print(" | ||
| + | |||
| + | lcd.setCursor(0, | ||
| + | lcd.print(" | ||
| + | lcd.print(t); | ||
| + | lcd.print(" | ||
| + | |||
| + | delay(1000); | ||
| + | } | ||
| + | |||
| + | } | ||
| + | </ | ||