Need more outputs on my arduino mega ! (yes ... i know ...)

Graynomad:
You simply shift 16 bits out by calling shiftOut() twice. EG

int pin_bits0 = 0x0F;   // example, sets lower 4 bits

int pin_bits1 = 0x80;    // and the upper bit
shiftOut(dataPin, clockPin, MSBFIRST, pin_bits1);  // send upper 8 bits
shiftOut(dataPin, clockPin, MSBFIRST, pin_bits0);  // send lower 8 bits




The variables pin_bits0 and 1 remember the current state of the outputs.

I can't believe that it is so easy to do $) :grin:

In fact as i didn't know about shiftOut() function, i did not thought it was generating the clock signal by its own !
This is great news !

But now, i have some more questions ... XD

  • Time = 0 >>> I want to turn ON relay 3
  • Time = 1 >>> I want to keep relay 3 ON and turn ON relay 7
  • Time = 2 >>> Now i want to turn OFF relay 3

While being at Time = 1, does the shifting-register keeps in mind the state of the relay 3 ?
If it keeps it in mind, will there be some kind of short cut OFF/ON while turning on the relay 7 ?

Thanks for your precious help !

PS : i found this thread which the last post describes that he could drive 40 relays with a CD4094 (and with a 74HC595). http://forums.adafruit.com/viewtopic.php?f=25&t=7239&start=0
So i now feel it is the good way :slight_smile:

Hi,

In fact, i just came to read this page : http://www.arduino.cc/en/Tutorial/ShiftOut ... by the way ... hum ... let's say SHAME ON ME :grin:

Well well well ... Ok, i think i will go with this component : 74HC595 ; Datasheet : http://www.taydaelectronics.com/datasheets/A-251.pdf
On eBay china, it is possible to get 20x pieces for 3$ with free shipping :grin: YEAH !

I'm just wondering how is done the ENABLING or DISABLING state for an output pin ... (i hope you will explain it to me :. )
Another thing i'm wondering too is the fact that i need 16 outputs more (with only 3 pins it is a great deal !) and this component can be daisy chained ... but how to drive the 2nd one ?

Thanks !

The '595 is set up so the output of say #2 feeds the input of the next in line, say #1.
So you do two shiftout()s (or SPI. transfer if you want to operate faster, for a hardware to hardware transfer).
The first byte gets shifted thru #2 and ends up in #1, the 2nd byte ends up in #2. The latch signal moves the data from the '595 shift-in register to its output register so all outputs change at the same time.
There is an output enable pin also if you want the chip to Not drive the output line so something else can drive it.

In fact, i don't think the 74HC595 is a good idea because i will be driving 2N2222 transistors (finally) for long periods, and based on the datasheet, they eats too much current to the poor 74HC595 (it would only be possible to drive 2 of them simultaneously).

So, now, i'm looking for a replacement component instead of the 74HC595 ... there was the TPIC6C595 but could it be wired the same way /AND/ driven the same way thru the code given upper in this thread ?

By the way, if i use the TPIC6C595 daisy chained, i will not need to buy 2N2222 transistors as i will be able to use my TIP120s :slight_smile:

After some research, it seems that the 595 family are driven the same way !

So this is a good point.
Now i'm wondering if i will need to use a capacitance like the 74HC595 has to use ... ?!

Yes, put a capacitor across each '595s power & ground pin.
If you are using NPNs, then you will need a pullup resistor from 5V to the NPN gate, that will turn the NPN on; when the TPIC6595 output goes low, that will turn the NPN off.

http://www.fairchildsemi.com/ds/TI/TIP120.pdf

Depending on the current draw needed thru the relay coil, you may be able to just the the tpic6595 directly. Still need the pullup resistor to turn the relay off.

Yes, it is possible that i use th TPIC6C595 directly to power up the relays coils.
The relays coils are 12V DC.
I will add a reverse diode to avoid feedback current to flow where it shouldn't goes.

You're telling me that i have to add a capacitor across "Vcc" and "GND" pins of each TPIC6C595 ?

Reading the datasheet, it shows that a resistor and a capacitor should be used on each output ... ?!?! I just don't understand if i have to do it or not ?

By the way, how do i drive the 2nd TPIC6C595 connected on the SerialOut of the 1st TPIC6C595 ?

Thanks !

Reading the datasheet, it shows that a resistor and a capacitor should be used on each output

I think you are looking at the test circuits, these are just to show how the manufacturer (or you) can test the chip. Nothing to do with using it normally.

No resistors or caps required on the outputs.

how do i drive the 2nd TPIC6C595 connected on the SerialOut of the 1st TPIC6C595 ?

Just daisy chain ser out to ser in etc for as many chips as you like.

