(4051) Analog Multiplexer / DeMultiplexer library update

Hi all,

I had some time this weekend to hit off a task that had been sitting on my TODO for a while and @spoocter asked me nicely as well so I decided to update my 4051 Analog Mux/Demux library.

Besides a stack of clean up after having written a lot more Arduino code over the last 18 months, it's now got the ability to use multiple multiplexers in a daisy chain. Just wire them up, call a constructor with the master and slave pins and then just index away to read or write to the pin (up to 64 now with 9 4051s daisy chained).

There's also some new and updated examples including the multi multiplexer set up.

If anyone is keen to wire up 64 LEDs and write a demo for doing that I do accept pull requests :stuck_out_tongue_winking_eye:

As always any feedback greatly appreciated and feel free to fork (and pull request!) and log any issues over on GitHub.

Cheers
ajfisher

Hi,

I've been looking around but i'm a bit lost using IC 4051.
Can you share a scheme for a matrix buttons input?
I try to follow this: Arduino Playground - HomePage
but i didn't understand very well. Its a bit confuse.

If you have, please share a circuit diagram. Thanks!

Dear All,

first of all, sorry if my question had been posted before, but I'm not able to search.

I have 2 IC 4051 and I wanted to build a input matrix to connect 16 switchs.

I've searched all google, but didn't get any luck.
I only found this: Arduino Playground - HomePage
but I didn't understand it.

Does any of you have a sample scheme / code for a input matrix with two IC 4051?

My main goal, is to have the 16 inputs, and get the button pressed result on serial.print.
Like: you press button number X

Thanks for your support.

Have a nice day.

HI John.

What are you trying to do? I couldn't really understand from your post.

Are you just using a single 4051 to mux some buttons coming in or are you trying to chain them so you can have like 64 buttons off one analog input.

If you give me some context / explain how you're using it I can probably give you some more firm direction.

Cheers
Andrew

Hi,
thanks for your fast reply. (Sorry, English is not my native language)

I will try to explain my project, I believe it will be easier for you understand.

I want to connect a dart board to PC.

This is the only project similar I found. http://www.martinpersson.org/wordpress/2010/08/electronic-darts-board-to-pc/

I was following this scheme: http://www.martinpersson.org/wordpress/2011/02/dartboard-circuit-layout/ but I'm a bit lost with connections.

The dart board have 2 flat sheets, like a keyboard. They touch each other on press and close the circuit.
http://dart.martinpersson.org/dart8.jpg

I want to connect this connectors: http://dart.martinpersson.org/dart6.jpg
to arduino.
I want to use two IC 4051 to be able to connect that connectors and make an input switch matrix.

The connector have 10 pints, and we can only have 8 pins on IC4051 but, i think i can connect the other pins directly to arduino.

Please, let me know if you need any more information.

Thanks for your support.

Okay that makes more sense now.

So if you have 2 4051s and you want 16 inputs then there's pretty much only one way to attack this.

You have the 4051s separately and run each of them into a separate analog pin (if you want an analog reading on your button. If it's a push button then you can just attach it to a digital pin for reading as you're only checking on off statement).

Now you'll need to look at your data sheet for your pin out but essentially you end up with Vcc and GND, Vee you attach to ground as well.

Then you have what might be marked as INH or E - This is the input/output selector pin. This is USUALLY attached to ground if you want the 4051 to work as an INPUT. If you push it HIGH then it will work as an output instead.

Beyond that you'll have two sets of pins, one set of three usually marked as A, B and C and then another set marked 0 - 7.

The 0-8 are your inputs or outputs (depending on whether you set INH LOW or HIGH). They are what you connect your buttons to. I'm just going to call these pins inputs from now on for simplicity.

The 3 control pins are used to select which of the 8 inputs you want to switch to and then measure. These work as three binary values which collectively work together to create a 3 bit integer (providing the range 0-7).

Your data sheet will have the details of which pin represents each bit.

The last pin we haven't looked at yet, usually called Z or Out/In, is the one you connect to the arduino that you are going to read.

So once you know what your IC looks like, grounded the pins that need grounding, added +5v to the Vcc and wired up your buttons, and put the Z line to an Arduino input, you just need to set up your A, B, C pins to three digital outs on the Arduino to control the switching.

At this point I'll point you to this example in my library: arduino-analog-multiplexer/MuxPot.ino at master · ajfisher/arduino-analog-multiplexer · GitHub which uses potentiometers on three inputs to demonstrate connecting and reading the value.

Replace the pots with buttons, and make it 8 instead of 3 and you've pretty much got what you need. The library I built makes this dead simple and means you don't need to worry about the bit manipulation etc.

Really the key is to check your data sheet to orient yourself to the pin out and then use the concepts I've described above.

Cheers
Andrew

Thanks for this reply. It was very kind from you to take your time to give me an help.

I'm much clear now, soon as I get home I will make some tests.
Do you have any schematic of the potentiometers or something that I can follow to connect the buttons?
Any way, I will try to make this by myself and I will post my schematic and the code for debugging.

Once again, thanks for your help.

PS. I was able to follow the schematic of the 3 leds and make them to work with one IC4051.

Hi,

yesterday I started my first attempt of connecting the dartboard to arduino.
The problem I found, was the delay reading the value from the dart when hits the dartboard.
I was using the keypad library. The arduino have to scan all ROWS and COLS, scan one by one.
The problem is, sometimes, when the dart hits the dartboard, the arduino can cacth it. (The circuit is closed and opened very fast). Other times doesn't.
If I'm not wrong, arduino must read the correct ROW and COL at the exact time that the circuit is closed, when the dart hited the board.

Any suggestion?

Thanks!

Your dartboard is not going to signal for enough time for the arduino to read it.

Exactly!
But do you know any way to by pass it?
How can I solve that problem?