Exemplo n.º 1
0
    def __init__(self, address=0x2F, **kwargs):
        #Initialise the AD5272 device.
        #:param address: The address of the AD5272 default: 0x2F when ADDR=0, 2E when ADD= FLOAT (see schematics)
        #

        I2CDevice.__init__(self, address, **kwargs)
	self.write8(0x1C, 0x02) # enable the update of wiper position by default

        #Read back current wiper settings
        self.write8(0x08, 0x00) # Have to write code 0x0800 to initiate a read of the wiper 
        tmp=self.readU16(0) # read the result into tmp variable
        self.__wiper_pos = ((tmp&0x03) << 8) + ((tmp&0xFF00) >> 8) #mask off lower 8 bits and shift down 8, mask off upper 8 bits and bits 7-2 & shift up 8
	
        #read the contents of the control register
        #0x1 = 50-TP program enable 0 = default, dissable
        #0x2 = RDAC register write protect 0 = default, wiper position frozen, 1 = allow update via i2c
        #0x4 = Resistance performance enable 0 = default = enabled, 1 = dissbale
        #0x8 = 50-TP memory program success bit 0 = default = unsuccessful, 1 = successful
        
        #send the command to read the contents of the control register
        self.write8(0x20, 0x00) #send the command to read the contents of the control register
        
        # when read, byte swap to get register contents
        self.__control_reg = (self.readU16(0)&0xF00 >> 8) 


        #Internal variable settings depending on device / voltage connections
        self.__num_wiper_pos = 1024
        self.__tot_resistance = 100.0
        self.__low_pd = 0.0
        self.__high_pd = 3.3
Exemplo n.º 2
0
    def __init__(self, address, **kwargs):

        I2CDevice.__init__(self, address, **kwargs)
        self.address = address
	#addresses of the 4 DACs
        self.dacs = [0x01, 0x02, 0x04, 0x08]
	#store dac values to minimise i2c traffic	
        self.dac_values = [0x00, 0x00, 0x00, 0x00]
Exemplo n.º 3
0
    def __init__(self, address=0x20, **kwargs):
        """Initialise the AD7998 device.

        :param address: address of the AD7998 device on the I2C bus
        :param kwargs: keyword arguments to be passed to the underlying I2CDevice
        """
        # Initialise the I2CDevice superclass instance
        I2CDevice.__init__(self, address, **kwargs)

        # Set cycle register to fastest conversion mode
        self.write8(3, 1)
Exemplo n.º 4
0
 def __init__(self, i2c):
     self._accel_device = I2CDevice(i2c, _ADDRESS_ACCEL)
     self._mag_device = I2CDevice(i2c, _ADDRESS_MAG)
     self._write_u8(self._accel_device, _REG_ACCEL_CTRL_REG1_A,
                    0x27)  # Enable the accelerometer
     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
Exemplo n.º 5
0
	def __init__(self, address=0x50, **kwargs):
		"""Initialise the TPL0102 device.
		:param address: The address of the TPL0102 default: 0x50
		"""

		I2CDevice.__init__(self, address, **kwargs)

		#Read back current wiper settings
		self.__wiper_pos = [self.readU8(0), self.readU8(1)]
		self.__tot_resistance = 100.0
		self.__low_pd = [0.0,0.0]
		self.__high_pd = [3.3, 3.3]
Exemplo n.º 6
0
    def __init__(self, address=0x2c, **kwargs):
        """Initialises the AD5245 device.
		:param addresss: Address of the AD5245 on the I2C bus
		:param kwargs: Parameters to pass to the I2CDevice
		"""

        I2CDevice.__init__(self, address, **kwargs)

        #Read back current wiper settings
        self.__wiper_pos = self.readU8(0)
        self.__tot_resistance = 100.0
        self.__low_pd = 0.0
        self.__high_pd = 3.3
Exemplo n.º 7
0
    def __init__(self, address=0x20, **kwargs):
        """Initialise the MCP23008 device.

        :param address: address of the MCP23008 deviceon the I2C bus
        :param kwargs: keyword arguments to be passed to the underlying I2CDevice
        """
        # Initialise the I2CDevice superclass instance
        I2CDevice.__init__(self, address, **kwargs)

        # Synchronise local buffered register values with state of device
        self.__iodir = self.readU8(self.IODIR)
        self.__gppu = self.readU8(self.GPPU)
        self.__gpio = self.readU8(self.GPIO)
