Arduino and shift registers - Page 1
Forum section: electronics / beginners

author: Rihards Veips
author_rank: Contributor
timestamp: April 08, 2014, 01:27:42 pm
content: I have a school project and I have to make a 8x16 lamp screen.To drive relays for the screen I will use shift registers [74HC595 8bit] but I need 16 of them connected together to control the 16 rows of 8 lampsI can't find a good tutorial on how to connect multiple of them together so I posted a topic here.Can anyone please help me with how to connect multiple of them together(16)?I found this schematic but for the reigtsers I bought pin 9 is QH / Q7 not Overflow Is the Q7 the overflow pin that connects to the next register's data pin?

author: Skimask
author_rank: Super Contributor
timestamp: April 08, 2014, 01:58:07 pm
content: Quote from: Rihards Veips on April 08, 2014, 01:27:42 pmYes....just like it says in the datasheet.

author: MLXXXp
author_rank: Frequent Contributor
timestamp: April 08, 2014, 01:58:56 pm
content: Quote from: Rihards Veips on April 08, 2014, 01:27:42 pmYes, you connect pin 9, (QH', oroverflowon your schematic) from one 74HC595 to pin 14 (dataon your schmatic) of the next one.This article may be of some help:http://www.protostack.com/blog/2010/05/introduction-to-74hc595-shift-register-controlling-16-leds/

author: Rihards Veips
author_rank: Contributor
timestamp: April 08, 2014, 02:03:07 pm
content: Quote from: Skimask on April 08, 2014, 01:58:07 pmok, but what [shiftOut(dataPin, clockPin, bitOrder, value)] value do i have to send to turn on the last lamp? row 8 collumn 16

author: Rihards Veips
author_rank: Contributor
timestamp: April 08, 2014, 02:04:11 pm
content: Quote from: MLXXXp on April 08, 2014, 01:58:56 pmOk, but what do I do if I need to control 128 outputs? the is the same thing? Q7 to data, Q7 to data..................................?

author: MLXXXp
author_rank: Frequent Contributor
timestamp: April 08, 2014, 02:12:49 pm
content: Quote from: Rihards Veips on April 08, 2014, 02:04:11 pmYes, but make sure what you're referring to as Q7 is really Q7'/QH'/overflow/pin 9, which goes to data pin 14.

author: Rihards Veips
author_rank: Contributor
timestamp: April 08, 2014, 02:18:42 pm
content: Quote from: MLXXXp on April 08, 2014, 02:12:49 pmAnd if i want to turn on the last lamp I shift in 1 high and 127 low signals?

author: MLXXXp
author_rank: Frequent Contributor
timestamp: April 08, 2014, 02:22:11 pm
content: Quote from: Rihards Veips on April 08, 2014, 02:18:42 pmThis is a school project. I'll let you figure that out for yourself. Do some research or wire it up and experiment.

author: Rihards Veips
author_rank: Contributor
timestamp: April 08, 2014, 02:23:31 pm
content: Quote from: MLXXXp on April 08, 2014, 02:22:11 pmOkthank you for the help.

author: zapta
author_rank: Super Contributor
timestamp: April 08, 2014, 03:45:45 pm
content: Have you considered connecting the leds in a 12x12 matrix and time multiplex rows and columns? This way you will need only 24 outputs.Search around, for examplehttp://forum.arduino.cc/index.php?topic=53152.0

author: Rihards Veips
author_rank: Contributor
timestamp: April 08, 2014, 03:49:39 pm
content: I think it needs to be 8x16 (maybe the size will change) and with the shift registers I will be driving transistors that will be driving relays that will turn on 7W 220VAC LED lamps

author: linux-works
author_rank: Super Contributor
timestamp: April 09, 2014, 12:48:49 am
content: my choice is to use regular port expanders instead of shift registers. i2c makes life easy and you can address just the group of 8 or 16 things at a time and not have to 'shift thru' to everyone.

author: mariush
author_rank: Super Contributor
timestamp: April 09, 2014, 01:02:07 am
content: Don't forget some decoupling capacitors (0.01uF - 0.1uF) very close to the Vcc and GND of each chip.Instead of transistors, you may want to consider using chips like ULN2803A - 8 darlington transistors each with its own base resistor in an 18 pin DIP package (or SOIC if you want to):http://uk.farnell.com/stmicroelectronics/uln2803a/darlington-array-8npn-2803-dip18/dp/1094428So instead of soldering 8 resistors and 24 leads (3 leads on each transistor) and worry about the beta of each transistor and cooling each one, you can just put a DIP chip there and you will also be able to basically connect it almost in straight line with the shift register so it makes it easy to use prototyping boards.later edit:If you're paying for the parts, you really should ask your teacher if you can use some high brightness leds instead of those 7w bulbs. Relays + lightbulbs + diodes for relays are going to be more expensive compared to LEDs and the (optional) led drivers.A 7w incandescent lightbulb does about 46 lumens .. you can buy leds that are close to that power or match it cheaply (2 for a euro or something like that) :http://uk.farnell.com/cree/mleswt-a1-0000-0002e7/led-xlamp-white-mle-39-8lm/dp/2097584http://uk.farnell.com/cree/mleswt-a1-0000-0003e3/led-xlamp-white-mle-45-7lm/dp/2097586This way you could repurpose a computer power supply for 5v for the chips and 12v for the leds (the above leds run at 9.6v 160mA each) so you can either limit current using a resistor (for 12v in and about 150mA current, 15-18 ohm or higher, 0.5w or higher resistors will do) or use a led driver for each one (you can buy about 3 for 1 euro).

author: mariush
author_rank: Super Contributor
timestamp: April 09, 2014, 02:42:53 pm
content: You asked me in a private message to explain how to use ULN2803A.Ok, first let's understand how you'd power a relay using a simple transistor :You have 12v coming into the relay, going into the collector pin of your transistor and coming out through the emitter which you connect to ground. When there's some current going into the base pin (how much current depends on the resistor you choose), the transistor lets electricity flow from collector to emitter so the circuit closes, and now electricity flows all the way from 12v down to ground and the relay works.When you no longer send current into the base pin, the transistor no longer lets electricity flow from collector to emitter so the circuit is open. But now there's a lot of energy in that coil which has nowhere to go.While the circuit works, the voltage on each side of that coil is about 12v, slightly lower than 12v on the collector side because the coil has a relatively small resistance so there's a voltage drop on the coil. When the circuit is interrupted, that magnetic field in the relay coil turns into energy and the energy from the coil shows up at the collector pin as a voltage much higher than 12v and this can damage the transistor (because transistors can only handle up to a certain voltage, let's say 35v or 50v).In order to protect the collector pin, we have that diode which sends the electricity that's higher than 12v back to the 12v, instead of staying there on the collector pin damaging it. This diode is also called "free wheeling" diode.Now an ULN2803A looks like this :Every triangle in that picture on the right side is a darlington transistor, which is basically a npn transistor that's more powerful. So on one side of the chip you have the bases of each transistor and on the other side you have the collector pins of each transistor. The emitter pins don't exist, because they're all connected together to the GND pin. The COM is a common pin which will make sense in a moment.Let's look at just one of those triangles... it may seem scary but stay with me:At the bottom you see the simplified drawing of one out of 8 identical sections of the chips. You have the input B which is the base of the transistor, there's a built in resistor to protect the darlington transistor, you have the Output C which is the collector pin of the transistor and the emitter of the transistor is connected to the ground pin. You also see a diode that that goes to the COM PIN and if you check the previous picture, you can see that all eight diodes are connected together and go into the COM pin.So now you can simply adapt the circuit with the transistor to connect the relay to it:Easy.Now, you only need to check the datasheet and make sure your circuit does not exceed the specifications. For example, the collector of each transistor accepts a maximum of 50v but the common can only work with 30v, so if you need to use the common pin, you shouldn't use voltages higher than 30v. This means you can safely use relays that work with up to 24v.The only other thing that you have to be careful is that there is a bit of voltage drop between the collector and emitter:For example looking at the picture above, if your relay is 12v and needs 100mA to switch, then between Collector and Ground of a darlington transistor in ULN2803a, there's going to be about 0.8-1v drop, so your relay will actually see only about 11v. With a classic npn transistor, this voltage drop is only about 0.2-0.4v. Most relays work with as low as 10v so this isn't really a problem, but if you're really worried, you can pair transistors in the chip by connecting the base pins and the collector pins to reduce the current going through each individual transistors (if you have 4 pairs, you will only switch 4 relays with a uln2803a, but the current through each transistor is smaller, so the voltage drop will also be smaller)

