From 835f20f2d309d6c677e26ae5583f9b485336e2e6 Mon Sep 17 00:00:00 2001 From: Arnaud Watlet <arnaud.watlet@umons.ac.be> Date: Tue, 14 Feb 2023 15:12:46 +0100 Subject: [PATCH] Updates mux v2024 addressing --- .../2024.0.0/relay_board_32/MUX_settings.csv | 2 +- .../relay_board_32/addresses_table_4roles.csv | 64 +++++++++--------- .../compiled_mux_addressing_table.csv | 66 +++++++++---------- .../2024.0.0/relay_board_32/test_MUX_32.py | 43 ++++++++++++ ohmpi.py | 5 +- 5 files changed, 113 insertions(+), 67 deletions(-) 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 af1c4538..824715b4 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 62d2fe8c..a3ce13b8 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 b2866dfb..0d321d59 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 e69de29b..6d516256 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 018fdfd6..aa77211d 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') -- GitLab