Skip to content

i2c native doesnt require lock #229

Closed
@ladyada

Description

@ladyada

shouldnt work :)

import board
import busio

BYTES_TO_READ = 2

with busio.I2C(board.SCL, board.SDA) as i2c:
    while not i2c.scan():
        pass
    print("I2C addresses found:", [hex(i) for i in i2c.scan()])

    i2c_addr = i2c.scan()[0]

    print("Reading each address")
    for addr in range(255):
        buffer = bytearray(BYTES_TO_READ)  # read n bytes from each addr
        try:
            i2c.writeto(i2c_addr, bytearray([addr]))
            i2c.readfrom_into(i2c_addr, buffer)
        except:
            # failed to read from that address, keep going
            continue
        print("\nAddress 0x%x : " % addr, end="")
        for b in buffer:
            print("0x%02x " % b, end="")

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions