Pages: [1]   Go Down
Author Topic: Trying to get 4051 Mux/ Demux setup working -- HELP PLEASE  (Read 915 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

~All,

I'm fairly new at Arduino  / and am trying to learn by doing.   My current project is -- I am trying to build an application that reads about 20+ digital buttons.  I thought I would try to get a 4051 Mux/ Demux setup working with a series of 74HCT4051N's to experiment with.

My objective is to fully understand how to read (4) four momentary switches (and identify them from each other) and armed with that I can expand on my own. 

I am struggling with getting the basic understanding.  I have built the attached circuit. 

Trying to learn from examples below -- but they are confusing me quite a bit.

http://playground.arduino.cc/learning/4051
http://tomekness.files.wordpress.com/2007/02/analog_multiplexer_demultiplexer_4051.pdf

They are confusing me a good deal.

I understand that the muiltplexer / demux setup sequerntially runs throught the switches is suppose to reads the value for each button.  I haven't got that to work for me. 

Any pointers to get me headed in the right direction would be super apprecaited.


* codeexample for useing a 4051 * analog multiplexer / demultiplexer
* by david c. and tomek n.* for k3 / malmö högskola
*
*/
int led = 13; //just a led
int r0 = 0; //value select pin at the 4051 (s0)
int r1 = 0; //value select pin at the 4051 (s1)
int r2 = 0; //value select pin at the 4051 (s2)
int row = 0; // storeing the bin code
int count = 0; // just a count
int bin [] = {000, 1, 10, 11, 100, 101, 110, 111};//bin = binär, some times it is so easy
void setup(){
pinMode(2, OUTPUT); // s0
pinMode(3, OUTPUT); // s1
pinMode(4, OUTPUT); // s2
digitalWrite(led, HIGH);
beginSerial(9600);
}
void loop () {
for (count=0; count<=7; count++) {
row = bin[count];
r0 = row & 0x01;
r1 = (row>>1) & 0x01;
r2 = (row>>2) & 0x01;
digitalWrite(2, r0);
digitalWrite(3, r1);
digitalWrite(4, r2);
//Serial.println(bin[count]);
delay (1000);
}
}


* 4051_test_bb.png (316.95 KB, 1524x2460 - viewed 61 times.)
* 4051_test.fzz (15.94 KB - downloaded 11 times.)
Logged

The Netherlands
Online Online
Edison Member
*
Karma: 50
Posts: 1711
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, and welcome.

You're showing a Fritzing sketch you say you built.
Did you do it exactly the way you're showing in the sketch ?
So just what's in there and nothing else ?
I'm asking because i see some errors in there, just watching that Fritzing sketch (so the hardware).
First, in that sketch, there is no power supply to the 4051 chips.
They need power.
2nd. you have wired the buttons to pins 1, 2, 3, and 4 of one of those chips.
I have to assume that the small PCB's the chips are mounted on, have a 1 to 1 connections from chip to PCB pins.
So i took a peek and got me the NXP datasheet.
That datasheet tells me pin 3 is the output of that chip.
You want to connect that to your Arduino input.
The first 4 inputs of the chip are on pins 13, 14, 15, and 12 respectively.
Pins 11, 10 and 9 are the select pins.
Those are the ones you should control by your Arduino and select the input you want to read.

I see a connection from pin 9 of the lower PCB to pin 1 of the upper PCB.
I guess you want to cascade, but you can't use these pins for this.
I can also see some connection from pin 1 to pin 5 on the lower PCB, but i guess that isn't really there, is it ?

Last, but certainly not least:
You have put a resistor at each pushbutton.
The value printed on it is 100 Ohms (brown, black, black).
That is a bit low as a pull down resistor, the most likely reason for those resistors to be there.
A 10 K (brown, black, orange) will do and will reduce current flow drastically.
You also need to check you are connecting the switches correct.
If they are by accident rotated 90 degrees (clockwise or counterclockwise), you can never see the switch switching and the resistor is permanent connected between the power rails.

This was what i can see by just looking at the hardware.
I just also had a quick look at the code.
You seem to scan by selecting different inputs (after you have checked your connections).
But that's all you seem to do:
Select inputs of the 4051, but then nothing...

If you post code, put that in code tags.
And post all of it, or else you keep us guessing about what's supposed to happen.
Logged

Have a look at "blink without delay".
Did you connect the grounds ?
Je kunt hier ook in het Nederlands terecht: http://arduino.cc/forum/index.php/board,77.0.html

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 546
Posts: 27361
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Expanded your schematic a little. 3 select lines will choose 1 of 8 inputs on each bank, 2 other select lines will choose one of the 3 banks.
Drive the select lines, wait 300uS, read the input. Can be a digital input line, you're looking for a Low input to determine  a pressed button.


* 4051expansion.jpg (47.81 KB, 960x418 - viewed 37 times.)
« Last Edit: January 01, 2014, 08:31:15 pm by CrossRoads » Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok those last two reponses helped me a great deal -- I was confused by the logic symbol versus pin configuration and definately had a newbie confusion about the powering the chip too...

I've taken ONE STEP BACK to make sure I can read the results of just one 4051 chip.  If I can get that right then I will take the next step of reading more than one value on the same chip and then expand to nesting 4051's (more than one chip)

I think I have the first 4051 chip properly wired now. See attached Fritzing sketch.

I think I've got a simple push button circuit that should be able to send one signal to the y0 on the 4051 and then I want to send that through the Z to the Arduino Uno's A0 pin

HERE is my code

//*****
int r0 = 0;      //value of select pin at the 4051 (s0)
int r1 = 0;      //value of select pin at the 4051 (s1)
int r2 = 0;      //value of select pin at the 4051 (s2)
int count = 0;   //which y pin we are selecting

void setup(){

  pinMode(2, OUTPUT);    // s0 
  pinMode(3, OUTPUT);    // s1
  pinMode(4, OUTPUT);    // s2
  pinMode(A0, INPUT);    // z

  Serial.begin(9600);
}


void loop () {

  for (count=0; count<=7; count++) {
 
    // select the bit 

    r0 = bitRead(count,0);    // use this with arduino 0013 (and newer versions)     
    r1 = bitRead(count,1);    // use this with arduino 0013 (and newer versions)     
    r2 = bitRead(count,2);    // use this with arduino 0013 (and newer versions)     

    digitalWrite(2, r0);
    digitalWrite(3, r1);
    digitalWrite(4, r2);
   
    //Either read or write the multiplexed pin here

    digitalRead(A0);
    Serial.println(A0);
    delay(100);
  } 

}


Now the results that I expected to get was either a "0" or a "1" respectively.

The results I am getting is a repeating "14" ?  This doesn't make any sense to me?

I am struggling to read the pin value (0 or 1) -- any help would be greatly appreciated!





* 4051_test_2.fzz (8.27 KB - downloaded 13 times.)
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 546
Posts: 27361
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

post a .pdf  .jpg  .png  something for those without fritzing.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

here is a the image to go with the frizing file


* 4051_test_2_bb.png (448.66 KB, 1293x2244 - viewed 27 times.)
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 546
Posts: 27361
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok that is useless as it gives no clue as to functionality desired. might as well be two black boxes with wires in between.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

Offline Offline
Newbie
*
Karma: 0
Posts: 5
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@CrossRoads,

The only functionality I am trying to achieve with this one is to get a "0"  or "1" value (from the button press) through y0 of the 4051 chip along through it's z -- and into the Arduino's A0.

Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 546
Posts: 27361
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

A 4051 with pin functions provides  no info as to what the pins do. the svhematic I posted makes it very clear what is intended.
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

The Netherlands
Online Online
Edison Member
*
Karma: 50
Posts: 1711
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You did not connect that orange wire to Y0.
The other orange wire doesn't do anything different when you press that button.
Also, what's with the LED ?

Put code in code tags please.
« Last Edit: January 04, 2014, 03:42:55 pm by MAS3 » Logged

Have a look at "blink without delay".
Did you connect the grounds ?
Je kunt hier ook in het Nederlands terecht: http://arduino.cc/forum/index.php/board,77.0.html

Pages: [1]   Go Up
Jump to: