Beispiel #1
0
    def __init__(self,
                 i2c_bus,
                 *,
                 address=_GPSI2C_DEFAULT_ADDRESS,
                 debug=False,
                 timeout=5):
        import adafruit_bus_device.i2c_device as i2c_device  # pylint: disable=import-outside-toplevel

        super().__init__(None, debug)  # init the parent with no UART
        self._i2c = i2c_device.I2CDevice(i2c_bus, address)
        self._lastbyte = None
        self._charbuff = bytearray(1)
        self._internalbuffer = []
        self._timeout = timeout
Beispiel #2
0
    def __init__(self, i2c_bus, address=_LIS3MDL_DEFAULT_ADDRESS):
        # pylint: disable=no-member
        self.i2c_device = i2c_device.I2CDevice(i2c_bus, address)
        if self._chip_id != _LIS3MDL_CHIP_ID:
            raise RuntimeError("Failed to find LIS3MDL - check your wiring!")

        self.reset()
        self.performance_mode = PerformanceMode.MODE_ULTRA

        self.data_rate = Rate.RATE_155_HZ
        self.range = Range.RANGE_4_GAUSS
        self.operation_mode = OperationMode.CONTINUOUS

        sleep(0.010)
    def __init__(self, i2c_bus, address=0x40):
        self.i2c_device = i2cdevice.I2CDevice(i2c_bus, address)

        if self._manufacturer_id != self.TEXAS_INSTRUMENT_ID:
            raise RuntimeError(
                "Failed to find Texas Instrument ID, read {} while expected {}"
                " - check your wiring!".format(self._manufacturer_id,
                                               self.TEXAS_INSTRUMENT_ID))

        if self._device_id != self.INA260_ID:
            raise RuntimeError(
                "Failed to find INA260 ID, read {} while expected {}"
                " - check your wiring!".format(self._device_id,
                                               self.INA260_ID))
Beispiel #4
0
    def __init__(self, i2c, address=_STMPE_ADDR):
        """
        Check the STMPE610 was founnd
        Default address is 0x41 but another address can be passed in as an argument
        """
        import adafruit_bus_device.i2c_device as i2cdev  # pylint: disable=import-outside-toplevel

        self._i2c = i2cdev.I2CDevice(i2c, address)
        # Check device version.
        version = self.get_version
        if _STMPE_VERSION != version:
            raise RuntimeError("Failed to find STMPE610! Chip Version 0x%x" %
                               version)
        super().__init__()
    def __init__(self,
                 i2c: busio.I2C,
                 address: int = MPR121_I2CADDR_DEFAULT) -> None:
        """Creates a new ``MPR121`` instance.

        :param i2c: An I2C driver.
        :type i2c: class:`busio.I2C`
        :param address: The address of the touch sensor (0x5A - 0x5D).
        :type address: int
        """
        self._i2c = i2c_device.I2CDevice(i2c, address)
        self._buffer = bytearray(2)
        self._channels = [None] * 12
        self.reset()
Beispiel #6
0
 def __init__(
     self,
     i2c: I2C,
     address: Union[int, Tuple, List] = 0x70,
     auto_write: bool = True,
     brightness: float = 1.0,
 ) -> None:
     if isinstance(address, (tuple, list)):
         self.i2c_device = []
         for addr in address:
             self.i2c_device.append(i2c_device.I2CDevice(i2c, addr))
     else:
         self.i2c_device = [i2c_device.I2CDevice(i2c, address)]
     self._temp = bytearray(1)
     self._buffer_size = 17
     self._buffer = bytearray((self._buffer_size) * len(self.i2c_device))
     self._auto_write = auto_write
     self.fill(0)
     for i, _ in enumerate(self.i2c_device):
         self._write_cmd(_HT16K33_OSCILATOR_ON, i)
     self._blink_rate = None
     self._brightness = None
     self.blink_rate = 0
     self.brightness = brightness
    def __init__(self, i2c, address=0x70, auto_write=True, brightness=1.0):

        self.i2c_device = i2c_device.I2CDevice(i2c, address)

        self._ram_buffer = bytearray(17)
        self._mv_buffer = memoryview(self._ram_buffer)
        self._display_ram = self._mv_buffer[1:]
        self._content = [None] * 4
        self._auto_write = auto_write
        self._write_cmd(_HT16K33_OSCILATOR_ON)
        self.clear()
        self._blink_rate = None
        self._brightness = None
        self.blink_rate = 0
        self.brightness = brightness
    def __init__(self, i2c, address=0x60):
        self.i2c_device = i2cdevice.I2CDevice(i2c, address)
        if self._device_id != 0x186:
            raise RuntimeError("Failed to find VCNL4040 - check wiring!")

        self.cached_interrupt_state = {
            self.ALS_IF_L: False,
            self.ALS_IF_H: False,
            self.PS_IF_CLOSE: False,
            self.PS_IF_AWAY: False,
        }

        self.proximity_shutdown = False
        self.light_shutdown = False
        self.white_shutdown = False
