4067 Analog Multiplexer (again)

Hello guys (and gals for that matter)

1stly, I'm a complete novice when it comes to programming so please excuse me if I don't know the terminology and such and sometimes just comes forward as plain stupid! :-[ Oh-yes, English isn't my 1st language to top it all off! :wink:
Now with that out of the way, I'm busy designing a Online PC Data Recorder with the Arduino to monitor a stationary diesel Engine and Generator for various conditions like Temperatures, RPM, Pressures, Volts, Amps, exec.
I've decided to use analog sensors with a 0-5Vdc scale for data input and obviously I ran out of Analog I/O channels.
I found the 4067 multiplexer threads on this forum and some code to run it from the links provided in them.
I build an extension board with the IC & 16ch connectors on it plus a few odds and ends, and got it connected to the Arduino.
I modified the code I found on the web a bit to suit my needs, but for the live of me I cannot get it to work correctly! I even tried the code as-is when I found it, but still no go.
Could someone please have a look at the code and the cct diagram below and try and help?
At the moment it just serial print the channel number, address selector output and channel value to the port so that I can see what its doing. When I plug a LM35 Temp sensor in the 1st channel I get a reading on ch0&4, the other inputs are all over the place and some don't even register! Also right at the bottom of this post is a screen capture of the com monitor screen.

/*
16 Channel Analog Extender for Arduino
*/

int ChActive = 16; // The number of channels active.
int ChNumber = 0; // Keeping count of the channel number to read.
int ChValues[15]; // Store channel value in Array here (NOT used yet)

// Set Analog I/O pin to use for reading channel values from multiplexer.
int ComIOpin = 0; // HEF4067BP(X)(ICpin-01)

// Set Address Outputs to Multiplexer
int AdrOutD = 0;
int AdrOutC = 0;
int AdrOutB = 0;
int AdrOutA = 0;

// Set which pins tell the multiplexer which input to read from.
int DpinA0 = 10; // HEF4067BP Address Input A0 (A)(ICpin-10)
int DpinA1 = 11; // HEF4067BP Address Input A1 (B)(ICpin-11)
int DpinA2 = 12; // HEF4067BP Address Input A2 (C)(ICpin-14)
int DpinA3 = 13; // HEF4067BP Address Input A3 (D)(ICpin-13)

void setup() {

// Set the digital pins to outputs.
pinMode(DpinA0, OUTPUT); // HEF4067BP Address Input A = pin10
pinMode(DpinA1, OUTPUT); // HEF4067BP Address Input B = pin11
pinMode(DpinA2, OUTPUT); // HEF4067BP Address Input C = pin12
pinMode(DpinA3, OUTPUT); // HEF4067BP Address Input D = pin13

Serial.begin(115200); // Set Serial COMM's to PC
}

void loop() {

Serial.println("Start of reading"); // Serial print START of reading through channels
Serial.println("Ch \tD C B A \tVal "); // Print description of data.

// Loop through the channels and read each one.
for (ChNumber = 0; ChNumber < ChActive; ChNumber++) {

// Generate Address Inputs for HEF4067BP A0 to A3 (pin 10 to 13)
AdrOutA = ((ChNumber & 1)); // Create 1st bit for Address A0(A)
AdrOutB = ((ChNumber & 3) >> 1); // Create 2nd bit for Address A1(B)
AdrOutC = ((ChNumber & 7) >> 2); // Create 3rd bit for Address A2(C)
AdrOutD = ((ChNumber & 15) >> 3); // Create 4th bit for Address A3(D)

// Send current Address Output to Multiplexer
digitalWrite(DpinA0, AdrOutA); // bit 1
digitalWrite(DpinA1, AdrOutB); // bit 2
digitalWrite(DpinA2, AdrOutC); // bit 3
digitalWrite(DpinA3, AdrOutD); // bit 4

// Print current Channel Number
Serial.print(ChNumber, DEC); // Print Current Channel number in decimal
Serial.print("\t"); // Print TAB

// Print current Address Output in reverse for binary to Serial Port.
Serial.print(AdrOutD, DEC); // HEF4067BP Address Input D
Serial.print(" "); // Print SPACE
Serial.print(AdrOutC, DEC); // HEF4067BP Address Input C
Serial.print(" "); // Print SPACE
Serial.print(AdrOutB, DEC); // HEF4067BP Address Input B
Serial.print(" "); // Print SPACE
Serial.print(AdrOutA, DEC); // HEF4067BP Address Input A
Serial.print(" \t"); // Print TAB

// Read the common I/O pin value for current channel and send to serial port.
Serial.print(analogRead(ComIOpin), DEC);

if(ChNumber < (ChActive - 1)) { // Step through all channels until end
Serial.println(""); // Continue next Print from next line.
}
else {

Serial.println(""); // Continue next Print from next line.
Serial.println("End of reading"); // Serial print END of reading through channels
}
}
// Take delay to give me a change to monitor Serial Output (1000 = 1sec)
delay(3000); // Wait a while before starting over
}

Here is an attached PDF cct diagram of my extender board:
http://stashbox.org/714871/16ch%20Analog-IN%20Extender.sch.pdf

and screen capture of the com monitor:

Thanks all, any help will be greatly appreciated!
dubbleUJay

Please post code between the brackets that pop up when you hit this hash icon.

Like a compiler I stopped at the first error I spotted:-

 // Generate Address Inputs for HEF4067BP A0 to A3 (pin 10 to 13)
    AdrOutA = ((ChNumber & 1));        // Create 1st bit for Address A0(A)
    AdrOutB = ((ChNumber & 3) >> 1);   // Create 2nd bit for Address A1(B)
    AdrOutC = ((ChNumber & 7) >> 2);   // Create 3rd bit for Address A2(C)
    AdrOutD = ((ChNumber & 15) >> 3);  // Create 4th bit for Address A3(D)

You have the masks wrong, you want only a logic 1 in the bit you want to detect.

 // Generate Address Inputs for HEF4067BP A0 to A3 (pin 10 to 13)
    AdrOutA = ((ChNumber & 1));        // Create 1st bit for Address A0(A)
    AdrOutB = ((ChNumber & 2) >> 1);   // Create 2nd bit for Address A1(B)
    AdrOutC = ((ChNumber & 4) >> 2);   // Create 3rd bit for Address A2(C)
    AdrOutD = ((ChNumber & 8) >> 3);  // Create 4th bit for Address A3(D)

Indecently it is a bit of a rubbish way of doing it but maybe it has the advantage of being simple minded.

Thank you Grumpy_Mike!
Sorry about the way I posted the code, but that was my 1st time and I did it from the Arduino software, I'm still not to sure what you mean, I will check next time I post code.

The masking error was a stupid mistake on my side, but I suppose that's what you get for cut&past someone else code and I didn't know EXACTLY what it did! It came from a 4x 16ch multiplexer project, hence the bigger numbers :-[
So, I've done the changes, but still it gives me incorrect channels. I've got all the inputs "open" and I'm inserting a LM35 temp probe into the one by one and this is what happens:
probe in XX, reading on XX
ch0---ch0&2
ch1---ch1&3
ch2---none
ch3---none
ch4---ch4&6
ch5---ch5&7
ch6---none
ch7---none
ch8---ch8&10
ch9---ch9&11
ch10---none
ch11---none
ch12---ch12&14
ch13---ch13&15
ch14---none
ch15---none
Obviously there's a pattern, but I'm stumped, how can it read 2 channels when only one has a value?
As I said in my 1st post sir, I'm new to coding and something obvious to you guys might not be the same to me, so I'm sorry for the ignorance on my side! :-[
Also, if you have another better way of sending the "binary" to the multiplexer via the 4x D-ports, I'll gladly use it. :sunglasses:

Thanks again for your help thus far,
dubbleUJay
PS- I secretly wish "Human Compilers" can log & step over errors, but that's just me. :wink:

Sorry about the way I posted the code, but that was my 1st time and I did it from the Arduino software, I'm still not to sure what you mean, I will check next time I post code.

I've posted about this here http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1259327352

Jeroen

I've posted about this here http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1259327352

Gotcha!! That was easy enough, thanks! :wink: