Sorry if I posted in the wrong place. I picked this category because it had multiplexing in the name.
I'm working on a project where I hope to use an Uno R3 to make resistance measurements for a cable assembly. Of course, this will be a calculated resistance via a voltage divider. Unfortunately, I can't seem to get the MUX board to work reliably.
I'm using a 16-channel analog multiplexer breakout package based on the 74HC4067. The data reported has little if anything to do with the input value. I can set it for 5V or ground and get the same crazy outputs.
Here is the setup. It's everywhere so I copied it from somewhere:
Here is the code I'm using. I've tried so many different variations on the same code I can't remember how many examples I've tried:
`
// 74HC4067 multiplexer (16 to 1)
// control pins output table in array form
// see truth table on page 2 of TI 74HC4067 data sheet
// connect 74HC4067 S0~S3 to Arduino D7~D4 respectively
// connect 74HC4067 pin 1 to Arduino A0
byte controlPins[] = {B00000000,
B10000000,
B01000000,
B11000000,
B00100000,
B10100000,
B01100000,
B11100000,
B00010000,
B10010000,
B01010000,
B11010000,
B00110000,
B10110000,
B01110000,
B11110000 };
// holds incoming values from 74HC4067
byte muxValues[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,};
void setup()
{
Serial.begin(9600);
DDRD = B11111111; // set PORTD (digital 7~0) to outputs
}
void setPin(int outputPin)
// function to select pin on 74HC4067
{
PORTD = controlPins[outputPin];
}
void displayData()
// dumps captured data from array to serial monitor
{
Serial.println();
Serial.println("Values from multiplexer:");
Serial.println("========================");
for (int i = 0; i < 16; i++)
{
Serial.print("input I");
Serial.print(i);
Serial.print(" = ");
Serial.println(muxValues[i]);
delay(50);
}
Serial.println("========================");
}
void loop()
{
for (int i = 0; i < 16; i++)
{
setPin(i); // choose an input pin on the 74HC4067
delay (500);
muxValues[i]=analogRead(0); // read the vlaue on that pin and store in array
// int val = analogRead(0);
//muxValues[i]=(val * 5.0) / 1024.0;
//muxValues[i] = val;
}
// display captured data
displayData();
delay(2000);
}
I've tried different modules, two different Uno boards, and wired and rewired everything multiple times.
Here is what I know:
- The program is setting the binary address properly. I verified it with LEDs.
- Placing 5 VDC or 3.3 VDC on the channel doesn't change anything. I've even tied all unused channels to ground with the same results.
- I'm getting similar results with all modules I try
- I get the same results if I set the binary address manually
- I've tried various pull-up resistors and even voltage dividers to see if it's an issue.
Here is an example of the output data I'm seeing:
It's never the same data twice. The boxed channel has a 5V input.
Usually, when this happens to me I smack my head because I missed something very obvious. I have asprin on stand-by for when someone tells me of an obvious solution.
Thanks!
Dave.