User avatar
coreywi
Posts: 17
Joined: Thu Dec 31, 2015 6:56 pm
Location: Calgary, Canada

interfacing to 74x595 controlled LED displays

Sat Mar 05, 2016 6:17 am

Hi there!

I'm having problems running a LED driver board that has 2, 7-segment displays, each with a 74595 shift register and ULN2003 pair on a driver board driving the actual LED segments. The driver board needs a 12V for the LED's and 5V for the control lines. The problem is that no matter what I do, the LED segments go on and stay on.

<editted useless stuff out>

Could the power setup I have mean something? I have a 12V regulated PSU driving the boards 12V requirement, and the 5V control lines are coming from the PI with power from separate mini-USB connected PSU.

The GND pins on the driver board are tied back to the 12V PSU.

I could really use some advice. I'm sure I'm missing something fundamental here.
Last edited by coreywi on Tue Mar 08, 2016 3:47 am, edited 1 time in total.

User avatar
Burngate
Posts: 6302
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: interfacing to 74x595 controlled LED displays

Sat Mar 05, 2016 5:50 pm

I'm not sure, but I have a couple of questions.

First, I assume the grounds of the 12v supply and the Pi are connected together, but confirmation would be good.
In fact, given that the uln2003 darlingtons are sinking current from the displays (because the diplays are lit), and that requires current into their inputs which has to return to where it came from, I think you must have the grounds all connected.

What sort of level converter are you using? Some also invert the signals, whereas others don't, and that might cause the symptoms you're seeing.
Though if you have inverting ones, OE would be high when you want it low, which would put the 595 outputs tristate, so no current out, so no current through the darlingtons ...

I don't think tying both clocks together would cause you this problem. It might later on, if signals for segment A appear on segment B, or vice versa, but that's not yet your problem.

Given that the 595 outputs are driving the darlington inputs, tristate has no meaning.
So I would tie the OE inputs to ground, and use the GPIO that was driving OE to drive the STCP pins.
Then you should be able to toggle SHCP 16 times as you are doing, then toggle STCP to load the output registers.

User avatar
coreywi
Posts: 17
Joined: Thu Dec 31, 2015 6:56 pm
Location: Calgary, Canada

Re: interfacing to 74x595 controlled LED displays

Sat Mar 05, 2016 6:22 pm

Thanks for the reply and the suggestions, Burngate.

I verified the logic level converter. Wasn't inverting anything.

On the PSU configuration, here's a little more detail:

The display/driver board has +12V power inputs, the 3 control inputs I mention above at +5V, and several ground pins for distribution. The control pins come from the logic-converted GPIO pins, the +12V comes from the regulated PSU and all the GNDs go to the REGULATED PSU ground.

My rPI is powered by a AC adapter coming in via the mini-USB port. Could things be getting screwed up because the GNDs all go back to the regulated PSU and I'm not going back to GND anywhere on the rPI side? I'm waiting for a UBEC to supply 5V off a 12V PSU, so I thought I'd try just running the rPI off a separate adapter. Doesn't make sense more I think about it. :oops:

Note that the driver board has both the SHCP and STCP chip pins tied to the single CLK input. Out of my control, unfortunately. It's this configuration that I'm scratching my head on what clocking strategy I'm to use.

User avatar
Burngate
Posts: 6302
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: interfacing to 74x595 controlled LED displays

Sun Mar 06, 2016 12:18 pm

The grounds must all be connected together!

To light a segment on the display, current has to flow from the 12v supply's positive terminal, through the segment, through its darlington, and back to the supply's negative terminal.

For the darlington to conduct, current - in this case supplied by the 595 output pin - has to flow through its input and back out through its ground to where-ever it came from, which is where the 595 got its current from.

The 595 is providing its output current from its 5v supply's positive terminal, and that current has to return to the supply's negative terminal
It will only do so if there's a voltage difference between its input and its ground (and current will flow through its input and out through its ground, to charge the capacitance of the gate)

The Pi will create a voltage difference between its GPIO pin and its ground pin. The 595 will only see the same difference if the grounds are the same.


I'm 5ft 11½. My daughter's eyes are level with mine. Is she also 5ft 11½, or is she hanging upside down from her trapeze?

