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


Python machine.I2C属性代码示例

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


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

示例1: __init__

# 需要导入模块: import machine [as 别名]
# 或者: from machine import I2C [as 别名]
def __init__(self,
                 pin_id_led = ON_BOARD_LED_PIN_NO,
                 on_board_led_high_is_on = ON_BOARD_LED_HIGH_IS_ON,
                 pin_id_reset = PIN_ID_FOR_LORA_RESET,
                 blink_on_start = (2, 0.5, 0.5),
                 oled_width = OLED_WIDTH, oled_height = OLED_HEIGHT,
                 scl_pin_id = PIN_ID_SCL, sda_pin_id = PIN_ID_SDA,
                 freq = OLED_I2C_FREQ):

        controller_esp.Controller.__init__(self,
                                           pin_id_led,
                                           on_board_led_high_is_on,
                                           pin_id_reset,
                                           blink_on_start)

        self.reset_pin(self.prepare_pin(self.PIN_ID_FOR_OLED_RESET))

        i2c = machine.I2C(scl = machine.Pin(scl_pin_id, machine.Pin.OUT),
                          sda = machine.Pin(sda_pin_id),
                          freq = freq)
        display_ssd1306_i2c.Display.__init__(self, i2c,
                                             width = oled_width, height = oled_height)
        self.show_text('Hello !') 
开发者ID:Wei1234c,项目名称:SX127x_driver_for_MicroPython_on_ESP8266,代码行数:25,代码来源:controller_esp_ttgo_lora_oled.py

示例2: __init__

# 需要导入模块: import machine [as 别名]
# 或者: from machine import I2C [as 别名]
def __init__(
        self, i2c, address=0x68,
        accel_fs=ACCEL_FS_SEL_2G, gyro_fs=GYRO_FS_SEL_250DPS,
        accel_sf=SF_M_S2, gyro_sf=SF_RAD_S,
        gyro_offset=(0, 0, 0)
    ):
        self.i2c = i2c
        self.address = address

        # 0x70 = standalone MPU6500, 0x71 = MPU6250 SIP
        if self.whoami not in [0x71, 0x70]:
            raise RuntimeError("MPU6500 not found in I2C bus.")

        self._accel_so = self._accel_fs(accel_fs)
        self._gyro_so = self._gyro_fs(gyro_fs)
        self._accel_sf = accel_sf
        self._gyro_sf = gyro_sf
        self._gyro_offset = gyro_offset 
开发者ID:tuupola,项目名称:micropython-mpu9250,代码行数:20,代码来源:mpu6500.py

示例3: get

# 需要导入模块: import machine [as 别名]
# 或者: from machine import I2C [as 别名]
def get(port):
    global bus_0, bus_1, bus_other
    if port == PORTA or port == M_BUS:
        if bus_0 == None:
            bus_0 = I2C(id=0, sda=port[0], scl=port[1])
        return bus_0
    elif port == PORTC:
        if bus_1 == None:
            bus_1 = I2C(id=1, sda=port[0], scl=port[1])
        return bus_1
    else:
        if bus_1 == None:
            if bus_other == None:
                bus_other = I2C(id=1, sda=port[0], scl=port[1])
                return bus_other
            else:
                return bus_other
        else:
            raise OSError('I2C bus not support 3') 
开发者ID:m5stack,项目名称:UIFlow-Code,代码行数:21,代码来源:i2c_bus.py

示例4: i2c_read

# 需要导入模块: import machine [as 别名]
# 或者: from machine import I2C [as 别名]
def i2c_read(self, payload):
        """
        Establish an i2c object if not already establed and
        read from the device.
        :param payload:
        :return:
        """
        if not self.i2c:
            self.i2c = I2C(scl=Pin(5), sda=Pin(4), freq=100000)
        try:
            data = self.i2c.readfrom_mem(payload['addr'], payload['register'], payload['number_of_bytes'])
        except TypeError:
            print('read')
            raise
        try:
            data = list(data)
        except TypeError:
            print(payload, data)
            raise
        payload = {'report': 'i2c_data', 'value': data}
        self.send_payload_to_gateway(payload) 
