Wio Terminal Weather station using BME280 and PlatformIO

This tutorial covers how to build a Weather station using Seeed Wio Terminal and BME280 sensor. To build this project we will use the Wio Terminal with PlatformIO. This is an interesting project because it helps us to explore this new device developed by Seeed Studio. Moreover, it covers several aspects related to Wio Terminal. In more details, you will learn:

  • How to use BME280 sensor with Wio Terminal
  • Wio Terminal LCD display and how to show data
  • how to use PlatformIO with Wio Terminal

What is Seeed Studio Wio Terminal?

Wio Terminal is all-in-one device with a set of great features. You can have more information here. Just to recap brifily, this devices has:

  • ATSAMD51P19 with ARM Cortex-M4F core running at 120MHz
  • Built-in Wifi and Bluetooth
  • 2.4” LCD display
  • Raspberry Pi 40-pin Compatible GPIO
  • Grove module compatibility
  • Support Arduino support MicroPython

and much more.

This is a perfect device when you want to build an all-in-one solution. In this tutorial, we will explore how to use Wio Studio connecting it to a BME280 sensor exploiting the Arduino support.

Project overview: Weather station with Wio Terminal

Before going deeper in to the details of this project, it is useful to describe it briefly. The Wio Terminal uses a BME280 sensor to read:

  • temperature
  • humidity
  • pressure

moreover, in this project, we wil calculate the heat index. The final result is shown in the picture below:

Wio Terminal Weather station using BME280

The circle in the left bottom corner is the heat index. Let us explore how to build this weather station.

PlatformIO and Wio Terminal

Even if you can use the Arduino IDE to develop this project or an Arduino IDE alternative, I prefer to develop this project using PlatformIO. In more detail, I will use VSCode with the PlatformIO plugin.

Let’s create a new project using PlatformIO:

Wio terminal with PlatformIO

Once you have created your project we can start implementing it.

To know more: How to use ESP32 with BMP280 and SSD1306

Connecting Wio Terminal to BME280 sensor

Even if you can chose Grove sensor family, this project uses a BME280 sensor connected to Wio Terminal. Therefore, we will use the pins located on the back side of the terminal. The BME280 sensor is a I2C sensor, therefore we have to connect four wires:

Wio TerminalBME280 sensor
PIN1 (Vcc)Vcc

The image below shows the connections:

Seeed Wio Terminal BME280 connection

Reading the temperature, humidity and pressure

Once we have connected the sensor to the device, let us this code to your project to read the temperature, humidity and pressure:

#include <Adafruit_BME280.h> #include <Adafruit_Sensor.h> #include <Wire.h> Adafruit_BME280 bme; void setup() { Serial.begin(9600); if (!bme.begin(0x76)) { Serial.println("I Have some problem to initialize the sensor"); } ... } void loop() { temp = bme.readTemperature(); hum = bme.readHumidity(); press = bme.readPressure(); heatIndex = computeHeatIndex(temp, hum); delay(10000); }

Notice that in the code above 0x76 refer to the address of the sensor. Change it according to your needs.

The heat index is an index based on temperature and humidity. Matching the index value with a table we can know how risky is the current condition for the human body. You can find more information here.

Showing the sensor readings using Wio Terminal

As described previously, Seeed Wio Terminal has a built-in 2.4” color display that we can use to display the sensor readings and the heat index. The nice aspect of this device is that it has already the LCD display integrated and we don’t have to use cables to connect it. It is very easy to use this LCD display because it is based on X,Y coordinates where (0,0) is the upper left corner.

Before using the Wio Terminal LCD display, add the following line to the code:

#include "TFT_eSPI.h"

Next, it is necessary to initialize the display:

void setup() { ... // Initialize TFT tft.begin(); digitalWrite(LCD_BACKLIGHT, HIGH); tft.fillScreen(TFT_BLACK); tft.setRotation(3); }

At line 6, we set the background to Black while at line 7, we adjust the LDC display rotation in the the “portrait” mode.

Finally, we can draw all the sensor readings:

void drawTemperature(float temp) { tft.setTextSize(20); switch ( (int) temp) { case -30 ... 5: tft.setTextColor(TFT_CYAN, TFT_BLACK); break; case 6 ... 20: tft.setTextColor(TFT_YELLOW, TFT_BLACK); break; case 21 ... 30: tft.setTextColor(TFT_GREEN, TFT_BLACK); break; case 31 ... 50: tft.setTextColor(TFT_RED, TFT_BLACK); break; default: break; } xpos = tft.drawString(String((int) temp), 5, 100); tft.setTextSize(4); tft.setTextColor(TFT_WHITE); xpos += tft.drawString("c", xpos + 5,100); } void drawHum(float hum) { int xpos1 = 0; tft.setTextSize(4); tft.setTextColor(TFT_CYAN, TFT_BLACK); xpos1 = tft.drawString(String(hum), xpos + 45, Y_OFFSET + 30); tft.setTextSize(2); tft.drawString("%", xpos + xpos1 + 50, Y_OFFSET + 30); } void drawPres(float press) { int xpos1 = 0; tft.setTextSize(4); tft.setTextColor(TFT_CYAN, TFT_BLACK); xpos1 = tft.drawString(String((int) (press / 100)), xpos + 45, Y_OFFSET + 160); tft.setTextSize(2); tft.drawString("mbar", xpos + xpos1 + 50, Y_OFFSET + 160); } void drawHeatIndex(float hi) { // Select color uint32_t color = TFT_GREEN; if (hi > HI_NORMAL && hi < HI_CAUTION) color = TFT_YELLOW; else if (hi >= HI_CAUTION && hi < HI_DANGER) color = 0xFFD700; else if (hi >= HI_DANGER && hi < HI_EXTREME) color = 0xFF8C00; else if (hi >= HI_EXTREME) color = TFT_RED; tft.fillCircle(30, 200, 20, color); }

A few things to notice:

  • The temperature font color changes according to the temperature value
  • The Heat Index is represented as a filled circle where the background color depends on the risk level

Wrapping up

At the end of this Wio tutorial, we have explored how to use Seeed Wio Terminal to build a weather station. We have learned how to connect the Wio Terminal to the BME280 sensor and how to read the temperature, humidity and pressure. Moreover, we have covered how to use Wio Terminal LCD display to create an UI to show data.

Wio Terminal is a really powerful device with interesting features and a set of built-in sensors. You can use this device in several IoT projects. Moreover, Wio Terminal can be used with PlatformIO and it really simplifies the development process.