本文整理汇总了Python中Adafruit_GPIO.I2C类的典型用法代码示例。如果您正苦于以下问题:Python I2C类的具体用法?Python I2C怎么用?Python I2C使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了I2C类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: activate_ready
def activate_ready():
"""
swaps the high and low threshold registers so that the conversion
ready pin will be activated on the ADC
"""
high = I2C.reverseByteOrder(0x8000)
low = I2C.reverseByteOrder(0x7fff)
D.dut.write16(D.highThreshReg, high)
D.dut.write16(D.lowThreshReg,low)
示例2: __init__
def __init__(
self,
width,
height,
rst,
dc=None,
sclk=None,
din=None,
cs=None,
gpio=None,
spi=None,
i2c_bus=None,
i2c_address=SSD1306_I2C_ADDRESS,
i2c=None,
):
self._log = logging.getLogger("Adafruit_SSD1306.SSD1306Base")
self._spi = None
self._i2c = None
self.width = width
self.height = height
self._pages = height / 8
self._buffer = [0] * (width * self._pages)
# Default to platform GPIO if not provided.
self._gpio = gpio
if self._gpio is None:
self._gpio = GPIO.get_platform_gpio()
# Setup reset pin.
self._rst = rst
self._gpio.setup(self._rst, GPIO.OUT)
# Handle hardware SPI
if spi is not None:
self._log.debug("Using hardware SPI")
self._spi = spi
self._spi.set_clock_hz(8000000)
# Handle software SPI
elif sclk is not None and din is not None and cs is not None:
self._log.debug("Using software SPI")
self._spi = SPI.BitBang(self._gpio, sclk, din, None, cs)
# Handle hardware I2C
elif i2c is not None:
self._log.debug("Using hardware I2C with custom I2C provider.")
self._i2c = i2c.get_i2c_device(i2c_address)
else:
self._log.debug("Using hardware I2C with platform I2C provider.")
import Adafruit_GPIO.I2C as I2C
if i2c_bus is None:
self._i2c = I2C.get_i2c_device(i2c_address)
else:
self._i2c = I2C.get_i2c_device(i2c_address, busnum=i2c_bus)
# Initialize DC pin if using SPI.
if self._spi is not None:
if dc is None:
raise ValueError("DC pin must be provided when using SPI.")
self._dc = dc
self._gpio.setup(self._dc, GPIO.OUT)
示例3: get_i2c_device
def get_i2c_device(address, i2c, i2c_bus):
# Helper method to get a device at the specified address from the I2C bus.
# If no i2c bus is specified (i2c param is None) then the default I2C bus
# for the platform will be used.
if i2c is not None:
return i2c.get_i2c_device(address)
else:
import Adafruit_GPIO.I2C as I2C
if i2c_bus is None:
return I2C.get_i2c_device(address)
else:
return I2C.get_i2c_device(address, busnum=i2c_bus)
示例4: dry_sensor
def dry_sensor(self):
"""
Cribbed from the Adafruit Arduino code. Guess it makes sure the
sensor is ready for reading after normalizing in a room.
"""
orig_config = self._device.readU16BE(HDC1000_CONFIG)
# reset, heat up, and select 14 bit temp & humidity
#
new_config = I2C.reverseByteOrder(HDC1000_CONFIG_RST |
HDC1000_CONFIG_HEAT |
HDC1000_CONFIG_MODE |
HDC1000_CONFIG_TRES_14 |
HDC1000_CONFIG_HRES_14)
self._device.write16(HDC1000_CONFIG, new_config)
time.sleep(0.015)
# Take 1000 readings and toss the results.
#
for i in range(1000):
self._read32(HDC1000_TEMP)
time.sleep(0.001)
# Write our original config back out to the device.
#
self._device.write16(HDC1000_CONFIG, orig_config)
time.sleep(0.015)
示例5: __init__
def __init__(self, width, height, rst, dc=None, sclk=None, din=None, cs=None,
gpio=None, spi=None, i2c_bus=I2C.get_default_bus(), i2c_address=SSD1306_I2C_ADDRESS):
self._log = logging.getLogger('Adafruit_SSD1306.SSD1306Base')
self._spi = None
self._i2c = None
self.width = width
self.height = height
self._pages = height/8
self._buffer = [0]*(width*self._pages)
# Default to platform GPIO if not provided.
self._gpio = gpio if gpio is not None else GPIO.get_platform_gpio()
# Setup reset pin.
self._rst = rst
self._gpio.setup(self._rst, GPIO.OUT)
# Handle hardware SPI
if spi is not None:
self._log.debug('Using hardware SPI')
self._spi = spi
# Handle software SPI
elif sclk is not None and din is not None and cs is not None:
self._log.debug('Using software SPI')
self._spi = SPI.BitBang(self._gpio, sclk, din, None, cs)
# Handle hardware I2C
elif i2c_bus is not None:
self._log.debug('Using hardware I2C')
self._i2c = I2C.Device(i2c_address, i2c_bus)
else:
raise ValueError('Unable to determine if using SPI or I2C.')
# Initialize DC pin if using SPI.
if self._spi is not None:
if dc is None:
raise ValueError('DC pin must be provided when using SPI.')
self._dc = dc
self._gpio.setup(self._dc, GPIO.OUT)
示例6: __init__
def __init__(self, options={}):
self.options = core.mergeOptions(DEFAULT_OPTIONS, options)
self.device = I2C.get_i2c_device(self.options["address"])
self.value = {"uv": 0, "ir":0,"visible":0}
self.lastUpdate = time.time()
self._reset()
self._load_calibration()
示例7: _configure_logging
def _configure_logging(self):
logging.basicConfig(level=logging.WARNING,
format='%(asctime)-15s %(levelname)-5s %(message)s')
# TODO put log configuration in a (yaml) config file
# The basic config doesn't hold through tests
radio_logger = logging.getLogger("RPiNWR")
radio_logger.setLevel(logging.DEBUG)
radio_log_handler = logging.FileHandler("radio.log", encoding='utf-8')
radio_log_handler.setFormatter(logging.Formatter(fmt='%(asctime)-15s %(levelname)-5s %(message)s', datefmt=""))
radio_log_handler.setLevel(logging.DEBUG)
radio_logger.addHandler(radio_log_handler)
message_logger = logging.getLogger("RPiNWR.same.message")
message_logger.setLevel(logging.DEBUG)
message_log_handler = logging.FileHandler("messages.log", encoding='utf-8')
message_log_handler.setFormatter(logging.Formatter(datefmt=""))
message_log_handler.setLevel(logging.DEBUG) # DEBUG=test, INFO=watches & emergencies, WARN=warnings
message_logger.addHandler(message_log_handler)
# Since this is logging lots of things, best to not also log every time we check for status
try:
import Adafruit_GPIO.I2C as i2c
i2cLogger = logging.getLogger('Adafruit_I2C.Device.Bus.{0}.Address.{1:#0X}'
.format(i2c.get_default_bus(), 0x11))
except ImportError:
i2cLogger = logging.getLogger(
'Adafruit_I2C.Device.Bus') # a little less specific, but probably just as good
i2cLogger.addFilter(Radio.exclude_routine_status_checks)
示例8: __init__
def __init__(self, address=MCP9808_I2CADDR_DEFAULT, busnum=I2C.get_default_bus()):
"""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')
self._device = I2C.Device(address, busnum)
示例9: write_config
def write_config():
"""
Write the desired options to the ADC configuration register.
Get data from global options
"""
global D
# bit shift everything into its right place in the message. Check datasheet.
# Some options were not broken out for changing. The "magic bits" are
# those options. Combine all the options through bit-wise OR
newConfig = ( 1 << 15 | # OS - trigger conversion
D.mux << 12 | # MUX
D.pga << 9 | # PGA
1 << 8 | # MODE - singal shot
D.dr << 5 | # DR
0 << 4 | # COMP_MODE
0 << 3 | # COMP_POL
0 << 2 | # COMP_LAT
0 << 1 ) # COMP_QUE
# print "mux: ", bin(D.mux)
# print "pga: ", bin(D.pga)
# print "dr: ", bin(D.dr)
# due to something with byte-writing order, we need to flip
# the bytes before writing. I don't know the full details
# print "config: %s"%bin(newConfig)
# print "length: %d"%len(bin(newConfig))
rev = I2C.reverseByteOrder(newConfig)
# print "Reversed byte order: ", bin(rev)
# write it!
D.dut.write16(D.configReg,rev)
示例10: __init__
def __init__(self, address=0x39, debug=0, pause=0.8):
self.i2c = I2C.get_i2c_device(address)
self.address = address
self.pause = pause
self.debug = debug
self.gain = 0 # no gain preselected
self.i2c.write8(0x80, 0x03) # enable the device
示例11: set_config
def set_config(self):
"""Set the 16 bit Big Endian INA219 configuration register (0x00)
"""
reg_00 = self.reg_00
if self.host_endian_is_little:
reg_00 = I2C.reverseByteOrder(reg_00)
self.device.write16(0x00, reg_00)
示例12: __init__
def __init__(self, options={}):
self.options = core.mergeOptions(DEFAULT_OPTIONS, options)
self.device = I2C.get_i2c_device(self.options["address"])
self.valueLock = threading.Lock()
self.value = {"pressure": 0, "temperature": 0}
self.lastUpdate = time.time()
self._setup()
示例13: reset
def reset(self):
"""
reset, and select 14 bit temp & humidity
"""
self._device.write16(HDC1000_CONFIG,
I2C.reverseByteOrder(HDC1000_CONFIG_RST |
HDC1000_CONFIG_MODE |
HDC1000_CONFIG_TRES_14 |
HDC1000_CONFIG_HRES_14))
time.sleep(0.015)
示例14: __init__
def __init__(self, width, height, rst, dc=None, sclk=None, din=None, cs=None, gpio=None,
spi=None, i2c_bus=None, i2c_address=SSD1306_I2C_ADDRESS,
i2c=None):
self._spi = None
self._i2c = None
self.width = width
self.height = height
self._pages = height // 8
self._buffer = [0] * width * self._pages
self._cursor = 0
# Default to platform GPIO if not provided.
self._gpio = gpio
if self._gpio is None:
self._gpio = GPIO.get_platform_gpio()
# Setup reset pin.
self._rst = rst
self._gpio.setup(self._rst, GPIO.OUT)
# Handle hardware SPI
if spi is not None:
self._spi = spi
self._spi.set_clock_hz(8000000)
# Handle software SPI
elif sclk is not None and din is not None and cs is not None:
self._spi = SPI.BitBang(self._gpio, sclk, din, None, cs)
# Handle hardware I2C
elif i2c is not None:
self._i2c = i2c.get_i2c_device(i2c_address)
else:
import Adafruit_GPIO.I2C as I2C
self._i2c = I2C.get_i2c_device(i2c_address) if i2c_bus is None else I2C.get_i2c_device(i2c_address,
busnum=i2c_bus)
# Initialize DC pin if using SPI.
if self._spi is not None:
if dc is None:
raise ValueError('DC pin must be provided when using SPI.')
self._dc = dc
self._gpio.setup(self._dc, GPIO.OUT)
示例15: __init__
def __init__(self, mode=BMP280_STANDARD, address=BMP280_I2CADDR,
busnum=I2C.get_default_bus()):
self._logger = logging.getLogger('Adafruit_BMP.BMP280')
# Check that mode is valid.
if mode not in [BMP280_ULTRALOWPOWER, BMP280_STANDARD, BMP280_HIGHRES, BMP280_ULTRAHIGHRES]:
raise ValueError('Unexpected mode value {0}. Set mode to one of BMP280_ULTRALOWPOWER, BMP280_STANDARD, BMP280_HIGHRES, or BMP280_ULTRAHIGHRES'.format(mode))
self._mode = mode
# Create I2C device.
self._device = I2C.Device(address, busnum)
# Load calibration values.
self._load_calibration()