Exemplo n.º 8
0
    def __init__(self, address=0x70, allowMultiple=True, **kwargs):
        """Initialise the the TCA9548 device.

        :param address: address of TCA9548 on the I2C bus
        :param kwargs: keyword arguments to be passed to underlying I2CDevice
        """
        # Initialise the I2CDevice superclass instance
        I2CDevice.__init__(self, address, **kwargs)

        # Clear attached devices and currently enabled channel
        self._attached_devices = {}
        self._selected_channel = None

        # Disable any already enabled devices by clearing output bus selection
        self.write8(0, 0)
Exemplo n.º 9
0
 def __init__(self,
              i2c,
              address=_SHT31_DEFAULT_ADDRESS,
              probe=False,
              lock=None,
              debug=False,
              calibrate=None,
              raw=None):
     if address not in _SHT31_ADDRESSES:
         raise ValueError("Invalid address: 0x%x" % (address))
     self.i2c_device = I2CDevice(i2c, address, lock=lock)  #
     self.calibrate = {'temperature': None, 'humidity': None}
     # added calibration
     self.raw = raw
     self.debug = debug
     if (not raw) and (type(calibrate) is dict):
         for k in calibrate.keys():
             if (not k in self.calibrate.keys()) or (
                     not type(calibrate[k]) is list):
                 continue
             self.calibrate[k] = calibrate[k]
     self._mode = MODE_SINGLE
     self._repeatability = REP_HIGH
     self._frequency = FREQUENCY_4
     self._clock_stretching = False
     self._art = False
     self._last_read = 0
     self._cached_temperature = None
     self._cached_humidity = None
     self._reset()
Exemplo n.º 10
0
    def __init__(self,
                 width,
                 height,
                 i2cBus,
                 address=0x3c,
                 probe=False,
                 lock=None,
                 debug=False,
                 external_vcc=False):
        if not lock:  # I2C sema
            import _thread
            lock = _thread.allocate_lock()

        from i2c_device import I2CDevice
        self._i2c = I2CDevice(i2cBus, address, probe=probe, lock=lock)  #
        self._debug = debug
        self.addr = address

        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
        self.framebuf = framebuf.FrameBuffer1(
            memoryview(self.buffer)[1:], width, height)
        self.pixel = super().pixel
        super().__init__(width, height, external_vcc)
 def __init__(self, i2c_bus, address=_SHT31_DEFAULT_ADDRESS):
     self.i2c_device = I2CDevice(i2c_bus, address)
     self._repeatability = REP_HIGH
     self._frequency = FREQUENCY_4
     self._last_read = 0
     self._cached_temperature = None
     self._cached_humidity = None
     self._reset()
Exemplo n.º 12
0
    def __init__(self, address=0x55, model=SI570_C, **kwargs):
        """Initialise the SI570 and determine the crystal frequency.
		This resets the device to the factory programmed frequency.
		"""

        I2CDevice.__init__(self, address, busnum=1, **kwargs)

        #Registers used are dependant on the device model
        self.__register = 13 if model == self.SI570_C else 7

        #Reset device to 156.25MHz and calculate fXTAL
        self.write8(135, 1 << 7)
        while self.readU8(135) & 1:
            continue

        #Device is reset, read initial register configurations
        data = self.readList(self.__register, 6)
        self.__hs_div, self.__n1, self.__rfreq = self.__calculate_params(data)
        self.__fxtal = (156250000 * self.__hs_div *
                        self.__n1) / self.__rfreq / 1000000
Exemplo n.º 13
0
 def __init__(self, i2c_bus, address=_SHT31_DEFAULT_ADDRESS):
     if address not in _SHT31_ADDRESSES:
         raise ValueError("Invalid address: 0x%x" % (address))
     self.i2c_device = I2CDevice(i2c_bus, address)
     self._mode = MODE_SINGLE
     self._repeatability = REP_HIGH
     self._frequency = FREQUENCY_4
     self._clock_stretching = False
     self._art = False
     self._last_read = 0
     self._cached_temperature = None
     self._cached_humidity = None
     self._reset()
