File tree Expand file tree Collapse file tree 1 file changed +30
-0
lines changed
micropython/examples/breakout_ioexpander Expand file tree Collapse file tree 1 file changed +30
-0
lines changed Original file line number Diff line number Diff line change
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 ))
You can’t perform that action at this time.
0 commit comments