for anyone who will ever need it
using python to control outputs (will make an edit soon to add the input)
import pyb # Import module for board related functions
from pyb import Pin,ADC
from machine import SoftI2C
import time
I2C_ADDRESS22 = 0x22
i2c = SoftI2C(sda=Pin('PH8'), scl=Pin('PH7'), freq=100000)
class I2CIO:
def __init__(self, address, i2c, pin , pintype):
if pin == 4:
pin = 7
elif pin == 5:
pin = 6
elif pin == 6:
pin = 5
elif pin == 7:
pin = 4
reg_addr = 0x00 + (pin // 8) # TCA6424A_RA_OUTPUT0 + (pin / 8)
bit_num = pin % 8
self.address = address
self.reg_addr = reg_addr
self.bit_num = bit_num
self.i2c = i2c
self.write_setup(pintype)
if pintype==0:
self.off()
# setup pin
def write_setup(self, pintype):
b = i2c.readfrom_mem(self.address, self.reg_addr+12, 1)[0]
if pintype != 0:
b |= (1 << self.bit_num)
else:
b &= ~(1 << self.bit_num)
i2c.writeto_mem(self.address, self.reg_addr+12, bytes([b]))
return b
def on(self):
self.write_output(1)
def off(self):
self.write_output(0)
def write_output(self, value):
b = i2c.readfrom_mem(self.address, self.reg_addr+4, 1)[0]
if value != 0:
b |= (1 << self.bit_num)
else:
b &= ~(1 << self.bit_num)
i2c.writeto_mem(self.address, self.reg_addr+4, bytes([b]))
return b
DO_0 = Pin('PI6', Pin.OUT_PP, Pin.PULL_NONE)
DO_1 = Pin('PH9', Pin.OUT_PP, Pin.PULL_NONE)
DO_2 = Pin('PJ9', Pin.OUT_PP, Pin.PULL_NONE)
DO_3 = Pin('PE2', Pin.OUT_PP, Pin.PULL_NONE)
DO_4 = Pin('PI3', Pin.OUT_PP, Pin.PULL_NONE)
DO_5 = Pin('PI2', Pin.OUT_PP, Pin.PULL_NONE)
DO_6 = Pin('PD3', Pin.OUT_PP, Pin.PULL_NONE)
DO_7 = Pin('PA14', Pin.OUT_PP, Pin.PULL_NONE)
ProCH00 = I2CIO(I2C_ADDRESS22, i2c, 0,0)
ProCH01 = I2CIO(I2C_ADDRESS22, i2c, 1,0)
ProCH02 = I2CIO(I2C_ADDRESS22, i2c, 2,0)
ProCH03 = I2CIO(I2C_ADDRESS22, i2c, 3,0)
ProCH04 = I2CIO(I2C_ADDRESS22, i2c, 4,0)
ProCH05 = I2CIO(I2C_ADDRESS22, i2c, 5,0)
ProCH06 = I2CIO(I2C_ADDRESS22, i2c, 6,0)
ProCH07 = I2CIO(I2C_ADDRESS22, i2c, 7,0)
ProCH08 = I2CIO(I2C_ADDRESS22, i2c, 8,0)
ProCH09 = I2CIO(I2C_ADDRESS22, i2c, 9,0)
ProCH010 = I2CIO(I2C_ADDRESS22, i2c, 10,0)
ProCH011 = I2CIO(I2C_ADDRESS22, i2c, 11,0)
print ("____ SETUP complete_____")
while True:
pausetime = 200
DO_0.on()
pyb.delay(pausetime)
DO_0.off()
DO_1.on()
pyb.delay(pausetime)
DO_1.off()
DO_2.on()
pyb.delay(pausetime)
DO_2.off()
DO_3.on()
pyb.delay(pausetime)
DO_3.off()
DO_4.on()
pyb.delay(pausetime)
DO_4.off()
DO_5.on()
pyb.delay(pausetime)
DO_5.off()
DO_6.on()
pyb.delay(pausetime)
DO_6.off()
DO_7.on()
pyb.delay(pausetime)
DO_7.off()
ProCH00.on()
pyb.delay(pausetime)
ProCH00.off()
ProCH01.on()
pyb.delay(pausetime)
ProCH01.off()
ProCH02.on()
pyb.delay(pausetime)
ProCH02.off()
ProCH03.on()
pyb.delay(pausetime)
ProCH03.off()
ProCH04.on()
pyb.delay(pausetime)
ProCH04.off()
ProCH05.on()
pyb.delay(pausetime)
ProCH05.off()
ProCH06.on()
pyb.delay(pausetime)
ProCH06.off()
ProCH07.on()
pyb.delay(pausetime)
ProCH07.off()
ProCH08.on()
pyb.delay(pausetime)
ProCH08.off()
ProCH09.on()
pyb.delay(pausetime)
ProCH09.off()
ProCH010.on()
pyb.delay(pausetime)
ProCH010.off()
ProCH011.on()
pyb.delay(pausetime)
ProCH011.off()