mirror of
https://github.com/pybricks/pybricks-api.git
synced 2026-09-14 18:47:32 +00:00
First pass including Image and ImageFile. Largely migrated from old ev3dev version. We can refine this for the embedded version in the next commits.
23 lines
609 B
Python
23 lines
609 B
Python
from pybricks.hubs import EV3Brick
|
|
from pybricks.iodevices import I2CDevice
|
|
from pybricks.parameters import Port
|
|
|
|
# Initialize the EV3
|
|
ev3 = EV3Brick()
|
|
|
|
# Initialize I2C Sensor
|
|
device = I2CDevice(Port.S2, 0xD2 >> 1)
|
|
|
|
# Read one byte from the device.
|
|
# For this device, we can read the Who Am I
|
|
# register (0x0F) for the expected value: 211.
|
|
if 211 not in device.read(0x0F):
|
|
raise ValueError("Unexpected I2C device ID")
|
|
|
|
# To write data, create a bytes object of one
|
|
# or more bytes. For example:
|
|
# data = bytes((1, 2, 3))
|
|
|
|
# Write one byte (value 0x08) to register 0x22
|
|
device.write(0x22, bytes((0x08,)))
|