import board import busio import adafruit_bme280 i2c = busio.I2C(board.SCL, board.SDA) bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c,address=0x76) # address can be known from sudo i2cdetect -y 1 print("\nTemperature: %0.1f C" % bme280.temperature) print("Humidity: %0.1f %%" % bme280.humidity) print("Pressure: %0.1f hPa" % bme280.pressure) bme280.sea_level_pressure = 1013.25 print("Altitude = %0.2f meters" % bme280.altitude)
wind_event_time = 0 last_time = 0 humidity = 0 ambient_temp = 23.4 pressure = 1067 ground_temp = 16.3 update_flag = 2 # Set-up Raspberry-Pi ports gpio.setmode(gpio.BCM) gpio.setup(RAIN_GPIO, gpio.IN, pull_up_down=gpio.PUD_UP) gpio.setup(WIND_SPEED_GPIO, gpio.IN, pull_up_down=gpio.PUD_UP) # Create library object using our Bus I2C port i2c = busio.I2C(board.SCL, board.SDA) bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) # change this to match the location's pressure (hPa) at sea level bme280.sea_level_pressure = 1013.25 # create a string to hold the first part of the URL WUurl = "https://weatherstation.wunderground.com/weatherstation/updateweatherstation.php?" WU_station_id = "" # Replace XXXX with your PWS ID WU_station_pwd = "" # Replace YYYY with your Password WUcreds = "ID=" + WU_station_id + "&PASSWORD="******"&action=updateraw" # define a threaded callback function # this will run in another thread when a rain event is triggered def rain_callback(channel):
def __init__(self): self.i2c = busio.I2C(board.SCL, board.SDA) self. bme280 = adafruit_bme280.Adafruit_BME280_I2C( self.i2c, address=0x76)
from influxdb import InfluxDBClient from mlx90614 import MLX90614 # Default device I2C address for IR IR_thermometer_address = 0x5a thermometer = MLX90614(IR_thermometer_address) #read and define IR measurements tempObj = thermometer.get_obj_temp() tempIRAmb = thermometer.get_amb_temp() # Create library object using our Bus I2C port i2c = busio.I2C(board.SCL, board.SDA) #bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c) #or with other sensor address bme280amb = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76) bme280enc = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x77) # change this to match the location's pressure (hPa) at sea level bme280amb.sea_level_pressure = 1013.25 #line to adjust the measurements by adding or subtracting last value pressureCorrAmb = (bme280amb.pressure + 0) humidityCorrAmb = (bme280amb.humidity + 0) tempertureCorrAmb = (bme280amb.temperature - 0) #dewpoint calculation b = 17.62 c = 243.12 gamma = (b * tempertureCorrAmb / (c + tempertureCorrAmb)) + math.log(humidityCorrAmb / 100.0)
from adafruit_bitmap_font import bitmap_font from adafruit_display_text import label import adafruit_bme280 import adafruit_ds3231 import eclockhw import eclocknet import eclockui ALTITUDE_ADJUSTMENT = 10.5 tpl5111 = eclockhw.PowerSwitch(board.D5) i2c = busio.I2C(board.SCL, board.SDA) rtc = adafruit_ds3231.DS3231(i2c) bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76) battery = eclockhw.Battery(board.VOLTAGE_MONITOR) display = eclockui.Display() net = eclocknet.NetCache(cs=DigitalInOut(board.D13), ready=DigitalInOut(board.D11), reset=DigitalInOut(board.D12)) font = terminalio.FONT #bitmap_font.load_font("/cantarell-18.bdf") if net.seconds_since_last_refresh(rtc) > 3600: net.refresh(rtc) temperature = rtc.temperature voltage = battery.voltage() clk = rtc.datetime if clk.tm_hour < 12:
import time from datetime import datetime import board import adafruit_bme280 from google.oauth2.service_account import Credentials from googleapiclient.discovery import build #--| User Config |----------------------------------------------- SERVICE_ACCOUNT_FILE = 'YOUR_CREDENTIALS_FILE.json' SPREADSHEET_ID = 'YOUR_SHEET_ID' DATA_LOCATION = 'A1' UPDATE_RATE = 60 #--| User Config |----------------------------------------------- # Sensor setup bme = adafruit_bme280.Adafruit_BME280_I2C(board.I2C()) # Google Sheets API setup SCOPES = [ 'https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive' ] CREDS = Credentials.from_service_account_file(SERVICE_ACCOUNT_FILE, scopes=SCOPES) SHEET = build('sheets', 'v4', credentials=CREDS).spreadsheets() # Logging loop print("Logging...") while True: values = [[ datetime.now().isoformat(), bme.pressure, bme.temperature, bme.humidity