author: tszaboo
author_rank: Super Contributor
timestamp: April 09, 2014, 02:52:06 pm
content: Quote from: linux-works on April 09, 2014, 12:48:49 amI2C is limited to 400Khz, while SPI is capable up to 50Mhz, I2C needs addressing, and ultimately, it is more expensive than shift registers. Also, not expendable, since you run out of addresses after the 8. device. For this application, shift register connected to an SPI port is ultimately better.

author: linux-works
author_rank: Super Contributor
timestamp: April 09, 2014, 06:27:13 pm
content: otoh, I could update just the 8 bits in a single port expander by talking JUST to it. if I had to shift an entire series of 8bit chips, that wastes more time, causes display update jitter.so, its not obvious that the PE solution is that much worse

author: zapta
author_rank: Super Contributor
timestamp: April 09, 2014, 06:37:33 pm
content: Quote from: NANDBlog on April 09, 2014, 02:52:06 pmHe is driving relays and 220AC leds so update time is not an issue.

author: tszaboo
author_rank: Super Contributor
timestamp: April 10, 2014, 08:01:42 am
content: Writing 64 bits (ie) with SPI line operating at 4 Mhz (easily achievable by an ATmega) takes like 16uS. Writing 3 bye on a 400Khz I2C line takes 60uS. You will not have any "update issues" if you use the correct, latched configuration to update all the outputs of the shift registers at the same time. in contrast, you cannot update the I2C expanders at the same time, if they are on different ICs. So with SPI, you can set 64 outputs faster than 1 output on the I2C solution. With the right part you can connect different voltage level families together, with the I2C solution you are limited.Yeah, I get it that it will be relays, still the SPI is better.