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!
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 = pin13Serial.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