Hackster is hosting Hackster Holidays, Ep. 5: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 5 on Friday!
Patrick Fitzgerald
Published © GPL3+

Micro:Bit i2c Scanner

Make a useful diagnostic tool with a microbit board and a bit of code

AdvancedProtip3 hours51

Things used in this project

Hardware components

micro:bit ARM Cortex-M Development Board
×1
ssd1306 OLED display
×1

Software apps and online services

tera terminal emulator for windows

Story

Read more

Code

i2cScanner.py

Python
Python script that runs on the MicroBit
scans i2c addresses from 0 to 127
displays responding addresses on LEDs
prints addresses onto Serial port
# scan i2c bus for responding devices
from microbit import *
start = 0x00
end = 0x7F
while True:
    print("Scanning I2C bus...now..")
    for i in range(start, end + 1):
            try:
                i2c.read(i, 1)
            except OSError:
                pass
            else:
                print("Found:  [%s]" % hex(i))
                display.scroll(hex(i))
    print("Scanning done")
    sleep(1)

Credits

Patrick Fitzgerald

Patrick Fitzgerald

118 projects • 40 followers

Comments