Exemplo n.º 14
0
 def __init__(self,
              i2c,
              address=0x77,
              debug=False,
              raw=False,
              calibrate=None):
     """Initialize the I2C device at the 'address' given"""
     #import adafruit_bus_device.i2c_device as i2c_device
     from i2c_device import I2CDevice
     #self._i2c = i2c_device.I2CDevice(i2c, address)
     self._i2c = I2CDevice(i2c, address)
     #from Device import *
     #self._i2c = Device(address, i2c)
     self._debug = debug
     super().__init__(raw=raw, calibrate=calibrate, debug=debug)
Exemplo n.º 15
0
    def __init__(self,
                 i2c,
                 address=_BME280_ADDRESS,
                 mode=MODE_SLEEP,
                 probe=False,
                 lock=None,
                 debug=False,
                 raw=False,
                 calibrate=None):
        #import adafruit_bus_device.i2c_device as i2c_device  # pylint: disable=import-outside-toplevel
        from i2c_device import I2CDevice  # pylint: disable=import-outside-toplevel

        self._i2c = I2CDevice(i2c, address, probe=probe, lock=lock)
        super().__init__(i2c,
                         mode=mode,
                         address=address,
                         debug=debug,
                         raw=raw,
                         calibrate=calibrate)  #
Exemplo n.º 16
0
    def __init__(self,
                 i2c,
                 address=0x77,
                 refresh_rate=10,
                 probe=False,
                 lock=None,
                 debug=False,
                 raw=False,
                 calibrate=None):
        """Initialize the I2C device at the 'address' given"""
        #from adafruit_bus_device import (  # pylint: disable=import-outside-toplevel
        #    i2c_device,
        #)
        from i2c_device import I2CDevice

        self._i2c = I2CDevice(i2c, address, probe=probe, lock=lock)  #
        self._debug = debug
        super().__init__(raw=raw,
                         calibrate=calibrate,
                         debug=debug,
                         refresh_rate=refresh_rate)  #
Exemplo n.º 17
0
    def __init__(self, id, verify=False, bus=1, logger=None):
        """Create I2C interface, optionally verify DMCC

        :param id: The cape index or I2C address of the DMCC to initialzie
        :param verify: Perform an active test to verify the presence of a DMCC

        """
        if logger == None:
            self.logger = lib.get_logger()
        else:
            self.logger = logger

        if not (0 <= id <= 3) and not (BASE_ADDR <= id <= BASE_ADDR + 3):
            err_msg = (
                "DMCC id can either be an index (0-3) " +
                "or an address ({}-{})".format(BASE_ADDR, BASE_ADDR + 3))
            self.logger.error(err_msg)
            raise ValueError(err_msg)

        if (id <= 3):
            self.cape_num = id
        else:
            self.cape_num = id - BASE_ADDR

        self.i2c = I2CDevice(bus, address=self.address, config='dmcc_i2c.yaml')

        self.logger.debug("Verifying {:#04x}".format(self.address))
        if verify and not self.verify():
            msg = "Failed to verify DMCC at {:#04x}".format(self.address)
            self.logger.warning(msg)
            raise RuntimeError()

        self.motors = {}
        for i in [1, 2]:
            self.motors[i] = Motor(self.i2c, i)

        self.logger.debug("DMCC {} ({:#04x}) initialized".format(
            self.cape_num, self.address))
Exemplo n.º 18
0
 def setUp(self):
     self.i2c = I2CDevice(None,0x01,test_config)
     self.i2c.write_byte = Mock()
Exemplo n.º 19
0
 def setUp(self):
     self.i2c = I2CDevice(None,0x01,test_config)
Exemplo n.º 20
0
 def setUp(self):
     self.i2c = I2CDevice(None,0x01,test_config)
     self.bits = self.i2c.registers['TestBitfield'].bits
     self.bit_names = self.i2c.registers['TestBitfield'].bit_names