Setting up RPi for a BME280 Temp Humidity Pressure sensor - Hives/makers-weather-station GitHub Wiki
Components
- A Raspberry Pi, either one that has built-in wireless connectivity or has a a WiFi dongle
- A BME280 pressure, temperature, and humidity sensor
- Some 5mm-pitch PCB mount screw terminal blocks
- A breadboard (board with pin holes not a breadboard ;-) ), some jumper wires
Installing the sensor
Check this helpful link for detailed wiring instructions... I recommend soldering as the electrical connection is dodgy if you just plug it in with pins.
RPi
- Install Raspbian and check all up to date
- Check you have python3 installed with pip3 package manager in terminal:
python3 --version
- if not install latest
sudo apt-get update
sudo apt-get install python3
- Install python library for bme280 sensor:
sudo pip3 install RPi.bme280
Your code
- Import libraries into your code and write and save as a py file (
read_sensor.py
)
import bme280 # Import library of methods for sensor
import smbus2 # Import library to read RPi system bus
port = 1 # system bus port 1 where sensor is connected
address = 0x77 # BME280 address, default on production, could be different
bus = smbus2.SMBus(port) # var for connection to port
# load current calibration settings on bme280 before sampling
bme280.load_calibration_params(bus, address)
# bme280 library method to take a sample and store into variable as dictionary
sensor_data = bme280.sample(bus, adress)
# access that dictionary for the sample data
ambient_temperature = sensor_data.temperature
humidity = sensor_data.humidity
pressure = sensor_data.pressure
print(ambient_temperature, humidity, pressure) # print the data vars!
- Finally run the python program in terminal
python3 read_sensor.py
And marvel at the data!