def __init__(self): self.pin = self.CONFIG['downlink_pin'] custom_i2c = False try: i2c = I2C( getattr(board, f"D{self.CONFIG['connection']['scl']}"), getattr(board, f"D{self.CONFIG['connection']['sda']}") ) custom_i2c = True except (TypeError, KeyError): i2c = I2C(board.SCL, board.SDA) try: self.adc = ads1115.ADS1115(i2c) except (ValueError, TimeoutError) as error: if str(error).find('No I2C device at address') != -1: if custom_i2c: self._error(f"Connection to ads1115 failed, using custom ports: \"" f"scl=>{self.CONFIG['connection']['scl']}, sda=>{self.CONFIG['connection']['sda']}\", " f"check the wiring and configuration") else: self._error("Connection to ads1115 failed, check the wiring") self.data = self._get_data()
def __init__(self, frequency: int = 1): i2c = I2C(SCL, SDA) self.sensor = adafruit_bno055.BNO055_I2C(i2c) self.sensor.mode = SENSOR_MODES['NDOF'] self.frequency = frequency self.calibration_cache = dict() self.acceleration_log = list()
def __init__(self, i2c_address, i2c_dev=None, bit_width=8, registers=None): self._bit_width = bit_width self.locked = {} self.registers = {} self.values = {} if type(i2c_address) is list: self._i2c_addresses = i2c_address self._i2c_address = i2c_address[0] else: self._i2c_addresses = [i2c_address] self._i2c_address = i2c_address self._i2c = i2c_dev if self._i2c is None: import board from busio import I2C self._i2c = I2C(board.SCL, board.SDA) for register in registers: self.locked[register.name] = False self.values[register.name] = 0 self.registers[register.name] = register self.__dict__[register.name] = _RegisterProxy(self, register)
def rover_initialize(): global RMotor, LMotor, MotorWake, AtmoSensor, LeftEye, RightEye, Accelo, Gyro # Initializing I2C for sensors i2c = I2C(board.SCL, board.SDA) # Initializing Gyro and Magnetometer Accelo = FXOS8700(i2c) Gyro = FXAS21002C(i2c) # Initializing Atmo Sensor AtmoSensor = SI7021(i2c) # Annoyingly it looks like the HCSR04 Libary uses DPI Pin Numbering instead # of Broadcom. Check here https://pinout.xyz/pinout/pin18_gpio24 # Read about speed of sound calibration in doc # BCM 23 & 24 are DPI 19 and 20 LeftEye = Echo(23, 24) RightEye = Echo(17, 27) MotorWake = LED(17) MotorWake.off() # Args are GPIO Pins for forward, backward, and motor controller sleep RMotor = Motor(20, 21) # Motor(19, 26, 13) LMotor = Motor(19, 26) # Motor(20, 21, 13) return True
def init(self): self.i2c = I2C(board.SCL, board.SDA) self._sensor = adafruit_bme280.Adafruit_BME280_I2C( self.i2c, address=self.config['address']) # 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 __init__(self): import adafruit_bno055 from busio import I2C import board self._i2c = I2C(board.SCL, board.SDA) self._sensor = adafruit_bno055.BNO055(self._i2c) # turn on "compass mode" self._sensor.mode = adafruit_bno055.COMPASS_MODE
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__(self) -> None: i2c = I2C(SCL, SDA) tsl = adafruit_tsl2591.TSL2591(i2c) # set gain and integration time; gain 0 = 1x & 1 = 16x. Integration time of 1 = 101ms tsl.gain = 0 tsl.integration_time = 1 # 101 ms intergration time. self.tsl = tsl
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): """ 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): """ 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 __init__(self, name, simulation): self.name = name self.simulation = simulation if simulation is False: from busio import I2C from board import SDA, SCL from hardware.sensors.lib.adafruit_bno055 import BNO055_I2C i2c = I2C(SCL, SDA) self.sensor = BNO055_I2C(i2c)
def __init__(self, _freq, _scl, _sda): self._i2cDevList = [] self._i2c = I2C(scl=_scl, sda=_sda, frequency=_freq) if not self._i2c.try_lock(): print("ERROR: busio.I2CBus: no lock for scan()") else: try: self._i2cDevList = self._i2c.scan() finally: self._i2c.unlock()
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 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 read_sht31(address=0x44): """ Read temperature and humidity data from a SHT31 sensor :param int address: 0x44 or 0x45 defaults to 0x44 """ if address not in SHT31_ADDRESSES: raise ValueError( "Invalid address {address} must be one of {addresses}".format( address=address, addresses=SHT31_ADDRESSES)) i2c = I2C(SCL, SDA) sensor = sht31d.SHT31D(i2c, address=address) return (round(sensor.temperature, 1), round(sensor.relative_humidity, 1))
def __init__(self, address, name='Sensor', key=None, redis_conn=None): self.address = address self.name = name self.key = key.replace( " ", "_").lower() if key is not None else self.name.replace( " ", "_").lower() self.gpio = GPIO self.i2c = I2C(board.SCL, board.SDA) try: self.r = redis_conn if redis_conn is not None else redis.Redis( host='127.0.0.1', port=6379) except KeyError: self.r = redis.Redis(host='127.0.0.1', port=6379) return
def __init__(self): self._MIN_TEMP = 20. self._MAX_TEMP = 32. self._COLOR_DEPTH = 1024 self._blue = Color('indigo') self._colors = list( self._blue.range_to(Color('red'), self._COLOR_DEPTH)) self._colors = [[ int(c.red * 255), int(c.green * 255), int(c.blue * 255) ] for c in self._colors] self._i2c = I2C(board.SCL, board.SDA) self._amg = AMG88XX(self._i2c)
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_sensors(): import board from adafruit_bme280 import basic as adafruit_bme280 from busio import I2C i2c = I2C(board.SCL, board.SDA) bme280 = None try: bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x77) except Exception as e: logger.debug('Couldnt init BME280: {}'.format(e)) bme280 = DummySensor() bme280.sea_level_pressure = 1013.25 return bme280
def __init__(self, address, name=None, key=None, redis_conn=None): self.address = address if key is None: raise Exception('No "key" Found in I2C Sensor Config') else: self.key = key.replace(" ", "_").lower() if name is None: self.name = self.key.replace("_", " ").title() else: self.name = name self.i2c = I2C(board.SCL, board.SDA) try: self.r = redis_conn if redis_conn is not None else redis.Redis( host='127.0.0.1', port=6379) except KeyError: self.r = redis.Redis(host='127.0.0.1', port=6379) return
def __init__(self, SDA, SCL, toDisplay="ACTIVE LAYER", oWidth=128, oHeight=32, tileWidth=128, tileHeight=32, gridWidth=1, gridHeight=1): releaseDisp() self._toDisplay = toDisplay self._display = SSD1306(displayio.I2CDisplay(I2C(SDA, SCL), device_address=0x3C), width=oWidth, height=oHeight) self._tileHeight = tileHeight self._tileWidth = tileWidth self._gridWidth = gridWidth self._gridHeight = gridHeight self._prevLayers = 0
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 setup_platform(hass, config, add_entities, discovery_info=None): """Set up the sensor platform.""" try: # initializing I2C bus using the auto-detected pins i2c = I2C(board.SCL, board.SDA) # initializing the sensor bmp280 = Adafruit_BMP280_I2C(i2c, address=config[CONF_I2C_ADDRESS]) except ValueError as error: # this usually happens when the board is I2C capable, but the device can't be found at the configured address if str(error.args[0]).startswith("No I2C device at address"): _LOGGER.error( "%s. Hint: Check wiring and make sure that the SDO pin is tied to either ground (0x76) or VCC (0x77)", error.args[0], ) raise PlatformNotReady() from error _LOGGER.error(error) return # use custom name if there's any name = config[CONF_NAME] # BMP280 has both temperature and pressure sensing capability add_entities( [Bmp280TemperatureSensor(bmp280, name), Bmp280PressureSensor(bmp280, name)] )
def setup_platform( hass: HomeAssistant, config: ConfigType, add_entities: AddEntitiesCallback, discovery_info: DiscoveryInfoType | None = None, ) -> None: """Set up the sensor platform.""" _LOGGER.warning( "The Bosch BMP280 Environmental Sensor integration is deprecated and " "will be removed in Home Assistant Core 2022.4; " "this integration is removed under Architectural Decision Record 0019, " "more information can be found here: " "https://github.com/home-assistant/architecture/blob/master/adr/0019-GPIO.md" ) try: # initializing I2C bus using the auto-detected pins i2c = I2C(board.SCL, board.SDA) # initializing the sensor bmp280 = Adafruit_BMP280_I2C(i2c, address=config[CONF_I2C_ADDRESS]) except ValueError as error: # this usually happens when the board is I2C capable, but the device can't be found at the configured address if str(error.args[0]).startswith("No I2C device at address"): _LOGGER.error( "%s. Hint: Check wiring and make sure that the SDO pin is tied to either ground (0x76) or VCC (0x77)", error.args[0], ) raise PlatformNotReady() from error _LOGGER.error(error) return # use custom name if there's any name = config[CONF_NAME] # BMP280 has both temperature and pressure sensing capability add_entities([ Bmp280TemperatureSensor(bmp280, name), Bmp280PressureSensor(bmp280, name) ])
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()
from busio import I2C from adafruit_seesaw.seesaw import Seesaw from adafruit_seesaw.pwmout import PWMOut from adafruit_motor import motor import board import time # Create seesaw object i2c = I2C(board.SCL, board.SDA) seesaw = Seesaw(i2c) # Create one motor on seesaw PWM pins 22 & 23 motor_a = motor.DCMotor(PWMOut(seesaw, 22), PWMOut(seesaw, 23)) motor_a.throttle = 0.5 # half speed forward # Create drive (PWM) object my_drive = PWMOut(seesaw, 13) # Drive 1 is on s.s. pin 13 my_drive.frequency = 1000 # Our default frequency is 1KHz while True: my_drive.duty_cycle = 32768 # half on time.sleep(0.8) my_drive.duty_cycle = 16384 # dim time.sleep(0.1) # and repeat!
# set the resolution of the pi camera # note: you can only send images <100kb to feeds camera.resolution = (200, 200) # set up door sensor door_sensor = digitalio.DigitalInOut(D24) door_sensor.direction = digitalio.Direction.INPUT # set up motion sensor pir_sensor = digitalio.DigitalInOut(D22) pir_sensor.direction = digitalio.Direction.INPUT prev_pir_value = pir_sensor.value is_pir_activated = False # set up sgp30 i2c_bus = I2C(SCL, SDA, frequency=100000) sgp30 = adafruit_sgp30.Adafruit_SGP30(i2c_bus) # set up the neopixel strip pixels = neopixel.NeoPixel(D18, NUM_PIXELS_STRIP) pixels.fill((0, 0, 0)) pixels.show() def alarm_trigger(): """Alarm is triggered by the dashboard toggle and a sensor detecting movement. """ print('* SYSTEM ALARM!') for j in range(NUM_PIXELS_JEWEL): pixels[j] = RED pixels.show()
def __init__(self) -> None: i2c = I2C(SCL, SDA) sgp30 = adafruit_sgp30.Adafruit_SGP30(i2c) sgp30.iaq_init() self.sgp30 = sgp30
DEVICE_ADDRESS = 0x68 # device address of DS3231 board A_DEVICE_REGISTER = 0x0E # control register on the DS3231 board class DeviceControl: # pylint: disable-msg=too-few-public-methods def __init__(self, i2c): self.i2c_device = i2c # self.i2c_device required by RWBit class flag1 = RWBit(A_DEVICE_REGISTER, 0) # bit 0 of the control register flag2 = RWBit(A_DEVICE_REGISTER, 1) # bit 1 flag3 = RWBit(A_DEVICE_REGISTER, 7) # bit 7 # The follow is for I2C communications comm_port = I2C(SCL, SDA) device = I2CDevice(comm_port, DEVICE_ADDRESS) flags = DeviceControl(device) # set the bits in the device flags.flag1 = False flags.flag2 = True flags.flag3 = False # display the device values for the bits print("flag1: {}; flag2: {}; flag3: {}".format(flags.flag1, flags.flag2, flags.flag3)) # toggle the bits flags.flag1 = not flags.flag1 flags.flag2 = not flags.flag2 flags.flag3 = not flags.flag3 # display the device values for the bits