BME280 I2C sensor with OLED display

Dependencies:   mbed OLED_SSD1306_SH1106 BME280

Files at this revision

API Documentation at this revision

Comitter:
cspista
Date:
Thu Feb 03 14:52:47 2022 +0000
Commit message:
final version

Changed in this revision

BME280.lib Show annotated file Show diff for this revision Revisions of this file
OLED_SSD1306_SH1106.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BME280.lib	Thu Feb 03 14:52:47 2022 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/MACRUM/code/BME280/#bce5ac62b015
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/OLED_SSD1306_SH1106.lib	Thu Feb 03 14:52:47 2022 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/cspista/code/OLED_SSD1306_SH1106/#da33cca77ce5
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Feb 03 14:52:47 2022 +0000
@@ -0,0 +1,39 @@
+#include "mbed.h"
+#include "BME280.h"
+#include "Adafruit_SSD1306.h"
+#include "Adafruit_SSD1306.h"
+
+I2C i2c(D14,D15);
+
+BME280 sensor(i2c, 0x76<<1);
+Adafruit_SH1106_I2c oled(i2c, NC, 0x78, 64, 128);     // SH1106  I2C 128x64, with no reset pin
+// Adafruit_SSD1306_I2c oled(i2c, NC, 0x78, 64, 128); // SSD1306 I2C 128x64, with no reset pin
+// Adafruit_SSD1306_I2c oled(i2c, NC, 0x78, 32, 128); // SSD1306 I2C 128x32, with no reset pin
+
+int main()
+{
+    char fok = 9;
+    i2c.frequency(400000);
+    oled.setRotation(0);
+    oled.clearDisplay();
+    oled.setTextColor(WHITE);
+    oled.setTextSize(2);
+    oled.setTextCursor(10,8);
+    oled.printf("BME280 \r\n  demo");
+    oled.display();
+    wait(5.0);
+    while(1) {
+        float tempC = sensor.getTemperature();
+        float pressure = sensor.getPressure();
+        float humidity = sensor.getHumidity();
+        oled.clearDisplay();
+        oled.setTextCursor(20,4);
+        oled.printf("%.1f %cC",tempC,fok);
+        oled.setTextCursor(8,24);
+        oled.printf("%.1f hPa",pressure/0.985);
+        oled.setTextCursor(20,44);
+        oled.printf("%.0f %%",humidity);
+        oled.display();
+        wait(2);
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Feb 03 14:52:47 2022 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file