Example: 50-OpenMV-Boards/53-N6-Boards/50-Board-Control/i2c_control.py
# 本作品采用MIT许可证授权。
# Copyright (c) 2013-2026 OpenMV LLC. All rights reserved.
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# I2C Control
#
# This example shows how to use the i2c bus on your OpenMV Cam by dumping the
# contents on a standard EEPROM. To run this example connect an I2C EEPROM
# to your OpenMV Cam (P4 = SCL, P5 = SDA).
from machine import I2C
i2c = I2C(2) # The user-accessible i2c bus is bus 2 on the OpenMV N6.
print(i2c.scan()) # 显示已连接的设备。
mem = i2c.readfrom_mem(0x50, 0, 256) # The eeprom slave address is 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("]")