本文整理汇总了Python中Adafruit_GPIO.I2C属性的典型用法代码示例。如果您正苦于以下问题:Python Adafruit_GPIO.I2C属性的具体用法?Python Adafruit_GPIO.I2C怎么用?Python Adafruit_GPIO.I2C使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类Adafruit_GPIO
的用法示例。
在下文中一共展示了Adafruit_GPIO.I2C属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import Adafruit_GPIO [as 别名]
# 或者: from Adafruit_GPIO import I2C [as 别名]
def __init__(self, address=0x20, busnum=None, i2c=None, num_gpios=16, **kwargs):
address = int(address)
self.__name__ = "PCA955"
# Create I2C device.
i2c = i2c or I2C
busnum = busnum or i2c.get_default_bus()
self._device = i2c.get_i2c_device(address, busnum, **kwargs)
self.num_gpios = num_gpios
if self.num_gpios <= 8:
self.iodir = self._device.readU8(CONFIG_PORT)
self.outputvalue = self._device.readU8(OUTPUT_PORT)
elif self.num_gpios > 8 and self.num_gpios <= 16:
self.iodir = self._device.readU16(CONFIG_PORT<< 1)
self.outputvalue = self._device.readU16(OUTPUT_PORT << 1)
示例2: __init__
# 需要导入模块: import Adafruit_GPIO [as 别名]
# 或者: from Adafruit_GPIO import I2C [as 别名]
def __init__(self, address=0x27, busnum=None, i2c=None, **kwargs):
address = int(address)
self.__name__ = \
"PCF8574" if address in range(0x20, 0x28) else \
"PCF8574A" if address in range(0x38, 0x40) else \
"Bad address for PCF8574(A): 0x%02X not in range [0x20..0x27, 0x38..0x3F]" % address
if self.__name__[0] != 'P':
raise ValueError(self.__name__)
# Create I2C device.
i2c = i2c or I2C
busnum = busnum or i2c.get_default_bus()
self._device = i2c.get_i2c_device(address, busnum, **kwargs)
# Buffer register values so they can be changed without reading.
self.iodir = 0xFF # Default direction to all inputs is in
self.gpio = 0x00
self._write_pins()
示例3: __init__
# 需要导入模块: import Adafruit_GPIO [as 别名]
# 或者: from Adafruit_GPIO import I2C [as 别名]
def __init__(self, address, i2c=None, **kwargs):
"""Initialize MCP230xx at specified I2C address and bus number. If bus
is not specified it will default to the appropriate platform detected bus.
"""
# Create I2C device.
if i2c is None:
import Adafruit_GPIO.I2C as I2C
i2c = I2C
self._device = i2c.get_i2c_device(address, **kwargs)
# Assume starting in ICON.BANK = 0 mode (sequential access).
# Compute how many bytes are needed to store count of GPIO.
self.gpio_bytes = int(math.ceil(self.NUM_GPIO/8.0))
# Buffer register values so they can be changed without reading.
self.iodir = [0xFF]*self.gpio_bytes # Default direction to all inputs.
self.gppu = [0x00]*self.gpio_bytes # Default to pullups disabled.
self.gpio = [0x00]*self.gpio_bytes
# Write current direction and pullup buffer state.
self.write_iodir()
self.write_gppu()
示例4: __init__
# 需要导入模块: import Adafruit_GPIO [as 别名]
# 或者: from Adafruit_GPIO import I2C [as 别名]
def __init__(self, hires=True, accel_address=LSM303_ADDRESS_ACCEL,
mag_address=LSM303_ADDRESS_MAG, i2c=None, **kwargs):
"""Initialize the LSM303 accelerometer & magnetometer. The hires
boolean indicates if high resolution (12-bit) mode vs. low resolution
(10-bit, faster and lower power) mode should be used.
"""
# Setup I2C interface for accelerometer and magnetometer.
if i2c is None:
import Adafruit_GPIO.I2C as I2C
i2c = I2C
self._accel = i2c.get_i2c_device(accel_address, **kwargs)
self._mag = i2c.get_i2c_device(mag_address, **kwargs)
# Enable the accelerometer
self._accel.write8(LSM303_REGISTER_ACCEL_CTRL_REG1_A, 0x27)
# Select hi-res (12-bit) or low-res (10-bit) output mode.
# Low-res mode uses less power and sustains a higher update rate,
# output is padded to compatible 12-bit units.
if hires:
self._accel.write8(LSM303_REGISTER_ACCEL_CTRL_REG4_A, 0b00001000)
else:
self._accel.write8(LSM303_REGISTER_ACCEL_CTRL_REG4_A, 0)
# Enable the magnetometer
self._mag.write8(LSM303_REGISTER_MAG_MR_REG_M, 0x00)
示例5: __init__
# 需要导入模块: import Adafruit_GPIO [as 别名]
# 或者: from Adafruit_GPIO import I2C [as 别名]
def __init__(self, integration_time=TCS34725_INTEGRATIONTIME_2_4MS,
gain=TCS34725_GAIN_4X, address=TCS34725_ADDRESS, i2c=None, **kwargs):
"""Initialize the TCS34725 sensor."""
# Setup I2C interface for the device.
if i2c is None:
import Adafruit_GPIO.I2C as I2C
i2c = I2C
self._device = i2c.get_i2c_device(address, **kwargs)
# Make sure we're connected to the sensor.
chip_id = self._readU8(TCS34725_ID)
if chip_id != 0x44:
raise RuntimeError('Failed to read TCS34725 chip ID, check your wiring.')
# Set default integration time and gain.
self.set_integration_time(integration_time)
self.set_gain(gain)
# Enable the device (by default, the device is in power down mode on bootup).
self.enable()
示例6: __init__
# 需要导入模块: import Adafruit_GPIO [as 别名]
# 或者: from Adafruit_GPIO import I2C [as 别名]
def __init__(self, address=DEFAULT_ADDRESS, i2c=None, **kwargs):
"""Create an HT16K33 driver for devie on the specified I2C address
(defaults to 0x70) and I2C bus (defaults to platform specific bus).
"""
if i2c is None:
import Adafruit_GPIO.I2C as I2C
i2c = I2C
self._device = i2c.get_i2c_device(address, **kwargs)
self.buffer = bytearray([0]*16)
示例7: __init__
# 需要导入模块: import Adafruit_GPIO [as 别名]
# 或者: from Adafruit_GPIO import I2C [as 别名]
def __init__(self, mode=BMP085_STANDARD, address=BMP085_I2CADDR, i2c=None, **kwargs):
self._logger = logging.getLogger('Adafruit_BMP.BMP085')
# Check that mode is valid.
if mode not in [BMP085_ULTRALOWPOWER, BMP085_STANDARD, BMP085_HIGHRES, BMP085_ULTRAHIGHRES]:
raise ValueError('Unexpected mode value {0}. Set mode to one of BMP085_ULTRALOWPOWER, BMP085_STANDARD, BMP085_HIGHRES, or BMP085_ULTRAHIGHRES'.format(mode))
self._mode = mode
# Create I2C device.
if i2c is None:
import Adafruit_GPIO.I2C as I2C
i2c = I2C
self._device = i2c.get_i2c_device(address, **kwargs)
# Load calibration values.
self._load_calibration()
示例8: software_reset
# 需要导入模块: import Adafruit_GPIO [as 别名]
# 或者: from Adafruit_GPIO import I2C [as 别名]
def software_reset(i2c=None, **kwargs):
"""Sends a software reset (SWRST) command to all servo drivers on the bus."""
# Setup I2C interface for device 0x00 to talk to all of them.
if i2c is None:
import Adafruit_GPIO.I2C as I2C
i2c = I2C
self._device = i2c.get_i2c_device(0x00, **kwargs)
self._device.writeRaw8(0x06) # SWRST
示例9: __init__
# 需要导入模块: import Adafruit_GPIO [as 别名]
# 或者: from Adafruit_GPIO import I2C [as 别名]
def __init__(self, address=PCA9685_ADDRESS, i2c=None, **kwargs):
"""Initialize the PCA9685."""
# Setup I2C interface for the device.
if i2c is None:
import Adafruit_GPIO.I2C as I2C
i2c = I2C
self._device = i2c.get_i2c_device(address, **kwargs)
self.set_all_pwm(0, 0)
self._device.write8(MODE2, OUTDRV)
self._device.write8(MODE1, ALLCALL)
time.sleep(0.005) # wait for oscillator
mode1 = self._device.readU8(MODE1)
mode1 = mode1 & ~SLEEP # wake up (reset sleep)
self._device.write8(MODE1, mode1)
time.sleep(0.005) # wait for oscillator
示例10: __init__
# 需要导入模块: import Adafruit_GPIO [as 别名]
# 或者: from Adafruit_GPIO import I2C [as 别名]
def __init__(self, address=MCP9808_I2CADDR_DEFAULT, i2c=None, **kwargs):
"""Initialize MCP9808 device on the specified I2C address and bus number.
Address defaults to 0x18 and bus number defaults to the appropriate bus
for the hardware.
"""
self._logger = logging.getLogger('Adafruit_MCP9808.MCP9808')
if i2c is None:
import Adafruit_GPIO.I2C as I2C
i2c = I2C
self._device = i2c.get_i2c_device(address, **kwargs)
示例11: __init__
# 需要导入模块: import Adafruit_GPIO [as 别名]
# 或者: from Adafruit_GPIO import I2C [as 别名]
def __init__(self, mode=BMP085_STANDARD, address=BMP085_I2CADDR, i2c=None, **kwargs):
self._logger = logging.getLogger('Adafruit_BMP.BMP085')
# Check that mode is valid.
if mode not in [BMP085_ULTRALOWPOWER, BMP085_STANDARD, BMP085_HIGHRES, BMP085_ULTRAHIGHRES]:
raise ValueError('Unexpected mode value {0}. Set mode to one of BMP085_ULTRALOWPOWER, BMP085_STANDARD, BMP085_HIGHRES, or BMP085_ULTRAHIGHRES'.format(mode))
self._mode = mode
# Create I2C device.
if i2c is None:
import Adafruit_GPIO.I2C as I2C
i2c = I2C
self._device = i2c.get_i2c_device(address, **kwargs)
# Load calibration values.
self._load_calibration()
示例12: __init__
# 需要导入模块: import Adafruit_GPIO [as 别名]
# 或者: from Adafruit_GPIO import I2C [as 别名]
def __init__(self, address=ADXL345_ADDRESS, i2c=None, **kwargs):
"""Initialize the ADXL345 accelerometer using its I2C interface.
"""
# Setup I2C interface for the device.
if i2c is None:
import Adafruit_GPIO.I2C as I2C
i2c = I2C
self._device = i2c.get_i2c_device(address, **kwargs)
# Check that the acclerometer is connected, then enable it.
if self._device.readU8(ADXL345_REG_DEVID) == 0xE5:
self._device.write8(ADXL345_REG_POWER_CTL, 0x08)
else:
raise RuntimeError('Failed to find the expected device ID register value, check your wiring.')
示例13: __init__
# 需要导入模块: import Adafruit_GPIO [as 别名]
# 或者: from Adafruit_GPIO import I2C [as 别名]
def __init__(self, address=DEFAULT_ADDRESS, i2c=None, **kwargs):
"""Create an HT16K33 driver for device on the specified I2C address
(defaults to 0x70) and I2C bus (defaults to platform specific bus).
"""
if i2c is None:
import Adafruit_GPIO.I2C as I2C
i2c = I2C
self._device = i2c.get_i2c_device(address, **kwargs)
self.buffer = bytearray([0]*16)
示例14: __init__
# 需要导入模块: import Adafruit_GPIO [as 别名]
# 或者: from Adafruit_GPIO import I2C [as 别名]
def __init__(self, mode=CCS811_DRIVE_MODE_1SEC, address=CCS811_ADDRESS, i2c=None, **kwargs):
self._logger = logging.getLogger('Adafruit_CCS811.CCS811')
# Check that mode is valid.
if mode not in [CCS811_DRIVE_MODE_IDLE, CCS811_DRIVE_MODE_1SEC, CCS811_DRIVE_MODE_10SEC, CCS811_DRIVE_MODE_60SEC, CCS811_DRIVE_MODE_250MS]:
raise ValueError('Unexpected mode value {0}. Set mode to one of CCS811_DRIVE_MODE_IDLE, CCS811_DRIVE_MODE_1SEC, CCS811_DRIVE_MODE_10SEC, CCS811_DRIVE_MODE_60SEC or CCS811_DRIVE_MODE_250MS'.format(mode))
# Create I2C device.
if i2c is None:
import Adafruit_GPIO.I2C as I2C
i2c = I2C
self._device = i2c.get_i2c_device(address, **kwargs)
#set up the registers
self._status = Adafruit_bitfield([('ERROR' , 1), ('unused', 2), ('DATA_READY' , 1), ('APP_VALID', 1), ('unused2' , 2), ('FW_MODE' , 1)])
self._meas_mode = Adafruit_bitfield([('unused', 2), ('INT_THRESH', 1), ('INT_DATARDY', 1), ('DRIVE_MODE', 3)])
self._error_id = Adafruit_bitfield([('WRITE_REG_INVALID', 1), ('READ_REG_INVALID', 1), ('MEASMODE_INVALID', 1), ('MAX_RESISTANCE', 1), ('HEATER_FAULT', 1), ('HEATER_SUPPLY', 1)])
self._TVOC = 0
self._eCO2 = 0
self.tempOffset = 0
#check that the HW id is correct
if(self._device.readU8(CCS811_HW_ID) != CCS811_HW_ID_CODE):
raise Exception("Device ID returned is not correct! Please check your wiring.")
#try to start the app
self._device.writeList(CCS811_BOOTLOADER_APP_START, [])
sleep(.1)
#make sure there are no errors and we have entered application mode
if(self.checkError()):
raise Exception("Device returned an Error! Try removing and reapplying power to the device and running the code again.")
if(not self._status.FW_MODE):
raise Exception("Device did not enter application mode! If you got here, there may be a problem with the firmware on your sensor.")
self.disableInterrupt()
#default to read every second
self.setDriveMode(CCS811_DRIVE_MODE_1SEC)
示例15: __init__
# 需要导入模块: import Adafruit_GPIO [as 别名]
# 或者: from Adafruit_GPIO import I2C [as 别名]
def __init__(self, t_mode=BME280_OSAMPLE_1, p_mode=BME280_OSAMPLE_1, h_mode=BME280_OSAMPLE_1,
standby=BME280_STANDBY_250, filter=BME280_FILTER_off, address=BME280_I2CADDR, i2c=None,
**kwargs):
self._logger = logging.getLogger('Adafruit_BMP.BMP085')
# Check that t_mode is valid.
if t_mode not in [BME280_OSAMPLE_1, BME280_OSAMPLE_2, BME280_OSAMPLE_4,
BME280_OSAMPLE_8, BME280_OSAMPLE_16]:
raise ValueError(
'Unexpected t_mode value {0}.'.format(t_mode))
self._t_mode = t_mode
# Check that p_mode is valid.
if p_mode not in [BME280_OSAMPLE_1, BME280_OSAMPLE_2, BME280_OSAMPLE_4,
BME280_OSAMPLE_8, BME280_OSAMPLE_16]:
raise ValueError(
'Unexpected p_mode value {0}.'.format(p_mode))
self._p_mode = p_mode
# Check that h_mode is valid.
if h_mode not in [BME280_OSAMPLE_1, BME280_OSAMPLE_2, BME280_OSAMPLE_4,
BME280_OSAMPLE_8, BME280_OSAMPLE_16]:
raise ValueError(
'Unexpected h_mode value {0}.'.format(h_mode))
self._h_mode = h_mode
# Check that standby is valid.
if standby not in [BME280_STANDBY_0p5, BME280_STANDBY_62p5, BME280_STANDBY_125, BME280_STANDBY_250,
BME280_STANDBY_500, BME280_STANDBY_1000, BME280_STANDBY_10, BME280_STANDBY_20]:
raise ValueError(
'Unexpected standby value {0}.'.format(standby))
self._standby = standby
# Check that filter is valid.
if filter not in [BME280_FILTER_off, BME280_FILTER_2, BME280_FILTER_4, BME280_FILTER_8, BME280_FILTER_16]:
raise ValueError(
'Unexpected filter value {0}.'.format(filter))
self._filter = filter
# Create I2C device.
if i2c is None:
import Adafruit_GPIO.I2C as I2C
i2c = I2C
# Create device, catch permission errors
try:
self._device = i2c.get_i2c_device(address, **kwargs)
except IOError:
print("Unable to communicate with sensor, check permissions.")
exit()
# Load calibration values.
self._load_calibration()
self._device.write8(BME280_REGISTER_CONTROL, 0x24) # Sleep mode
time.sleep(0.002)
self._device.write8(BME280_REGISTER_CONFIG, ((standby << 5) | (filter << 2)))
time.sleep(0.002)
self._device.write8(BME280_REGISTER_CONTROL_HUM, h_mode) # Set Humidity Oversample
self._device.write8(BME280_REGISTER_CONTROL, ((t_mode << 5) | (p_mode << 2) | 3)) # Set Temp/Pressure Oversample and enter Normal mode
self.t_fine = 0.0