I struggle to get a very simple multiplexing example working and would like to ask for some help. After setting up everthing I get random readings from the analog pin which receives the output of the mux (values averaging around 500).
The setup is very simple: a poti is connected to the first input of a mux (using sparkfuns CD74HC4067 analog mux). The mux output is connected to A0 of my Arduino Uno. I made sure everything else is wired up correctly as well. Here is the schematic:
//Mux control pins
int MUXPIN0 = 8;
int MUXPIN1 = 9;
int MUXPIN2 = 10;
int MUXPIN3 = 11;
//Mux in "SIG" pin
int MUXPINSIG = A0;
int readMux(){
digitalWrite(MUXPIN0, LOW);
digitalWrite(MUXPIN1, LOW);
digitalWrite(MUXPIN2, LOW);
digitalWrite(MUXPIN3, LOW);
//read the value at the SIG pin
return analogRead(MUXPINSIG);
}
void setup() {
// setup mux
pinMode(MUXPIN0, OUTPUT);
pinMode(MUXPIN1, OUTPUT);
pinMode(MUXPIN2, OUTPUT);
pinMode(MUXPIN3, OUTPUT);
digitalWrite(MUXPIN0, LOW);
digitalWrite(MUXPIN1, LOW);
digitalWrite(MUXPIN2, LOW);
digitalWrite(MUXPIN3, LOW);
// Begin serial communication at a baud rate of 9600:
Serial.begin(9600);
}
void loop() {
Serial.print("value = ");
Serial.print(readMux());
Serial.println("");
delay(500); //Delay 500 ms.
}
Further notes:
unused inputs: for analog inputs this should be fine (see here) but I made a test where I connected all unused input pins to ground
connecting the poti output to A0 directly works as expected
the example is inspired by this example and I am doing it exactly like this
I am running out of ideas for debugging this. Any hints or comments would be appreciated.
Paul__B:
If you have that actual layout depicted, do the common supply and ground strips happen to have a break in the middle?
Thanks for your message. I think they are going through. Otherwise the direct connection from poti to A0 wouldn't work either. Also the breadboard lines for +- are going though which indicates that there are no breaks. Also here it seems to be like this too.
Well, it is arguable that - if you are just seeing random readings - the potentiometer is not actually connected to A0 as A0 is obviously floating.
Further that that I can't see. Haven't fully checked the code but have to get to work now.
And by the way, when you post a link, please do not click the "Prevent this page from creating additional dialogs" checkbox; this is just a nuisance for people trying to follow the links.
Erik_Baas:
If your breadboard looks like the one in the picture, you have to connect them yourself.
It won't hurt to try adding those links. But I'm pretty sure that David is correct. The markings on the BB indicate the rails are connected. As he said, if there was a break in the rails, connecting the pot directly to A0 would not work, but it does.
David, do you have another mux? I guess you would have tried it already if you had one.
Remove everything from the BB and rebuild the circuit on a different part of the BB, or a different BB, if you have one. Also I assume you are using Dupont cables? Test each one with a multimeter to check it has a resistance close to zero.
I hope that helps. I can't see a problem with your code or circuit. In your position I would think about placing an order for another mux.
Paul__B:
And David has now removed the image from the first post for some reason!
I used a shared image on dropbox which I referenced in my post. Apparently dropbox only returns a thumbnail of that image for a period of 4hours after sharing. Then it produces a #410 http error. Further I learned that my VPN does some quite heavy html caching
I moved the image to github. It should work again now.
I tried another mux and that produces the same result. I must be doing something inherently wrong. Will test with the meter once it arrives. Thansk for all the comments so far. Much appreciated!
I moved the image to github. It should work again now.
Don't do that, just attach the image to your post.
Will test with the meter once it arrives.
You can also test that the breadboard connections are working by testing the resistance between the top of one of the pins on the mux module and the far end of the dupont cable connected to it. That way, you are testing the cable and two BB connections at once. Anything over a few ohms is not normal. Do all tests with power disconnected!
Thanks everyone for trying to help me so far. I got the meter and the restistance values are fine (meaning: very low) indicating that there is no problem with the breadboard or the connections.
I considered adding a decoupling capacitor as suggested here but then realized that the breakout board I am using already has one. So I think it is save to assume that this is not the issue.
PaulRB:
So we still have a mystery problem to solve.
Can you post some clear, sharp, bright photos, so we can see where each wire is connected?
Have you soldered the pin headers to the mux module? Only pushing them in will not be reliable.
Thank you for your comment! That was it. How embarassing. I was under the impression that you can just put the breakoutboard on the pins but they indeed need to be soldered, or at least held tight. With that it worked. Thanks everybody and PaulRB in particular!
Paul__B:
Well, it is arguable that - if you are just seeing random readings - the potentiometer is not actually connected to A0 as A0 is obviously floating.
OK, this is not the first time this has happened here, not the second and not the third (or fourth) either I fancy.
Hopefully we will get it right inside a dozen replies next time.
Why is it so difficult for us "oldies" to figure such things? I suppose we just instinctively know what it means to electrically connect something.