Multiple Mux Shield II

Hello!

I am working on a fuel cell.

To observe and control it i need to check the running voltage of the 167 individual cells in it.

Is there a way to connect mutiple Mux Shield II´s:

https://www.sparkfun.com/products/11723

to a capable Arduino, f.e. the Mega2560 R3 with, as i think, enough Digital and Analog-Ins?

https://www.sparkfun.com/products/11061

If this works, is the library for the Mux Shiled II capable of controlling multiples of them?

Thank you in advance for your brain power!

Hi Haegar.

One Mux Shield can give you up to 48 analog in’s , and you could conceivably use multiple shields, but there are some catches.

  • - The first shield can plug directly into a Arduino, but any additional shields would need some pins moved.
  • - The library is only written to control a single Mux Shield. You'd need to modify the library or write your own code outside the library to use more than one shield if you wanted independent control over each shields Mux.
  • For the first issue, you’d need to reassign the analog pins between the shield and Arduino for additional shields. By default they are A0,A1, and A2 and that works for the first shield, but additional shields would need those moved to other analog pins is groups of three. There are 4 digital pins that select what channel each of the analog inputs are connected too and could be shared if you wanted.

    The second issue isn’t really all that bad if you don’t need independent control over each shield. As long as you’re OK switching every input bank at the same time, you wouldn’t need to modify anything. You would need to keep track in your code what channel was connected at any given time though.

    The maximum number of analog in’s you could have with a Mega with 6 shields would be 256. (16 analog in’s each split 16 ways, 16 x 16 = 256)

    Hi SparkFun Forums -

    I Am A Rookie In Electronics, I Got This Project On The Go. I Am Using A Host Of MyoWare Muscle Sensors To Trigger Pneumatic Valves For A Robotics Project. Please Excuse Me In My Long Post, As My Programming Skills Are Still, Kind Of Weak. I Am Kindly Asking, For Your Help :slight_smile:

    I Am Wanting To Kindly, Inquire About How To Successfully Interface, And Run 2 Mux Shield II’s using One Arduino Uno Or Mega.

    I Am Trying To Get One Mux Shield II To Be For Reading Analog Inputs, From The Array Of MyoWare Sensors, And The Other Mux Sheild II, For Writing Digital Outputs For Activating Power Transistors, For Driving Solenoid Valves.

    I Have Already Had Major Success With Interfacing Multiple Myoware Sensors With The Arduino Uno, Using The Mayhew Labs, Mux II Arduino Shield. I Trigger One Of The Myoware Muscle Sensors, And The Corresponding LED Indicator Light, Lights Up. The LED Is To Indicate Which Of The Power Transistor Is On.

    I Have, So Far Successfully Interfaced 2 Myoware Sensors, Individually Activating 2 Solenoids (Sol A & Sol B) For 1 Pneumatic Directional 5/3 Way Valve. In The Program I Went Ahead And Did The Programming For 8 Pneumatic Valves, Using 16 MyoWare Muscle Sensors, Just Repeating The Same Programming Structure.

    My Current Arduino Uno Programming Is Set Up For I/O Line 2, Digital Outputs, And I/O Line 3, Is Set Up For Analog Inputs. I/O Line 1 Is N/A.

    What I Am Trying To Do Is To Set Up Mux Shield II 1, As Analog Input For I/O Lines 1-3. The Other Mux II Shield As Digital Outputs, For I/O Lines 1-3.

    My Technical Issue & Inquiry; How To Do The Programming To Interface Between Two, Mux II Shields With Either An Arduino Uno/Arduino Mega 2560. Is The Mayhew Labs Mux II Shields Even Compatible With Arduino Mega 2560.

    I Read & Saw Your Post, I Don’t Understand In How To Do The Actual Programming For Interfacing Multiple Mux Shield With One Arduino Microcontroller.

    Again, Please Excuse Me In My Long Post. I Appreciate, & Thank You, For Any Help, With My Programming Challenges

    Thanks

    Again - Sorry For The Long Post —

    Here Is My Code - Using Programming For One Valve - Please Help In Advise Where I Should Add, &/Or Modify Code For Interfacing Multiple Mux Shield II’s With Arduino. Thanks - :wink:

    //Mux Shield Library
    #include <MuxShield.h>
    
    //Initializing the Mux Shield
    MuxShield muxShield;
    
    //Declaring Variables
    //Declaration For Solenoid Valve #1
    int voltageThreshold1B = 700;   // any reading higher will trigger an action
    
    int voltageThreshold1A = 700;   // any reading higher will trigger an action
    
    void setup()  // put your setup code here, to run when Arduino Uno is on:
    {
    
     Serial.begin(19200);
    
     muxShield.setMode(2, DIGITAL_OUT);        //set I/O line 2 as digital outputs
    
     muxShield.setMode(3, ANALOG_IN);          //set I/O line 3 as analog inputs
    }
    
    void loop() // put your main code here, to run repeatedly:
    {
    
    //5/3 Directional Control Valve (5 Port, 3 Position) #1 
    
    //Solenoid B Valve Programming
    int currentVoltage1B = muxShield.analogReadMS(3,15);  // store the incoming analog voltage
    
     // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
    
     float voltage0  = currentVoltage1B * (5.0 / 1023.0);
    
     if(currentVoltage1B > voltageThreshold1B)
     {
    
       // trigger actions
    
        Serial.println(" MUSCLE CONTRACTION!"); // prints string + new line
    
        Serial.println(" CYLINDER RETRACTION!"); // prints string + new line
    
        Serial.println(voltage0);
    
        muxShield.digitalWriteMS(2,0, HIGH);  //this sends 5V, turning on solenoidB for  digital output
    
        delay(100);
     }
    
     else
     {
    
        Serial.println("");              //add new line for sereil monitor prinout
    
        muxShield.digitalWriteMS(2,0, LOW); //this sends 0V, turning off solenoidB for  digital output
    
        delay(100);
        // turn off the solenoid as threshold is not met
     }
    

    Hi SparkFun

    Good Afternoon, Ladies & Gentalmen.

    I Was Eventually Was Successful, In Interfacing Multiple Mux Shield II’s , With 1 Arduino

    Uno Micro Controller. I Didn’t Have To Modify The Mux Shield II Library, I Did The "Programming

    Magic" In The Initializing , & Void Set Up, Sections Of The Program.

    Instead Of Initializing For 1 Shield.

    MuxShield muxShield;

    I Had To Initialize 2 Shields.

    MuxShield muxShield0; //1st Mux Shield For Reading Analog Inputs

    MuxShield muxShield1; //2nd Mux Shield For Writing Digital Inputs

    To Be Able To Read (ANALOG) Digital Values -

    Program The muxShield0.SetMode ----- I/O Lines 1-3, As ANALOG_IN

    Please Se Example Code Below

    muxShield0.setMode(1, ANALOG_IN); //set I/O line 2 as digital outputs

    Just Repeat For I/O Lines 1-3

    To Be Able To Write (HIGH, or LOW) Digital Logic Values To Digital Outputs -

    Program The muxShield1.SetMode ----- I/O Lines 1-3, As DIGITAL_OUT

    Please Se Example Code Below

    muxShield1.setMode(1, DIGITAL_OUT); //set I/O line 2 as digital outputs

    Just Repeat For I/O Lines 1-3

    ATTENTION:

    When Reading Analog Values From 1st Shield, Pay Close Attention – muxShield0 – For Reading Analog Inputs

    When Writing Digital Values From 2nd Shield, Pay Close Attention – muxShield1 – For Writing Digital Outputs

    Lastly - I Would Like Constructive Suggestions, In “Condensing/Optimizing” My Arduino C++ Code, So That Will Take Up Less Memory Space.

    I Need My Program To Be Able To Process The Data As Fast As Possible As There Cant Be Delay Between Muscle Sensor Readings, And Triggering

    Of Solenoid Valves, For My Robotics Projects

    Please See & Review Example Code Below.


    //MuxShield Library
    #include <MuxShield.h>
    
    //Initializing the Multiple Mux Shield II's 
    //1st Mux Shield II, Reads Analog Values, As Analog Inputs, From Sensors  
    MuxShield muxShield0;
    //2nd Mux Shield II, Writes Digital Values (HIGH, or LOW), As Digital Outputs
    MuxShield muxShield1; 
    
    //Declaring Variables
    //Declaration For Solenoid Valve #1-#8
    //Array With Value OF 700 In voltageThreshold Array
    int voltageThreshold [] = {700}; // any reading higher, 700, will trigger an action
    int voltageThresholdB = voltageThreshold [0];
    int voltageThresholdA = voltageThreshold [0];
    
    //------------------------------------------------- VOID SETUP -------------------------------------------------
    void setup() // put your setup code here, to run when Arduino Uno is on:
    {
      Serial.begin(19200);
      muxShield0.setMode(1, ANALOG_IN);        //set I/O line 2 as analog inputs
      muxShield0.setMode(2, ANALOG_IN);        //set I/O line 2 as analog inputs
      muxShield0.setMode(3, ANALOG_IN);        //set I/O line 3 as analog inputs
    
      muxShield1.setMode(1, DIGITAL_OUT);      //set I/O line 2 as digital outputs
      muxShield1.setMode(2, DIGITAL_OUT);      //set I/O line 2 as digital outputs
      muxShield1.setMode(3, DIGITAL_OUT);      //set I/O line 3 as digital outputs
    
    }
    //------------------------------------------------- VOID LOOP -------------------------------------------------
    void loop()
    // put your main code here, to run repeatedly:
    {
      //5/3 Directional Control Valve (5 Port, 3 Position) #1
      //Solenoid B Valve Programming
      int currentVoltage1B = muxShield0.analogReadMS(3, 15); // store the incoming analog voltage
    
      // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
      float voltage0  = currentVoltage1B * (5.0 / 1023.0);
    
      if (currentVoltage1B > voltageThresholdB)
      { //Safety Programming Feature, Where Two Solenoids Are Not On At Same Time, Per DCV!!
        muxShield1.digitalWriteMS(2, 1, LOW); //this sends 0V, turning off solenoidA for  digital output
        delay(100);
        // trigger actions
        Serial.println(" MUSCLE CONTRACTION!"); // prints string + new line
        Serial.println(" CYLINDER RETRACTION!"); // prints string + new line
        Serial.println(voltage0);
    
        muxShield1.digitalWriteMS(2, 0, HIGH); //this sends 5V, turning on solenoidB for  digital output
        delay(100);
      }
      else
      {
        Serial.println("");              //add new line for sereil monitor prinout
        muxShield1.digitalWriteMS(2, 0, LOW); //this sends 0V, turning off solenoidB for  digital output
        delay(100); // turn off the solenoid as threshold is not met
      }
    
      //////////////////////////////////////////////////////////////////////////////////////////////
    
      //Solenoid A Valve Programming
      int currentVoltage1A = muxShield0.analogReadMS(3, 14); // store the incoming analog voltage
    
      // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
      float voltage1  = currentVoltage1A * (5.0 / 1023.0);
    
      if (currentVoltage1A > voltageThresholdA)
      { //Safety Programming Feature, Where Two Solenoids Are Not On At Same Time, Per DCV!!
        muxShield1.digitalWriteMS(2, 0, LOW); //this sends 0V, turning off solenoidA for  digital output
        delay(100);
        // trigger actions
        Serial.println(" MUSCLE CONTRACTION!"); // prints string + new line
        Serial.println(" CYLINDER RETRACTION!"); // prints string + new line
        Serial.println(voltage1);
    
        muxShield1.digitalWriteMS(2, 1, HIGH); //this sends 5V, turning on solenoid for  digital output
        delay(100);
      }
      else
      {
        Serial.println("");  //adds a new line
        muxShield1.digitalWriteMS(2, 1, LOW); //this sends 0V, turning off solenoid for  digital output
        delay(100); // turn off the solenoid as threshold is not met
      }