Last active
July 21, 2024 11:14
-
-
Save sehraf/876c8eed6a1ede743439623ac6574def to your computer and use it in GitHub Desktop.
Arduino sketch to show BME280 readings on a LCD display
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Wire.h> | |
#include <SPI.h> | |
#include <Adafruit_Sensor.h> | |
#include <Adafruit_BME280.h> | |
#include <LiquidCrystal_I2C.h> | |
#define BME280_Addr (0x76) | |
#define SEALEVELPRESSURE_HPA (1013.25) | |
#define LCD_Addr (0x3f) | |
#define LCD_Col 20 | |
#define LCD_Row 2 | |
Adafruit_BME280 bme; // I2C | |
LiquidCrystal_I2C lcd(LCD_Addr, LCD_Col, LCD_Row); | |
// used to show pressure and humidity alternating | |
bool flip; | |
void setup() { | |
Serial.begin(115200); | |
while(!Serial); // time to get serial running | |
Serial.println(F("BME280 test")); | |
unsigned status; | |
// default settings | |
// (you can also pass in a Wire library object like &Wire2) | |
status = bme.begin(BME280_Addr); | |
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); | |
} | |
lcd.init(); | |
lcd.backlight(); | |
flip = false; | |
} | |
void loop() { | |
printValues(); | |
delay(2000); | |
} | |
void printValues() { | |
/* | |
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(); | |
*/ | |
// clear lcd | |
lcd.clear(); | |
// temperatur | |
lcd.setCursor(0, 0); | |
lcd.print("Temp: "); | |
lcd.print(bme.readTemperature()); | |
lcd.print(" *C"); | |
// either humidity or pressure | |
lcd.setCursor(0, 1); | |
if (flip) { | |
lcd.print("Pres: "); | |
lcd.print(bme.readPressure() / 100.0F); | |
lcd.print(" hPa"); | |
} else { | |
lcd.print("Humi: "); | |
lcd.print(bme.readHumidity()); | |
lcd.print(" %"); | |
} | |
flip = !flip; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Подскажите пожалуйста распиновку LCD.
Please tell me the pinout of the LCD.