Pages: [1] 2   Go Down
Author Topic: 595 & 4021 multiplexing  (Read 2091 times)
0 Members and 1 Guest are viewing this topic.
UK
Offline Offline
Jr. Member
**
Karma: 1
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello all,

I know you're busy so I'll be brief, ish. I have an array of 16 solid state arrays which I want to drive with two 595 shift registers. I also have over 18 buttons, rotary encoders and switches which I'd like to use as inputs for them through three or more 4021 shift registers.

I have worked out how to read the pins of a single 4021 and I'm confident I can use the existing examples to work out how to read the pins of two or three more, so I don't think that's a problem at the moment. The part I'm struggling with is the code to set the outputs to the 595's if I need to have multiple pins high simultaneously as the corresponding buttons are pressed in a completely random pattern.

As far as I currently know, I can't shift out one byte for one pin then another byte for another pin without overwriting the byte currently stored in the register, so I'd have to code every possible combination of input presses and therefore every possible combination of pins high and low. Of course, this is ludicrous when you have potentially over 18 inputs and 16 outputs, and there must be a way to do this, but I can't find it on the internet or in my brain.

I'm guessing there's some kind of mathematical calculation for this or an automatically generating array trick (I did read about a method of generating an array then reading from it in Processing, actually, but I suspect doing that would fill the memory of the Arduino pretty quickly if I have all those combinations to do), but to be honest I've fallen behind in learning Arduino coding and have been concentrating more on learning the actual electronics. Plus I was in the bottom class for maths at school so I have no idea what I'm doing there, either.


Thanks for taking the time to read this and thank you in advance for any replies you might send my way.

Cheers,
Neema
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8620
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Just keep byte variables for each shift register, modify the bits in the variables then shift all of them out.

byte x = 0;
byte y = 0;

shiftOut (y...);
shiftOut (x...);

x |= B00010000;
y |= B00010001;

shiftOut (y...);  // turn on bits 0 and 4 in one SR
shiftOut (x...);  // turn on bit 4 in the other SR

y &= B1111110;

shiftOut (y...);  // turn off bit 0 in the other SR, bit 4 stays on
shiftOut (x...);  // no change here

_____
Rob
 
« Last Edit: May 10, 2011, 10:05:40 am by Graynomad » Logged

Rob Gray aka the GRAYnomad www.robgray.com

UK
Offline Offline
Jr. Member
**
Karma: 1
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Just keep byte variables for each shift register, modify the bits in the variables then shift all of them out.

Wow, thanks, I think that kind of went over my head, though... Actually, I've just looked up the Bitwise Compound Or and And operators (I've never seen |= or &= before); I take it they're what I want to use if I want to be able to 'stack' two bytes together? Like, if I wanted 00000001 and 00000010 together I'd use one of those operators (|=) to get 00000011, or something along those lines?

Thanks again!
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34724
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If you are not conformable with bit wise operations try the bitSet() and bitClear() functions they might be easer to get your head round.
Logged

UK
Offline Offline
Jr. Member
**
Karma: 1
Posts: 53
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

If you are not conformable with bit wise operations try the bitSet() and bitClear() functions they might be easer to get your head round.

Thank you, I'll look into that, though I found this http://www.arduino.cc/playground/Code/BitMath and it's explaining it quite well. I'll have a play around with some code when I can and see what I get.

Cheers guys!
Logged

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

Hello, nemma_t.

I am new here on this forum, singed in this week, and from Slovenia, so if I write anything incorrectly, don`t be mad;)

I am working on the same project as you are/had, I need to do this in one month, for my presentation in school, so I could finish school subject. Hope you understand, What I mean.

So, here It goes.
I bought shift in register HCF4014BE, and wired it exactly as the circuit on Arduino page shows. All though I did not use the 10k resistors, I use 8,2k, but I think that is not the point. Then I copied and pasted the program called "What is pressed", also from arduino page. When I run the program, I don`t get any understanding code on Serial monitor. I thought that, when I would push the, let us say third button, that is 3 in DEC, I could get 00000100 in BIN and nothing else. Now, when I upload the code on my arduino uno board, I don`t even have to push any button, I always get some incorrect BIN code.

This is my first step I am working on now in my project, and it is all going wrong. Later I meant to add a second shift in register, so I could have sixteen buttons, and two shift out registers, so I could lit up that LED diode, which could represent the button I would push. I know you know, what I mean;)

I don`t have much knowledge, we studied Arduino language in school, but on much easier, basic examples. I surfed all over the internet to find any example based on shiftIn/shiftOut, I read all about shifting on Arduino page many times, but I didn`t get far. Now I am turning up to you guys, help me.

I would be really grateful I you, or anyone, who read this post, could help me a bit. 

Frenk
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8620
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I can't find that "What is pressed" code, can you post it here.

How are you sending the data to the serial monitor?

If you are doing Serial.print (x) and x = B00000100 then you won't see anything because B00000100 == 4 and that's not a printable character.

Try Serial.print (x,HEX) or Serial.print (x,BIN)

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

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

Thanks for replying, here is the link to the code I am using.
http://arduino.cc/en/Tutorial/ShftIn12

Sorry, I miscalculated the logic number, it is 4. My brains don`t work fine today.
I use Serial.println (X, BIN);


Logged

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

11100
e
f
g
-------------------
111000
f
g
a
-------------------
1110000
g
a
b
-------------------
11100001
C
a
b
c
-------------------
11000011
C
d
b
c
-------------------
10000111
C
d
e
c
-------------------
1110
d
e
f
-------------------
11100
e
f
g
-------------------
111000
f
g
a
-------------------
1110000
g
a
b
-------------------
11100001
C
a
b
c
-------------------


Hey, this is what I get on serial monitor, when I upload the program. Like I said, I don`t have to push any button, and I get this.

Maybe I forget to say, that now I have only one shift in register and eight buttons.

Thanks for your time
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8620
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

That code prints the raw value then several chars from an array.

So what numbers/characters are you seeing?

Are you sure the SR is connected correctly?

OK, crossed posts. I'll have a think.

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 130
Posts: 8620
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I don`t have to push any button, and I get this.
It looks like the data is essentially random, you should get all 1s or 0s. Are you sure the SR is connected correctly?

______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34724
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Have you got pull up resistors on the push button inputs to the shift register?
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html
Logged

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

Quote
It looks like the data is essentially random, you should get all 1s or 0s. Are you sure the SR is connected correctly?
Hello Rob.
I am sure, that the register is connected correctly. I checked a few times. Maybe my protoboard is a problem. But I checked the connections with multimeter and all seems fine.

Quote
Have you got pull up resistors on the push button inputs to the shift register?
http://www.thebox.myzen.co.uk/Tutorial/Inputs.html
Hello Mike.
Great page! I read all about inputs, I have a pull down connection, now I think that I am having problems with my wires connected from buttons to register? Maybe there are too long and there are acting as an antenna?

Thanks for reply
Logged

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

I forgot to say something. I am using 8,2k resistors in my connection. Do I have to replace them with smaller value resistors?

thanks
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 639
Posts: 34724
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Pull downs aren't great most professionals would always use pull ups when given the choice. Any interference picked up by long wires is then automatically grounded instead of having to work its way through the supply to ground. Also you don't need as low a value for the resistors. A value of 8K2 might be alright but it depends on exactly what chip you have for example for a 74LS595 it is a bit high.
Logged

Pages: [1] 2   Go Up
Jump to: