def read(self, SIO): if not self.bme680: i2c = busio.I2C(board.SCL, board.SDA) self.bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c) self.bme680.temperature_oversample = 16 self.bme680.pressure_oversample = 16 self.bme680.humidity_oversampe = 16 try: T = self.bme680.temperature RH = self.bme680.humidity P = self.bme680.pressure VOC = 1000. / self.bme680.gas except: traceback.print_exc() self.bme680 = None return self.t = time.time() print("BME680 at t =", self.t, ":\n\t", "%.3f C\n\t" % T, "%.3f mbar\n\t" % P, "%.2f %% humidity\n\t" % RH, "%.3g millimho VOC\n" % VOC) SIO.log_readout(self.T_id, T, self.t) SIO.log_readout(self.P_id, P, self.t) SIO.log_readout(self.RH_id, RH, self.t) SIO.log_readout(self.VOC_id, VOC, self.t)
def get_data(): i2c = busio.I2C( board.SCL, board.SDA) # Erstellen eines Objektes zum Nutzen des I2C Busses sensor = adafruit_bme680.Adafruit_BME680_I2C( i2c) # Erstellen eines Objektes unseren Sensors inklusive der Daten return sensor.humidity, sensor.pressure, sensor.temperature # Rueckgabe der aktuellen Sensordaten
def sensor_filt(selected_meas, filt_pts, filt_int): """filter the measured values""" sensor_polls = [] for i in range(0, filt_pts): try: sensor = adafruit_bme680.Adafruit_BME680_I2C(i2c) command = { "temp": sensor.temperature, "humidity": sensor.humidity, "gas": sensor.gas, "pressure": sensor.pressure } cur_poll = command[selected_meas] except: print("UNKNOWN: sensor polling error") sys.exit(3) sensor_polls.append(cur_poll) sensor = None time.sleep(filt_int) # sleep for input number of seconds filt_val = statistics.median(sensor_polls) return filt_val, sensor_polls
def __init__(self): """ connects to bme680 sensor via I2C """ # load bme settings self.i2c = I2C(board.SCL, board.SDA) self.bme680 = adabme.Adafruit_BME680_I2C(self.i2c, debug=False) self.bme680.sea_level_pressure = 978.33 #estimated pressure of germany self.ErrorMsg = False
def __init__(self, i2c: I2C, config: Config): super().__init__(self.__class__.__name__, config) try: self.i2c = i2c self.sensor = adafruit_bme680.Adafruit_BME680_I2C(self.i2c) self.sensor.sea_level_pressure = self.config.pressure self.enabled = True except: self.enabled = False
def init(): """ init bme680 sensor via I2C :return: """ global bme680 i2c = I2C(board.SCL, board.SDA) bme680 = adabme.Adafruit_BME680_I2C(i2c, debug=False) bme680.sea_level_pressure = 953.25
def init(): global i2c global sensor global start_time i2c = busio.I2C(board.SCL, board.SDA) sensor = adafruit_bme680.Adafruit_BME680_I2C(i2c) start_time = time.time() sensor.sea_level_pressure = 1013.25 # Avg sea-level pressure return sensor
def __init__(self): #global i2c #global bme680 # Create library object using our Bus I2C port self._i2c = I2C(board.SCL, board.SDA) self._bme680 = adafruit_bme680.Adafruit_BME680_I2C(self._i2c) # change this to match the location's pressure (hPa) at sea level self._bme680.sea_level_pressure = 1013.25
def __init__(self, i2c_bus, name="sns_thg", interval=SENSOR_UPDATE_INTERVAL, *args, **kwargs): Device.__init__(self, name=name, interval=interval, *args, **kwargs) import adafruit_bme680 self.sensor = adafruit_bme680.Adafruit_BME680_I2C(i2c_bus)
def init(self): """ Connect to the device """ self.i2c = I2C(board.SCL, board.SDA) self._sensor = adafruit_bme680.Adafruit_BME680_I2C( self.i2c, address=self.config['address'], debug=False) # Change this to match the location's pressure (hPa) at sea level self._sensor.sea_level_pressure = self.config.get( 'calibration_pressure', 1013.25) return True
def bme680_data(): i2c = I2C(board.SCL, board.SDA) bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c) return { 'temperature': bme680.temperature, 'gas': bme680.gas, 'humidity': bme680.humidity, 'pressure': bme680.pressure, 'altitude': bme680.altitude }
def __init__(self, feed_name): self.feed_name = feed_name # Create library object using our Bus I2C port self.i2c = I2C(board.SCL, board.SDA) self.bme680 = adafruit_bme680.Adafruit_BME680_I2C(self.i2c, debug=False) # change this to match the location's pressure (hPa) at sea level self.bme680.sea_level_pressure = 1013.25 # Raleigh value
def show_air_readings(air_temp, air_gas, air_humid, air_pressure): bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c, debug=False) # change this to match the location's pressure (hPa) at sea level bme680.sea_level_pressure = 1013.25 air_temp = bme680.temperature air_gas = bme680.gas air_humid = bme680.humidity air_pressure = bme680.pressure return(air_temp, air_gas, air_humid, air_pressure)
class bme680: _i2c = busio.I2C(board.SCL, board.SDA) _sensor = adafruit_bme680.Adafruit_BME680_I2C(_i2c) POST_URL = "http://127.0.0.1:5000/api/v1/bme680/{}".format(ESP8266_ID) @classmethod def get_reading(cls): return { "tempature": cls._sensor.temperature, "gas": cls._sensor.gas, "humidity": cls._sensor.humidity, "pressure": cls._sensor.pressure, }
def bme680(): print(colored("BME680 started. . .", 'green')) bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c, debug=False) bme680.sea_level_pressure = 101325 / 100 gas_baseline, hum_baseline, hum_weighting = gas_warmup(bme680, 0) while True: temp = round(bme680.temperature, 2) humidity = round(bme680.humidity, 2) pressure = round(bme680.pressure, 2) altitude = round(bme680.altitude, 2) with lock: database.create_record(conn, "Measurements", ("temp", temp)) # client.publish("greenhouse/temperature", temp) database.create_record(conn, "Measurements", ("humidity", humidity)) # client.publish("greenhouse/humidity", humidity) database.create_record(conn, "Measurements", ("pressure", pressure)) # client.publish("greenhouse/pressure", pressure) database.create_record(conn, "Measurements", ("altitude", altitude)) # client.publish("greenhouse/altitude", altitude) gas = bme680.gas gas_offset = gas_baseline - gas hum = humidity hum_offset = hum - hum_baseline # Calculate hum_score as the distance from the hum_baseline. if hum_offset > 0: hum_score = (100 - hum_baseline - hum_offset) hum_score /= (100 - hum_baseline) hum_score *= (hum_weighting * 100) else: hum_score = (hum_baseline + hum_offset) hum_score /= hum_baseline hum_score *= (hum_weighting * 100) # Calculate gas_score as the distance from the gas_baseline. if gas_offset > 0: gas_score = (gas / gas_baseline) gas_score *= (100 - (hum_weighting * 100)) else: gas_score = 100 - (hum_weighting * 100) # Calculate air_quality_score. air_quality_score = round(hum_score + gas_score, 2) with lock: database.create_record(conn, "Measurements", ("gas", air_quality_score)) # client.publish("greenhouse/gas", air_quality_score) # print(temp, "°C, ", hum, "%, ", pressure, "hPa, ", altitude, "m, ", air_quality_score) time.sleep(measurement_interval)
def initialize(self): import adafruit_bme680 from adafruit_extended_bus import ExtendedI2C self.sensor = adafruit_bme680.Adafruit_BME680_I2C( ExtendedI2C(self.input_dev.i2c_bus), address=int(str(self.input_dev.i2c_location), 16)) # Set oversampling settings (can be tweaked to balance accuracy and noise in data self.sensor.humidity_oversample = int(self.humidity_oversample) self.sensor.temperature_oversample = int(self.temperature_oversample) self.sensor.pressure_oversample = int(self.pressure_oversample) self.sensor.filter_size = int(self.iir_filter) self.sensor.sea_level_pressure = self.sea_level_pressure_ha
def get_sensor_values_function(sensor_str): # print ('sensor_str =', sensor_str) if False: pass # elif sensor_str == 'DHT22': # import Adafruit_DHT # DHT_TYPE = Adafruit_DHT.DHT22 # DHT_PIN = sys.argv[3] # return Adafruit_DHT.read_retry # DHT11, DHT22 # pip3 install Adafruit-DHT elif sensor_str == 'BME280': import adafruit_bme280 i2c = busio.I2C(board.SCL, board.SDA) bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76) bme280.sea_level_pressure = 1013.25 def get_bme280_values(): vals = (bme280.temperature, bme280.relative_humidity, bme280.pressure, bme280.altitude) # print (vals) return vals return get_bme280_values # KEINE KLAMMERN! => Funktion wird zurückgegeben ! elif sensor_str == 'BME680': import adafruit_bme680 i2c = busio.I2C(board.SCL, board.SDA) # print ('i2c = ', i2c) bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c, debug=False, address=0x76) # bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c, debug=False) bme680.sea_level_pressure = 1013.25 def get_bme680_values(): vals = (bme680.temperature, bme680.relative_humidity, bme680.pressure, bme680.altitude, bme680.gas) # print (vals) return vals return get_bme680_values # KEINE KLAMMERN! => Funktion wird zurückgegeben ! else: raise ValueError("\ndef get_sensor_values: Keine Sensorfunktion gefunden \n") return
def update_obd_values(times, temp_vals, gas_vals, hum_vals, pres_vals): i2c = busio.I2C(board.SCL, board.SDA) sensor = adafruit_bme680.Adafruit_BME680_I2C(i2c) times.append(time.time()) temp_vals.append(sensor.temperature) gas_vals.append(sensor.gas) hum_vals.append(sensor.humidity) pres_vals.append(sensor.pressure) tot_time.append(times[-1]) tot_temp.append(temp_vals[-1]) tot_gas.append(gas_vals[-1]) tot_hum.append(hum_vals[-1]) tot_pres.append(pres_vals[-1]) return times, temp_vals, gas_vals, hum_vals, pres_vals
def enable(self): # Use virtual to test iot functionality on computers without busio / sensors. if not self.island.virtual and not hasattr(self, 'bme680'): from busio import I2C import adafruit_bme680 import board # Create library object using our Bus I2C port i2c = I2C(board.SCL, board.SDA) self.bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c, debug=False) # change this to match the location's pressure (hPa) at sea level # this could be dynamically updated from, e.g., # https://forecast.weather.gov/MapClick.php?x=266&y=134&site=sew&zmx=&zmy=&map_x=266&mapy=134#.X2jtB2hKiUk self.bme680.sea_level_pressure = 1013.89 # Start the scheduled work self.schedule(self.publishResults, 60)
def __init__(self, interval=0, temp_in_f=False, pressure_in_inches=False): """ ``` interval How long in seconds to sleep between returning records. temp_in_f Return temperature in Farenheit pressure_in_inches Return pressure in inches of mercury ``` """ self.interval = interval # seconds between records self.temp_in_f = temp_in_f self.pressure_in_inches = pressure_in_inches self.last_record = 0 # timestamp at our last record # Create sensor object, communicating over the board's default I2C bus self.i2c = board.I2C() # uses board.SCL and board.SDA self.bme680 = adafruit_bme680.Adafruit_BME680_I2C(self.i2c)
def Read_data(): ts = time.strftime("%H%M%S") file.write(str(ts) + "\t") # Fusion / Gyroscope data x, y, z = imu.getFusionData() x = round(math.degrees(x),2) y = round(math.degrees(y),2) z = round(math.degrees(z),2) file.write(str(x) + "\t"+ str(y) + "\t" + str(z)+ "\t") #resetfusion imu.getGyro # Acceleration data, accely is spin, accelz is acceleration, accelx, accely, accelz = imu.getAccel() accelx = round(accelx,2) accely = round(accely,2) accelz = round(accelz,2) file.write(str(accelx) + "\t" + str(accely) + "\t" + str(accelz) + "\t" ) # Compass data compx, compy, compz = imu.getIMUData()['compass'] compx = round(compx,2) compy = round(compy,2) compz = round(compz,2) file.write(str(compx) + "\t" + str(compy) + "\t" + str(compz) + "\t") #time.sleep(poll_interval*1.0/1000.0) i2c = busio.I2C(board.SCL, board.SDA) bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c) bme680.sea_level_pressure = 1018 temp = bme680.temperature humidity = bme680.humidity altitude = bme680.altitude pressure = bme680.pressure gas = bme680.gas file.write(str(temp) + "\t" + str(humidity) + "\t" + str(altitude) + "\t" + str(pressure) + '\t' + str(gas) + "\t") mcp = adafruit_mcp9808.MCP9808(i2c) ptemp = mcp.temperature #deg celsius file.write(str(ptemp) + "\t")
def __init__(self, use_sps30=True, use_bme680=True): self.use_sps30 = use_sps30 self.use_bme680 = use_bme680 if self.use_bme680: i2c = I2C(board.SCL, board.SDA) self.bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c, debug=False) self.bme680.sea_level_pressure = 1013.25 else: self.bme680 = None if self.use_sps30: self.sps30 = SPS30() self.sps30.readArticleCode() or exit(1) self.sps30.reset() time.sleep(0.1) # note: needed after reset self.sps30.readSerialNr() self.sps30.readCleaningInterval() self.sps30.initialize()
def run(ctx, param, value): if not value or ctx.resilient_parsing: return click.secho('Start running the AzatAI Techno Console:', fg='green') click.secho("AzatAI Techno Console Started!", fg='green') click.secho("Please Press Cntrl + Z to stop! \n WARN: Running code too much time may cause hardware problem!", fg='yellow') click.secho('INFO: The default see level pressure is: 1013.25', fg='blue') while True: i2c = I2C(SCL, SDA) orientation_sensor = adafruit_bno055.BNO055(i2c) light_sensor = SI1145.SI1145() gc.collect() bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c) # change this to match the location's pressure (hPa) at sea level bme680.sea_level_pressure = 1013.25 print(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())) click.secho('BME680:', fg='blue') print("\nTemperature: %0.1f C" % bme680.temperature) print("Gas: %d ohm" % bme680.gas) print("Humidity: %0.1f %%" % bme680.humidity) print("Pressure: %0.3f hPa" % bme680.pressure) print("Altitude = %0.2f meters" % bme680.altitude) click.secho('BNO055', fg='blue') print(orientation_sensor.temperature) print(orientation_sensor.euler) print(orientation_sensor.gravity) click.secho('SI1145', fg='blue') vis = light_sensor.readVisible() _IR = light_sensor.readIR() _UV = light_sensor.readUV() uvindex = _UV / 100.0 print('Vis:'+str(vis)) print("IR"+str(_IR)) print("UV Index"+str(uvindex)) time.sleep(3) ctx.exit()
# Import Dependencies import sqlite3 import time import board from busio import I2C import adafruit_bme680 import datetime # Create library object using our Bus I2C port i2c = I2C(board.SCL, board.SDA) bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c, debug=False) # change this to match the location's pressure (hPa) at sea level bme680.sea_level_pressure = 1013.25 # Define database name to which data will be stored dbname = 'Sensors.db' # Using while loop capture the data in variables and store it in database while True: # Create the now variable to capture the current moment now = datetime.datetime.now() TEMPERATURE = round(bme680.temperature, 1) GAS = round(bme680.gas, 1) HUMIDITY = round(bme680.humidity, 1) PRESSURE = round(bme680.pressure, 1) ALTITUDE = round(bme680.altitude, 1) TIME_STAMP = (now) conn = sqlite3.connect(dbname) curs = conn.cursor() curs.execute( "INSERT INTO BME_DATA (TIME_STAMP, TEMPERATURE, GAS, HUMIDITY, PRESSURE, ALTITUDE) values(?,?,?,?,?,?)", (TIME_STAMP, TEMPERATURE, GAS, HUMIDITY, PRESSURE, ALTITUDE)) conn.commit()
def __init__(self): self.i2c = busio.I2C(board.SCL, board.SDA) self.sensor = adafruit_bme680.Adafruit_BME680_I2C(self.i2c) print("BME680 I2C initialized!") self.read_data()
# # Valid I2C ports: ((3, 3, 2), (1, 3, 2), (0, 1, 0)) # # i2c = I2C(6, 70) # print(board.SCL) # print(board.SDA) i2c = I2C(board.SCL, board.SDA) # Lock the I2C device before we try to scan while not i2c.try_lock(): pass # Print the addresses found once print("I2C addresses found:", [hex(device_address) for device_address in i2c.scan()]) # Unlock I2C now that we're done scanning. i2c.unlock() print(i2c._i2c.__dict__) bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c) # change this to match the location's pressure (hPa) at sea level bme680.sea_level_pressure = 1013.25 while True: print("\nTemperature: %0.1f C" % bme680.temperature) print("Gas: %d ohm" % bme680.gas) print("Humidity: %0.1f %%" % bme680.humidity) print("Pressure: %0.3f hPa" % bme680.pressure) print("Altitude = %0.2f meters" % bme680.altitude) time.sleep(2)
def configure_bme680(): i2c = board.I2C() return adafruit_bme680.Adafruit_BME680_I2C(i2c) # address=int(0x77)
# Create an instance of the REST client. aio = Client(ADAFRUIT_IO_USERNAME, ADAFRUIT_IO_KEY) # Set up Adafruit IO Feeds. temperature_feed = aio.feeds('temperature') humidity_feed = aio.feeds('humidity') pressure_feed = aio.feeds('pressure') #TODO: altitude_feed = aio.feeds('altitude') gas_feed = aio.feeds('gas') # setup environment sensor # Set up BME680 Sensor at I2C i2c = I2C(board.SCL, board.SDA) BME680_I2CADDRESS = 0x77 # BME280: 0x76 env_sensor = adafruit_bme680.Adafruit_BME680_I2C(i2c, BME680_I2CADDRESS) def calibrate(value): print(f"... BME680 sensor calibrating for sea level pressure: {value}") env_sensor.sea_level_pressure = value assert env_sensor.sea_level_pressure == value """ location's pressure (hPa) at sea level from: https://www.weatheronline.co.uk/weather/maps/current?LANG=en&CONT=euro®ION=0003&LAND=NL&LEVEL=4&R=310&CEL=C&ART=tabelle&TYP=druck The value changes the Alt-value! I use 'Amsterdam/Schiphol' sea level value """ calibrate(1025) # 10 Nov 2020 19:00
from secrets import secrets import wifi RED = (16, 0, 0) GREEN = (0, 16, 0) pixel = neopixel.NeoPixel(board.NEOPIXEL_POWER, 1, auto_write=True) pixel.fill(GREEN) pixel.show() pixels = neopixel.NeoPixel(board.NEOPIXEL, 4, auto_write=True) pixels.fill(GREEN) pixels.show() print('Setting up sensors') i2c = busio.I2C(board.SCL, board.SDA) bme680_sensor = adafruit_bme680.Adafruit_BME680_I2C(i2c) sgp30_sensor = adafruit_sgp30.Adafruit_SGP30(i2c) print('Setting up display') display = board.DISPLAY group = displayio.Group(max_size=20) # background rect1 = Rect(0, 0, 199, 90, fill=0xFFFFFF) rect2 = Rect(200, 0, 296, 90, fill=0xBBBBBB) rect3 = Rect(0, 91, 296, 128, fill=0x444444) # Create fonts print("Loading fonts") big_font = bitmap_font.load_font("/Exo-Bold-42.bdf") medium_font = bitmap_font.load_font("/Exo-SemiBold-18.bdf")
import time import board from busio import I2C import adafruit_bme680 # Create library object using our Bus I2C port i2c = I2C(board.SCL, board.SDA) bme680 = adafruit_bme680.Adafruit_BME680_I2C(i2c, address=118, debug=False) # change this to match the location's pressure (hPa) at sea level bme680.sea_level_pressure = 1013.25 while True: print("\nTemperature: %0.1f C" % bme680.temperature) print("Gas: %d ohm" % bme680.gas) print("Humidity: %0.1f %%" % bme680.humidity) print("Pressure: %0.3f hPa" % bme680.pressure) print("Altitude = %0.2f meters" % bme680.altitude) time.sleep(1)