WeMos (b5) I2C (BMP280+1602 LCD)

/*
 * 
 */
#include <Wire.h> 
#include <Adafruit_BMP280.h>
#include <LiquidCrystal_I2C.h>
 
//For SPI connection!
#define BMP_SCK D5
#define BMP_MISO D6
#define BMP_MOSI D7 
#define BMP_CS D3

Adafruit_BMP280 bmp; // I2C
// Adafruit_BMP280 bmp(BMP_CS); // hardware SPI
// Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO,  BMP_SCK);

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup()
{
  lcd.begin(0,2);  // sda=GPIO_0, scl=GPIO_2

  lcd.init();

  // Turn on the backlight.
  lcd.backlight();
    
  // Print a message to the LCD.
  lcd.print("hello, world!");

  if (!bmp.begin(0x76)) 
  {
    Serial.println("Could not find BMP180 or BMP085 sensor at 0x77");
    while (1) {}
  }
}

void loop()
{
  lcd.setCursor(0, 0);
  lcd.print("Temp = ");
  lcd.print(bmp.readTemperature());
  lcd.println(" Celsius");
     
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  lcd.print("Pres = ");
  lcd.print(bmp.readPressure());
  lcd.print(" Pascal ");
  // print the number of seconds since reset:
  lcd.print(millis() / 1000);
  delay(2000);

}

Leave a Reply

Your email address will not be published. Required fields are marked *