// Variables
float pressure; // To store the barometric pressure (Pa)
float temperature; // To store the temperature (oC)
int altimeter; // To store the altimeter (m) (you can also use it as a float variable)
void setup() {
display.begin(); // Begin OLED display
bmp.begin(); // Begin the sensor
Serial.begin(9600); // Begin serial communication at 9600bps
Serial.println("Adafruit BMP280 test:");
}
void loop() {
// Read values from the sensor:
pressure = bmp.readPressure();
temperature = bmp.readTemperature();
altimeter = bmp.readAltitude(1050.35); // Change the "1050.35" to your city's current barometric pressure (https://www.wunderground.com)
// Print values to serial monitor:
Serial.print(F("Pressure: "));
Serial.print(pressure);
Serial.print(" Pa");
Serial.print("\t");
Serial.print(("Temp: "));
Serial.print(temperature);
Serial.print(" oC");
Serial.print("\t");
Serial.print("Altimeter: ");
Serial.print(altimeter); // This should be adjusted to your local forecast
Serial.println(" m");
// Display values on OLED display:
display.clearDisplay();
display.setCursor(0, 0);
display.println("Pressure: " + String(pressure) + " Pa");
display.println("Temperature: " + String(temperature) + " oC");
display.println("Altimeter: " + String(altimeter) + " m");
display.display();
delay(5000); // Update
Are you trying to change the display type to an SSD1331 from some other type of display?
The SSD1331 library has no clearDisplay() or display() functions.
here i try to fix the code still geting bugs!// Inkludera bibliotek för I2C-kommunikation, OLED display och BMP280 sensorn #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1331.h> #include <Adafruit_Sensor.h> #include "Adafruit_BMP280.h"
// Skapa objekt för OLED displayen och BMP280 sensorn
Adafruit_SSD1331 display(OLED_DC, OLED_CS, OLED_CLK, OLED_MOSI, OLED_RESET);
Adafruit_BMP280 bmp;
no deliberately i forget to tell you that i fixed the code !
// Inkludera bibliotek för I2C-kommunikation, OLED display och BMP280 sensorn #include <Wire.h> #include <Adafruit_GFX.h> #include <Adafruit_SSD1331.h> #include <Adafruit_Sensor.h> #include "Adafruit_BMP280.h"
// Skapa objekt för OLED displayen och BMP280 sensorn
Adafruit_SSD1331 display(OLED_DC, OLED_CS, OLED_CLK, OLED_MOSI, OLED_RESET);
Adafruit_BMP280 bmp;
// Initiera BMP280 sensorn
if (bmp.getStatus() == 0) {
Serial.println("Kunde inte hitta BMP280 sensorn!");
Serial.println("Error: " + String(bmp.getStatus()));
while (true); // Fastna i en oändlig loop om sensorn inte hittas
}
}
void loop() {
// Läs värden från BMP280 sensorn
float temperature = bmp.readTemperature();
float pressure = bmp.readPressure();
float altitude = bmp.readAltitude();
// Skriv ut värdena på seriell monitor
Serial.print("Temperatur: ");
Serial.print(temperature);
Serial.println("°C");
Serial.print("Lufttryck: ");
Serial.print(pressure);
Serial.println(" hPa");
Serial.print("Höjd: ");
Serial.print(altitude);
Serial.println(" m");
Serial.println(); // Tom rad för att få lite mellanrum i ut
}