Beispiel #9
0
 def __init__(self,
              i2c,
              *,
              address=_SI4710_ADDR1,
              reset=None,
              timeout_s=0.1):
     self._timeout_s = timeout_s
     self._device = i2c_device.I2CDevice(i2c, address)
     # Configure reset line if it was provided.
     self._reset = reset
     if self._reset is not None:
         self._reset.switch_to_output(value=True)
     self.reset()
     # Check product ID.
     if self._get_product_number() != 13:
         raise RuntimeError('Failed to find SI4713, check wiring!')
    def set_address(self, new_address):
        """Set a new I2C address to the instantaited object. This is only called when using
        multiple VL53L0X sensors on the same I2C bus (SDA & SCL pins). See also the
        `example <examples.html#multiple-vl53l0x-on-same-i2c-bus>`_ for proper usage.

        :param int new_address: The 7-bit `int` that is to be assigned to the VL53L0X sensor.
            The address that is assigned should NOT be already in use by another device on the
            I2C bus.

        .. important:: To properly set the address to an individual VL53L0X sensor, you must
            first ensure that all other VL53L0X sensors (using the default address of ``0x29``)
            on the same I2C bus are in their off state by pulling the "SHDN" pins LOW. When the
            "SHDN" pin is pulled HIGH again the default I2C address is ``0x29``.
        """
        self._write_u8(_I2C_SLAVE_DEVICE_ADDRESS, new_address & 0x7F)
        self._device = i2c_device.I2CDevice(self._i2c, new_address)
Beispiel #11
0
    def __init__(self,
                 i2c_bus,
                 mpu_addr=_MPU6500_DEFAULT_ADDRESS,
                 akm_addr=_AK8963_DEFAULT_ADDRESS):
        self.i2c_device = i2c_device.I2CDevice(i2c_bus, mpu_addr)

        if self._device_id != _MPU9250_DEVICE_ID:
            raise RuntimeError("Failed to find MPU9250 - check your wiring!")

        self._mpu = MPU6500(i2c_bus, mpu_addr)

        self._bypass = 1
        self._ready = 1
        sleep(0.100)

        self._akm = AK8963(i2c_bus, akm_addr)
    def __init__(self, i2c_bus, address=_TLV493D_DEFAULT_ADDRESS, addr_reg=0):
        self.i2c_device = i2cdevice.I2CDevice(i2c_bus, address)
        self.read_buffer = bytearray(10)
        self.write_buffer = bytearray(4)

        # read in data from sensor, including data that must be set on a write
        self._setup_write_buffer()

        # write correct i2c address
        self._set_write_key("ADDR", addr_reg)

        # setup MASTERCONTROLLEDMODE which takes a measurement for every read
        self._set_write_key("PARITY", 1)
        self._set_write_key("FAST", 1)
        self._set_write_key("LOWPOWER", 1)
        self._write_i2c()
    def __init__(self, i2c_bus, address=_MPU6050_DEFAULT_ADDRESS):
        self.i2c_device = i2c_device.I2CDevice(i2c_bus, address)

        if self._device_id != _MPU6050_DEVICE_ID:
            raise RuntimeError("Failed to find MPU6050 - check your wiring!")

        self.reset()

        self._sample_rate_divisor = 0
        self._filter_bandwidth = Bandwidth.BAND_260_HZ
        self._gyro_range = GyroRange.RANGE_500_DPS
        self._accel_range = Range.RANGE_2_G
        sleep(0.100)
        self._clock_source = 1  # set to use gyro x-axis as reference
        sleep(0.100)
        self.sleep = False
        sleep(0.010)
    def __init__(self, i2c, gain=CONST_GAIN_1X, integration=CONST_INT_100, rate=CONST_RATE_500):
        import adafruit_bus_device.i2c_device as i2c_device
        self._i2c = i2c_device.I2CDevice(i2c, LTR_ADDRESS)
        self._buffer = bytearray(2)
        self._gain = gain
        self._integration = integration
        self._rate = rate
        self._active = 0x01

        # just in case it we are just starting, choip needs 10ms after boot
        time.sleep(0.1)

        self._write_register_byte(
            REG_ALS_MEAS_RATE, self._get_meas_rate(integration, rate))
        self._write_register_byte(
            REG_ALS_CONTR, self._get_contr(gain) | self._active)

        time.sleep(0.01)
Beispiel #15
0
    def __init__(self, i2c_bus, ambient_pressure=0, address=SCD30_DEFAULT_ADDR):
        if ambient_pressure != 0:
            if ambient_pressure < 700 or ambient_pressure > 1200:
                raise AttributeError("`ambient_pressure` must be from 700-1200 mBar")

        self.i2c_device = i2c_device.I2CDevice(i2c_bus, address)
        self._buffer = bytearray(18)
        self._crc_buffer = bytearray(2)

        # set continuous measurement interval in seconds
        self.measurement_interval = 2
        # trigger continuous measurements with optional ambient pressure compensation
        self.ambient_pressure = ambient_pressure

        # cached readings
        self._temperature = None
        self._relative_humidity = None
        self._co2 = None
    def __init__(self, bus, address=0x40):
        self.config_data = None
        self._bus = i2c_device.I2CDevice(bus, address)

        if self.device_id == b"\x01\x2B\xa0\x43":
            # Mach XO2 1200
            pass
        elif self.device_id == b"\x61\x2B\xd0\x43":
            # Mach XO3 6900
            pass
        elif self.device_id == b"\x01\x2B\x50\x43":
            # Mach X02 7000
            pass
        else:
            print([hex(x) for x in self.device_id])
            raise ValueError("Unable to confirm Mach XO device id")

        self._erased = False
        self._config_mode = False
Beispiel #17
0
    def __init__(self, i2c_bus, address=_LSM6DSOX_DEFAULT_ADDRESS):
        self.i2c_device = i2c_device.I2CDevice(i2c_bus, address)

        if self._chip_id not in [_LSM6DSOX_CHIP_ID, _ISM330DHCX_CHIP_ID]:
            raise RuntimeError(
                "Failed to find LSM6DSOX or ISM330DHCX - check your wiring!")
        self.reset()

        self._bdu = True
        self._i3c_disable = True
        self._if_inc = True

        self._accel_data_rate = Rate.RATE_104_HZ  #pylint: disable=no-member
        self._gyro_data_rate = Rate.RATE_104_HZ  #pylint: disable=no-member

        self._accel_range = AccelRange.RANGE_4G  #pylint: disable=no-member
        self._cached_accel_range = self._accel_range
        self._gyro_range = GyroRange.RANGE_250_DPS  #pylint: disable=no-member
        self._cached_gyro_range = self._gyro_range
Beispiel #18
0
 def __init__(self, i2c, *, address=_MMA8451_DEFAULT_ADDRESS):
     self._device = i2c_device.I2CDevice(i2c, address)
     # Verify device ID.
     if self._read_u8(_MMA8451_REG_WHOAMI) != 0x1A:
         raise RuntimeError('Failed to find MMA8451, check wiring!')
     # Reset and wait for chip to be ready.
     self._write_u8(_MMA8451_REG_CTRL_REG2, 0x40)
     while self._read_u8(_MMA8451_REG_CTRL_REG2) & 0x40 > 0:
         pass
     # Enable 4G range.
     self._write_u8(_MMA8451_REG_XYZ_DATA_CFG, RANGE_4G)
     # High resolution mode.
     self._write_u8(_MMA8451_REG_CTRL_REG2, 0x02)
     # DRDY on INT1
     self._write_u8(_MMA8451_REG_CTRL_REG4, 0x01)
     self._write_u8(_MMA8451_REG_CTRL_REG5, 0x01)
     # Turn on orientation config
     self._write_u8(_MMA8451_REG_PL_CFG, 0x40)
     # Activate at max rate, low noise mode
     self._write_u8(_MMA8451_REG_CTRL_REG1, 0x01 | 0x04)
