4
\$\begingroup\$

So Im following the diagram here for wiring up a MC14067BCP: http://fluidforms.eu/docs/MultiplexedArduinoWiringDiagram.pdf

The only difference being that I am doing one set of 16 sensors and not four. Additionally, my sensors are 5k - 250k LDRs (light sensitive resistors) that I have connected to ground on the end opposite of those connected to the connections shown in the diagram above.

When I run my sketch, the serial line shows output that is similar to what would be shown if no wires were connected to my analog in at all. (see the question here to see what I mean by that: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1238854387) This is really stressing me out and it would be amazing if someone could enlighten me as to what is going on.

Here is my code:

int CONTROLpin1 = 2;
int CONTROLpin2 = 3;
int CONTROLpin3 = 4;
int CONTROLpin4 = 5;
int analogPin = 0;


// Variables:
int actualSensorValue = 0;             // value from the analog input


void sendCommand(int value) {
  Serial.println(value);
}


void setup() {
  //  set the states of the I/O pins:
  pinMode(CONTROLpin1, OUTPUT);
  pinMode(CONTROLpin2, OUTPUT);
  pinMode(CONTROLpin3, OUTPUT);
  pinMode(CONTROLpin4, OUTPUT);
  pinMode(analogPin, INPUT); 

  Serial.begin(9600);
}


void loop() {
  int i;
  for (i=0; i <16; i++) {

    // set control pins on the multiplexers
    digitalWrite(CONTROLpin1, bitRead(i,0));//bit4
    digitalWrite(CONTROLpin2, bitRead(i,1));//bit3
    digitalWrite(CONTROLpin3, bitRead(i,2));//bit2
    digitalWrite(CONTROLpin4, bitRead(i,3));//bit1


    Serial.println(i); // print which pin we are on
    actualSensorValue = analogRead(analogPin);
    sendCommand(actualSensorValue);


    delay(1000); 
  }
}

Additionally, I have tried cutting it down to the bare minimum and only wiring up a single sensor. When looking at the output, there appears to be no change. Here is a picture of the bare bones wiring:

picture

(but to be clear my end goal is still the diagram at the top of this post).

\$\endgroup\$
  • 2
    \$\begingroup\$ Please post a schematic of your setup \$\endgroup\$ – clabacchio May 2 '12 at 8:20
  • \$\begingroup\$ @clabacchio it's the first link \$\endgroup\$ – bradleygriffith May 2 '12 at 8:24
  • 2
    \$\begingroup\$ Can you post a schematic of your single sensor setup ? \$\endgroup\$ – Rocketmagnet May 2 '12 at 8:27
  • \$\begingroup\$ will a picture do? i.imgur.com/IaTD1.jpg \$\endgroup\$ – bradleygriffith May 2 '12 at 8:30
  • 2
    \$\begingroup\$ That's the schematic you are trying to reproduce, but you are making changes, so I was asking the actual schematic. A picture may do, but the schematic is better \$\endgroup\$ – clabacchio May 2 '12 at 9:01
1
\$\begingroup\$

To do "multiplexing" you'd need some way to control the select line of the mux (which means an extra log base 2 inputs according to the number of sensors you have, so for 16 sensors you'd need four more outputs to control the select line). And you'd need a bunch of AND gates to select which mux channel you want to connect to the inputs.

If they had CS (Chip Select) pins themselves, you could avoid the gates. But you still have to worry about converting 4 outputs into 16 chip selects; could probably get a 4-bit decoder to do that.

I don't like any of those solutions, though. They're very messy. Personally, I would use a couple I2C input buffers and then wire all the inputs to those and then read the buffers with the Arduino. Easier to handle, and only uses two inputs on the Arduino. Easily extensible too, so long as you don't have any address conflicts.

\$\endgroup\$
  • \$\begingroup\$ +1 for the I2C buffer solution. If I recall correctly, the Microchip MCP23016 is the most popular part for this purpose. \$\endgroup\$ – Kevin Vermeer May 3 '12 at 16:33
1
\$\begingroup\$

The easiest way to connect lots of inputs to a micro using common parts is to use a shift register like a 74HC165 for each group of 8 bits. Tie the "/PL" wire of every shift register together, and do likewise for "CP". Those wires should go to one CPU pin each. Tie /CE of every device low. Tie the Q7 output of all but the last device to the DS wire of the next; the Q7 wire from the last device should tie to a third CPU pin. To read all the inputs, drive CP low, pulse PL low and then let it sit high. The Q7 wire from the last device will be the state that device's D7 input had when /PL went high. Pulse CP high and then low, and the Q7 wire from the last device will show the value its D6 input had when /PL went high. Pulse it again, D5, etc. After the last device's D0 has been output, the next pulse will output the previous device's D7, then D6, D5, etc. If you have 12 chips with 8 inputs each, 96 pulses will let you read the 96 inputs. This approach is expandable to any number of chips, with the only caveat being that one can't read the state of e.g. the 1000th input pin without reading the state of the other 999 first.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.