Project 6: Integrated Devices
Last week was midterms, didn’t do any ESP32 exploration but we’re backkk todayy! Entitled Integrated Devices, there will be 2 devices on our project today. Integrating OLED & Sensors.
As usual, lets gear up. Collect ESP32, breadboard, male-to-male jumper wires, OLED and in todays project i’m using BMP280 for the sensor. All of these components were used from our last project so make sure they’re all in a good condition to be explored.
For the software prerequisites, if you’ve been following my journey of ESP32 from the start, there will be nothing to do no more. But if you don’t, kindly check my previous posts!
After installing and setting up the sensor’s environment we can start to arrange the circuit like this. To be simple so that nothing gets messed up here’s where should we connect the jumper to (exactly).
We need to find the address of the BMP280 and OLED beforehand. There are some programs to run such as in ().
After finding both addresses, compile the program for today’s exploration. We need to see the sensor’s output from our LED.
/*
Rui Santos
Complete project details at https://RandomNerdTutorials.com/esp32-i2c-communication-arduino-ide/
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
*/
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
Adafruit_BMP280 bmp;void setup() {
Serial.begin(115200);
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F(“SSD1306 allocation failed”));
for(;;);
}
bool status = bmp.begin(0x76);
if (!status) {
Serial.println(“Could not find a valid BMP280 sensor, check wiring!”);
while (1);
}
delay(2000);
display.clearDisplay();
display.setTextColor(WHITE);
}
void loop() {
display.clearDisplay();
// display Temperature
display.setTextSize(1);
display.setCursor(0,0);
display.print(“Temperature: “);
display.setTextSize(1.5);
display.setCursor(0,10);
display.print(String(bmp.readTemperature()));
display.print(“ “);
display.setTextSize(1);
display.cp437(true);
display.write(167);
display.setTextSize(1.5);
display.print(“C”);
// display Pressure
display.setTextSize(1);
display.setCursor(0, 30);
display.print(“Pressure: “);
display.setTextSize(1.5);
display.setCursor(0, 40);
display.print(String(bmp.readPressure()));
display.print(“ Pa”);
display.display();
delay(1000);}