Pages: [1]   Go Down
Author Topic: 595 to drive multiple 4051  (Read 1605 times)
0 Members and 1 Guest are viewing this topic.
Indonesia
Offline Offline
Jr. Member
**
Karma: 0
Posts: 70
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dear All ...

I need more digital out.
What i'm thinking of is using 595 to drive 3 x 4051

The first 3 Output of 595 (QA,QB,QC) will drive all A-B-C pin of 4051 in paralel
The second 3 (QD, QE, QF) output will drive the ENABLE (INH) pin of Each 4051.

This is what I got currently

My plan is , If I want to Set only IC1-X01 to HIGH I just need to ShiftOut : 11110000 to IC-MASTER.

Will (I don't have any IC on hand currently) this work ?

Do I have to put transistor between QD-QE-QF of master and EnablePin of Each 4501 and Ground .... so that the shifout will be : 00001000 ?

Sincerely
-bino-



* 595-4501.png (16.35 KB, 1958x788 - viewed 139 times.)
« Last Edit: October 14, 2012, 08:57:02 pm by binooetomo » Logged

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dear All ...

I need more digital out.
What i'm thinking of is using 595 to drive 3 x 4051
hi

Why not just cascade more 595s if you only need digital outputs?  The serial data output pin allows you to pass data through to one or more other 595s down the line.

Cheers! Geoff
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

California
Offline Offline
God Member
*****
Karma: 14
Posts: 629
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I totally agree with strykeroz,

http://bildr.org/2011/08/74hc595-breakout-arduino/

Quote
Code
Because it is so much easier to use a lot of these now, we wanted the code to be the same. So we made an Arduino library that is capable of controlling near 2000 of these chained together and still enable you to call each pin individually. (this library can be used with the plain 74hc959[typo - spc] chip as well)

Logged


Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Bino,

Another alternative along the same lines as the 74HC595, if you need to have higher power switched than a standard 595 can do for you, the TPIC595B can be used which can switch 150mA per pin (as a GND/drain rather than a source of 5V).  I've used a pair of those cascaded to switch segments of 12V LED strip lighting.

Cheers ! Geoff
« Last Edit: October 14, 2012, 11:36:19 pm by strykeroz » Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 634
Posts: 34549
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Only a fool uses a 4051 as an output. This is because only one output can be active at any one time. It is simply the wrong chip to use.
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
3 x 4051

4051 is simply a switch: it connects the output to one of eight inputs.

Maybe you are looking for some decoders that will generate 8 different output based on 3 input pins?
Logged

Indonesia
Offline Offline
Jr. Member
**
Karma: 0
Posts: 70
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dear All.
I really appreciate your response.

1. I dont use 4051 to 'read'.
2. I just want more digital output.

I knew that I can stack more 595, but it'll need me to do Shiftout more then once.

I want use this schematic for Digital/Analaog input that will read by Arduino Analog pin.

The 3x 8 output pin of 4051 will threaded as 'Row', and the Arduino Analog pins as 'Column'

This is the basic sketch :
Code:
//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;
uint8_t rows[]={8,
9,
10,
11,
12,
13,
14,
15,
16,
17,
18,
19,
20,
21,
22,
23,
32,
33,
34,
35,
36,
37,
38,
39};
byte readmode[]={'t', // 't' = digital read, and
't', // ~ (NOT) the last value
't',
't',
't',
'm', // 'm' = digital read, Send HIGH=NoteOn , LOW=NoteOFF
'a', // 'a' = Analog read, Send CC
'a',
't',
't',
't',
't',
't',
'm',
'a',
'a',
't',
't',
't',
't',
't',
'm',
'a',
'a'};
uint8_t midchans[]={1,2,3}; //MIDI Channel of Left, Master, Right
uint8_t keyvals[3][2][24] = {};
uint8_t x,y,z =0; //Z=Row, Y=Sub-Group/Chan , X=Group/Chan

int loopcount=0;
long startmils=0;

void setup(){
  Serial.begin(115200);
  pinMode(latchPin, OUTPUT);
  pinMode(14, INPUT);
  pinMode(15, INPUT);
  pinMode(16, INPUT);
  pinMode(17, INPUT);
  pinMode(18, INPUT);
  pinMode(19, INPUT);
  for (x = 0 ; x <3 ; x++){
    for (y = 0 ; y<2; y++) {
      for (z = 0 ; z<24; z++) {
        keyvals[x][y][z]=0;
      }
    }
  }
}
void loop(){
  for (z = 0; z < 24; z++) {
    Serial.print("Z");
    moverow(z);
    for (y=0 ; y<3; y++){
      //pinstart = x*2
      Serial.print("Y");
      for (x=0; x<2; x++ ){
        Serial.print("X");
        //readpin=(x*2)+y
        prockey(x,y,z);
      }
    }
  }
}

void moverow(int thisrow){
    digitalWrite(latchPin, LOW);
    shiftOut(dataPin, clockPin, MSBFIRST, rows[thisrow]);
    digitalWrite(latchPin, HIGH);
}

void prockey(int proc_x, int proc_y, int proc_z){
  //First we read the analog pin
  int readpin=(proc_x*2)+proc_y ;
  int keyval=0;
  switch (readmode[proc_z]){
    case 't' : //Only Togled every time it's HIGH
      keyval=digitalRead(14+readpin);
      if (keyval) { //button pressed
        keyvals[proc_x][proc_y][proc_z]=~keyvals[proc_x][proc_y][proc_z]; //togle last key val.
        //Here you must send the midi :
        sendNote(proc_x,proc_y,proc_z);
      }
      break;
    case 'm' : // Only togled when current_keyval != last_keyvals
      keyval=digitalRead(14+readpin);
      if (keyval != keyvals[proc_x][proc_y][proc_z]){
        keyvals[proc_x][proc_y][proc_z]=keyval;
        sendNote(proc_x,proc_y,proc_z);
      }
      break;
    case 'a' : //Only Togled when current_keyval != last_keyvals
      keyval=int((analogRead(14+readpin)/1023)*127); //converted to 0-127 for midi compatible
      if (keyval != keyvals[proc_x][proc_y][proc_z]){
        keyvals[proc_x][proc_y][proc_z]=keyval;
        /*Send MidiChange
          midi channel = midichans[proc_x]
          keynumber = keynum
          value = keyval
        */
      }
      break;
  }
}

void sendNote(int send_x, int send_y, int send_z){
  int keynum=(send_z*(send_y+1))+1;
  if (keyvals[send_x][send_y][send_z]){
    /*NoteON with :
      midi channel = midichans[send_x]
      keynumber = keynum
      midival = 1
    */
  }
  else {
    /*NoteOff with :
      midi channel = midichans[send_x]
      keynumber = keynum
    */          
  }  
}
« Last Edit: October 16, 2012, 12:52:38 am by binooetomo » Logged

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 634
Posts: 34549
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
1. I dont use 4051 to 'read'.
But you say
Quote
I want use this schematic for Digital/Analaog input that will read by Arduino Analog pin.
These two statements do not match.

Then you say
Quote
The 3x 8 output pin of 4051 will threaded as 'Row', and the Arduino Analog pins as 'Column'
Which implies you are wanting to drive a matrix.

Let me say again, using a 4051 for outputs is a bad idea. You need to say what you are trying to do and what you are trying to drive.
Logged

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi again,

In addition to the inconsistancies Mike has asked for clarifications on...
Quote
I knew that I can stack more 595, but it'll need me to do Shiftout more then once.
If you have a concern for how many times shiftout() is called, in the configuration you propose you'll actually be calling shiftout() up to 8 times more than with a 595 cascaded alternative.  This is because for each individual pin you update you're setting the addresses in parallel on all of the 4051's but only enabling one for output, so you'll need to send that 595 a different bit pattern to update each pin on each 4051.  In contrast, with 3x cascaded 595s, you would need to output just 3 bytes via only 3 calls to shiftout() rather than the 24 needed to do the same in your proposed configuration.
1. I dont use 4051 to 'read'.
2. I just want more digital output.
Based on this, multiple 595 is ideal.  Keeping in mind the questions Mike has raised above.

Cheers ! Geoff
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Indonesia
Offline Offline
Jr. Member
**
Karma: 0
Posts: 70
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Dear All.
Thankyou for all of your helps

Let me say again, using a 4051 for outputs is a bad idea. You need to say what you are trying to do and what you are trying to drive.

I need to have 24 x 6 buttons and pots
the '6' is the number of Analog input pins.
I'll use analog input pins both with analogread() and digitalRead()

Sincerely
-bino-

Logged

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1123
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi

Is that a matrix of 144 buttons and 144 pots, or 24 buttons with 6 pots?

Are you intending from what you're saying to directly sample the pots from the A0 thru A5 analog inputs on the Arduino and read the buttons via the matrix you're attempting to create with these ICs?

Geoff
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Manchester (England England)
Online Online
Brattain Member
*****
Karma: 634
Posts: 34549
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I'll use analog input pins both with analogread() and digitalRead()
That doesn't make too much sense.

If you want to read a lot of pots then use the arrangement shown in this project of mine:-
http://www.thebox.myzen.co.uk/Hardware/MIDI_Footsteps.html
That has 16 analogue inputs. It is easily extended to 40 inputs by using the other analogue input pins with a 4051 on each pin.
Logged

Pages: [1]   Go Up
Jump to: