本文整理匯總了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
示例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')
示例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)
示例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()
示例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)
示例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
示例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
示例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
示例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()
示例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()
示例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
示例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
示例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
示例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)