Skip to content

Commit 169ed9c

Browse files
committed
IOExpander: add I2C address change example
1 parent 8eac60a commit 169ed9c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""
2+
This example shows you how to change the I2C address of an IO Expander breakout (or any of our other Nuvoton based breakouts).
3+
"""
4+
5+
from pimoroni_i2c import PimoroniI2C
6+
from pimoroni import BREAKOUT_GARDEN_I2C_PINS # or PICO_EXPLORER_I2C_PINS or HEADER_I2C_PINS
7+
8+
# enter the current and desired I2C addresses here
9+
EXISTING_ADDRESS = 0x18
10+
NEW_ADDRESS = 0x20
11+
12+
i2c = PimoroniI2C(**BREAKOUT_GARDEN_I2C_PINS)
13+
14+
# Uncomment these lines to change the address
15+
# from breakout_ioexpander import BreakoutIOExpander
16+
# ioe = BreakoutIOExpander(i2c, address=EXISTING_ADDRESS)
17+
# ioe.set_address(NEW_ADDRESS)
18+
19+
# List all the connected I2C devices so we can see the change
20+
print('Scanning i2c bus')
21+
devices = i2c.scan()
22+
23+
if len(devices) == 0:
24+
print("No i2c device !")
25+
26+
else:
27+
print('i2c devices found:', len(devices))
28+
29+
for device in devices:
30+
print("Decimal address: ", device, " | Hexa address: ", hex(device))

0 commit comments

Comments
 (0)