Beispiel #19
0
 def __init__(
     self, width, height, i2c, *, addr=0x3C, external_vcc=False, reset=None
 ):
     self.i2c_device = i2c_device.I2CDevice(i2c, addr)
     self.addr = addr
     self.temp = bytearray(2)
     # Add an extra byte to the data buffer to hold an I2C data/command byte
     # to use hardware-compatible I2C transactions.  A memoryview of the
     # buffer is used to mask this byte from the framebuffer operations
     # (without a major memory hit as memoryview doesn't copy to a separate
     # buffer).
     self.buffer = bytearray(((height // 8) * width) + 1)
     self.buffer[0] = 0x40  # Set first byte of data buffer to Co=0, D/C=1
     super().__init__(
         memoryview(self.buffer)[1:],
         width,
         height,
         external_vcc=external_vcc,
         reset=reset,
     )
    def __init__(self, i2c_bus, address=_LSM6DS_DEFAULT_ADDRESS):
        self._cached_accel_range = None
        self._cached_gyro_range = None

        self.i2c_device = i2c_device.I2CDevice(i2c_bus, address)
        if self.CHIP_ID is None:
            raise AttributeError(
                "LSM6DS Parent Class cannot be directly instantiated")
        if self._chip_id != self.CHIP_ID:
            raise RuntimeError("Failed to find %s - check your wiring!" %
                               self.__class__.__name__)
        self.reset()

        self._bdu = True

        self.accelerometer_data_rate = Rate.RATE_104_HZ  # pylint: disable=no-member
        self.gyro_data_rate = Rate.RATE_104_HZ  # pylint: disable=no-member

        self.accelerometer_range = AccelRange.RANGE_4G  # pylint: disable=no-member
        self.gyro_range = GyroRange.RANGE_250_DPS  # pylint: disable=no-member
 def __init__(self, i2c, *, address=_MPL3115A2_ADDRESS):
     self._device = i2c_device.I2CDevice(i2c, address)
     # Validate the chip ID.
     if self._read_u8(_MPL3115A2_WHOAMI) != 0xC4:
         raise RuntimeError('Failed to find MPL3115A2, check your wiring!')
     # Reset.  Note the chip immediately resets and won't send an I2C back
     # so we need to catch the OSError and swallow it (otherwise this fails
     # expecting an ACK that never comes).
     try:
         self._write_u8(_MPL3115A2_CTRL_REG1, _MPL3115A2_CTRL_REG1_RST)
     except OSError:
         pass
     time.sleep(0.01)
     # Poll for the reset to finish.
     self._poll_reg1(_MPL3115A2_CTRL_REG1_RST)
     # Configure the chip registers with default values.
     self._ctrl_reg1 = _MPL3115A2_CTRL_REG1_OS128 | _MPL3115A2_CTRL_REG1_ALT
     self._write_u8(_MPL3115A2_CTRL_REG1, self._ctrl_reg1)
     self._write_u8(_MPL3115A2_PT_DATA_CFG, _MPL3115A2_PT_DATA_CFG_TDEFE | \
                                            _MPL3115A2_PT_DATA_CFG_PDEFE | \
                                            _MPL3115A2_PT_DATA_CFG_DREM)
Beispiel #22
0
    def __init__(self, i2c_bus, address=_DPS310_DEFAULT_ADDRESS):
        self.i2c_device = i2c_device.I2CDevice(i2c_bus, address)

        if self._device_id != _DPS310_DEVICE_ID:
            raise RuntimeError("Failed to find DPS310 - check your wiring!")
        self._pressure_scale = None
        self._temp_scale = None
        self._c0 = None
        self._c1 = None
        self._c00 = None
        self._c00 = None
        self._c10 = None
        self._c10 = None
        self._c01 = None
        self._c11 = None
        self._c20 = None
        self._c21 = None
        self._c30 = None
        self._oversample_scalefactor = (524288, 1572864, 3670016, 7864320, 253952,
                                        516096, 1040384, 2088960)
        self.initialize()
Beispiel #23
0
    def __init__(self,
                 i2c_interface=None,
                 busnum=1,
                 address=0x0c,
                 mode=MODE_CONTINUOUS_MEASURE_2,
                 output=OUTPUT_16_BIT,
                 offset=(0, 0, 0),
                 scale=(1, 1, 1)):
        self.i2c = i2c_device.I2CDevice(i2c_interface, address)

        self.address = address
        self._offset = offset
        self._scale = scale

        if 0x48 != self.read_whoami():
            raise RuntimeError("AK8963 not found in I2C bus.")

        # Sensitivity adjustment values
        self._write_u8(_CNTL1, _MODE_FUSE_ROM_ACCESS)
        asax = self._read_u8(_ASAX)
        asay = self._read_u8(_ASAY)
        asaz = self._read_u8(_ASAZ)
        self._write_u8(_CNTL1, _MODE_POWER_DOWN)

        # Should wait at least 100us before next mode
        time.sleep(100e-6)

        self._adjustment = ((0.5 * (asax - 128)) / 128 + 1,
                            (0.5 * (asay - 128)) / 128 + 1,
                            (0.5 * (asaz - 128)) / 128 + 1)

        # Power on
        self._write_u8(_CNTL1, (mode | output))

        if output is OUTPUT_16_BIT:
            self._so = _SO_16BIT
        else:
            self._so = _SO_14BIT
Beispiel #24
0
 def __init__(self, i2c, *, address=_SI5351_ADDRESS):
     self._device = i2c_device.I2CDevice(i2c, address)
     # Setup the SI5351.
     # Disable all outputs setting CLKx_DIS high.
     self._write_u8(_SI5351_REGISTER_3_OUTPUT_ENABLE_CONTROL, 0xFF)
     # Power down all output drivers
     self._write_u8(_SI5351_REGISTER_16_CLK0_CONTROL, 0x80)
     self._write_u8(_SI5351_REGISTER_17_CLK1_CONTROL, 0x80)
     self._write_u8(_SI5351_REGISTER_18_CLK2_CONTROL, 0x80)
     self._write_u8(_SI5351_REGISTER_19_CLK3_CONTROL, 0x80)
     self._write_u8(_SI5351_REGISTER_20_CLK4_CONTROL, 0x80)
     self._write_u8(_SI5351_REGISTER_21_CLK5_CONTROL, 0x80)
     self._write_u8(_SI5351_REGISTER_22_CLK6_CONTROL, 0x80)
     self._write_u8(_SI5351_REGISTER_23_CLK7_CONTROL, 0x80)
     # Initialize PLL A and B objects.
     self.pll_a = self._PLL(self, 26, 0)
     self.pll_b = self._PLL(self, 34, (1 << 5))
     # Initialize the 3 clock outputs.
     self.clock_0 = self._Clock(
         self,
         _SI5351_REGISTER_42_MULTISYNTH0_PARAMETERS_1,
         _SI5351_REGISTER_16_CLK0_CONTROL,
         _SI5351_REGISTER_44_MULTISYNTH0_PARAMETERS_3,
     )
     self.clock_1 = self._Clock(
         self,
         _SI5351_REGISTER_50_MULTISYNTH1_PARAMETERS_1,
         _SI5351_REGISTER_17_CLK1_CONTROL,
         _SI5351_REGISTER_52_MULTISYNTH1_PARAMETERS_3,
     )
     self.clock_2 = self._Clock(
         self,
         _SI5351_REGISTER_58_MULTISYNTH2_PARAMETERS_1,
         _SI5351_REGISTER_18_CLK2_CONTROL,
         _SI5351_REGISTER_60_MULTISYNTH2_PARAMETERS_3,
     )
Beispiel #25
0
 def __init__(self, i2c, address=_FXOS8700_ADDRESS, accel_range=ACCEL_RANGE_2G):
     assert accel_range in (ACCEL_RANGE_2G, ACCEL_RANGE_4G, ACCEL_RANGE_8G)
     self._accel_range = accel_range
     self._device = i2c_dev.I2CDevice(i2c, address)
     # Check for chip ID value.
     if self._read_u8(_FXOS8700_REGISTER_WHO_AM_I) != _FXOS8700_ID:
         raise RuntimeError("Failed to find FXOS8700, check wiring!")
     # Set to standby mode (required to make changes to this register)
     self._write_u8(_FXOS8700_REGISTER_CTRL_REG1, 0)
     if accel_range == ACCEL_RANGE_2G:
         self._write_u8(_FXOS8700_REGISTER_XYZ_DATA_CFG, 0x00)
     elif accel_range == ACCEL_RANGE_4G:
         self._write_u8(_FXOS8700_REGISTER_XYZ_DATA_CFG, 0x01)
     elif accel_range == ACCEL_RANGE_8G:
         self._write_u8(_FXOS8700_REGISTER_XYZ_DATA_CFG, 0x02)
     # High resolution
     self._write_u8(_FXOS8700_REGISTER_CTRL_REG2, 0x02)
     # Active, Normal Mode, Low Noise, 100Hz in Hybrid Mode
     self._write_u8(_FXOS8700_REGISTER_CTRL_REG1, 0x15)
     # Configure the magnetometer
     # Hybrid Mode, Over Sampling Rate = 16
     self._write_u8(_FXOS8700_REGISTER_MCTRL_REG1, 0x1F)
     # Jump to reg 0x33 after reading 0x06
     self._write_u8(_FXOS8700_REGISTER_MCTRL_REG2, 0x20)
Beispiel #26
0
    def __init__(self, i2c, *, address=_SI4710_ADDR1, reset=None, timeout_s=0.1):
        self._timeout_s = timeout_s

        # Configure reset line if it was provided.
        self._reset = reset

        if self._reset is not None:
            self._reset.switch_to_output(value=True)

            # Toggle reset line low to reset the chip and then wait a bit for
            # startup - this is necessary before initializing as an i2c device
            # on at least the Raspberry Pi, and potentially elsewhere:
            self._reset.value = True
            time.sleep(0.01)
            self._reset.value = False
            time.sleep(0.01)
            self._reset.value = True
            time.sleep(0.25)

        self._device = i2c_device.I2CDevice(i2c, address)
        self.reset()
        # Check product ID.
        if self._get_product_number() != 13:
            raise RuntimeError('Failed to find SI4713, check wiring!')
Beispiel #27
0
    def __init__(
        self, i2c_interface=None, busnum=1, address=0x68,
        accel_fs=ACCEL_FS_SEL_2G, gyro_fs=GYRO_FS_SEL_500DPS,
        accel_sf=SF_M_S2, gyro_sf=_GYRO_SO_500DPS,
        gyro_offset=(0, 0, 0)
    ):
        self.i2c = i2c_device.I2CDevice(i2c_interface, address)
        
        self.address = address

        if 0x71 != self.read_whoami():
            raise RuntimeError("MPU6500 not found in I2C bus.")

        self._accel_so = self._accel_fs(accel_fs)
        self._gyro_so = self._gyro_fs(gyro_fs)
        self._accel_sf = accel_sf
        self._gyro_sf = gyro_sf
        self._gyro_offset = gyro_offset

        # Enable I2C bypass to access for MPU9250 magnetometer access.
        char = self._read_u8(_INT_PIN_CFG)
        char &= ~_I2C_BYPASS_MASK # clear I2C bits
        char |= _I2C_BYPASS_EN
        self._write_u8(_INT_PIN_CFG, char)
Beispiel #28
0
 def __init__(self, i2c, rng=L3DS20_RANGE_250DPS, address=0x6B):
     import adafruit_bus_device.i2c_device as i2c_device
     self.i2c_device = i2c_device.I2CDevice(i2c, address)
     self.buffer = bytearray(2)
     super().__init__(rng)
Beispiel #29
0
 def __init__(self, i2c, address=_MPL115A2_ADDRESS):
     self._i2c = i2c_device.I2CDevice(i2c, address)
     self._buf = bytearray(4)
     self._read_coefficients()
 def __init__(self, i2c, *, address=0x18, int1=None, int2=None):
     import adafruit_bus_device.i2c_device as i2c_device
     self._i2c = i2c_device.I2CDevice(i2c, address)
     self._buffer = bytearray(6)
     super().__init__(int1=int1, int2=int2)