-
-
Save machinechat/40f4a9ac75757f6a07a22810c787d3e4 to your computer and use it in GitHub Desktop.
Python code to read BME280 Module connected to a Red Pitaya STEMlab 125-14
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# | |
# First line is needed for JEDI to use proper Python version | |
# | |
# RPitaya_bme280.py - JEDI One (https://www.machinechat.io/jedi) Custom Plug-in Python script for Red Pitaya | |
# to read a BME280 sensor connected via i2c on Extension connectors and make the data | |
# available to Machinechat's JEDI One. Tested on a STEMlab 125-14 with SparkFun Qwiic BME280 module (address 0x77) | |
# If you use a generic BME280 module, the address may be 0x76 | |
# | |
# Connect a BME280 module to the Red Pitaya's Extension connectors as follows: | |
# | |
# Sensor Red Pitaya Extension connector | |
# VIN E1 - +3V3 | |
# GND E1 - GND | |
# SDA E2 - I2C_SDA | |
# SCL E2 - I2C_SCL | |
# | |
# Install needed libraries: "pip3 install rpi.bme280" | |
# | |
# This will also install smbus2, which is needed | |
# You can read about the library here: https://pypi.org/project/RPi.bme280/ | |
# | |
# v0.1 DRM 12/31/2022 | |
import smbus2 | |
import bme280 | |
# Red Pitaya i2c port number | |
port = 0 | |
# Address of BME280 i2c sensor - 0x76 or 0x77, depends on bme280 sensor module | |
address = 0x77 | |
# Unique name (your choice - one unique word) that will be used within JEDI One | |
# to identify data from this sensor | |
Target_ID = "bme280-office1231" | |
bus = smbus2.SMBus(port) | |
calibration_params = bme280.load_calibration_params(bus, address) | |
data = bme280.sample(bus, address, calibration_params) | |
# Make the data available to JEDI One | |
print("metric:id=%s,n=Temperature,vd=%0.2f,u=F" % (Target_ID, ((data.temperature * 1.8) + 32.0))) | |
print("metric:id=%s,n=Humidity,vd=%0.2f,u=%%" % (Target_ID, data.humidity)) | |
print("metric:id=%s,n=Pressure,vd=%0.2f,u=inHg" % (Target_ID, (data.pressure * 0.0295300586))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment