Ejemplo n.º 1
0
    def __init__(self, i2c_bus, address=MAX17048_I2CADDR_DEFAULT):
        self.i2c_device = I2CDevice(i2c_bus, address)

        # Preallocate buffers for sending/receiving I2C data
        self._bufSend = bytearray(2)
        self._bufSend[1] = MAX17048_I2CREAD  # always use bufSend for reading
        self._bufData = bytearray(2)
        self._bufWrite = bytearray(3)
Ejemplo n.º 2
0
 def __init__(self, i2c, address=ADS1X15_DEFAULT_ADDRESS):
     self.buf = bytearray(3)
     self.i2c_device = I2CDevice(i2c, address)
     self.bits = None
     self._channels = [ADC_Channel(self, 0),
                       ADC_Channel(self, 1),
                       ADC_Channel(self, 2),
                       ADC_Channel(self, 3)]
Ejemplo n.º 3
0
 def __init__(self, i2c, address=0x68):
     self._i2c = I2CDevice(i2c, address)
     # Wake up the MPU-6050 since it starts in sleep mode
     self._write_byte(_PWR_MGMT_1, 0x00)
     self._accel_scale_modifier = None
     self.accel_range = ACCEL_RANGE_2G
     self._gyro_scale_modifier = None
     self.gyro_scale = GYRO_RANGE_250DEG
 def __init__(self,
              i2c: I2C,
              address: int = QWIIC_TWIST_ADDR,
              debug: bool = False):
     """Initialize Qwiic Twist for i2c communication."""
     self._device = I2CDevice(i2c, address)
     # save handle to i2c bus in case address is changed
     self._i2c = i2c
     self._debug = debug
Ejemplo n.º 5
0
 def __init__(self, i2c):
     self._mag_device = I2CDevice(i2c, _ADDRESS_MAG)
     self._write_u8(
         self._mag_device, _REG_MAG_MR_REG_M, 0x00
     )  # Enable the magnetometer
     self._lsm303mag_gauss_lsb_xy = 1100.0
     self._lsm303mag_gauss_lsb_z = 980.0
     self._mag_gain = MAGGAIN_1_3
     self._mag_rate = MAGRATE_0_7
Ejemplo n.º 6
0
 def __init__(self, i2c_bus, address=AHTX0_I2CADDR_DEFAULT):
     time.sleep(0.02)  # 20ms delay to wake up
     self.i2c_device = I2CDevice(i2c_bus, address)
     self._buf = bytearray(6)
     self.reset()
     if not self.calibrate():
         raise RuntimeError("Could not calibrate")
     self._temp = None
     self._humidity = None
 def __init__(self, i2c, address=_DEFAULT_ADDRESS):
     self.buf = bytearray(3)
     self.i2c_device = I2CDevice(i2c, address)
     partno, revno = self.chip_id
     # data sheet says TSL2561 = 0001, reality says 0101
     if not partno == 5:
         raise RuntimeError('Failed to find TSL2561! Part 0x%x Rev 0x%x' %
                            (partno, revno))
     self.enabled = True
    def __init__(self, i2c_bus, addr=0x40):
        self.i2c_device = I2CDevice(i2c_bus, addr)
        self.i2c_addr = addr

        # Set chip to known config values to start
        self._cal_value = 0
        self._current_lsb = 0
        self._power_lsb = 0
        self.set_calibration_32V_2A()
Ejemplo n.º 9
0
def is_HAT_present() -> bool:
    with I2C(SCL, SDA) as i2c:
        try:
            I2CDevice(i2c, DAC,
                      probe=True)  # DAC, so we don't interfere with the ADC.
            present = True
        except ValueError:
            present = False
    return present
    def __init__(self, address=ADS1x15_DEFAULT_ADDRESS, i2c=None, **kwargs):
        self.buf = bytearray(3)
        if i2c is None:
            import board
            import busio
            i2c = busio.I2C(board.SCL, board.SDA)
        self.i2c_device = I2CDevice(i2c, address)

        self.bits = None
Ejemplo n.º 11
0
 def __init__(self, i2c_bus, address=0x48):
     self.i2c_device = I2CDevice(i2c_bus, address)
     self._buf = bytearray(3)
     # Verify the manufacturer and device ids to ensure we are talking to
     # what we expect.
     _id = (self._read_register(_ADT7410_ID)[0]) & 0xF8
     if _id != 0xC8:
         raise ValueError("Unable to find ADT7410 at i2c address " +
                          str(hex(address)))
     self.reset()
Ejemplo n.º 12
0
    def __init__(self, i2c, VDD=3.3, address=0x5a):
        """ setup the MPR121 as a singelton with defaults
			   VDD is the supply voltage for the MPR121 chip
			   i2c_address is its address on the I2C bus
			   
		"""
        if MPR121._mpr121 == None:
            MPR121._mpr121 = I2CDevice(i2c, address)

        self.AutoConfig(VDD)