User avatar
coreywi
Posts: 17
Joined: Thu Dec 31, 2015 6:56 pm
Location: Calgary, Canada

Re: interfacing to 74x595 controlled LED displays

Sun Mar 06, 2016 9:59 pm

Yeah, I know. :oops:

Impatient waiting for the UBEC. D-uh. So when it does come in, here's my plan. Maybe you could comment if this is ok.

The driver/display board has 12V power inputs, 5V control inputs, and a punch of GND pins. I was planning on a single 12V PSU that will be connected to the 12V power pin on the driver/display board. From that 12V PSU, I'll have a 5VDC/2A UBEC that will feed the rPI using a mini-USB plug (so I can get the overage protection)

Then I tie the UBEC GND line to the 12V PSU GND, and that is tied to all the GND pins on the driver/display board? I don't need to tie a GPIO GND in here as well do I?

Thanks for the help.

User avatar
Burngate
Posts: 6302
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: interfacing to 74x595 controlled LED displays

Mon Mar 07, 2016 4:16 pm

So I spent a little time drawing what I think you have.
Here it is.
display.png
display.png (9.23 KiB) Viewed 1260 times
If you don't have the grounds joined, that is the red line is missing, there's no route for current into the 595 to return to the 5v supply.

A ubec fed from the 12v supply will have a common ground for its input and output, so replacing the separate 5v supply with a ubec will join everything together.
The negative terminal of the micro-USB socket on the Pi is connected to all the grounds on the header, so no more connections are necessary

User avatar
coreywi
Posts: 17
Joined: Thu Dec 31, 2015 6:56 pm
Location: Calgary, Canada

Re: interfacing to 74x595 controlled LED displays

Tue Mar 08, 2016 3:37 am

Wow, that's above and beyond Burngate!

Yeah, the driver/display board combines the 595/2003/display.

So this is what I was planning (sorry if it's too small, couldn't figure out how to make it bigger).
Drawing1.png
Drawing1.png (11.18 KiB) Viewed 1221 times
I think from your diagram this looks like the same thing and should do the trick right?

Thanks again for the help. Serves me right for just cobbling something together while waiting for parts.

danjperron
Posts: 3502
Joined: Thu Dec 27, 2012 4:05 am
Location: Québec, Canada

Re: interfacing to 74x595 controlled LED displays

Tue Mar 08, 2016 12:44 pm

I don't know if you are interested about the STP16CP05 which contains already the current driver.

This way you don't need driver and level shifter.

It is similar like the 74HC595 but it has 16 bits I/O with current adjustable from 0 to 100 ma. The only bug is that it cames on SOIC or TSSOP version. but you could by soic/tssop adapter.

But at least it is way easier . No need to put driver. The cost of the chip is a little more than the 74HC595 so it is cheap.

I use it in multiplexing mode with a TB6612 driver.

Image
https://dl.dropboxusercontent.com/s/g4u ... tiplex.mov

And the code.

Code: Select all

import RPi.GPIO as GPIO
import time
import threading
import spidev

