4
\$\begingroup\$

I am trying to get a Multiplexer to work with the Arduino. Description at sparkfun Datasheet

I thought the wiring was pretty simple and as a basic test, I have AREF connected to C1(multiplexer) and a floating wire connected to C0. Everything on the interfacing side maps almost 1 to 1 with the arduino.

I am using this simple code for switching the multiplexer

void select_wire(char which){
    digitalWrite(S0,which&0x01);
    digitalWrite(S1,which&0x02);
    digitalWrite(S2,which&0x04);
    digitalWrite(S3,which&0x08);
    digitalWrite(EN,0);
    delay(1); //required?
}

and then I just read from the Analog pin at S on the multiplexer. My problem is that it is not switching! How do I fix this so that it will behave as intended and give a zero(or close) whenever I do select_wire(1) and read the analog pin?

Also, I am not using the Wiring "language" but I am using the Wiring library. I have also set all the appropriate pinModes in the init

\$\endgroup\$
  • \$\begingroup\$ If pin C0 floats HIGH and C1 is connected to AREF which is also HIGH, then there shouldn't be any change. Did you try connecting C1 to ground to get zero when you run select_wire(1)? \$\endgroup\$ – rzrgenesys187 Apr 19 '10 at 3:31
  • \$\begingroup\$ @rzr oh wait... yea, you may be right. I got confused and thought AREF was ground(and thus, 0)... yea I'll look into this tonight.. Also, you should've just made your comment an answer :) \$\endgroup\$ – Earlz Apr 19 '10 at 18:55
  • \$\begingroup\$ Didn't seem good enough for an actual answer :) \$\endgroup\$ – rzrgenesys187 Apr 20 '10 at 2:39
3
\$\begingroup\$

As rzrgenesys187 said:

If pin C0 floats HIGH and C1 is connected to AREF which is also HIGH, then there shouldn't be any change. Did you try connecting C1 to ground to get zero when you run select_wire(1)?

Yea, so it actually was switching the entire time.. however, there is a lot more distortion, so the wire connected to ground floated somewhere in the 10s. And AREF isn't high, so I don't understand how that works. AREF for me gave about the same values as ground when using

analogReference(DEFAULT);

so not sure why, but AREF is giving me near-ground values... very strange, but the MUX does infact switch, so this question is answered.. and I actually never had any problems.. meh.

EDIT:

Actually, hooking straight into AREF does make it the input go high to 1023, so I have no idea why the input won't go that high with the MUX. maybe some kinda voltage limit, idk. I have to read up on it..

EDIT2:

Ok, finally think I'm figuring it out. Apparently breadboards leak a lot of current, so that if I was connected to C0 and it was reading C1, then a lot of voltage would leak to C1. Anyway though, connecting to AREF to C3 makes both inputs go high, so now I'm just even more confused.

\$\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.