Project 6: Serial Communication

https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/
#include <Wire.h>
#include <SPI.h>
#include <LiquidCrystal_I2C.h>
#include <Adafruit_BMP280.h>
#define BMP_SCK (13)
#define BMP_MISO (12)
#define BMP_MOSI (11)
#define BMP_CS (10)
// set the LCD number of columns and rows
int lcdColumns = 16;
int lcdRows = 2;
// set LCD address, number of columns and rows
// if you don't know your display address, run an 12C scanner sketch
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
Adafruit_BMP280 bmp; // 12C
//adatruit_BMP280 bap (BMP_cS); // hardware SPI
//Adafruit BMP280 bap (BMP Cs, EMP_MOSI, BMP_MISO, BMP_SCK):
void setup () {
Serial.begin (115200);

bool status = bmp.begin (0x76);
if (!status) {
Serial.println("Could not find a valid BMP280 sensor, check wiring!");
while (1);
}
/* Default settings from datasheet */
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,
Adafruit_BMP280::SAMPLING_X2,
Adafruit_BMP280::SAMPLING_X16,
Adafruit_BMP280::FILTER_X16,
Adafruit_BMP280::STANDBY_MS_500);
// initialize LCD
lcd.init();
// turn on LCD backlight
lcd.backlight();
}
void loop () {
// set cursor to firat colunn, firet zow
lcd.setCursor(0, 0);
// print message
lcd.print("Temperature: ");
// set cursor to firat column, second row
lcd.setCursor(0, 1);
// print message
lcd.print(String(bmp.readTemperature()));
lcd.setCursor(6, 1);
lcd.print("*C");
delay(3000);
lcd.clear();

lcd.setCursor(0, 0);
lcd.print("Pressure: ");
lcd.setCursor(0, 1);
lcd.print(String(bmp.readPressure()));
lcd.setCursor(10, 1);
lcd.print("Pa");
delay(3000);
lcd.clear();

lcd.setCursor(0, 0);
lcd.print("Approx Altitude: ");
lcd.setCursor(0, 1);
lcd.print(String(bmp.readAltitude(1010)));
lcd.setCursor(6, 1);
lcd.print("m");
delay(3000);
lcd.clear();
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store