Example explanation-02-i2c_control i2c control

# I2C 控制
#
# 这个例子真是了如何使用i2c总线在标准的EEPROM上转换数据,为了运行这个例子,
# 你需要插入Thermopile热成像扩展板。

from pyb import I2C

i2c = I2C(2, I2C.MASTER) # i2c总线必须是2。
mem = i2c.mem_read(256, 0x50, 0) # eeprom从地址是0x50。

print("\n[")
for i in range(16):
    print("\t[", end='')
    for j in range(16):
        print("%03d" % mem[(i*16)+j], end='')
        if j != 15: print(", ", end='')
    print("]," if i != 15 else "]")
print("]")

The pyb module cannot be used on OpenMV RT, only the following machine module can be used:

# I2C 控制
#
# 这个例子真是了如何使用i2c总线在标准的EEPROM上转换数据,为了运行这个例子,
# 你需要插入Thermopile热成像扩展板或者一个I2C EEPROM。
from machine import I2C

i2c = I2C(1)  # i2c总线必须是1。
print(i2c.scan())  # 扫描连接的设备
mem = i2c.readfrom_mem(0x50, 0, 256)  # eeprom从地址是0x50。

print("\n[")
for i in range(16):
    print("\t[", end="")
    for j in range(16):
        print("%03d" % mem[(i * 16) + j], end="")
        if j != 15:
            print(", ", end="")
    print("]," if i != 15 else "]")
print("]")

I2C.mem_read function documentation in the pyb module: Singtown Technology OpenMV official Chinese document function explanation:

results matching ""

    No results matching ""