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

Hi all !

I'm facing some problematic where i can't find the answer (probably because i have some lacks on reading datasheets ...).

Here is what i want to do : I'm actually working on a project where i will need more outputs on my arduino mega 2560 because i'm running out of them ... (i know ... it already has lots of outputs, but not enough for my project ;) ). These outputs will drive some TRANSISTORS (TIP120 or 2N2222 but as i already have a LOT of TIP120 ...) that will actuate RELAYS (12V ones like Finder 40.51 // 40.52). ---> Eventually, if these outputs could be analogs, it would be best (because i will probably need some ones)

I saw, doing some reseaarch, that lots of people use this component : CD74HC4067 But, reading the datasheet, i could see, in absolute maximum ratings, that "DC DRAIN CURRENT" could not exceed 25mA (at max !!! so well less than this value).

I'm looking into just 1 component that would do the job and that can, if i understood the datasheets correctly, outputs something like 150mA / output.

Thanks !

I found this thing which appears to fits my needs, but i never had any with serial shifting registers ... ... Especially with the clock to use ?! Can anyone points me to the good direction ?

TPIC6C595N : http://www.ti.com/lit/ds/symlink/tpic6c595.pdf

Thanks !

CD74HC4067

This chip is an analogue MUX, it's not suitable for outputs mostly because you can only select one at a time.

If you are using transistors why do you need 150mA outputs?

Most people use a '595 shift reg for more outputs but it's not very powerful, there are versions that are like the TPIC6B595 that would be suitable.


Rob

You beat me to it :)

Can anyone points me to the good direction ?

There are examples on the Arduino playground I think, but you can just use the shiftOut() function.


Rob

Graynomad: You beat me to it :)

Can anyone points me to the good direction ?

There are examples on the Arduino playground I think, but you can just use the shiftOut() function.


Rob

Ok so you're telling me that i can use this kind of register (a shame that they are not delivered with 16 outputs at a time ! GRRR !!!) and driving them only by using shiftOut() function ? I can see others pins like : G/, RCK, CLR/, SRCK, SER OUT ... I just don't know how to use them.

By the way, do you know other registers that are 16 outputs and can drive 2N2222 transistors while being commanded thru 4 pins (4 bits control) ?

Thanks !

can drive 2N2222 transistors

Every chip in the known universe will drive a 2n2222.

As I asked before, why use a high-current chip AND transistors? Surely either one or the other will do.

I can't think of any 16-bits SRs though.

I can see others pins like : G/, RCK, CLR/, SRCK, SER OUT ...

We'll talk pins when we decide on a chip.

EDIT: The SN54LS673 and family are 16 bits. Hint, try Googling "16-bit shift register" :)


Rob

Graynomad: EDIT: The SN54LS673 and family are 16 bits. Hint, try Googling "16-bit shift register" :)

In fact, i need something that keeps in memory the state i defined earlier. Let's say, i need to power 6 relays ON from my 16 relays, but not at the same time, how can i achieve this with this kind of component ?

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.


Rob

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 :)

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 :)

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 http://www.ti.com/product/tpic6595

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 ;) (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 :) ... 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 :)

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

:) ouffff ! i thought i had to read many things ! hahaha ;)

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