These days if you wanted to know the temperature outside, or even the humidity levels you would probably just look it up on your phone or better still ask Alexa or Google about it. Here’s a project to challenge the maker in you. Instead of asking Google or Alexa the weather conditions how about building your own simple home weather monitoring project using a Raspberry Pi Pico and a BME 280 programmed with Micropython.
This tutorial is slightly different from the previous BME 280 tutorials. In this tutorial we will be using the PiStop PiMoroni module to light up some LED’s, trigger reading of the values from the BME 280 (using a push button switch) to display the temperature, humidity values on an OLED display. If you do not have the PiStop PiMoroni module lying around you could consider using 3 LED’s and 3 x 10K Ohm resistors. You will need a BME280, SSD1306 OLED Display in addition to the PiStop module (or 3 LED’s, 3 x 10K resistors) and a Pi Pico.
PiStop by PiMoroni : The PiStop module from PiMoroni is a simple traffic light module consisting of three LED’S i.e. Green, Amber, Red along with resistors on board to allow you directly interface with any maker board. In our case we chose to use PiStop from PiMoroni along with the Raspberry Pi Pico. The PiStop includes resistors in line with each of the LED’s along with a separate Vcc (power) and GND (ground) line, thus making it really easy for anyone to get started with their traffic light project. The entire package makes it very easy to work with the LED’s and allows embedding the PiStop into various maker projects where a visual traffic light setup might be required.
You can purchase the PiStop from PiMoroni from the following link – PiStop at PiMoroni
Raspberry Pi Pico – Raspberry Pi Pico is a tiny, fast, and versatile board built using RP2040, the flagship microcontroller chip designed by Raspberry Pi in the UK. From light displays and IoT devices to signage and manufacturing processes, Raspberry Pi Pico gives the maker the power to control countless home, hobby, and industrial projects. Programmable in C and MicroPython, the Pi Pico is adaptable to a vast range of applications and skill levels, and getting started is as easy as dragging and dropping a file. More experienced users can take advantage of Raspberry Pi Pico’s rich peripheral set, including SPI, I2C, and eight Programmable I/O (PIO) state machines for custom peripheral support.
Here’s the specifications (from Raspberry Pi Foundation website) of the Raspberry Pi Pico in case you are interested –
- 21 mm × 51 mm form factor
- RP2040 microcontroller chip designed by Raspberry Pi in the UK
- Dual-core Arm Cortex-M0+ processor, flexible clock running up to 133 MHz
- 264kB on-chip SRAM
- 2MB on-board QSPI flash
- 2.4GHz 802.11n wireless LAN (Raspberry Pi Pico W and WH only)
- 26 multifunction GPIO pins, including 3 analogue inputs
- 2 × UART, 2 × SPI controllers, 2 × I2C controllers, 16 × PWM channels
- 1 × USB 1.1 controller and PHY, with host and device support
- 8 × Programmable I/O (PIO) state machines for custom peripheral support
- Supported input power 1.8–5.5V DC
- Operating temperature -20°C to +85°C (Raspberry Pi Pico and Pico H); -20°C to +70°C (Raspberry Pi Pico W and Pico WH)
- Castellated module allows soldering direct to carrier boards (Raspberry Pi Pico and Pico W only)
- Drag-and-drop programming using mass storage over USB
- Low-power sleep and dormant modes
- Accurate on-chip clock
- Temperature sensor
- Accelerated integer and floating-point libraries on-chip
Pinout diagram for the Raspberry Pi Pico – To help you work out which pins are located where and what they are called you can refer to the pinout diagram for the Raspberry Pi Pico provided below.
BME 280 sensor – The BME280 is a humidity sensor especially developed for mobile applications and wearables where size and low power consumption are key design parameters. The unit combines high linearity and high accuracy sensors and is perfectly feasible for low current consumption, long-term stability and high EMC robustness. The humidity sensor offers an extremely fast response time and therefore supports performance requirements for emerging applications such as context awareness, and high accuracy over a wide temperature range. Operational range for the BME280 is :
- Pressure: 300…1100 hPa
- Temperature: -40…85°C
SSD1306 OLED I2C Display – The SSD1306 is a single-chip monochrome OLED graphic display. Its screen is 128 pixels wide and 64 pixels deep (128×64). The SSD1306 is available as a monochrome or as a color display. As you may be able to surmise, the SSD1306’s display is really tiny. It’s just under 3 centimeters when measured diagonally. The SSD1306 includes a bright, high-contrast OLED screen.
The SSD1306 controller chip governs each pixel on the screen – turning it on or off. Many graphic displays require a backlight to make their output more visible. However, since the SSD1306 uses an OLED screen, it produces its light. Thus, it does not require any additional background illumination.
SSD1306 is designed to consume low amounts of power but deliver a screen with a high contrast. The SSD1306 can be interfaced with using either the SPI or i2C protocol. We can achieve this by using the jumpers on the back of the unit. In our tutorials we will be accessing the SSD1306 OLED over I2C. The SSD1306 has a built-in boost converter and an onboard regulator. Thus, the SSD1306 is directly compatible with 3V and 5V microcontrollers (no level shifter required).
Additional technical specifications provided below.
- OLED Driver: SSD1306
- I2C address: 0x3C (ASW:OFF) or 0x3D (ASW:ON)
- Dimensions PCB: 25.4×25.4mm
- OLED: 27×19.5mm (Glass panel), 23x11mm (effective display area)
- Mounting Holes: 2x M2.5
- Operating Voltage: 3.3V or 5V
Bill Of Material – Here are the components you will need to build your home weather station –
- Raspberry Pi Pico microcontroller x 1
- BME280 (not a BMP280) x 1
- Dupont male to male wires x 15
- USB micro cable x 1
- 800 point Breadboard x 1
- 1 x Pi Stop PiMoroni board or 3 LED’s with 3 x 10K resistors
- 1 x Push button switch
- 1 x SSD1306 OLED Display
Circuit diagram – Follow the circuit diagram provided below and assemble the circuit before you proceed with programming the Pi Pico to fetch temperature, pressure and humidity from the BME 280.
The above diagram was put together in Fritzing, not being able to access a PiStop module within Fritzing we have displayed the PiStop as three LED’s, each connected to a 10K Ohm resistors (in line with each LED). The connections for this tutorial are to be made as follows –
- PiStop Red LED connected to GPIO 18
- PiStop Amber LED connected to GPIO 17
- PiStop Green LED connected to GPIO 16
- PiStop Vcc connected to Vcc or 3V3 OUT
- PiStop GND (Ground) connected to GND
- BME 280 Vcc connected to Vcc or 3V3 OUT
- BME 280 GND (Ground) connected to GND
- BME 280 SCL connected to GPIO 1
- BME 280 SDA connected to GPIO 0
- SSD1306 OLED Display Vcc connected to Vcc or 3V3 OUT
- SSD1306 OLED Display GND (Ground) connected to GND
- SSD1306 OLED Display SCL connected to GPIO 1
- SSD1306 OLED Display SDA connected to GPIO 0
- 1 end of the push button connected to 3V3
- other end of the push button connected to GPIO 14
If you are using the PiStop PiMoroni module you do not have to use the resistors we’ve shown above. These PiStop module includes SMD resistors on the module. If you do not have the PiStop module you can just use 3 x 10K Ohm resistors instead.
Code for the tutorial – Open up your favourite Micropython editor and type in the following code. There are a number of editors out there for you to choose from. The two most commonly used editors for Micropython are Thonny and Mu. We tend to use Thonny a lot in class with our kids.
from machine import Pin, I2C #importing relevant modules & classes import time from ssd1306 import SSD1306_I2C import bme280 # Setting up the pin which we'll use to blink the onboard LED: led_green = Pin(16, Pin.OUT) led_amber = Pin(17, Pin.OUT) led_red = Pin(18, Pin.OUT) # Setting up the button with a Pull_Down resistor button = Pin(14, Pin.IN, Pin.PULL_DOWN) # Setting up I2C pin for use with the BME280 i2c1=I2C(0,sda=Pin(0), scl=Pin(1), freq=400000) #Setting up the BME280 for use in the program bme = bme280.BME280(i2c=i2c1) # Setting up I2C pin for use with the OLED i2c2=I2C(0,sda=Pin(0), scl=Pin(1), freq=400000) #Setting up the OLED Display oled = SSD1306_I2C(128, 64, i2c2) #oled.text("Hello!!!", 0, 0) #oled.text("This is a test", 0, 16) #oled.text("Thank You", 0, 32) #oled.show() while True: if button.value() == 1: #Printing welcome message to OLED screen oled.fill(0) #clearing up screen oled.text("Welcome!!!", 0, 0) #line 1 of the OLED oled.text("Fetching Data....", 0, 16) #line 2 of the OLD oled.text("Please Wait...", 0, 32) #line 3 of the OLED oled.show() #display on the OLED time.sleep(1) oled.fill(0) #clearing up the screen temp = bme.values pressure = bme.values humidity = bme.values tempString = "Temp - " + temp pressureString = "Pr - " + pressure #Print to console print("Temp is ",temp," || Pressure is ",pressure," || Humidity is ",humidity) #print(bme.values) #Print to OLED display oled.text("Welcome!!!", 0, 0) oled.text(tempString, 0, 16) oled.text(pressureString, 0, 32) oled.show() # Blinking the Green LED led_green.on() time.sleep(.5) led_green.off() # Blinking the Amber LED led_amber.on() time.sleep(.5) led_amber.off() # Blinking the Red LED led_red.on() time.sleep(.5) led_red.off() # Sleeping for 3s time.sleep(2) else: # Turning all the LED's off led_green.off() led_red.off() led_amber.off()
Summary – In this tutorial we used Micropython to program the Raspberry Pi Pico to grab temperature, pressure and humidity from the BME 280, display those details on the SSD1306 OLED display. The code would trigger the reading of the temperature, humidity, pressure from the BME280 once the push button was pressed and light up the LED’s at the end. When the switch isn’t pressed the LED’s remain turned off and the BME280 is not queried.
We hope you enjoyed the tutorial. Drop us a note at trevor at hack2 dot live if you have any questions, comments or suggestions.