class LEDs:

    def __init__(self, bus, A1=18,A2=23,B1=24,B2=25,ENABLE=4):
        self.A1 = A1
        self.A2 = A2
        self.B1 = B1
        self.B2 = B2
        self.ENABLE = ENABLE

        # digit segment
        A = 1
        B = 2
        C = 4
        D = 8
        E = 16
        F = 32
        G = 64
        DP = 128
        
        GPIO.setwarnings(False)
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(A1, GPIO.OUT)
        GPIO.setup(A2, GPIO.OUT)
        GPIO.setup(B1, GPIO.OUT)
        GPIO.setup(B2, GPIO.OUT)
        GPIO.setup(ENABLE, GPIO.OUT)

        GPIO.output(ENABLE,1)
        GPIO.output(A1,0)
        GPIO.output(B1,0)
        GPIO.output(A2,0)
        GPIO.output(B2,0)

        # creation d'un dictionaire pour convertir le chiffre en segment
        #    segment
        #
        #
        #    -A-
        #   |   |
        #   F   B
        #   |   |
        #    -G-
        #   |   |
        #   E   C
        #   |   |
        #    -D-   DP
        #
        #
        #   creation de la correspondance digit versus segment
        #

        D0 = (A | B | C | D | E | F)
        D1 = (B | C)
        D2 = (A | B | G | E | D)
        D3 = (A | B | G | C | D)
        D4 = (F | B | G | C)
        D5 = (A | F | G | C |D)
        D6 = (A | F | G | C |D |E)
        D7 = (A | B | C)
        D8 = (A | B | C | D | E | F | G)
        D9 = (A | B | C | D | F | G)
        DMOINS = G
        DBLANK = 0
        DQUESTION = ( A | B | G | E)

        # dictionaire des valeurs
        self.Chiffre = {0: D0, 1: D1, 2: D2, 3: D3, 4: D4,
                        5: D5, 6: D6, 7: D7, 8: D8, 9: D9,
                        '-': DMOINS, ' ': DBLANK, '?': DQUESTION,
                        'SEGA': A, 'SEGB': B, 'SEGC': C,
                        'SEGD': D, 'SEGE': E, 'SEGF': F,
                        'SEGG': G, 'SEGDP': DP}

        self.digits = [ 0, 0, 0, 0, 0, 0, 0, 0 ]
        self.digitsIdx = 0
    
        self.spi = spidev.SpiDev()
        self.speed=2000000
        self.spi.open(0,bus)
        self.spi.max_speed_hz=self.speed
        self.Exit = False
        self.timer = threading.Thread(target=self.nextDigits)
        self.timer.start()


    def __del__(self):
        self.Exit = True

    
    def nextDigits(self):
        while not self.Exit:
            # Desactive sortie
            GPIO.output(self.ENABLE,1)
            # Active les bons digits
            if self.digitsIdx == 0:
               GPIO.output(self.B2, 0)
               GPIO.output(self.A1, 1)
            elif self.digitsIdx == 1:
               GPIO.output(self.A1, 0)
               GPIO.output(self.A2, 1)
            elif self.digitsIdx == 2:
               GPIO.output(self.A2, 0)
               GPIO.output(self.B1, 1)
            else:
               GPIO.output(self.B1, 0)
               GPIO.output(self.B2, 1)

            # Ecrire deux prochains digits sur SPI
            # Swap MSB byte LSB Byte
            Data = [ self.digits[self.digitsIdx*2+1],
                     self.digits[self.digitsIdx*2]]
            self.spi.xfer(Data)
            #activer la sortie
            GPIO.output(self.ENABLE,0)
            self.digitsIdx = self.digitsIdx + 1
            if self.digitsIdx > 3 :
                self.digitsIdx=0
            time.sleep(0.005)
        GPIO.output(self.ENABLE,1)

    def GetByte(self, Dval=' ', DP=False):
        if DP:
            BData = DP
        else:
            BData = 0
        if Dval in self.Chiffre:
            BData = BData | self.Chiffre[Dval]
        else:
            BData = BData | self.Chiffre['?']
        return BData

    def numero(self,valeur):
        ivaleur = int(valeur)
        d = [ 0 , 0 , 0 , 0 , 0 , 0, 0 , 0]
        for i in range(8):
            d[i] = self.Chiffre[ivaleur % 10]
            ivaleur = ivaleur // 10
            if ivaleur == 0:
                break;
        self.digits=d
        
        


    def stop(self):
        for i in range(8):
            dp.digits[i] = 0 
        self.Exit= True      

def ShiftDisplay(dp,n):
    for i in range(8):
        dp.digits[i]= dp.GetByte(n);
        time.sleep(0.1)

if __name__ == "__main__":

    dp = LEDs(0)

    try:

        i = 79999990
        while True:
            dp.numero(i)
            i = i + 1
            time.sleep(0.1)

    except KeyboardInterrupt:
        dp.stop()
                           
    
Last edited by danjperron on Wed Oct 04, 2017 6:48 pm, edited 1 time in total.

User avatar
Burngate
Posts: 6302
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK Tralfamadore
Contact: Website

Re: interfacing to 74x595 controlled LED displays

Wed Mar 09, 2016 5:46 pm

coreywi wrote:... So this is what I was planning (sorry if it's too small, couldn't figure out how to make it bigger) ...
Technically, I believe it's correct.
Artistically, your picture is better. Also, in the Prosilver layout, yours fits better.

So you win both ways!

Return to “Interfacing (DSI, CSI, I2C, etc.)”