deckle studioOpen in the editor

ESP32: weather station (BME280 + OLED)

Arduino sketch on both Xtensa cores: BME280 → OLED.

  • BME280
  • SSD1306 OLED
Open in the simulatorNo account needed: press Simulate and it runs.

How it works

An ESP32-DevKitC runs an Arduino sketch (Arduino-ESP32 core, FreeRTOS on both Xtensa LX6 cores): the BME280 measures temperature, air pressure and humidity, the 0.96" OLED (SSD1306) shows them, and every 2 s they go to the serial console. Both sit on the I²C bus (SDA GPIO21, SCL GPIO22) with the original Adafruit libraries. Set the sensor's environment in the inspector while it runs; change the sketch in the code editor (Firmware: arduino or zephyr in the part's parameters).

Wiring

Each line is one connection (net) and the pins it joins.

NetPins
GNDA1 GNDDS1 GNDU2 GND
3V3A1 3V3DS1 VCCR1 1R2 1U2 VIN
SCLA1 GPIO22DS1 SCLR1 2U2 SCL
SDAA1 GPIO21DS1 SDAR2 2U2 SDA

Parts

Firmware

sketch.ino · 37 lines

// ESP32 weather station: a BME280 measures temperature, humidity and pressure, an SSD1306 OLED
// shows them; both on the I2C bus (SDA GPIO21, SCL GPIO22). Every 2 s also on the serial console.
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_BME280.h>

Adafruit_SSD1306 oled(128, 64, &Wire, -1);
Adafruit_BME280 bme;

void setup() {
  Serial.begin(115200);
  Wire.begin(21, 22);
  if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) Serial.println("no OLED at 0x3C");
  if (!bme.begin(0x76)) Serial.println("no BME280 at 0x76");
  oled.setTextColor(SSD1306_WHITE);
  Serial.println("ESP32 weather station");
}

void loop() {
  float t = bme.readTemperature(), h = bme.readHumidity(), p = bme.readPressure() / 100.0f;
  oled.clearDisplay();
  oled.setTextSize(1);
  oled.setCursor(0, 0);
  oled.print("ESP32 weather");
  oled.setTextSize(2);
  oled.setCursor(0, 16);
  oled.printf("%.1f C", t);
  oled.setTextSize(1);
  oled.setCursor(0, 40);
  oled.printf("Humidity %.0f %%", h);
  oled.setCursor(0, 52);
  oled.printf("%.1f hPa", p);
  oled.display();
  Serial.printf("T %.1f C  H %.0f %%  P %.1f hPa\n", t, h, p);
  delay(2000);
}
Open in the simulator

More examples: Microcontrollers