diff --git a/MUX_board/2024.0.0/relay_board_32/MUX_settings.csv b/MUX_board/2024.0.0/relay_board_32/MUX_settings.csv index af1c4538ab190742698ab41eb0ea170c28db7587..824715b4679640984a76de99612beb8d118dcd57 100644 --- a/MUX_board/2024.0.0/relay_board_32/MUX_settings.csv +++ b/MUX_board/2024.0.0/relay_board_32/MUX_settings.csv @@ -1,2 +1,2 @@ TCA_address,TCA_channel,MCP_address,Electrode_id_min -None,0,0x20,1 +None,0,0x22,1 diff --git a/MUX_board/2024.0.0/relay_board_32/addresses_table_4roles.csv b/MUX_board/2024.0.0/relay_board_32/addresses_table_4roles.csv index 62d2fe8c225a3ed4da311a535136da907f60aa8f..a3ce13b8b25b3dc226e63e1a8860efb7d5311c59 100644 --- a/MUX_board/2024.0.0/relay_board_32/addresses_table_4roles.csv +++ b/MUX_board/2024.0.0/relay_board_32/addresses_table_4roles.csv @@ -1,33 +1,33 @@ MCP_board_id,GPIO,Electrode_board_id,Role -0,0,0,X -0,1,1,X -0,2,2,X -0,3,3,X -0,4,4,X -0,5,5,X -0,6,6,X -0,7,7,X -0,8,0,Y -0,9,1,Y -0,10,2,Y -0,11,3,Y -0,12,4,Y -0,13,5,Y -0,14,6,Y -0,15,7,Y -1,0,7,XX -1,1,6,XX -1,2,5,XX -1,3,4,XX -1,4,3,XX -1,5,2,XX -1,6,1,XX -1,7,0,XX -1,8,7,YY -1,9,6,YY -1,10,5,YY -1,11,4,YY -1,12,3,YY -1,13,2,YY -1,14,1,YY -1,15,0,YY +0,0,0,A +0,1,1,A +0,2,2,A +0,3,3,A +0,4,4,A +0,5,5,A +0,6,6,A +0,7,7,A +0,8,0,B +0,9,1,B +0,10,2,B +0,11,3,B +0,12,4,B +0,13,5,B +0,14,6,B +0,15,7,B +1,0,7,M +1,1,6,M +1,2,5,M +1,3,4,M +1,4,3,M +1,5,2,M +1,6,1,M +1,7,0,M +1,8,7,N +1,9,6,N +1,10,5,N +1,11,4,N +1,12,3,N +1,13,2,N +1,14,1,N +1,15,0,N diff --git a/MUX_board/2024.0.0/relay_board_32/compiled_mux_addressing_table.csv b/MUX_board/2024.0.0/relay_board_32/compiled_mux_addressing_table.csv index b2866dfb043e5701068f9647c1cd1a2dcf77f8f1..0d321d59a086ffd5be00a2f0e8e6aca71c7dca9f 100644 --- a/MUX_board/2024.0.0/relay_board_32/compiled_mux_addressing_table.csv +++ b/MUX_board/2024.0.0/relay_board_32/compiled_mux_addressing_table.csv @@ -1,33 +1,33 @@ -TCA_address,TCA_channel,MCP_address,Electrode_id,Role,MCP_GPIO -None,0,0x20,1.0,X,None -None,0,0x20,2.0,X,None -None,0,0x20,3.0,X,None -None,0,0x20,4.0,X,None -None,0,0x20,5.0,X,None -None,0,0x20,6.0,X,None -None,0,0x20,7.0,X,None -None,0,0x20,8.0,X,None -None,0,0x20,1.0,Y,None -None,0,0x20,2.0,Y,None -None,0,0x20,3.0,Y,None -None,0,0x20,4.0,Y,None -None,0,0x20,5.0,Y,None -None,0,0x20,6.0,Y,None -None,0,0x20,7.0,Y,None -None,0,0x20,8.0,Y,None -None,0,0x21,8.0,XX,None -None,0,0x21,7.0,XX,None -None,0,0x21,6.0,XX,None -None,0,0x21,5.0,XX,None -None,0,0x21,4.0,XX,None -None,0,0x21,3.0,XX,None -None,0,0x21,2.0,XX,None -None,0,0x21,1.0,XX,None -None,0,0x21,8.0,YY,None -None,0,0x21,7.0,YY,None -None,0,0x21,6.0,YY,None -None,0,0x21,5.0,YY,None -None,0,0x21,4.0,YY,None -None,0,0x21,3.0,YY,None -None,0,0x21,2.0,YY,None -None,0,0x21,1.0,YY,None +TCA_address,TCA_channel,MCP_address,Electrode_id,MCP_GPIO,Role +None,0,0x22,1,0,A +None,0,0x22,2,1,A +None,0,0x22,3,2,A +None,0,0x22,4,3,A +None,0,0x22,5,4,A +None,0,0x22,6,5,A +None,0,0x22,7,6,A +None,0,0x22,8,7,A +None,0,0x22,1,8,B +None,0,0x22,2,9,B +None,0,0x22,3,10,B +None,0,0x22,4,11,B +None,0,0x22,5,12,B +None,0,0x22,6,13,B +None,0,0x22,7,14,B +None,0,0x22,8,15,B +None,0,0x23,8,0,M +None,0,0x23,7,1,M +None,0,0x23,6,2,M +None,0,0x23,5,3,M +None,0,0x23,4,4,M +None,0,0x23,3,5,M +None,0,0x23,2,6,M +None,0,0x23,1,7,M +None,0,0x23,8,8,N +None,0,0x23,7,9,N +None,0,0x23,6,10,N +None,0,0x23,5,11,N +None,0,0x23,4,12,N +None,0,0x23,3,13,N +None,0,0x23,2,14,N +None,0,0x23,1,15,N diff --git a/MUX_board/2024.0.0/relay_board_32/test_MUX_32.py b/MUX_board/2024.0.0/relay_board_32/test_MUX_32.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..6d5162565d88e66b8ae93c9349d0af91bb2914be 100644 --- a/MUX_board/2024.0.0/relay_board_32/test_MUX_32.py +++ b/MUX_board/2024.0.0/relay_board_32/test_MUX_32.py @@ -0,0 +1,43 @@ +from adafruit_mcp230xx.mcp23017 import MCP23017 +import adafruit_tca9548a +from digitalio import Direction +import busio +import board +import numpy as np +import time +import os + +mux_board_version = '2024.0.0' +mux_addressing_table_file = "compiled_mux_addressing_table.csv" +mux_addressing_table_file = os.path.join(mux_board_version,"relay_board_32",mux_addressing_table_file) + +electrode_nr = 1 +role = "A" + +with open(mux_addressing_table_file, 'r') as myfile: + header = myfile.readlines()[0].strip('\n').split(',') +mux_addressing_table = np.genfromtxt(mux_addressing_table_file, dtype=str, + delimiter=',', skip_header=1, ) +mux_addressing_table = {header[k]: mux_addressing_table.T[k] for k in range(len(header))} + + +def set_relay_state(mcp, mcp_pin, state=True): + pin_enable = mcp.get_pin(mcp_pin) + pin_enable.direction = Direction.OUTPUT + pin_enable.value = state + +i2c = busio.I2C(board.SCL, board.SDA) +idx = np.where((mux_addressing_table['Electrode_id'] == electrode_nr) & (mux_addressing_table['Role'] == role))[0] +tca_addr = mux_addressing_table['TCA_address'][idx][0] +tca_channel = mux_addressing_table['TCA_channel'][idx][0] +mcp_gpio = mux_addressing_table['MCP_GPIO'][idx][0] +if tca_addr is None: + tca = i2c +else: + tca = adafruit_tca9548a.TCA9548A(i2c, role) +#tca = adafruit_tca9548a.TCA9548A(i2c, hex(int(tca_addr, 16)))[tca_channel] +tca = i2c +mcp_addr = hex(int(mux_addressing_table['MCP_address'][idx][0], 16)) +MCP23017(tca, address=mcp_addr) +if state == 'on' + set_relay_state(mcp_addr,, True) \ No newline at end of file diff --git a/ohmpi.py b/ohmpi.py index 018fdfd63071c88cc9724a3013bab6e3af1961a3..aa77211d9d01328c6d4b749ca42ce28c12471dfc 100644 --- a/ohmpi.py +++ b/ohmpi.py @@ -1332,6 +1332,7 @@ class OhmPi(object): idx = np.where((mux_addressing_table['Electrode_id'] == electrode_nr) & (mux_addressing_table['Role'] == role))[0] tca_addr = mux_addressing_table['TCA_address'][idx][0] tca_channel = mux_addressing_table['TCA_channel'][idx][0] + mcp_gpio = mux_addressing_table['MCP_GPIO'][idx][0] if tca_addr is None: tca = self.i2c else: @@ -1340,7 +1341,9 @@ class OhmPi(object): mcp_addr = hex(int(mux_addressing_table['MCP_address'][idx][0], 16)) MCP23017(tca, address=mcp_addr) if state == 'on' - set_relay_state(mcp_addr, , True) + set_relay_state(mcp_addr, mcp_gpio, True) + if state == 'off' + set_relay_state(mcp_addr, mcp_gpio, False) else: self.exec_logger.warning('MUX board version not recognized')