Make Simple Raspberry Pi Pico W Weather Station With BME280

About the project

This exciting project uses Raspberry Pi Pico W as the hub device that connects readily to the existing network & creates a Web Server.

Items used in this project

Hardware components

Solderless Breadboard Half Size Solderless Breadboard Half Size x 1
Jumper wires (generic) Jumper wires (generic) x 1
DFRobot Gravity: I2C BME280 Environmental Sensor DFRobot Gravity: I2C BME280 Environmental Sensor x 1
Grove Starter Kit for Raspberry Pi Pico with Free Course Grove Starter Kit for Raspberry Pi Pico with Free Course x 1

Software apps and online services

MicroPython MicroPython

Story

Ever had plans ruined by rainfall or thunderstorms and or been surprised by an unexpectedly sunny day? Want to measure temperatures, and humidity levels precisely, ? Then build your own weather station to get more reliable data and control!

This exciting project uses Raspberry Pi Pico Was the hub device that connects readily to the existing network & creates a Web Server. When any connected device accesses this web server, Raspberry Pi Pico W reads the temperature, humidity, barometric pressure & altitude from BME280 & sends them to the web browser of that device with a snazzy interface. Excited much? Let’s get started!

Thank You NextPCB:

This project is successfully finished because of the help and sponsorship from NextPCB. Guys if you have a PCB project, please visit their website and get exciting discounts and coupons, and more.

Why NextPCB

  • Most Efficient, Economic, Inventive PCB Solutions
  • Higher Quality
  • Lower Price
  • Faster Delivery

Introduction - Pi Pico W BME280 Web Server

Did you ever see a remote monitoring system where an HMI-based system displays remote sensor values? Did you ever try to make a web server that can control or display the values of different sensors on your local server? If yes, then this tutorial is a step in the right direction for you.

In this tutorial, we will learn the example of interfacing BME280 with Pico W and how to display temperature, relative humidity, and pressure readings on a web server. you can check also How To Make Raspberry Pi Pico W Web Server with MicroPython

Required Material

Required Components

We will need the following components to connect our Pico W board with the BME280 sensor.

Raspberry Pi Pico W

The Raspberry Pi Pico W is great cost-for-performance metrics of the Pico and adds WiFi to the board. The Pico W features the same attributes as the Raspberry Pi Pico and also incorporates an Infineon CYW43439 wireless chip. CYW43439 supports IEEE 802.11 b/g/n wireless LAN, and Bluetooth:

Only Wireless LAN is supported on the Pico W at the moment, this will be updated as the new features become available). check out - Introduction to Raspberry Pi Pico W – Getting Started: Tutorials, Pinout

BME280 Temperature, Humidity and Pressure Sensor

BME280 is the digital temperature, humidity, and pressure sensor manufactured by Bosch. It’s a successor to sensors like BMP180 and BMP085.

The BME280 is an integrated environmental sensor by Bosch that measures humidity, pressure, and temperature which is able to give users a comprehensive and holistic measurement of the environment.

The module features a simple two-wire I2C interface for communication. The default I2C address of the BME280 module is 0x76 and can be changed to 0x77.

Pinout Diagram

The image below shows the BME280 sensor pinout.

  • VCC = 1.7 to 3.6V. Connect to the 3.3V output of the MCU
  • GND = Ground
  • SCL = Clock (SCL / SCK) for I2C and SPI
  • SDA = Data (SDA / SDI) for I2C and SPI
  • CSB = Chip Select Bus. Logic HIGH for I2C (default), logic LOW for SPI
  • SDO = Data Out (SDO) for SPI. Sets I2C address for I2C

Key Features Of The BME280 Sensor Module:
  • Temperature: -40 to 85°C
  • Humidity: 0 to 100%
  • Pressure: 300 to 1100 hPa
  • Altitude: 0 to 30, 000 ft
  • I2C and SPI Interface
  • 3.3V operation

Wiring Pico W With BME280

Connections are fairly simple. First, you need to connect the VIN pin to the 3.3V output on the Raspberry Pi Pico W and connect GND to the ground.

Next, Connect the SCL pin to the I2C clock 17 pins on your Raspberry Pi Pico Wand connect the SDA pin to the I2C data 16 pins on your Raspberry Pi Pico W.

The following diagram will help you wire everything.

Programming Code

To program the BME280 sensor with Pico W, we need the following libraries.

this library makes our program simple. We can just use a simple command to read the temperature, relative humidity, barometric pressure data, Dew point, and approx. Altitude data.

The Code is divided into two parts:

  • bme280.py
  • main.py

The main code needs a library for BME280

Measuring Temperature, Pressure & Humidity With BME280

