import smbus import time from constants import * from smbus import SMBus I2C_ID = 0x68 bus = SMBus(2) class MPU9250: """Constructor""" def __init__(self,address=MPU_9250_I2C_SLAVE_ADDR): self.address=address self.config_mpu9250(GYRO_RANGE_250, ACCEL_RANGE_2G) def is_connected(self): whoami = bus.read_byte_data(self.address, WHO_AM_I) if (whoami == MPU_9250_I2C_DEVICE_ID): return True else: return False def config_mpu9250(self,gyro_range,accel_range): if gyro_range == GYRO_RANGE_250: self.grange = 250.0/32768.0 elif gyro_range == GYRO_RANGE_500: self.grange = 500.0/32768.0 elif gyro_range == GYRO_RANGE_1000: self.grange = 1000.0/32768.0 elif gyro_range == GYRO_RANGE_2000: self.grange = 2000.0/32768.0
DIVICE = ', ' #指定デバイスをレート115200でオープン ser = serial.Serial(DEVICE, 115200) #指定デバイスの開放情報を確認 print(ser) #バスナンバーを指定する(Raspberry Pi 3Bなら1、それ以前は0) bus_number = 1 #センサの敗戦によって変更、テキストの内容だとGNdへのプルダウンのため0x76 i2c_address = 0x76 #バスナンバーで開く bus = SMBus(bus_number) #気象データの定義 digT = [] digP = [] digH = [] t_fine = 0.0 def writeReg(reg_address, data): #センサのアドレス、レジストリ関係(編集不可) bus.write_byte_data(i2c_address, reg_address, data) def get_calib_param(): #取得データの補正(編集不可) calib = []
#!/usr/bin/python from smbus import SMBus from time import sleep bus = SMBus(1) # Port 1 used on REV2 io_port = 0b00000000 def set_bit(value, bit): return value | (1<<bit) def clear_bit(value, bit): return value & ~(1<<bit) while True: io_port = set_bit(io_port,0) bus.write_byte(0x20,io_port) sleep(2) io_port = clear_bit(io_port,0) bus.write_byte(0x20,io_port) sleep(2)
#!/usr/bin/env python # # Simple I2C EEPROM routines # works with 16-bit addressable EEPROMs (up to 64kB) from smbus import SMBus smb = SMBus(1) slaveaddr = 0x50 def eeprom_set_current_address(addr): a1 = addr / 256 a0 = addr % 256 smb.write_i2c_block_data(slaveaddr, a1, [a0]) def eeprom_write_block(addr, data): a1 = addr / 256 a0 = addr % 256 data.insert(0, a0) smb.write_i2c_block_data(slaveaddr, a1, data) # wait until acknowledged ready = 0 while not ready: try: smb.read_byte(slaveaddr) ready = 1 except IOError:
from smbus import SMBus import Adafruit_PCA9685 import subprocess import math from SherControl_Scripts_clean import * from math import pi import psutil import os # import matplotlib.pyplot as plt # Global Variables pwm1 = Adafruit_PCA9685.PCA9685(address=0x41, busnum=1) pwm2 = Adafruit_PCA9685.PCA9685(address=0x40, busnum=1) pwm1.set_pwm_freq(50) pwm2.set_pwm_freq(50) bus = SMBus(1) FL_sensor = 0 FR_sensor = 0 HL_sensor = 0 HR_sensor = 0 p = psutil.Process(os.getpid()) p.nice(-19) p.cpu_affinity([3]) # Functions def adc_data_channel_1(): global FR_sensor bus.write_i2c_block_data(0x48, 0x01, [0xC3, 0x83]) adc0 = bus.read_i2c_block_data(0x48, 0x00, 2)
#!/usr/bin/env python from lib_oled96 import ssd1306 from smbus import SMBus i2cbus = SMBus(1) # 1 = Raspberry Pi but NOT early REV1 board oled = ssd1306(i2cbus) # create oled object, nominating the correct I2C bus, default address # we are ready to do some output ... # put border around the screen: oled.canvas.rectangle((0, 0, oled.width-1, oled.height-2), outline=1, fill=0) # Write two lines of text. oled.canvas.text((40,15), 'Hello', fill=1) oled.canvas.text((40,40), 'World!', fill=1) # now display that canvas out to the hardware oled.display()
#!/usr/bin/python # Filename: mcp23017_lib.py """This module provides an easy interface for the MCP23017""" # source: https://github.com/ResonantWave/mcp23017_lib __license__ = "GPLv3" from smbus import SMBus i2c = SMBus(1) OUT = 0 IN = 1 BANK_A = 0 BANK_B = 1 ALL = 2 LAT_A = 3 LAT_B = 4 PU_A = 5 PU_B = 6 HIGH = 1 LOW = 0 PUHIGH = 1 PULOW = 0 ADDRESS = 0x20 def puRead(bank=None):
#!/usr/bin/env python # INTEL EDISON VERSION # NOTE: You need to have PIL installed for your python at the Edison from lib_oled96 import ssd1306 from time import sleep from PIL import ImageFont, ImageDraw, Image font = ImageFont.load_default() from smbus import SMBus i2cbus = SMBus(6) oled = ssd1306(i2cbus) draw = oled.canvas # "draw" onto this canvas, then call display() to send the canvas contents to the hardware. # Draw some shapes. # First define some constants to allow easy resizing of shapes. padding = 2 shape_width = 20 top = padding bottom = oled.height - padding - 1 # Draw a rectangle of the same size of screen draw.rectangle((0, 0, oled.width-1, oled.height-1), outline=1, fill=0) # Move left to right keeping track of the current x position for drawing shapes. x = padding # Draw an ellipse.
def __init__(self, address): self.address = address self.i2c = SMBus() self.setup()
from smbus import SMBus from objects.anim_action import AnimAction I2C_ADDR = 0x8 # bus address I2C_BUS = SMBus(1) # indicates /dev/ic2-1 def write_anim_i2c(action): data = [action.device_type.encode()[0], action.device_id, action.setting] I2C_BUS.write_i2c_block_data(I2C_ADDR, 0x0, data) #I2C_BUS.write_byte(I2C_ADDR, action.device_type.encode()[0]) #I2C_BUS.write_byte(I2C_ADDR, action.device_id) #I2C_BUS.write_byte(I2C_ADDR, action.setting)
tty = "/dev/ttyPS1" ser = serial.Serial( port=tty, baudrate=10000000, bytesize=serial.EIGHTBITS, parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE, # interCharTimeout = 0.2, timeout=0.1, xonxoff=False, rtscts=False, dsrdtr=False) i2c2 = SMBus(2) adc_ch = [ "AN0", "AN1", "AN2", "AN3", "AN4", "AN8", "AN9", "AN10", "AN11", "AN12", "AN13", "AN14", "AN15", "AN16", "AN17", "AN18", "AN19", "AN27", "DAC2", "TEMP", "DAC1", "FVR" ] adc_pa = ["AN0", "AN1", "AN2", "AN3", None, "AN4", None, None] adc_pb = ["AN12", "AN10", "AN8", "AN9", "AN11", "AN13", None, None] adc_pc = [None, None, "AN14", "AN15", "AN16", "AN17", "AN18", "AN19"] adc_xx = ["DAC1", "DAC2", "TEMP", "AN27", "FVR", None, None, None] def wcmd(i2c, adr, cmd, data=None): if data is None:
# INITIALIZE MCPs # spi = busio.SPI(clock=board.SCK, MISO = board.MISO, MOSI = board.MOSI) cs5 = digitalio.DigitalInOut(board.D5) cs6 = digitalio.DigitalInOut(board.D6) cs13 = digitalio.DigitalInOut(board.D13) mcp5 = MCP.MCP3008(spi, cs5) mcp6 = MCP.MCP3008(spi, cs6) mcp13 = MCP.MCP3008(spi, cs13) # INITIALIZE IMUs # channel = 1 imu_address_1 = 0x69 imu_address_2 = 0x68 bus = SMBus(channel) bus.write_byte_data(imu_address_1, 0x06, 0x01) bus.write_byte_data(imu_address_2, 0x06, 0x01) time.sleep(0.5) accel_x_1 = -1 accel_y_1 = -1 accel_z_1 = -1 accel_x_2 = -1 accel_y_2 = -1 accel_z_2 = -1 gyro_x_1 = -1 gyro_y_1 = -1 gyro_z_1 = -1
import struct import wave from smbus import SMBus # Settings bus = 1 address = 0x48 duration = 10 # seconds filename = "test.wav" # Prepare file = wave.open(filename, 'w') file.setnchannels(1) # Mono file.setframerate(860) # Frames per second file.setsampwidth(2) # 2 bytes per frame adc = SMBus(bus) # Reset adc.write_byte(0x00, 0x06) time.sleep(0.5) # Set configuration # 1 101 111 0 = de # 111 0 1 0 00 = e8 adc.write_i2c_block_data(address, 0x01, [0xde, 0xe8]) time.sleep(0.5) # Record input for frame in range(int(duration * 860)): data = adc.read_i2c_block_data(address, 0x00, 2) value = data[0] * 256 + data[1]
def setup_bus(x): bus = SMBus(x) # x indicates /dev/i2c-x return bus
""" author: Thomas Kaulke, [email protected] """ from __future__ import absolute_import import utils.utils as utils import conf import subprocess from time import sleep from PIL import Image, ImageFont, ImageDraw from smbus import SMBus from lib_oled96 import Ssd1306 # Display setup, methods and members """ 0 = Raspberry Pi 1, 1 = Raspberry Pi > 1 """ i2cbus = SMBus(1) oled = Ssd1306(i2cbus) draw = oled.canvas c = '\'' left = 5 top = 7 switch_time = 15 # Fonts font = ImageFont.truetype( str(bot_dir) + 'peripherals/oled/fonts/arial.ttf', 12) font2 = ImageFont.truetype( str(bot_dir) + 'peripherals/oled/fonts/FreeSans.ttf', 12) def __get_release():
#!/bin/env python3 # Copyright (C) 2015 Herbert Poetzl import sys import serial import struct from smbus import SMBus from time import sleep from icsp import * sel = sys.argv[1] if len(sys.argv) > 1 else "N" i2c0 = SMBus(0) i2c2 = SMBus(2) pb_ver = "0.30" try: i2c2.read_byte(0x30) pb_ver = "0.29" except: pass try: i2c2.read_byte(0x70) pb_ver = "0.23" except: pass
# -*- coding: utf-8 -*- import time import binascii import RPi.GPIO as GPIO from smbus import SMBus XRservo = SMBus(1) GPIO.setmode(GPIO.BCM) GPIO.setwarnings(False) time.sleep(2) XRservo.XiaoRGEEK_SetServo(0x08, 90) print('ser1= 90') time.sleep(0.5) XRservo.XiaoRGEEK_SetServo(0x01, 30) print('ser1= 30°并存储') time.sleep(0.1) XRservo.XiaoRGEEK_SaveServo() time.sleep(0.5) XRservo.XiaoRGEEK_SetServo(0x01, 90) print('ser1= 90°') time.sleep(0.5) XRservo.XiaoRGEEK_SetServo(0x01, 150) print('ser1= 150°') time.sleep(1.5) XRservo.XiaoRGEEK_ReSetServo() print('恢复存储的角度30°') ''' 整个程序功能为: 舵机转动到90° 舵机转动到30°,并存储,
Args: values (list): channel number Raises: TypeError: if values is not a list of 18 integers. """ # SMBus.write_i2c_block_data does the type check, so we don't have to if len(values) != 18: raise TypeError("values must be a list of 18 integers") i2c.write_i2c_block_data(I2C_ADDRESS, CMD_SET_PWM_VALUES, values) i2c.write_i2c_block_data(I2C_ADDRESS, CMD_UPDATE, [0xFF]) try: i2c = SMBus(i2c_bus_id()) except IOError as e: warntxt = """ ###### ###### ###### ###### ###### ###### ###### ###### i2c initialization failed - is i2c enabled on this system? See https://github.com/pimoroni/sn3218/wiki/missing-i2c ###### ###### ###### ###### ###### ###### ###### ###### """ warnings.warn(warntxt) raise (e) # generate a good default gamma table default_gamma_table = [int(pow(255, float(i - 1) / 255)) for i in range(256)] channel_gamma_table = [default_gamma_table] * 18 enable_leds(0b111111111111111111)
from sys import exit, version_info try: from smbus import SMBus except ImportError: if version_info[0] < 3: exit("This library requires python-smbus\nInstall with: sudo apt-get install python-smbus") elif version_info[0] == 3: exit("This library requires python3-smbus\nInstall with: sudo apt-get install python3-smbus") from .pantilt import PanTilt, WS2812, PWM __version__ = '0.0.2' pantilthat = PanTilt(i2c_bus=SMBus(1)) brightness = pantilthat.brightness clear = pantilthat.clear light_mode = pantilthat.light_mode servo_one = pantilthat.servo_one servo_pulse_max = pantilthat.servo_pulse_max servo_pulse_min = pantilthat.servo_pulse_min servo_two = pantilthat.servo_two servo_enable = pantilthat.servo_enable
def __init__(self, I2C_bus_number=1, address=0x50): self.bus = SMBus(I2C_bus_number) self.address = address
#!/bin/env python3 # Copyright (C) 2016 Herbert Poetzl import sys from smbus import SMBus from bitarray import bitarray from jtag import * from mxo2 import * i2c = SMBus(2) jtag = JTag(i2c) jtag.on() jtag.reset() idcode = jtag.cmdout(IDCODE, 32) dev, cfg, ufm, _ = DEVID[idcode] print("found %s [%s]" % (dev, idcode)) jtag.cmdin(ISC_ENABLE, h2b("08")) status(jtag) print("dumping config memory ...") jtag.cmdin(LSC_INIT_ADDRESS, h2b("04")) jtag.cmd(LSC_READ_INCR_NV) for page in range(cfg): row = jtag.tdo(128) jtag.idle(2) print("%04X: %s [%s]" % (page, b2h(row), row))
table11bit = (0x3F8, 0x3F7, 0x3F1, 0x3E8, 0xC8, 0x001, 0x00, 0x7FF, 0x738, 0x649, 0x648) def ctofBytes(msb, lsb): bitWidth = 11 i = msb << 3 | lsb >> 5 if (i < 1024): degC = i * 0.125 else: degC = (i - int((i << 1) & 2**bitWidth)) * 0.125 return (degC * 1.8 + 32) tgtAddress = 0x4C devobj = SMBus(1) devobj.write_byte(tgtAddress, 0) if debug: for i in table11bit: msb = i >> 3 & 0xFF lsb = ((i & 0xFF) << 5) & 0xFF if debug: print('11 Bit MSB %2x LSB %2x' % (msb, lsb)) val = ctofBytes(msb, lsb) for i in range(10): devobj.write_byte(tgtAddress, 0) with SMBusWrapper(1) as bus: block = bus.read_i2c_block_data(tgtAddress, 0, 2) data = bytes(block) msb = data[0]
from smbus import SMBus addr = 0x08 # bus address bus = SMBus(1) # indicates /dev/ic2-1 numb = 0 numbold = 0 string = "" def isInt(value): try: int(value) return True except ValueError: return False while string != "exit": f = open("number_people.txt", "r") f2 = open("compliance.txt", "r") string2 = f2.readline() string = f.readline() if (isInt(string) == True): numb = int(string) if isinstance(numb, int): if numb != numbold: numbold = numb numb2 = int(string2) if isinstance(numb2, int): if numb2 == 1:
class IMUSensors: # Accelerometer: IMU.detectIMU() # Detect if BerryIMUv1 or BerryIMUv2 is connected. IMU.initIMU() # Initialise the accelerometer, gyroscope and compass # Gyro RAD_TO_DEG = 57.29578 M_PI = 3.14159265358979323846 G_GAIN = 0.070 # [deg/s/LSB] If you change the dps for gyro, you need to update this value accordingly AA = 0.40 # Complementary filter constant gyroXangle = 0.0 gyroYangle = 0.0 gyroZangle = 0.0 a = datetime.datetime.now() # Thermometer: addr = 0x77 oversampling = 3 # 0..3 bus = SMBus(1) # 0 for R-Pi Rev. 1, 1 for Rev. 2 # Returns two bytes from data as a signed 16-bit value def get_short(self, data, index): return c_short((data[index] << 8) + data[index + 1]).value # Returns two bytes from data as an unsigned 16-bit value def get_ushort(self, data, index): return (data[index] << 8) + data[index + 1] # Calls SensorArray class and passes array of sensor data if crash or fire detected in undateValues() def sensorCaller(self, dataArray): sense = SensorArray.SensorArray() sense.alertDriver(dataArray) #One function to rule them all. Or at least supply the bulk of sensor data. def updateValues(self): #--------------------Accelerometer sensor calculations----------------------- # Read the accelerometer,gyroscope and magnetometer values ACCx = IMU.readACCx() ACCy = IMU.readACCy() ACCz = IMU.readACCz() xG = (ACCx * 0.244) / 1000 yG = (ACCy * 0.244) / 1000 zG = (ACCz * 0.244) / 1000 #-----------------Gyroscope sensor calculations------------------------- GYRx = IMU.readGYRx() GYRy = IMU.readGYRy() GYRz = IMU.readGYRz() ##Calculate loop Period(LP). How long between Gyro Reads b = datetime.datetime.now() - self.a self.a = datetime.datetime.now() LP = b.microseconds / (1000000 * 1.0) # Convert Gyro raw to degrees per second rate_gyr_x = GYRx * self.G_GAIN rate_gyr_y = GYRy * self.G_GAIN rate_gyr_z = GYRz * self.G_GAIN # Calculate the angles from the gyro. self.gyroXangle += rate_gyr_x * LP self.gyroYangle += rate_gyr_y * LP self.gyroZangle += rate_gyr_z * LP # Convert Accelerometer values to degrees self.AccXangle = (math.atan2(ACCy, ACCz) * self.RAD_TO_DEG) self.AccYangle = (math.atan2(ACCz, ACCx) + self.M_PI) * self.RAD_TO_DEG # convert the values to -180 and +180 if self.AccYangle > 90: self.AccYangle -= 270.0 else: self.AccYangle += 90.0 #-------------------Thermometer calculations-------------------- # Read whole calibration EEPROM data cal = self.bus.read_i2c_block_data(self.addr, 0xAA, 22) # Convert byte data to word values ac5 = self.get_ushort(cal, 8) ac6 = self.get_ushort(cal, 10) mc = self.get_short(cal, 18) md = self.get_short(cal, 20) self.bus.write_byte_data(self.addr, 0xF4, 0x2E) sleep(0.005) (msb, lsb) = self.bus.read_i2c_block_data(self.addr, 0xF6, 2) ut = (msb << 8) + lsb x1 = ((ut - ac6) * ac5) >> 15 x2 = (mc << 11) / (x1 + md) b5 = x1 + x2 t = (b5 + 8) >> 4 temperature = t / 10.0 #-------------------Crash condition checker----------------------- if temperature > 80 or abs(xG) > 4 or abs(yG) > 2.25 or abs(zG + 1) > 2.5: #- creates list of data to send up to the SensorArray class sensorData = [ xG, yG, zG, self.gyroXangle, self.gyroYangle, self.gyroZangle, temperature ] #- Sends data to SensorArray self.sensorCaller(sensorData)
def __init__(self, sensorPort: str, linkID: int, i2cBus: str, i2cAddress=0x11, gyroFilterValue=GYRO_FILTER_SENSITIVITY_VALUE, gyroSensitivity='2G', odometryLoopTimeStep=GYRO_LOOP_TIMER): ''' Description:constructor for an angle sensor param:sensorPort:desc:input used on the lego robot (INPUT_1, INPUT_2, etc.) param:sensorPort:type:string param:linkID:linkid of the robot section containing the gyroscope param:linkID:int param:i2cBus:desc:device no (/dev/i2c-x)... for brickpi3, it's INPUT_N, it's N+2 param:i2cBus:type:int param:i2cAddress:desc:channel on the device - should be 0x11 param:i2cAddress:type:int or hex param:gyroFitlerValue:value between 0 and 7 for n-order filtering. 7 = slows down reading by 10ms 0 = 0ms param:gyroFitlerValue:int param:gyroSensitivity:desc:sensitivity, 2g, 4g, 8g or 16g - see documentation for the sensor param:gyroSensitivity:type:str ''' LOGGER_GS_MAIN_INSTANCE = LOGGER_GS_MAIN.format(linkID) # Place the port in I2C mode LegoPort(sensorPort).mode = GYRO_I2C_MODE self.__i2cBus = i2cBus self.__bus = SMBus(i2cBus) self.__i2cAddress = i2cAddress self.odometryLoopTimeStep = GYRO_LOOP_TIMER self.__linkID = linkID # Se gyro filter sensitivity log.debug(LOGGER_GS_MAIN_INSTANCE, 'Setting gyro filter sensitivity') # Set acceleration sensitivity to XG if gyroSensitivity == '2G': self.__GYRO_ACCEL_SENSITIVITY = GYRO_ACCEL_SENSITIVITY_2G_COMMAND self.__GYRO_DPS_SCALE = GYRO_DPS_SCALE_2G elif gyroSensitivity == '4G': self.__GYRO_ACCEL_SENSITIVITY == GYRO_ACCEL_SENSITIVITY_4G_COMMAND self.__GYRO_DPS_SCALE = GYRO_DPS_SCALE_4G elif gyroSensitivity == '8G': self.__GYRO_ACCEL_SENSITIVITY == GYRO_ACCEL_SENSITIVITY_8G_COMMAND self.__GYRO_DPS_SCALE = GYRO_DPS_SCALE_8G elif gyroSensitivity == '16G': self.__GYRO_ACCEL_SENSITIVITY == GYRO_ACCEL_SENSITIVITY_16G_COMMAND self.__GYRO_DPS_SCALE = GYRO_DPS_SCALE_16G # Configure device sensitivity self.__bus.write_byte_data(self.__i2cAddress, GYRO_FILTER_SENSITIVITY_ADDRESS, gyroFilterValue) self.__bus.write_byte_data(self.__i2cAddress, GYRO_IMU_COMMAND_REGISTER, self.__GYRO_ACCEL_SENSITIVITY) time.sleep(0.05) # sleep after changing sensor sensitivity # Calculate components of acceleration (ignore gyr data at initialization) accData, _ = self.__getSensorData() pitch = np.float(arctan2(accData[0], accData[2]) * 180 / pi) roll = np.float(arctan2(accData[1], accData[2]) * 180 / pi) yaw = 0 self.__angles = np.array([pitch, roll, yaw]) # Launch odometry thread # TODO : put this in a run function? self.killThread = False log.info(LOGGER_GS_MAIN_INSTANCE, 'Launching gyro thread') self.threadGyroLoop = threading.Thread( target=self.threadImplGyroLoop, args=([ self.odometryLoopTimeStep, ODOMETRY_GYRO_LOGGING_LOOP_AGGREGATED, GYRO_COMPLEMENTARY_FILTER_TIME_CONSTANT ]), name="threadImplGyroLoop_{}".format(self.__linkID)) self.threadGyroLoop.start() log.info(LOGGER_GS_MAIN_INSTANCE, 'Started gyro thread.')
from smbus import SMBus import Jetson.GPIO as GPIO from time import sleep addr = 0x8 # bus address bus = SMBus(0) # indicates /dev/ic2-0 controlPin = 11 def init_rpi(): GPIO.setmode(GPIO.BOARD) GPIO.setwarnings(False) GPIO.setup(controlPin, GPIO.OUT, initial = GPIO.LOW) init_rpi() while True: try: num = [69,127,254] GPIO.output(controlPin,GPIO.LOW) bus.write_block_data(addr,6,num) GPIO.output(controlPin, GPIO.HIGH) sleep(0.01) except Exception as e: print(e) pass
def _setup_bme680(config): """Set up and configure the BME680 sensor.""" from smbus import SMBus import bme680 sensor_handler = None sensor = None try: i2c_address = config.get(CONF_I2C_ADDRESS) bus = SMBus(config.get(CONF_I2C_BUS)) sensor = bme680.BME680(i2c_address, bus) # Configure Oversampling os_lookup = { 0: bme680.OS_NONE, 1: bme680.OS_1X, 2: bme680.OS_2X, 4: bme680.OS_4X, 8: bme680.OS_8X, 16: bme680.OS_16X } sensor.set_temperature_oversample( os_lookup[config.get(CONF_OVERSAMPLING_TEMP)]) sensor.set_humidity_oversample( os_lookup[config.get(CONF_OVERSAMPLING_HUM)]) sensor.set_pressure_oversample( os_lookup[config.get(CONF_OVERSAMPLING_PRES)]) # Configure IIR Filter filter_lookup = { 0: bme680.FILTER_SIZE_0, 1: bme680.FILTER_SIZE_1, 3: bme680.FILTER_SIZE_3, 7: bme680.FILTER_SIZE_7, 15: bme680.FILTER_SIZE_15, 31: bme680.FILTER_SIZE_31, 63: bme680.FILTER_SIZE_63, 127: bme680.FILTER_SIZE_127 } sensor.set_filter(filter_lookup[config.get(CONF_FILTER_SIZE)]) # Configure the Gas Heater if (SENSOR_GAS in config[CONF_MONITORED_CONDITIONS] or SENSOR_AQ in config[CONF_MONITORED_CONDITIONS]): sensor.set_gas_status(bme680.ENABLE_GAS_MEAS) sensor.set_gas_heater_duration(config[CONF_GAS_HEATER_DURATION]) sensor.set_gas_heater_temperature(config[CONF_GAS_HEATER_TEMP]) sensor.select_gas_heater_profile(0) else: sensor.set_gas_status(bme680.DISABLE_GAS_MEAS) except (RuntimeError, IOError): _LOGGER.error("BME680 sensor not detected at 0x%02x", i2c_address) return None sensor_handler = BME680Handler( sensor, True if (SENSOR_GAS in config[CONF_MONITORED_CONDITIONS] or SENSOR_AQ in config[CONF_MONITORED_CONDITIONS]) else False, config[CONF_AQ_BURN_IN_TIME], config[CONF_AQ_HUM_BASELINE], config[CONF_AQ_HUM_WEIGHTING]) sleep(0.5) # Wait for device to stabilize if not sensor_handler.sensor_data.temperature: _LOGGER.error("BME680 sensor failed to Initialize") return None return sensor_handler
def connect(self): if self.bus != None: self.bus.close() self.bus = SMBus(self.port)
def __init__(self, interface, address): self.addr = address self.i2c = SMBus(interface)
# 3 = Tequila # 4 = Cola # 5 = O-juice #importieren import drinksohnealk as d import time import RPi.GPIO as GPIO from lib_oled96 import ssd1306 from smbus import SMBus from PIL import ImageFont from PIL import Image #setup GPIO.setmode(GPIO.BOARD) GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_UP) GPIO.setup(18, GPIO.IN, pull_up_down=GPIO.PUD_UP) i2cbus = SMBus(1) # 0 = Raspberry Pi 1, 1 = Raspberry Pi > 1 oled = ssd1306(i2cbus) led1 = 36 led2 = 38 led3 = 40 GPIO.setup(led1, GPIO.OUT) GPIO.output(led1, GPIO.LOW) GPIO.setup(led2, GPIO.OUT) GPIO.output(led2, GPIO.LOW) GPIO.setup(led3, GPIO.OUT) GPIO.output(led3, GPIO.HIGH)