当前位置: 首页>>代码示例>>Python>>正文


Python I2C.get_i2c_device方法代码示例

本文整理汇总了Python中Adafruit_GPIO.I2C.get_i2c_device方法的典型用法代码示例。如果您正苦于以下问题:Python I2C.get_i2c_device方法的具体用法?Python I2C.get_i2c_device怎么用?Python I2C.get_i2c_device使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Adafruit_GPIO.I2C的用法示例。


在下文中一共展示了I2C.get_i2c_device方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_i2c_device [as 别名]
    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)
开发者ID:patthoyts,项目名称:Adafruit_Python_SSD1306,代码行数:58,代码来源:SSD1306.py

示例2: get_i2c_device

# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_i2c_device [as 别名]
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)
开发者ID:Henning-Klatt,项目名称:Robot,代码行数:14,代码来源:pwm.py

示例3: __init__

# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_i2c_device [as 别名]
 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()
开发者ID:zpiman,项目名称:Diaslab,代码行数:9,代码来源:si1145.py

示例4: __init__

# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_i2c_device [as 别名]
 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
开发者ID:mwbritton,项目名称:Raspberry-Pi-4x4-in-Schools-Project,代码行数:10,代码来源:TSL2561.py

示例5: __init__

# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_i2c_device [as 别名]
    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()
开发者ID:zpiman,项目名称:Diaslab,代码行数:11,代码来源:bmp180.py

示例6: __init__

# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_i2c_device [as 别名]
    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)
开发者ID:manyunkai,项目名称:python-bpi-oled,代码行数:44,代码来源:ssd1306.py

示例7: __init__

# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_i2c_device [as 别名]
    def __init__(self, busnum=None):
        # Each feature is given a call name. Although The magnetometer and
        # accelerometer use the same address, they've been given different
        # names for clarity.
        self.mag    = I2C.get_i2c_device(self.LSM9DS0_MAG_ADDRESS, busnum)
        self.accel  = I2C.get_i2c_device(self.LSM9DS0_ACCEL_ADDRESS, busnum)
        self.gyro   = I2C.get_i2c_device(self.LSM9DS0_GYRO_ADDRESS, busnum)

        # Magnetometer initialisation
        self.mag.write8(self.LSM9DS0_CTRL_REG5_XM, 0b11110000) # Temperature sensor enabled, high res mag, 50Hz
        self.mag.write8(self.LSM9DS0_CTRL_REG6_XM, 0b01100000) # +/- 12 gauss
        self.mag.write8(self.LSM9DS0_CTRL_REG7_XM, 0b00000000) # Normal mode, continuous-conversion mode

        # Accelerometer initialisation
        self.accel.write8(self.LSM9DS0_CTRL_REG1_XM, 0b01100111) # 100Hz, XYZ enabled
        self.accel.write8(self.LSM9DS0_CTRL_REG2_XM, 0b00100000) # +/- 16 g

        # Gyro initialisation
        self.gyro.write8(self.LSM9DS0_CTRL_REG1_G, 0b00001111) # Normal power mode, XYZ enabled
        self.gyro.write8(self.LSM9DS0_CTRL_REG4_G, 0b00110000) # Continuous update, 2000 dps
开发者ID:jackweath,项目名称:Adafruit_LSM9DS0,代码行数:22,代码来源:LSM9DS0.py

示例8: __init__

# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_i2c_device [as 别名]
   def __init__(self, gyro_dr=(LSM9DS0_GYRODR_95HZ | LSM9DS0_GYRO_CUTOFF_1), gyro_scale=LSM9DS0_GYROSCALE_245DPS, gyro_addr=LSM9DS0_GYRO_ADDR):
      """looks for the lsm9dso on i2c bus, and performs register configuration on it"""
      self._sensor = i2c.get_i2c_device(gyro_addr)
      
      #verify initialization by checking the who_am_i register
      if not (self._sensor.readU8(LSM9DS0_REG_WHO_AM_I_G) == LSM9DS0_GYRO_ID):
         #not the right device!
         print "Could not initialize the gyro!"
         #sys.exit()

      self.start_capture()
      self._config_gyro(gyro_scale, gyro_dr)
