Sparkfun I2C GPIO expanders



  • I needed extra GPIO pins, so I tried two of Sparkfun's I2C offerings. One is SparkFun 16 Output I/O Expander Breakout - SX1509, BOB-13601. By stacking a SparkFun Qwiic Adapter, DEV-14495, on top I connected the GPIO expander to the Omega Qwiic expansion as shown in the picture. 0_1576343494904_20191129_115741B.jpg. Driver software for this board and Python in the raspberry Pi environment is here: https://github.com/topherCantrell/pi-io-expander/find/master, which was easy to adapt for simple I/O. The Onion Omega Python-light version is here:

    #!/usr/bin/env python
    
    # adapted from <https://github.com/topherCantrell/pi-io-expander/find/master>
    
    from OmegaExpansion import onionI2C #need >>opkg install python-light pyOnionI2C
    import time
    
    CHIP_A = 0x3E # I2C address for chip A, cut jumpers for other addresses
    
    SX_RegDirA = 0x0F # Data direction registers...
    SX_RegDirB = 0x0E # ...default 0xFF, 0 is output, 1 is input
    
    SX_RegDataA = 0x11 # Data value registers... 
    SX_RegDataB = 0x10 # ...default 0xFF
    
    SX_RegPullDownA = 0x09 # Registers to enable pulldown resistors...
    SX_RegPullDownB = 0x08 # ... default 0x00, 0 is disabled, 1 is enabled
    
    bus = onionI2C.OnionI2C()
    
    #bus.writeByte(CHIP_A, SX_RegDirA, 0xFF)     # That's the default, so not needed
    #bus.writeByte(CHIP_A, SX_RegDirB, 0xFF-8)   # Just bit 11 as output. e.g. 1111 0111
    bus.writeByte(CHIP_A, SX_RegDirB, 0xFF-0x09) # Set bits 8 and 11 as outputs, e.g. 1111 0110
    
    bus.writeByte(CHIP_A, SX_RegDataB, 8) # Switch on pin 11
    time.sleep(1)
    bus.writeByte(CHIP_A, SX_RegDataB, 0) # Switch p1n 11 off
    
    while True:
    	
    	bus.writeByte(CHIP_A, SX_RegDataB, 8) # Switch on pin 11
    	a = bus.readBytes(CHIP_A, SX_RegDataB, 2)
    	print a[0], ',', a[1]
    	time.sleep(0.2)
    
    	bus.writeByte(CHIP_A, SX_RegDataB, 1) # Switch pin 11 off and pin 8 on 
    	a = bus.readBytes(CHIP_A, SX_RegDataB, 2)
    	print a[0], ',', a[1]
    	time.sleep(0.2)
    
    	bus.writeByte(CHIP_A, SX_RegDataB, 0) # All off
    	a = bus.readBytes(CHIP_A, SX_RegDataB, 2)
    	print a[0], ',', a[1]
    	time.sleep(0.2)
    	print ' '
    

    Another post describes a different GPIO expander.



Looks like your connection to Community was lost, please wait while we try to reconnect.