Ejemplo n.º 13
0
 def __init__(self, i2c, address=0x12):
     self.i2c_device = I2CDevice(i2c, address)
     self.buf = bytearray(3)
     self.reset()
     # Wait for device to  be reset
     time.sleep(0.05)
     self.axes = self._read_device_type()
     if self.axes != 1:
         raise RuntimeError("Invalid device type.")
     self.set_sample_rate(ADS_10_HZ)
Ejemplo n.º 14
0
 def __init__(self, i2c, address=_DEFAULT_ADDRESS):
     self.buffer = bytearray(6)
     self.i2c_device = I2CDevice(i2c, address)
     time.sleep(_I2C_INIT_DELAY)
     with self.i2c_device as i2c_dev:
         # turn off encrypted data
         # http://wiibrew.org/wiki/Wiimote/Extension_Controllers
         i2c_dev.write(b'\xF0\x55')
         time.sleep(_I2C_INIT_DELAY)
         i2c_dev.write(b'\xFB\x00')
Ejemplo n.º 15
0
 def __init__(self, i2c_bus: I2C, address: int = AM2320_DEFAULT_ADDR):
     for _ in range(3):
         # retry since we have to wake up the devices
         try:
             self._i2c = I2CDevice(i2c_bus, address)
             return
         except ValueError:
             pass
         time.sleep(0.25)
     raise ValueError("AM2320 not found")
Ejemplo n.º 16
0
    def __init__(self, i2c, address=_SGP30_DEFAULT_I2C_ADDR):
        """Initialize the sensor, get the serial # and verify that we found a proper SGP30"""
        self._device = I2CDevice(i2c, address)

        # get unique serial, its 48 bits so we store in an array
        self.serial = self._i2c_read_words_from_cmd([0x36, 0x82], 0.01, 3)
        # get featureset
        featureset = self._i2c_read_words_from_cmd([0x20, 0x2F], 0.01, 1)
        if featureset[0] not in _SGP30_FEATURESETS:
            raise RuntimeError("SGP30 Not detected")
        self.iaq_init()
Ejemplo n.º 17
0
    def __init__(self, i2c_bus, addr=0x40):
        self.i2c_device = I2CDevice(i2c_bus, addr)
        self.i2c_addr = addr

        # Set chip to known config values to start
        self._cal_value = 0
        self._current_lsb = 0
        self._power_lsb = 0
        self.num_averages = AVG_256
        self.bus_conv_time = VBUSCT_2MS
        self.shunt_conv_time = VSHCT_2MS
Ejemplo n.º 18
0
 def __init__(self, i2c, address=0x52, i2c_read_delay=0.002):
     self.buffer = bytearray(8)
     self.i2c_device = I2CDevice(i2c, address)
     self._i2c_read_delay = i2c_read_delay
     time.sleep(_I2C_INIT_DELAY)
     with self.i2c_device as i2c_dev:
         # turn off encrypted data
         # http://wiibrew.org/wiki/Wiimote/Extension_Controllers
         i2c_dev.write(b"\xF0\x55")
         time.sleep(_I2C_INIT_DELAY)
         i2c_dev.write(b"\xFB\x00")
Ejemplo n.º 19
0
    def __init__(self, i2c, *, debug=False):
        self._debug = debug
        self.set_psk = False
        self.set_crt = False
        self._buffer = bytearray(10)
        self._pbuf = bytearray(1)  # buffer for param read
        self._sendbuf = bytearray(256)  # buffer for command sending
        self._socknum_ll = [[0]]  # pre-made list of list of socket #

        self._i2c_device = I2CDevice(i2c, 0x45)
        self.reset()
Ejemplo n.º 20
0
    def __init__(self):
        # Camera mux hardware definitions
        self.i2c = busio.I2C(board.SCL, board.SDA)
        self.mux = I2CDevice(self.i2c, 0x70)

        self.sel_pin = DigitalInOut(board.D4)
        self.sel_pin.direction = Direction.OUTPUT
        self.oe1_pin = DigitalInOut(board.D17)
        self.oe1_pin.direction = Direction.OUTPUT
        self.oe2_pin = DigitalInOut(board.D18)
        self.oe2_pin.direction = Direction.OUTPUT
Ejemplo n.º 21
0
    def __init__(self, i2c_bus, address=_TLA_DEFAULT_ADDRESS):

        # pylint:disable=no-member

        self.i2c_device = I2CDevice(i2c_bus, address)
        self._last_one_shot = None
        self.mode = Mode.CONTINUOUS
        self.mux = Mux.MUX_AIN0_GND
        # default to widest range and highest sample rate
        self.data_rate = DataRate.RATE_3300SPS
        self.range = Range.RANGE_6_144V
Ejemplo n.º 22
0
    def __init__(self, i2c_bus):
        self.i2c_device = I2CDevice(i2c_bus, 0x68)

        # Try and verify this is the RTC we expect by checking the rate select
        # control bits which are 1 on reset and shouldn't ever be changed.
        buf = bytearray(2)
        buf[0] = 0x07
        with self.i2c_device as i2c:
            i2c.write_then_readinto(buf, buf, out_end=1, in_start=1)

        if (buf[1] & 0b00000011) != 0b00000011:
            raise ValueError("Unable to find DS1307 at i2c address 0x68.")
Ejemplo n.º 23
0
    def __init__(self,
                 i2c,
                 interrupt_pin=None,
                 address=_STUSB4500_DEFAULT_ADDRESS,
                 debug=False):
        self.debug = debug

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

        if self._read_register(_DEVICE_ID_REG, 1)[0] is not _DEVICE_ID:
            raise RuntimeError()
Ejemplo n.º 24
0
  def __init__(self, i2c, address=_DEFAULT_ADDRESS):
    self.buffer = bytearray(3)
    self.i2c_device = I2CDevice(i2c, address)

    self.get_ID()
    self._set_mode(_DEVICE_MODES["ALL"], False)
    self._write_register(_REGISTER_ATIME, _DEVICE_ATIMES["DEFAULT"])
    self._write_register(_REGISTER_PPULSE, _DEVICE_DEFAULT_PPULSE)
    self._write_register(_REGISTER_CONFIG1, _DEVICE_DEFAULT_CONFIG1)
    self._set_mask(_REGISTER_CONTROL, _DEVICE_LED_CURRENTS["25mA"], 6, 2) # set LED current
    self._set_mask(_REGISTER_CONTROL, _DEVICE_PGAIN["4X"], 2, 2) # set proximity gain
    self._set_mask(_REGISTER_CONTROL, _DEVICE_AGAIN["4X"], 0, 2) # set ambient light gain
Ejemplo n.º 25
0
    def __init__(self, i2c_bus, addr=0x40):
        self.i2c_device = I2CDevice(i2c_bus, addr)

        self.i2c_addr = addr
        # Multiplier in mA used to determine current from raw reading
        self._current_lsb = 0
        # Multiplier in W used to determine power from raw reading
        self._power_lsb = 0

        # Set chip to known config values to start
        self._cal_value = 4096
        self.set_calibration_32V_2A()
Ejemplo n.º 26
0
    def __init__(self, address=_AD5245_DEFAULT_ADDRESS, wiper=0):
        import board
        import busio

        self._i2c = busio.I2C(board.SCL, board.SDA)
        from adafruit_bus_device.i2c_device import I2CDevice
        self._device = I2CDevice(self._i2c, address)

        self._wiper = wiper
        self._default_wiper = wiper
        self._normalized_wiper = self._wiper / 255.0
        self._write_to_device(0, wiper)
    def __init__(self, i2c_bus, address=0x0C, gain=GAIN_1X, debug=False):
        self.i2c_device = I2CDevice(i2c_bus, address)
        self._debug = debug
        self._status_last = 0
        self._res_current = _RES_2_15
        self._gain_current = gain

        # Put the device in a known state to start
        self.reset()

        # Set gain to the supplied level
        self.gain = self._gain_current
    def __init__(self, i2c_bus, addr=0x2c):
        self.i2c_device = I2CDevice(i2c_bus, addr)

        ## Querry current output state to allow setup of the _config structure
        outputs = self._read_register(_REG_CONFIG)

        self._config = dict(
            adc_mode=_ADC_MODE_CURRENT,
            enc=
            True,  ## This is not the POR value, but we do want continuous ADC reading
            clr=True,
            outputs=[get_bit(outputs, idx) for idx in [0, 1, 2, 3]])
 def __init__(self, i2c, address=0x28):
     self.i2c_device = I2CDevice(i2c, address)
     self.buffer = bytearray(2)
     chip_id = self._read_register(_ID_REGISTER)
     if chip_id != _CHIP_ID:
         raise RuntimeError("bad chip id (%x != %x)" % (chip_id, _CHIP_ID))
     self.reset()
     self._write_register(_POWER_REGISTER, _POWER_NORMAL)
     self._write_register(_PAGE_REGISTER, 0x00)
     self._write_register(_TRIGGER_REGISTER, 0x00)
     time.sleep(0.01)
     self.mode = NDOF_MODE
     time.sleep(0.01)
Ejemplo n.º 30
0
    def __init__(self, i2c):
        self.i2c_device = I2CDevice(i2c, 0x68)

        # Try and verify this is the RTC we expect by checking the rate select
        # control bits which are 1 on reset and shouldn't ever be changed.
        buf = bytearray(2)
        buf[0] = 0x0e
        with self.i2c_device as i2c_device:
            i2c_device.write(buf, end=1, stop=False)
            i2c_device.readinto(buf, start=1)

        if (buf[1] & 0b00011000) != 0b00011000:
            raise ValueError("Unable to find DS3231 at i2c address 0x68.")