开发者ID:brahmstadtn,项目名称:osu_rocketry,代码行数:14,代码来源:LSM9DS0.py

示例9: __init__

# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_i2c_device [as 别名]
 def __init__(self, address=0x6b, debug=0, pause=0.8):
     self.i2c = I2C.get_i2c_device(address)
     self.address = address
     dataToWrite = 0 #Start Fresh!
     dataToWrite |= 0x03 # set at 50hz, bandwidth
     dataToWrite |= 0x00  # 2g accel range
     dataToWrite |= 0x10 # 13hz ODR
     self.i2c.write8(0X10, dataToWrite) #writeRegister(LSM6DS3_ACC_GYRO_CTRL2_G, dataToWrite);
     
     accel_center_x = self.i2c.readS16(0X28)
     accel_center_y = self.i2c.readS16(0x2A)
     accel_center_z = self.i2c.readS16(0x2C)
开发者ID:mwbritton,项目名称:Raspberry-Pi-4x4-in-Schools-Project,代码行数:14,代码来源:LSM6DS3.py

示例10: __init__

# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_i2c_device [as 别名]
 def __init__(self, address=0x53, debug=0, pause=0.8):
     self.i2c = I2C.get_i2c_device(address)
     self.address = address
     self.i2c.write8(0x2D, 0x08) #ADXL345_REG_POWER_CTL 0x2D
     
     dataToWrite = 0 #Start Fresh!
     dataToWrite |= 0b00
     self.i2c.write8(0X31, dataToWrite) #ADXL345_REG_DATA_FORMAT 0x31 2g
     
     dataToWrite = 0 #Start Fresh!
     dataToWrite |= 0b0101
     self.i2c.write8(0x2C, dataToWrite) #ADXL345_REG_DATA_FORMAT 0x31 2g
     
     accel_center_x = self.i2c.readS16(0X32)
     accel_center_y = self.i2c.readS16(0X34)
     accel_center_z = self.i2c.readS16(0X36)
开发者ID:mwbritton,项目名称:Raspberry-Pi-4x4-in-Schools-Project,代码行数:18,代码来源:ADXL345.py

示例11: __init__

# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_i2c_device [as 别名]
    def __init__(self, address=None, busnum=None,
                 integration_time=TSL2561_DELAY_INTTIME_402MS,
                 gain=TSL2561_GAIN_1X, autogain=False, debug=False):
        if address is not None:
            self.address = address
        else:
            self.address = TSL2561_ADDR_FLOAT

        self.i2c = I2C.get_i2c_device(self.address, busnum=busnum)

        self.debug = debug
        self.integration_time = integration_time
        self.gain = gain
        self.autogain = autogain

        self._begin()
开发者ID:mB-PiBox,项目名称:tsl2561,代码行数:18,代码来源:tsl2561.py

示例12: __init__

# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_i2c_device [as 别名]
    def __init__(self, ahrs, update_rate_hz, busnum=None, i2c_interface=None, **kwargs):
        self.i2c = I2C.get_i2c_device(0x32, busnum, i2c_interface, **kwargs)

        self.update_rate_hz = update_rate_hz
        self.running = True

        self.ahrs = ahrs
        self.raw_data_update = GyroUpdate()
        self.ahrs_update = AHRSUpdate()
        self.ahrspos_update = AHRSPosUpdate()
        self.board_id = BoardID()
        self.board_state = BoardState()

        self.last_sensor_timestamp = 0

        self.last_update_time = 0.0
        self.byte_count = 0
        self.update_count = 0
开发者ID:utk-robotics-2017,项目名称:navX-Python,代码行数:20,代码来源:i2c_io.py

示例13: init

# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_i2c_device [as 别名]
def init():
    '''
    Clear the screen
    '''
    global i2c_bus
    global image
    global draw
    global font
    global fix_font
    if i2c_bus == None:
        i2c_bus = I2C.get_i2c_device(0x3C)
        command(SSD1306_DISPLAYOFF)                    # 0xAE
        command(SSD1306_SETDISPLAYCLOCKDIV)            # 0xD5
        command(0x80)                                  # the suggested ratio 0x80
        command(SSD1306_SETMULTIPLEX)                  # 0xA8
        command(0x3F)
        command(SSD1306_SETDISPLAYOFFSET)              # 0xD3
        command(0x0)                                   # no offset
        command(SSD1306_SETSTARTLINE | 0x0)            # line #0
        command(SSD1306_CHARGEPUMP)                    # 0x8D
        command(0x14)
        command(SSD1306_MEMORYMODE)                    # 0x20
        command(0x00)                                  # 0x0 act like ks0108
        command(SSD1306_SEGREMAP | 0x1)
        command(SSD1306_COMSCANDEC)
        command(SSD1306_SETCOMPINS)                    # 0xDA
        command(0x12)
        command(SSD1306_SETCONTRAST)                   # 0x81
        command(0xCF)
        command(SSD1306_SETPRECHARGE)                  # 0xd9
        command(0xF1)
        command(SSD1306_SETVCOMDETECT)                 # 0xDB
        command(0x40)
        command(SSD1306_DISPLAYALLON_RESUME)           # 0xA4
        command(SSD1306_NORMALDISPLAY)                 # 0xA6
        command(SSD1306_DISPLAYON)
        image = Image.new('1', (WIDTH, HEIGHT))
        draw = ImageDraw.Draw(image)       
        if fix_font:
            font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSansMono.ttf", 10)
        else:
            font = ImageFont.truetype("/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf", 9)
    draw.rectangle((0, 0, WIDTH, HEIGHT), outline=0, fill=0)
开发者ID:steelsquid,项目名称:steelsquid-kiss-os,代码行数:45,代码来源:steelsquid_oled_ssd1306.py

示例14: read

# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_i2c_device [as 别名]
import time

import Adafruit_GPIO.I2C as i2c
import pynmea2

dev = i2c.get_i2c_device(busnum=2, address=0x42)

def read():
    hi = dev.readU8(0x7d)
    lo = dev.readU8(0x7e)
    nbytes = (hi << 8) | lo
    print('reading %d bytes' % nbytes)
    return ''.join(chr(dev.readU8(0xff)) for i in range(nbytes))

def read2():
    hi = dev.readU8(0x7d)
    lo = dev.readU8(0x7e)
    nbytes = (hi << 8) | lo
    line = []
    while 1:
        b = dev.readU8(0xff)
        if b == 0xff: break
        c = chr(b)
        if c == '\n': break
        line.append(c)
    return (nbytes, ''.join(line))

while 1:
    nb, line = read2()
    try:
        msg = pynmea2.parse(line)
开发者ID:Knio,项目名称:gps_tracker,代码行数:33,代码来源:gps.py

示例15: command

# 需要导入模块: from Adafruit_GPIO import I2C [as 别名]
# 或者: from Adafruit_GPIO.I2C import get_i2c_device [as 别名]
off = 0xAE
invert = 0xA7
no_invert = 0xA6
vertical_flip = 0xC8
no_vertical_flip = 0xC0
all_on = 0xA5
no_all_on = 0xA4
set_brightness = 0x81
set_column = 0x21
set_page = 0x22
set_high_column = 0x00
set_low_column = 0x10
set_start_line = 0x40
set_vertical_offset = 0xD3 # the number of pixels to wrap picture down

port = I2C.get_i2c_device(address)

buffer = Image.new('1', (128, 64))
temp_buffer = Image.new('1', (128, 64))
console_buffer = Image.new('1', (128, 64))
draw = ImageDraw.Draw(buffer)
console_draw = ImageDraw.Draw(console_buffer)
font8 = ImageFont.truetype("Minecraftia.ttf", 8)
font16 = ImageFont.truetype("Minecraftia.ttf", 16)
font24 = ImageFont.truetype("Minecraftia.ttf", 24)
font = font8 # font to actually display with. can be changed to font8/16/24
font_size = 8
old_cursor_line = 0

def command(hex):
	'''Sends hexadecimal value to OLED as a command eg. Oled.on.'''
开发者ID:welshgeekboy,项目名称:Lobsang_Pi_Wars,代码行数:33,代码来源:Oled.py


注:本文中的Adafruit_GPIO.I2C.get_i2c_device方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。