BME280 MicroPython CodeME280 library on our Raspberry Pi Pico, we can use the functions available in the library to get sensor readings. For example, you can use the BME280 library to read pressure readings and temperature readings

ME280 MicroPython Code
from machine import Pin, I2C        #importing relevant modules & classes
from time import sleep
import bme280 #importing BME280 library

i2c=I2C(0,sda=Pin(17), scl=Pin(16), freq=400000) #initializing the I2C method
while True:
bme = bme280.BME280(i2c=i2c) #BME280 object created
print(bme.values)
sleep(10) #delay of 10s

After you manually entered the following code onto the file click on the ‘Save’ icon to save your computer code on the hard drive. Save your file by naming it with the written name ending in.py. You may want to save your file in a specific directory. Enjoy!.

Main.py
from machine import Pin, I2C        #importing relevant modules & classes
from time import sleep
import utime
import socket
import network
import bme280 #importing BME280 library

i2c=I2C(0,sda=Pin(17), scl=Pin(16), freq=400000) #initializing the I2C method

wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect("Romeo","hackster")


def web_page():
bme = bme280.BME280(i2c=i2c) #BME280 object created
html = """<html><head><meta http-equiv="refresh" content="5"><meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" href="data:,"><style>body { text-align: center; font-family: "Helvetica", Arial;}
table { border-collapse: collapse; width:55%; margin-left:auto; margin-right:auto; }
th { padding: 12px; background-color: #87034F; color: white; }
tr { border: 2px solid #000556; padding: 12px; }
tr:hover { background-color: #bcbcbc; }
td { border: none; padding: 14px; }
.sensor { color:DarkBlue; font-weight: bold; background-color: #ffffff; padding: 1px;
</style></head><body><h1>BME280 Pi Pico W Weather Station</h1>
<table><tr><th>Parameters</th><th>Value</th></tr>
<tr><td>Temperature</td><td><span >""" + str(bme.values[0]) + """</span></td></tr>
<tr><td>Pressure</td><td><span >""" + str(bme.values[1]) + """</span></td></tr>
<tr><td>Humidity</td><td><span >""" + str(bme.values[2]) + """</span></td></tr>

<head><meta http-equiv="refresh" content="5"><meta name="viewport" content="width=device-width, initial-scale=1"><style>img{display: block; margin-left: auto; margin-right: auto;}</style></head><body><img src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/4gIoSUNDX1BST0ZJTEUAAQEAAAIYAAAAAAQwAABtbnRyUkdCIFhZWiAAAAAAAAAAAAAAAABhY3NwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAA9tYAAQAAAADTLQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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UgB6YWiqFVuKQECUlP1JWAAA8gFQT2UlzCeJo0EFWFenT91k9Ojy6fdm1twyKXFSVCXFhqqVPDYxk+uzyDY7jsSk/jS+/473K4v5Rq26f65PAJCHSrl4wE8/wDTRo0V0NpU/JYsrMlC8KBMODRoBe9h2vsmHY/S91l9SMxiFR9s6/Dpbykr+dqsZVLpyEEHC+boT6gGD/AFq/Hfvaj0VfDy296VI6Lvrsxi69w5DXFyrrY4MU4KThbUNCiSkHJSXVYWsDw2CUaNGugW2UTNzkxPRTFmXlzjyTcqXejRo11NkaNGjQQRo0aNBBf/2Q==" alt="pico" >
</body></html>"""
return html

# Wait for connect or fail
wait = 10
while wait > 0:
if wlan.status() < 0 or wlan.status() >= 3:
break
wait -= 1
print('waiting for connection...')
time.sleep(1)


# Handle connection error
if wlan.status() != 3:
raise RuntimeError('wifi connection failed')
else:
print('connected')
ip=wlan.ifconfig()[0]
print('IP: ', ip)

# Open socket
addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('', 80))
server.listen(5)
print('listening on', addr)

while True:
try:
conn, addr = server.accept()
conn.settimeout(3.0)
print('client connected from', addr)
request = conn.recv(1024)
conn.settimeout(None)
# HTTP-Request receive
print('Request:', request)
# HTTP-Response send
response = web_page()
conn.send('HTTP/1.0 200 OKrnContent-type: text/htmlrnrn')
conn.sendall(response)
conn.close()
except OSError as e:
conn.close()
print('connection closed')

Conclusion

Output

After uploading the program to Raspberry pi pico, in the thonny ide shell print the IP address it’s allocated in the local network. In order to access the Pico W web server, you need to open a web browser on any computer, tablet, or smartphone connected to the same WiFi network and type in the Pico W IP address in the URL field, and hit enter.

On receiving a client request, the Pico W serves as a webpage containing the BME sensor readings, as shown above.

Schematics, diagrams and documents

Schematics Diagram

Code

bme280.py

Credits

Leave your feedback...