开发者ID:MrYsLab,项目名称:python_banyan,代码行数:23,代码来源:esp_8266Full.py

示例5: i2c_read

# 需要导入模块: import machine [as 别名]
# 或者: from machine import I2C [as 别名]
def i2c_read(self, address: int, size: int, **kwargs) -> str:
        """
        Read data from the I2C bus.

        :param address: I2C address.
        :param size: Number of bytes to read.
        :param kwargs: Parameters to pass to :meth:`platypush.plugins.esp.EspPlugin.i2c_open` and
            :meth:`platypush.plugins.esp.EspPlugin.execute`.
        :return: String representation of the read bytes, or base64-encoded representation if the
            data can't be decoded to a string.
        """
        self.i2c_open(**kwargs)
        code = 'i2c.readfrom({address}, {size})'.format(address=address, size=size)
        response = self.execute(code, **kwargs).output

        try:
            return response.decode()
        except UnicodeDecodeError:
            return base64.encodebytes(response).decode() 
开发者ID:BlackLight,项目名称:platypush,代码行数:21,代码来源:__init__.py

示例6: i2c_write

# 需要导入模块: import machine [as 别名]
# 或者: from machine import I2C [as 别名]
def i2c_write(self, address: int, data: str, binary: bool = False, **kwargs):
        """
        Write data to the I2C bus.

        :param address: I2C address.
        :param data: Data to be sent.
        :param binary: By default data will be treated as a string. Set binary to True if it should
            instead be treated as a base64-encoded binary string to be decoded before being sent.
        :param kwargs: Parameters to pass to :meth:`platypush.plugins.esp.EspPlugin.i2c_open` and
            :meth:`platypush.plugins.esp.EspPlugin.execute`.
        :return: String representation of the read bytes, or base64-encoded representation if the
            data can't be decoded to a string.
        """
        if binary:
            data = base64.decodebytes(data.encode())
        else:
            data = data.encode()

        data = 'b"' + ''.join(['\\x{:02x}'.format(b) for b in data]) + '"'
        self.i2c_open(**kwargs)
        code = 'i2c.writeto({address}, {data})'.format(address=address, data=data)
        self.execute(code, **kwargs) 
开发者ID:BlackLight,项目名称:platypush,代码行数:24,代码来源:__init__.py

示例7: send_cmd

