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
}