Projects / Blue Pill weather node

Blue Pill weather node

Intermediate2.5 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. STM32ST

    Wire the programmer

    SWDIO, SWCLK, GND and 3.3V.

  2. STM32

    Wire the sensor and display

    SDA to PB7, SCL to PB6, power at 3.3 V.

  3. STM32BME28028.0°CSSD1306

    Install the libraries

    Adafruit BME280, Unified Sensor, SSD1306 and GFX.

  4. STM32

    Upload the sketch

    Readings appear on the display.

  5. STM32ST

    Plug in the USB cable and unplug the programmer power

    Open the serial monitor at 115200.

  6. STM32

    Wait a minute

    A new line arrives each minute.

  7. STM32

    Move the sensor a few centimetres from the board

    Compare the temperature.

In short

How do you build a blue Pill weather node?

A Blue Pill reads temperature, humidity and pressure from a BME280, shows them on an OLED and sends a line over USB serial every minute. You need STM32 Blue Pill (STM32F103C8T6), ST-Link V2 programmer (clone), BME280 Environmental Sensor, SSD1306 OLED Display and Breadboard 830 Tie Points. It takes 7 steps and about 150 minutes.

Level
Intermediate
Time
About 150 min
Parts
5

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
ST-Link GNDBlue Pill GNDGround
ST-Link SWDIOBlue Pill DIODebug data
ST-Link SWCLKBlue Pill DCLKDebug clock
ST-Link 3.3VBlue Pill 3.3 pinPower from the programmer (do not also plug in USB)
BME280 VCC and OLED VCCBlue Pill 3.3 pinPower at 3.3 V
BME280 GND and OLED GNDBlue Pill GNDCommon ground
BME280 SDA and OLED SDABlue Pill PB7Shared I2C data
BME280 SCL and OLED SCLBlue Pill PB6Shared I2C clock
USB cableBlue Pill USB socketSerial output (after programming, unplug the ST-Link power wire)

Code

The BME280 measures temperature, humidity and air pressure and holds factory calibration constants inside, which the library reads once and uses to turn the raw counts into real values. It talks over I2C and shares the bus with the OLED, and it answers at 0x76 or 0x77 depending on how the module is wired, so the sketch tries both. The Blue Pill runs at 3.3 V, which suits the sensor. The board has a USB socket that can act as a serial port, so the same sketch also prints a line each minute that you can read in the serial monitor or log to a file on a computer. Readings are indicative only. A sensor close to the board or in sun reads warm, and humidity is easily thrown off by a breath or a hot component, so mount the module on short wires a few centimetres away from the board and out of direct sun. Pressure falls with height, so a reading means more once you compare it with a local report.

Runs on a virtual STM32 Blue Pill in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <Wire.h>
#include <Adafruit_BME280.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

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

unsigned long lastDraw = 0, lastSend = 0;
bool sentFirst = false;

void setup() {
  Serial.begin(115200);                          // USB serial (CDC)
  Wire.begin();                                  // PB7 SDA, PB6 SCL
  if (!oled.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { while (true) {} }
  if (!bme.begin(0x76) && !bme.begin(0x77)) {    // the module uses one of two addresses
    oled.clearDisplay();
    oled.setTextColor(SSD1306_WHITE);
    oled.setCursor(0, 0); oled.print("BME280 not found");
    oled.display();
    while (true) {}
  }
}

void loop() {
  if (millis() - lastDraw >= 2000) {
    lastDraw = millis();
    float t = bme.readTemperature();
    float h = bme.readHumidity();
    float p = bme.readPressure() / 100.0F;       // hPa
    oled.clearDisplay();
    oled.setTextColor(SSD1306_WHITE);
    oled.setTextSize(1);
    oled.setCursor(0, 0);  oled.print("Weather node");
    oled.setTextSize(2);
    oled.setCursor(0, 14); oled.print(t, 1); oled.print(" C");
    oled.setCursor(0, 34); oled.print(h, 0);  oled.print(" % RH");
    oled.setTextSize(1);
    oled.setCursor(0, 56); oled.print(p, 1); oled.print(" hPa");
    oled.display();

    if (!sentFirst || millis() - lastSend >= 60000UL) {
      sentFirst = true;
      lastSend = millis();
      Serial.print("T="); Serial.print(t, 1);
      Serial.print(" C, RH="); Serial.print(h, 0);
      Serial.print(" %, P="); Serial.print(p, 1);
      Serial.println(" hPa");
    }
  }
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual STM32 Blue Pill (F103C8) with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

T=24.2 C, RH=52 %, P=1008.5 hPa

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Room conditionsPlausible temperature and humidity
Breathe near the sensorHumidity rises briefly
Move the sensor away from the boardTemperature reads a little lower
Serial monitor openOne line per minute
Cover the sensorReadings move slowly

If it does not work

BME280 not found

Check SDA, SCL and the 3.3 V supply, and the module is a BME280 and not a BMP280.

No serial output

Check USB support is set to CDC, and the port is selected.

Temperature reads high

Move the sensor away from the board and the regulator.

Garbled text

Set the monitor to 115200.

Upload fails

Check the ST-Link wires and boot jumpers.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the blue Pill weather node?

STM32 Blue Pill (STM32F103C8T6), ST-Link V2 programmer (clone), BME280 Environmental Sensor, SSD1306 OLED Display and Breadboard 830 Tie Points.

How long does the blue Pill weather node take to build?

About 150 minutes for a intermediate maker, in 7 steps.

How do I know the blue Pill weather node works?

Room conditions: Plausible temperature and humidity. Breathe near the sensor: Humidity rises briefly. Move the sensor away from the board: Temperature reads a little lower.

BME280 not found: what should I check?

Check SDA, SCL and the 3.3 V supply, and the module is a BME280 and not a BMP280.

No serial output: what should I check?

Check USB support is set to CDC, and the port is selected.

Temperature reads high: what should I check?

Move the sensor away from the board and the regulator.

Garbled text: what should I check?

Set the monitor to 115200.