# 需要导入模块: import machine [as 别名]
# 或者: from machine import I2C [as 别名]
def send_cmd(self, cmd_request, response_size=6, read_delay_ms=100):
        """
        Send a command to the sensor and read (optionally) the response
        The responsed data is validated by CRC
        """
        try:
            self.i2c.start(); 
            self.i2c.writeto(self.i2c_addr, cmd_request); 
            if not response_size:
                self.i2c.stop(); 	
                return
            time.sleep_ms(read_delay_ms)
            data = self.i2c.readfrom(self.i2c_addr, response_size) 
            self.i2c.stop(); 
            for i in range(response_size//3):
                if not self._check_crc(data[i*3:(i+1)*3]): # pos 2 and 5 are CRC
                    raise SHT30Error(SHT30Error.CRC_ERROR)
            if data == bytearray(response_size):
                raise SHT30Error(SHT30Error.DATA_ERROR)
            return data
        except OSError as ex:
            if 'I2C' in ex.args[0]:
                raise SHT30Error(SHT30Error.BUS_ERROR)
            raise ex 
开发者ID:rsc1975,项目名称:micropython-sht30,代码行数:26,代码来源:sht30.py

示例8: __init__

# 需要导入模块: import machine [as 别名]
# 或者: from machine import I2C [as 别名]
def __init__(self, sda=None, scl=None, disable_interrupts=False):

        # create i2c object
        self._timeout = 10
        self.disable_interrupts = False
        self._mpu_i2c = I2C(sda, scl)
        self.chip_id = int(unp('>h', self._read(1, 0x75, self.mpu_addr))[0])

        # now apply user setting for interrupts
        self.disable_interrupts = disable_interrupts

        # wake it up
        self.wake()
        self.accel_range(1)
        self._ar = self.accel_range()
        self.gyro_range(0)
        self._gr = self.gyro_range()

    # read from device 
开发者ID:ulno,项目名称:ulnoiot-upy,代码行数:21,代码来源:mpu6050.py

示例9: __init__

# 需要导入模块: import machine [as 别名]
# 或者: from machine import I2C [as 别名]
def __init__(self, type, scl, sda):
        self.type = type

        if self.type == 0:
            i2c_bus = I2C(scl=Pin(scl), sda=Pin(sda), freq=100000)
            self.sensor = BMP180.BMP180(i2c_bus)
            self.sensor.oversample_sett = 2
            self.sensor.baseline = 101325

        elif self.type == 1:
             pass #TODO

        else:
            log.error("Unknown sensor type '{}'. Cannot instantiate it.".format(self.type))

    # @timed_function 
开发者ID:idimitrakopoulos,项目名称:illuminOS,代码行数:18,代码来源:BMP.py

示例10: __init__

# 需要导入模块: import machine [as 别名]
# 或者: from machine import I2C [as 别名]
def __init__(self, address=0x20, gpioScl=5, gpioSda=4):
        """Initialize MCP230xx at specified I2C address and bus number.  If bus
        is not specified it will default to the appropriate platform detected bus.
        """
        self.address = address
        self.i2c = I2C(scl=Pin(gpioScl),sda=Pin(gpioSda))
        # Assume starting in ICON.BANK = 0 mode (sequential access).
        # Compute how many bytes are needed to store count of GPIO.
        self.gpio_bytes = self.NUM_GPIO//8
        # Buffer register values so they can be changed without reading.
        self.iodir = bytearray(self.gpio_bytes)  # Default direction to all inputs.
        self.gppu = bytearray(self.gpio_bytes)  # Default to pullups disabled.
        self.gpio = bytearray(self.gpio_bytes)
        # Write current direction and pullup buffer state.
        self.write_iodir()
        self.write_gppu() 
开发者ID:ShrimpingIt,项目名称:micropython-mcp230xx,代码行数:18,代码来源:mcp.py

示例11: __init__

# 需要导入模块: import machine [as 别名]
# 或者: from machine import I2C [as 别名]
def __init__(self, i2c, btm_servo_idx, top_servo_idx):
        '''
        PCA9685与ESP32之间通过I2C相连接
        @gpio_scl : I2C的SCL管脚GPIO编号
        @gpio_sda : I2C的SDA管脚的GPIO编号
        @btm_servo_idx: 云台下方舵机在PCA9685上面的编号
        @top_servo_idx: 云台上方电机在PCA9695上面的编号
        '''
        

        self.servos = Servos(i2c, address=0x40) # 实例化一个舵机控制板(servo control board)
        self.btm_servo_idx = btm_servo_idx # 底部舵机的编号
        self.top_servo_idx = top_servo_idx # 云台上方舵机的编号
        self.btm_min_angle = 0 # 底部舵机最小旋转角度
        self.btm_max_angle = 180 # 底部舵机最大旋转角度
        self.btm_init_angle = 100 # 底部舵机的初始角度
        self.top_min_angle = 0 # 顶部舵机的最小旋转角度
        self.top_max_angle = 180 # 顶部舵机的最大旋转角度
        self.top_init_angle = 100 # 顶部舵机的初始角度

        # 初始化云台角度
        self.init_cloud_platform() 
开发者ID:1zlab,项目名称:1ZLAB_Face_Track_Robot,代码行数:24,代码来源:cloud_platform.py

示例12: __init__

# 需要导入模块: import machine [as 别名]
# 或者: from machine import I2C [as 别名]
def __init__(self, 
                 width = 128, height = 64, 
                 scl_pin_id = 5, sda_pin_id = 4,
                 freq = 400000): 
                 
        self.width = width
        self.height = height
        self.i2c = machine.I2C(scl = machine.Pin(scl_pin_id, machine.Pin.OUT),
                               sda = machine.Pin(sda_pin_id), 
                               freq = freq) 
        self.display = ssd1306.SSD1306_I2C(width, height, self.i2c)
        self.show = self.display.show 
开发者ID:Wei1234c,项目名称:SX127x_driver_for_MicroPython_on_ESP8266,代码行数:14,代码来源:display_ssd1306_i2c.py

示例13: setup

# 需要导入模块: import machine [as 别名]
# 或者: from machine import I2C [as 别名]
def setup(use_spi=False, soft=True):
    if use_spi:
        # Pyb   SSD
        # 3v3   Vin
        # Gnd   Gnd
        # X1    DC
        # X2    CS
        # X3    Rst
        # X6    CLK
        # X8    DATA
        pdc = machine.Pin('X1', machine.Pin.OUT_PP)
        pcs = machine.Pin('X2', machine.Pin.OUT_PP)
        prst = machine.Pin('X3', machine.Pin.OUT_PP)
        if soft:
            spi = machine.SPI(sck=machine.Pin('X6'), mosi=machine.Pin('X8'), miso=machine.Pin('X7'))
        else:
            spi = machine.SPI(1)
        ssd = SSD1306_SPI(WIDTH, HEIGHT, spi, pdc, prst, pcs)
    else:  # I2C
        # Pyb   SSD
        # 3v3   Vin
        # Gnd   Gnd
        # Y9    CLK
        # Y10   DATA
        if soft:
            pscl = machine.Pin('Y9', machine.Pin.OPEN_DRAIN)
            psda = machine.Pin('Y10', machine.Pin.OPEN_DRAIN)
            i2c = machine.I2C(scl=pscl, sda=psda)
        else:
            i2c = machine.I2C(2)
        ssd = SSD1306_I2C(WIDTH, HEIGHT, i2c)
    return ssd 
开发者ID:peterhinch,项目名称:micropython-font-to-py,代码行数:34,代码来源:ssd1306_setup.py

示例14: __init__

# 需要导入模块: import machine [as 别名]
# 或者: from machine import I2C [as 别名]
def __init__(
        self, i2c, address=0x0c,
        mode=MODE_CONTINOUS_MEASURE_1, output=OUTPUT_16_BIT,
        offset=(0, 0, 0), scale=(1, 1, 1)
    ):
        self.i2c = i2c
        self.address = address
        self._offset = offset
        self._scale = scale

        if 0x48 != self.whoami:
            raise RuntimeError("AK8963 not found in I2C bus.")

        # Sensitivity adjustement values
        self._register_char(_CNTL1, _MODE_FUSE_ROM_ACCESS)
        asax = self._register_char(_ASAX)
        asay = self._register_char(_ASAY)
        asaz = self._register_char(_ASAZ)
        self._register_char(_CNTL1, _MODE_POWER_DOWN)

        # Should wait atleast 100us before next mode
        self._adjustement = (
            (0.5 * (asax - 128)) / 128 + 1,
            (0.5 * (asay - 128)) / 128 + 1,
            (0.5 * (asaz - 128)) / 128 + 1
        )

        # Power on
        self._register_char(_CNTL1, (mode | output))

        if output is OUTPUT_16_BIT:
            self._so = _SO_16BIT
        else:
            self._so = _SO_14BIT 
开发者ID:tuupola,项目名称:micropython-mpu9250,代码行数:36,代码来源:ak8963.py

示例15: __init__

# 需要导入模块: import machine [as 别名]
# 或者: from machine import I2C [as 别名]
def __init__(self, i2c=None, addr=0x5c):
        if i2c == None:
            from machine import I2C, Pin
            self.i2c = I2C(sda=21, scl=22)
        else:
            self.i2c = i2c
        self.addr = addr
        self.buf = bytearray(5) 
开发者ID:m5stack,项目名称:UIFlow-Code,代码行数:10,代码来源:dht12.py


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