Multiplexing 8 analog inputs using a CD4051B - Page 6
Page 6 of 6 FirstFirst ... 23456
Results 51 to 57 of 57
  1. #51
    Tech Wizard Brinx's Avatar
    Join Date
    Jun 2011
    Location
    Stockholm, Sweden
    Posts
    45

    Default

    @ Guywithknife

    Thank you so much!
    This will be extremely helpful when i get to the programming part!
    Im very interested in the instant midi channel changing part of your script.

  2. #52

    Default

    Quote Originally Posted by Fatlimey View Post
    Using a 16-way multiplexer like the 74HC4067 it should be simple enough.

    http://www.nxp.com/documents/data_sh...HC_HCT4067.pdf

    The 4 digital inputs to the chip would be the 4 digital pins of the Midifighter, so if you do this you get 16 analog inputs and no digital switches. If you want 16 inputs as well as additional switches it gets a lot more complicated and relies on you setting up an SPI bus on the digital pins and serially controling a pair of devices hanging off the same bus, or setting up a software-based I2C bus and addressing devices by bus number.

    At least if you do that then adding LEDs is simply another device on the chain.
    Is it possible to "stack" these 16 way multiplexers on the data pins to allow 64 total analog inputs to the 4 analog input spots on the MF board? I see that's how sidetrakd got 32 analog inputs for his build using 8 way multiplexers. The design I'm contemplating would need more than 32 analog inputs though.

    edit: nevermind, answered my own question: http://www.djtechtools.com/forum/sho...3&postcount=56
    Last edited by einsteinx2; 01-13-2012 at 05:48 PM.

  3. #53
    Newbie
    Join Date
    Dec 2012
    Location
    New York
    Posts
    4

    Default

    Hi guys,

    New to the forum. Very interesting topic, I was working on a multi-fader controller with Teensy and the multiplexer IC. I saw mention of Limey's Teensy code on here. Is that public anywhere? Would love to play around with it if it is

  4. #54
    Tech Mentor
    Join Date
    Apr 2011
    Location
    Ireland
    Posts
    114

    Default

    Hi awacs,

    Not sure if fatlimey has teensy code or where it is (too lazy to search), but what are you trying to do? I may be able to lend a hand. Not sure if I have any multiplexers handy, but I have a couple of teensy's and I remember the CD4051B being incredibly simple to use.

    Actually, they really are not hard to use once you have them wired up correctly:

    They have three digital inputs, a common in/out and a number of multiplexed in/out pins (8 I think it was?). Connect the common in/out to one of the teensy's analogue pins. Connect the multiplexed pins to the faders. Connect the three digital pins to three of the teensy's general purpose pins. Configure the analogue pin as an input and the three digital pins as outputs.

    Now your teensyduino code looks something like this (untested and off the top of my head, so please excuse typos and memory lapses):

    Code:
    int readFader (int fader_number) {
        // Select the fader from the multiplexer
        digitalWrite(MUX_DIGITAL_1, fader_number & 0x1 != 0);
        digitalWrite(MUX_DIGITAL_2, fader_number & 0x2 != 0);
        digitalWrite(MUX_DIGITAL_3, fader_number & 0x4 != 0);
        // Read the analogue value
        return analogRead(MUX_ANALOG_PIN);
    }
    And to use:

    Code:
    for (int fader = 0; fader < 8; fader++) {
        Serial.print("Fader ");
        Serial.print(fader + 1);
        Serial.print(" = ");
        Serial.println(readFader(fader));
    }
    Hope that helps!

  5. #55
    Newbie
    Join Date
    Dec 2012
    Location
    New York
    Posts
    4

    Default

    Was looking at this code from Mayhew, wasn't quite sure how the bitwise operator and & functionality was working to scan through the multiple inputs...

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

    /*
    This example shows how to read and store all 48 pins as analog inputs into arrays and print the results over serial.
    Multiplexer pin inputs that do not have a voltage reading (i.e nothing connected) will have erratic values.

    To simplify this code further, one might use nested for loops or function calls.
    */

    //Give convenient names to the control pins
    #define CONTROL0 5
    #define CONTROL1 4
    #define CONTROL2 3
    #define CONTROL3 2

    //Create arrays for data from the the MUXs
    //See the Arduino Array Reference: http://www.arduino.cc/en/Reference/Array
    int mux0array[16];
    int mux1array[16];
    int mux2array[16];

    void setup()
    {
    //Set MUX control pins to output
    pinMode(CONTROL0, OUTPUT);
    pinMode(CONTROL1, OUTPUT);
    pinMode(CONTROL2, OUTPUT);
    pinMode(CONTROL3, OUTPUT);

    //Open the serial port at 28800 bps
    Serial.begin(28800);
    }


    void loop()
    {
    //This for loop is used to scroll through and store the 16 inputs on the FIRST multiplexer
    for (int i=0; i<16; i++)
    {
    //The following 4 commands set the correct logic for the control pins to select the desired input
    //See the Arduino Bitwise AND Reference: http://www.arduino.cc/en/Reference/BitwiseAnd
    //See the Aruino Bitshift Reference: http://www.arduino.cc/en/Reference/Bitshift
    digitalWrite(CONTROL0, (i&15)>>3);
    digitalWrite(CONTROL1, (i&7)>>2);
    digitalWrite(CONTROL2, (i&3)>>1);
    digitalWrite(CONTROL3, (i&1));

    //Read and store the input value at a location in the array
    mux0array[i] = analogRead(0);
    }

    //This for loop is used to scroll through the SECOND multiplexer
    for (int i=0; i<16; i++)
    {
    digitalWrite(CONTROL0, (i&15)>>3);
    digitalWrite(CONTROL1, (i&7)>>2);
    digitalWrite(CONTROL2, (i&3)>>1);
    digitalWrite(CONTROL3, (i&1));
    mux1array[i] = analogRead(1);
    }

    //This for loop is used to scroll through the THIRD multiplexer
    for (int i=0; i<16; i++)
    {
    digitalWrite(CONTROL0, (i&15)>>3);
    digitalWrite(CONTROL1, (i&7)>>2);
    digitalWrite(CONTROL2, (i&3)>>1);
    digitalWrite(CONTROL3, (i&1));
    mux2array[i] = analogRead(2);
    }

    //The following lines are for printing out results of array0
    Serial.print("mux0array: ");
    for (int i=0; i<16; i++)
    {
    Serial.print(mux0array[i]);
    Serial.print("-");
    }
    Serial.println(); //line feed

    //The following lines are for printing out results of array1
    Serial.print("mux1array: ");
    for (int i=0; i<16; i++)
    {
    Serial.print(mux1array[i]);
    Serial.print("-");
    }
    Serial.println();

    //The following lines are for printing out results of array2
    Serial.print("mux2array: ");
    for (int i=0; i<16; i++)
    {
    Serial.print(mux2array[i]);
    Serial.print("-");
    }
    Serial.println();

    }

  6. #56
    Newbie
    Join Date
    Dec 2012
    Location
    New York
    Posts
    4

    Default

    I was working through this code, wasn't quite sure how the input select bit shift operator and & operator were working. It seems as a filter, but a bit unclear for me..






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

    /*
    This example shows how to read and store all 48 pins as analog inputs into arrays and print the results over serial.
    Multiplexer pin inputs that do not have a voltage reading (i.e nothing connected) will have erratic values.

    To simplify this code further, one might use nested for loops or function calls.
    */

    //Give convenient names to the control pins
    #define CONTROL0 5
    #define CONTROL1 4
    #define CONTROL2 3
    #define CONTROL3 2

    //Create arrays for data from the the MUXs
    //See the Arduino Array Reference: http://www.arduino.cc/en/Reference/Array
    int mux0array[16];
    int mux1array[16];
    int mux2array[16];

    void setup()
    {
    //Set MUX control pins to output
    pinMode(CONTROL0, OUTPUT);
    pinMode(CONTROL1, OUTPUT);
    pinMode(CONTROL2, OUTPUT);
    pinMode(CONTROL3, OUTPUT);

    //Open the serial port at 28800 bps
    Serial.begin(28800);
    }


    void loop()
    {
    //This for loop is used to scroll through and store the 16 inputs on the FIRST multiplexer
    for (int i=0; i<16; i++)
    {
    //The following 4 commands set the correct logic for the control pins to select the desired input
    //See the Arduino Bitwise AND Reference: http://www.arduino.cc/en/Reference/BitwiseAnd
    //See the Aruino Bitshift Reference: http://www.arduino.cc/en/Reference/Bitshift
    digitalWrite(CONTROL0, (i&15)>>3);
    digitalWrite(CONTROL1, (i&7)>>2);
    digitalWrite(CONTROL2, (i&3)>>1);
    digitalWrite(CONTROL3, (i&1));

    //Read and store the input value at a location in the array
    mux0array[i] = analogRead(0);
    }

    //This for loop is used to scroll through the SECOND multiplexer
    for (int i=0; i<16; i++)
    {
    digitalWrite(CONTROL0, (i&15)>>3);
    digitalWrite(CONTROL1, (i&7)>>2);
    digitalWrite(CONTROL2, (i&3)>>1);
    digitalWrite(CONTROL3, (i&1));
    mux1array[i] = analogRead(1);
    }

    //This for loop is used to scroll through the THIRD multiplexer
    for (int i=0; i<16; i++)
    {
    digitalWrite(CONTROL0, (i&15)>>3);
    digitalWrite(CONTROL1, (i&7)>>2);
    digitalWrite(CONTROL2, (i&3)>>1);
    digitalWrite(CONTROL3, (i&1));
    mux2array[i] = analogRead(2);
    }

    //The following lines are for printing out results of array0
    Serial.print("mux0array: ");
    for (int i=0; i<16; i++)
    {
    Serial.print(mux0array[i]);
    Serial.print("-");
    }
    Serial.println(); //line feed

    //The following lines are for printing out results of array1
    Serial.print("mux1array: ");
    for (int i=0; i<16; i++)
    {
    Serial.print(mux1array[i]);
    Serial.print("-");
    }
    Serial.println();

    //The following lines are for printing out results of array2
    Serial.print("mux2array: ");
    for (int i=0; i<16; i++)
    {
    Serial.print(mux2array[i]);
    Serial.print("-");
    }
    Serial.println();

    }

  7. #57
    Newbie
    Join Date
    Dec 2012
    Location
    New York
    Posts
    4

    Default

    I've been trying to figure out the select code from Mayhew. The bit shift and & operation seems a bit confusing to me. Not quite sure what is being done. I tried posting this as code, how do you guys do that? Also, am I getting the posting question cause im a newbie?

    http://mayhewlabs.com/code/Mux_Shiel...In_Example.pde

Page 6 of 6 FirstFirst ... 23456

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •