I am using an IC that has a data input of 8 bit. Instead of using 8 pins on my Arduino I want to use a multiplexer.
So I connected it in the same way it's here: http://www.arduino.cc/es_old/Tutoriales/74HC4051
but instead of doing a analogRead at the end, I do a digitalWrite to the "COM OUT/IN" pin on the multiplexer. And when trying to write a certain 8 bit value it doesn't work.
I did a test reading a control pin on the multiplexer outputs but it's not even stable, it's erratic.
Is it possible to use this multiplexer in the way I want? What's wrong????
oh... ok, so a multiplexer cannot be used to write?
There is the problem then, hehe. I thought it could be used for reading as well as writing.
I would need to use a shift register then, right?
The 74HC/HCT4051 are 8-channel analog
multiplexers/demultiplexers with three digital select inputs
(S0to S2), an active LOW enable input (E), eight
independent inputs/outputs (Y0to Y7) and a common
input/output (Z).
What I want to do is write on 8 different pins by using the multiplexer, one at a time by writing each time the selector value and then the pin value. Am I that wrong?
It's an "8-channel" multiplexer, not an "8-bit" multiplexer, which implies something
different [although I'm not sure what that would even be].
You can connect only 1 channel at a time, and it doesn't latch, so as soon as you
switch to another channel, the signal to the previous channel will no longer
be valid [ie, floats]. You can use it to read input lines.
If you want to write to 8 pins you will want to use an 8-bit latch, which will have
3 pins for channel select, plus a Din pin [hi/low].
It is not simple to both read and write to 8 pins, to do that you will need a latch
with ability to set the output channels to hi-Z, as well as a another chip to
do the reads. Even worse, most latches will not allow you set individual pins
to hi-Z, but do all pins at the same time.
If you look at the info on the I/O pins in the mega328 d/s, you'll see they have a
lot of circuitry for individual pin control. You would have to emulate something
like that in order to allow individual pins to be either input or output at the
time.
A shift register will work, although you want to be careful that
you're not sending flukey signals to the output pins as you're shifting
the 8-bits through the device.
I've tinkered a little with 4051 chips and had to put a high value resistor on the control pins to ground to prevent them from floating, causing some erratic behavior. Below is a 16 channel version.
Only a total idiot would use a 4051 to write data to each of its outputs. There are a lot of idiots on the web.
The example you showed was reading LDRs.
Normally the shift registers are latched so you don't have to worry about values changing as you shift them along.
I have used the 16-channel 4067 with good success to allow a high-accuracy, single channel ADC make its readings. Another option would have been using multiple ADCs but there were board space considerations. Plus, with 16 input channels and only a need for 11 inputs, I could set aside 5 channels for reference resistors - thus allowing calibration and verification.
I am using the 74HC4051 multiplexor and I connected 3 buttons and 2 pots to it.
I am getting very erratic readings on the pots, it might be accurate enough to use it for buttons, but not for the pot.
For example, I select channel 0 (0,0,0) for reading A0 wich is connected to the pot, I spin the pot to the maximum value and the output is this:
Also, if I press one of the buttons the reading is higher, if I press the 3 buttons at the same time more.
Maybe I need to use one multiplexor for the pots and another for the buttons???
As a test I connected every input from the multiplexor to the ground except a potentiometer.
*When I select one of the ground channels (A1-A7) it gives a reading of 47-49 when the pot is at maximum or at minimum, it's affecting it very little to nothing.
*When I select the pot channel (A0) and set the pot to minimum it gives me this:
Are you using a three-legged potentiometer as described here? If not, that could be your problem. A pot that doesn't feature a wiper + two other terminals will require a drop-down resistor of the right value to work as expected.
I've noticed that using or not the multiplexer when I press any button connected on the board the reading gets a little higher, that might be interference with the board I'm using, is not really a problem at this point.
But the weird thing is that it seems that the multiplexer every time in a while changes the channel it's reading
Unpredictable outputs may occurr with a 4051 type chip (this is the chip I have experimented with) when the input control lines (A, B, C, and D in the post) are either not driven at ~5v input or not connected to ground.
If the arduino digital output pins do not sink to ground when in the "low" state, then the control lines to the multiplex chip may "float" and produce undesired results.
Old post showing a possible parallel setup instead of using a shift regester: