Project 6: Serial Communication

Alvito Rizqi
2 min readMar 21, 2022

18220039/ Alvito Rizqi Sobri

In this article, you will know about data communication especially serial communication using I2C. I will connect to device, LCD display and bmp280 sensor.

Hardware and Software Requirements

  1. ESP32 Devkit V1
  2. BMP280 Sensor
  3. 16x2 LCD Display
  4. Jumper wire

The ESP32 supports I2C communication through its two I2C bus interfaces that can serve as I2C master or slave, depending on the user’s configuration. In this project, the ESP32 will be the master and the other two will be the slave.

Steps

https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/

Follow the schematic above. I know that the schematic using the OLED not the LCD but what matters is the pin. Here is a list where the pin should connect.

It will look like this.

Then, upload the following code.

#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();
}

Here is my video about the final result of the project. Thank you for reading!

--

--