You're telling me that i have to add a capacitor across "Vcc" and "GND" pins of each TPIC6C595 ?

Yes, standard procedure for just about any chip.

if i use the TPIC6C595 daisy chained, i will not need to buy 2N2222 transistors as i will be able to use my TIP120s

I still don't understand why you need both a high-current chip and transistors. Can you answer that question?

  • Time = 0 >>> I want to turn ON relay 3
  • Time = 1 >>> I want to keep relay 3 ON and turn ON relay 7
  • Time = 2 >>> Now i want to turn OFF relay 3
int pin_bits0 = B00000100;  // relay 3 on
int pin_bits1 = B00000000;

digitalWrite (latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, pin_bits1);  // send upper 8 bits
shiftOut(dataPin, clockPin, MSBFIRST, pin_bits0);  // send lower 8 bits  
digitalWrite (latchPin, HIGH);

delay (1000);

int pin_bits0 = B01000100;  // relays 3 and 7 on
int pin_bits1 = B00000000;

digitalWrite (latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, pin_bits1);  // send upper 8 bits
shiftOut(dataPin, clockPin, MSBFIRST, pin_bits0);  // send lower 8 bits  
digitalWrite (latchPin, HIGH);

delay (1000);

int pin_bits0 = B01000100;  // relay 3 off, 7 on
int pin_bits1 = B00000000;

digitalWrite (latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, pin_bits1);  // send upper 8 bits
shiftOut(dataPin, clockPin, MSBFIRST, pin_bits0);  // send lower 8 bits  
digitalWrite (latchPin, HIGH);

Rob

how do i drive the 2nd TPIC6C595 connected on the SerialOut of the 1st TPIC6C595 ?
-> Just daisy chain ser out to ser in etc for as many chips as you like.

Ok, i had saw these pins but i'm wondering how does the first TPIC6C595 passes the data to the second one ?

You're telling me that i have to add a capacitor across "Vcc" and "GND" pins of each TPIC6C595 ?
-> Yes, standard procedure for just about any chip.

What should be the value for the shift-register to works without troubles ?

if i use the TPIC6C595 daisy chained, i will not need to buy 2N2222 transistors as i will be able to use my TIP120s
-> I still don't understand why you need both a high-current chip and transistors. Can you answer that question?

