Integrate and include Adafruit_Sensor.h> #include "Adafruit_BMP280.h" the 0.95 inch RGB OLED with this C++ program for Arduino, you will need to inc

#include <Wire.h>

#include <Adafruit_Sensor.h>

#include "Adafruit_BMP280.h"

#include <Adafruit_SSD1331.h> // OLED library

#define OLED_DC 6 // OLED Data/Command pin

#define OLED_CS 10 // OLED Chip Select pin

#define OLED_CLK 13 // OLED Clock pin

#define OLED_MOSI 11 // OLED MOSI (Master Out Slave In) pin

#define OLED_RESET 9 // OLED Reset pin

Adafruit_BMP280 bmp; // I2C

Adafruit_SSD1331 display = Adafruit_SSD1331(OLED_DC, OLED_CS, OLED_CLK, OLED_MOSI, OLED_RESET);

float pressure; // To store the barometric pressure (Pa)

float temperature; // To store the temperature (oC)

float altitude; // To store the altitude (m)

void setup() {

Serial.begin(9600); // Initialize serial communication

display.begin(); // Initialize OLED display

if (!bmp.begin()) { // Initialize sensor

Serial.println("Could not find a valid BMP280 sensor, check wiring!");

while (1);

}

}

void loop() {

// Read and store sensor data

pressure = bmp.readPressure();

temperature = bmp.readTemperature();

altitude = bmp.readAltitude(SEALEVELPRESSURE_HPA);

// Print sensor data to serial monitor

Serial.print("Pressure: ");

Serial.print(pressure);

Serial.println(" Pa");

Serial.print("Temperature: ");

Serial.print(temperature);

Serial.println(" oC");

Serial.print("Altitude: ");

Serial.print(altitude);

Serial.println(" m");

// Update OLED display

display.setCursor(0,0); // Set cursor to top left corner of OLED

display.print("Pressure: ");

display.print(pressure);

display.print(" Pa");

display.setCursor(0,8); // Set cursor to next line of OLED

display.print("Temp: ");

display.print(temperature);

display.print(" oC");

display.setCursor(0,16); // Set cursor to next line of OLED

display.print("Altitude: ");

display.print(altitude);

display.print(" m");

delay(5000); // Delay between updates

When is our homework due?

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.