Le Mux (multiplexeur) Shield : ajoute aux Arduino et Arduino Mega jusqu'à 48 entrées ou sorties.

Si vous avez besoin de beaucoup d'entrées  et/ou de sorties, ceci est votre solution! En utilisant trois Texas Instruments CD74HC4067 Analog Multiplexers, le Shield Mux permet d'avoir 48 entrées analogiques / numériques ou sorties numériques dans de nombreuses combinaisons.

Caractéristiques:

http://mayhewlabs.com/arduino-mux-shield

http://www.sparkfun.com/products/9832

exemple de code d'entrée analogique

Cet exemple montre comment lire et stocker toutes les 48 pins comme entrées analogiques dans des tableaux et imprimer les résultats sur le port série.
Multiplexer des broches d'entrées qui n'ont pas une lecture de tension (rien de connecté) auront des valeurs erratiques.

 

 

Code source

  1.  //Mux_Shield_AnalogIn_Example
  2.  
  3.  //http://mayhewlabs.com/arduino-mux-shield
  4.  
  5.  
  6.  
  7.  /*
  8.  
  9.  This example shows how to read and store all 48 pins as analog inputs into arrays and print the results over serial.
  10.  
  11.  Multiplexer pin inputs that do not have a voltage reading (i.e nothing connected) will have erratic values.
  12.  
  13.  
  14.  
  15.  To simplify this code further, one might use nested for loops or function calls.
  16.  
  17.  */
  18.  
  19.  
  20.  
  21.  //Give convenient names to the control pins
  22.  
  23.  #define CONTROL0 5
  24.  
  25.  #define CONTROL1 4
  26.  
  27.  #define CONTROL2 3
  28.  
  29.  #define CONTROL3 2
  30.  
  31.  
  32.  
  33.  //Create arrays for data from the the MUXs
  34.  
  35.  //See the Arduino Array Reference: http://www.arduino.cc/en/Reference/Array
  36.  
  37.  int mux0array[16];
  38.  
  39.  int mux1array[16];
  40.  
  41.  int mux2array[16];
  42.  
  43.  
  44.  
  45.  void setup()
  46.  
  47.  {
  48.  
  49.   //Set MUX control pins to output
  50.  
  51.   pinMode(CONTROL0, OUTPUT);
  52.  
  53.   pinMode(CONTROL1, OUTPUT);
  54.  
  55.   pinMode(CONTROL2, OUTPUT);
  56.  
  57.   pinMode(CONTROL3, OUTPUT);
  58.  
  59.  
  60.  
  61.   //Open the serial port at 28800 bps
  62.  
  63.   Serial.begin(28800);
  64.  
  65.  }
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  void loop()
  72.  
  73.  {
  74.  
  75.   //This for loop is used to scroll through and store the 16 inputs on the FIRST multiplexer
  76.  
  77.   for (int i=0; i<16; i++)
  78.  
  79.   {
  80.  
  81.   //The following 4 commands set the correct logic for the control pins to select the desired input
  82.  
  83.   //See the Arduino Bitwise AND Reference: http://www.arduino.cc/en/Reference/BitwiseAnd
  84.  
  85.   //See the Aruino Bitshift Reference: http://www.arduino.cc/en/Reference/Bitshift
  86.  
  87.   digitalWrite(CONTROL0, (i&15)>>3);
  88.  
  89.   digitalWrite(CONTROL1, (i&7)>>2);
  90.  
  91.   digitalWrite(CONTROL2, (i&3)>>1);
  92.  
  93.   digitalWrite(CONTROL3, (i&1));
  94.  
  95.  
  96.  
  97.   //Read and store the input value at a location in the array
  98.  
  99.   mux0array[i] = analogRead(0);
  100.  
  101.   }
  102.  
  103.  
  104.  
  105.   //This for loop is used to scroll through the SECOND multiplexer
  106.  
  107.   for (int i=0; i<16; i++)
  108.  
  109.   {
  110.  
  111.   digitalWrite(CONTROL0, (i&15)>>3);
  112.  
  113.   digitalWrite(CONTROL1, (i&7)>>2);
  114.  
  115.   digitalWrite(CONTROL2, (i&3)>>1);
  116.  
  117.   digitalWrite(CONTROL3, (i&1));
  118.  
  119.   mux1array[i] = analogRead(1);
  120.  
  121.   }
  122.  
  123.  
  124.  
  125.   //This for loop is used to scroll through the THIRD multiplexer
  126.  
  127.   for (int i=0; i<16; i++)
  128.  
  129.   {
  130.  
  131.   digitalWrite(CONTROL0, (i&15)>>3);
  132.  
  133.   digitalWrite(CONTROL1, (i&7)>>2);
  134.  
  135.   digitalWrite(CONTROL2, (i&3)>>1);
  136.  
  137.   digitalWrite(CONTROL3, (i&1));
  138.  
  139.   mux2array[i] = analogRead(2);
  140.  
  141.   }
  142.  
  143.  
  144.  
  145.   //The following lines are for printing out results of array0
  146.  
  147.   Serial.print("mux0array: ");
  148.  
  149.   for (int i=0; i<16; i++)
  150.  
  151.   {
  152.  
  153.   Serial.print(mux0array[i]);
  154.  
  155.   Serial.print("-");
  156.  
  157.   }
  158.  
  159.   Serial.println(); //line feed
  160.  
  161.  
  162.  
  163.   //The following lines are for printing out results of array1
  164.  
  165.   Serial.print("mux1array: ");
  166.  
  167.   for (int i=0; i<16; i++)
  168.  
  169.   {
  170.  
  171.   Serial.print(mux1array[i]);
  172.  
  173.   Serial.print("-");
  174.  
  175.   }
  176.  
  177.   Serial.println();
  178.  
  179.  
  180.  
  181.   //The following lines are for printing out results of array2
  182.  
  183.   Serial.print("mux2array: ");
  184.  
  185.   for (int i=0; i<16; i++)
  186.  
  187.   {
  188.  
  189.   Serial.print(mux2array[i]);
  190.  
  191.   Serial.print("-");
  192.  
  193.   }
  194.  
  195.   Serial.println();
  196.  
  197.  
  198.  
  199.  }