Aaaahhhh ... please forgive me with this, i was in my dreams yesterday @ night :wink: (too much coding drove me crazy ! haha -> I'm actually working on a dynamic menu tree for KS0108 library)

  • Time = 0 >>> I want to turn ON relay 3
  • Time = 1 >>> I want to keep relay 3 ON and turn ON relay 7
  • Time = 2 >>> Now i want to turn OFF relay 3
int pin_bits0 = B00000100;  // relay 3 on

int pin_bits1 = B00000000;

digitalWrite (latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, pin_bits1);  // send upper 8 bits
shiftOut(dataPin, clockPin, MSBFIRST, pin_bits0);  // send lower 8 bits 
digitalWrite (latchPin, HIGH);

delay (1000);

int pin_bits0 = B01000100;  // relays 3 and 7 on
int pin_bits1 = B00000000;

digitalWrite (latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, pin_bits1);  // send upper 8 bits
shiftOut(dataPin, clockPin, MSBFIRST, pin_bits0);  // send lower 8 bits 
digitalWrite (latchPin, HIGH);

delay (1000);

int pin_bits0 = B01000100;  // relay 3 off, 7 on
int pin_bits1 = B00000000;

digitalWrite (latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, pin_bits1);  // send upper 8 bits
shiftOut(dataPin, clockPin, MSBFIRST, pin_bits0);  // send lower 8 bits 
digitalWrite (latchPin, HIGH);

-> You must had make a mistake on the last step ... wouldn't the last (int pin_bits0 = B01000100) be (int pin_bits0 = B01000000) instead ?
(if i'm wrong ... then i will REALLY need some reading about how the process of enabling/disabling outputs works ...)

Thanks to you for all your time spent on my questions !

how does the first TPIC6C595 passes the data to the second one ?

SEROUT -> SERIN, look at the names, they are pretty self explanatory.

What should be the value for the shift-register to works without troubles ?

Typically 0.1uF.

I'm actually working on a dynamic menu tree for KS0108 library

Sorry, that just makes me even more confused. The KS0108 is a GLCD right? Why does is need any high-current drivers to use it? And even if it does why both drivers and transistors.

wouldn't the last (int pin_bits0 = B01000100) be (int pin_bits0 = B01000000)

Yes, well spotted, the perils of cut and paste.


Rob

how does the first TPIC6C595 passes the data to the second one ?
SEROUT -> SERIN, look at the names, they are pretty self explanatory.

Yes but, what is the message i have to send to the first one to tell him to pass the message to the second one ?

What should be the value for the shift-register to works without troubles ?
Typically 0.1uF.

Ok, thanks for that !!!

I'm actually working on a dynamic menu tree for KS0108 library
Sorry, that just makes me even more confused. The KS0108 is a GLCD right? Why does is need any high-current drivers to use it? And even if it does why both drivers and transistors.

In fact, i want to explode some KS0108 :slight_smile: ... Nnnnooooo !!! just kidding, it is not related, i'm creating a "dynamic animated menu with user actions (4 buttons)" for GLCD library ... This was what i meant when saying i was working on it late last night and was totally decerebrated :slight_smile:

wouldn't the last (int pin_bits0 = B01000100) be (int pin_bits0 = B01000000)
Yes, well spotted, the perils of cut and paste.

:slight_smile: ouffff ! i thought i had to read many things ! hahaha :wink:

what is the message i have to send to the first one to tell him to pass the message to the second one ?

Just daisy-chain all SRs

MEGA dataPin -> SEROUT -> SERIN -> SEROUT -> SERIN -> SEROUT -> SERIN...

Connect all RCK ("latchPin" from the reference example) and SRCLK (clockPin) pins together, then treat the lot a one big shift register.

In fact, i want to explode some KS0108 ... Nnnnooooo !!! just kidding, it is not related, i'm creating a "dynamic animated menu with user actions (4 buttons)" for GLCD library ... This was what i meant when saying i was working on it late last night and was totally decerebrated

Sorry simkard but we are obviously on different planets, I've asked maybe 4 times about the high-current shift regs and transistors and I'm still no wiser.

Good luck with this.


Rob

In fact, i want to explode some KS0108 ... Nnnnooooo !!! just kidding, it is not related, i'm creating a "dynamic animated menu with user actions (4 buttons)" for GLCD library ... This was what i meant when saying i was working on it late last night and was totally decerebrated

Sorry simkard but we are obviously on different planets, I've asked maybe 4 times about the high-current shift regs and transistors and I'm still no wiser.

Yes we're on the same planet and i will definitely not need the transistors to drive my relays.
I just hope that i will not be running into some kind of problems with the relays coils (fly-backs) even if i use reverse-diodes.

The dynamic menu i'm working on for GLCD library is not related to what we are talking about in this thread.

Just daisy-chain all SRs

MEGA dataPin -> SEROUT -> SERIN -> SEROUT -> SERIN -> SEROUT -> SERIN...

Connect all RCK ("latchPin" from the reference example) and SRCLK (clockPin) pins together, then treat the lot a one big shift register.

Well, i still don't understand how do i drive the outputs of these shift-registers put in daisy chain ...

Ex. : Let's say i have 3 TPIC6C595, if i understood correctly, for driving the whole 24 outputs, i'll have to send 6 bytes which the first one will be ending on the 3rd TPIC6C595 ?

Thanks !

Here's a schematic using three '595s

The TPIC6B595 has a different pinout but you should get the idea from this.


Rob

driving the whole 24 outputs, i'll have to send 6 bytes which the first one will be ending on the 3rd TPIC6C595

24 outputs is 3 bytes (8 bits per byte), and yes the first byte in ends up at the farthest right shift register in GrayNomad's schematic.

Haha, well ... one more time i was tired of coding so i said dumb things ...

I really have to sleep sometimes ! :grin:

Ok now i understood the whole thing.

I going to order the components right now and hope to receive them tomorrow.

Thanks for your help guys ! it was really gentle ! I greatly appreciate !

By the way, as i'm really not familiar with MOS type transistors, how do you think is the best way for connecting them to relay coils (+12V) with fly-back and all problematics concerned included ?

Thanks (Yes, this will be my last question :wink: )

AFAIK the snubbing/flyback/whatever diode is all you need. FETs are more sensitive than transistors to ESD etc but I don't think you need to add anything more.


Rob

Graynomad:
AFAIK the snubbing/flyback/whatever diode is all you need. FETs are more sensitive than transistors to ESD etc but I don't think you need to add anything more.


Rob

It is what i thought.
The only thing that i'm not confident with is the fact that MOSFETs are ESD more sensitives than basics transistors like TIP12x ...
What sort of precautions i have to take before manipulating them ?

Thanks !

I've never seen anyone add more protection for FETs but it does make sense.

There are all manner of TVS diodes, MOVs, varistors etc designed for this purpose.

If you mean physically handling them you can get anti-static wrist straps etc but I normally just ensure my hands are grounded to the package and desk or whatever when I pick a component up.


Rob