def __init__(self, time=0.18, slave= 0x23,mode=4, name="gy_30"): I2C.__init__(self, toint(slave)) self.name = name # self.wake() # devices are powered down after power reset, wake them # self.setTime(toint(time)) if slave == 0: self.addr = self.I2C_ADDRESS_L else: self.addr = self.I2C_ADDRESS_H if mode == 0: self.mode = self.CONTINUOUSLY_H_RES_MODE self.wait = 0.18 # Wait 180ms for result self.resolution_div = 1 elif mode == 1: self.mode = self.CONTINUOUSLY_H_RES_MODE_2 self.wait = 0.18 # Wait 180ms for result self.resolution_div = 2 elif mode == 2: self.mode = self.CONTINUOUSLY_L_RES_MODE self.wait = 0.024 # Wait 24ms for result self.resolution_div = 1 elif mode == 3: self.mode = self.ONE_TIME_H_RES_MODE self.wait = 0.18 # Wait 180ms for result self.resolution_div = 1 elif mode == 4: self.mode = self.ONE_TIME_H_RES_MODE_2 self.wait = 0.18 # Wait 180ms for result self.resolution_div = 2 else: self.mode = self.ONE_TIME_L_RES_MODE self.wait = 0.024 # Wait 24ms for result self.resolution_div = 1
def __init__(self, slave, channel_count): """Initializes MCP230XX device. Arguments: slave: The I2C slave address channel_count: Number of channels on the device """ I2C.__init__(self, int(slave)) MCP23XXX.__init__(self, channel_count)
def __init__(self, slave=0x60, vref=3.3): """Initializes PCF8591 device. Arguments: slave: The slave address vref: The reference voltage """ I2C.__init__(self, int(slave)) DAC.__init__(self, 1, 12, float(vref))
def __init__(self, slave, time): """Initializes TSL device. Arguments: slave: The slave address time: Integration time """ I2C.__init__(self, int(slave)) self.wake() # devices are powered down after power reset, wake them self.set_time(int(time))
def __init__(self, slave=0x40, frequency=50): I2C.__init__(self, toint(slave)) PWM.__init__(self, 16, 12, toint(frequency)) self.VREF = 0 self.prescale = int(25000000.0 / ((2**12) * self.frequency)) self.mode1 = self.M1_RESTART | self.M1_AI self.writeRegister(self.MODE1, self.M1_SLEEP) self.writeRegister(self.PRESCALE, self.prescale) time.sleep(0.01) self.writeRegister(self.MODE1, self.mode1)
def __init__(self, slave=0x20): slave = toint(slave) if slave in range(0x20, 0x28): self.name = "PCF8574" elif slave in range(0x38, 0x40): self.name = "PCF8574A" else: raise ValueError( "Bad slave address for PCF8574(A) : 0x%02X not in range [0x20..0x27, 0x38..0x3F]" % slave) I2C.__init__(self, slave) GPIOPort.__init__(self, 8) self.portWrite(0xFF) self.portRead()
def __init__(self, altitude=0, external=None): I2C.__init__(self, 0x77) Pressure.__init__(self, altitude, external) self.ac1 = self.readSignedInteger(0xAA) self.ac2 = self.readSignedInteger(0xAC) self.ac3 = self.readSignedInteger(0xAE) self.ac4 = self.readUnsignedInteger(0xB0) self.ac5 = self.readUnsignedInteger(0xB2) self.ac6 = self.readUnsignedInteger(0xB4) self.b1 = self.readSignedInteger(0xB6) self.b2 = self.readSignedInteger(0xB8) self.mb = self.readSignedInteger(0xBA) self.mc = self.readSignedInteger(0xBC) self.md = self.readSignedInteger(0xBE)
def __init__(self, slave=0x40, frequency=50): """Initializes PCA9685 device. Arguments: slave: The slave address frequency: The PWM control frequency """ I2C.__init__(self, int(slave)) PWM.__init__(self, 16, 12, int(frequency)) self.VREF = 0 self.prescale = int(25000000.0 / ((2**12) * self.frequency)) self.mode1 = self.M1_RESTART | self.M1_AI self.writeRegister(self.MODE1, self.M1_SLEEP) self.writeRegister(self.PRESCALE, self.prescale) time.sleep(0.01) self.writeRegister(self.MODE1, self.mode1)
def __init__(self, slave=0x20): """Initializes PCF8574 device. Arguments: slave: The slave address """ slave = int(slave) if slave in range(0x20, 0x28): self.name = "PCF8574" elif slave in range(0x38, 0x40): self.name = "PCF8574A" else: raise ValueError("Bad slave address for PCF8574(A) : 0x%02X not in range [0x20..0x27, 0x38..0x3F]" % slave) I2C.__init__(self, slave) GPIOPort.__init__(self, 8) self.portWrite(0xFF) self.portRead()
def __init__(self, slave, channelCount, resolution, name): I2C.__init__(self, toint(slave)) ADC.__init__(self, channelCount, resolution, 4.096) self._analogMax = 2**(resolution-1) self.name = name config = self.readRegisters(self.CONFIG, 2) mode = 0 # continuous config[0] &= ~self.CONFIG_MODE_MASK config[0] |= mode gain = 0x1 # FS = +/- 4.096V config[0] &= ~self.CONFIG_GAIN_MASK config[0] |= gain << 1 self.writeRegisters(self.CONFIG, config)
def __init__(self, slave=0b0010011, current=20, frequency=781, prox_threshold=15, prox_cycles=10, cal_cycles=5): I2C.__init__(self, toint(slave)) self.setCurrent(toint(current)) self.setFrequency(toint(frequency)) self.prox_threshold = toint(prox_threshold) self.prox_cycles = toint(prox_cycles) self.cal_cycles = toint(cal_cycles) self.__setProximityTiming__() self.__setAmbientMeasuringMode__() time.sleep(0.001) self.calibrate( ) # may have to be repeated from time to time or before every proximity measurement
def __init__(self, altitude=0, external=None, temperature=True, pressure=True): self.temperature = temperature self.pressure = pressure I2C.__init__(self, 0x77, True) if self.pressure: Pressure.__init__(self, altitude, external) self.ac1 = self.readSignedInteger(0xAA) self.ac2 = self.readSignedInteger(0xAC) self.ac3 = self.readSignedInteger(0xAE) self.ac4 = self.readUnsignedInteger(0xB0) self.ac5 = self.readUnsignedInteger(0xB2) self.ac6 = self.readUnsignedInteger(0xB4) self.b1 = self.readSignedInteger(0xB6) self.b2 = self.readSignedInteger(0xB8) self.mb = self.readSignedInteger(0xBA) self.mc = self.readSignedInteger(0xBC) self.md = self.readSignedInteger(0xBE)
def __init__(self, slave, channel_count, resolution): """Initializes ADS1XXX device. Arguments: slave: The slave address channel_count: Number of channels on the device resolution: Bits of resolution """ I2C.__init__(self, int(slave)) ADC.__init__(self, channel_count, resolution, 4.096) self._analogMax = 2**(resolution - 1) config = self.readRegisters(self.CONFIG, 2) mode = 0 # continuous config[0] &= ~self.CONFIG_MODE_MASK config[0] |= mode gain = 0x1 # FS = +/- 4.096V config[0] &= ~self.CONFIG_GAIN_MASK config[0] |= gain << 1 self.writeRegisters(self.CONFIG, config)
def __init__(self, slave=0x48): I2C.__init__(self, toint(slave))
def __init__(self, slave=0x28): I2C.__init__(self, toint(slave)) self.__startMeasuring__()
def __init__(self, slave=0x60, vref=3.3): I2C.__init__(self, toint(slave)) DAC.__init__(self, 1, 12, float(vref))
def __init__(self, slave=0x48, vref=3.3): I2C.__init__(self, toint(slave)) DAC.__init__(self, 5, 8, float(vref)) self.daValue = 0
def __init__(self, slave, time, name="TSL_LIGHT_X"): I2C.__init__(self, toint(slave)) self.name = name self.wake() # devices are powered down after power reset, wake them self.setTime(toint(time))
def __init__(self, slave, channelCount, name): I2C.__init__(self, toint(slave)) MCP23XXX.__init__(self, channelCount) self.name = name