4015 Shift Register + 7 Segment 2 Digits Display

Hi,

i salvaged 5pcs of 4015 Shift Register from old Electronics today.
I wanted to use it together with my arduino to run 2 7 Segment 2 Digits Displays for a project im working on.
But i just dont understand how they work.

I have never used shift registers before and everything i can find about this topic is about the 74HC... Shift register.
The 4015 is missing the latch pin, thats why all the example codes dont work.

I have played around with it for a while today, my setup is ardunio+1 4015 + 4 LEDs.
I connected everything according to the Datasheet (Vdd, GND, Data, Reset) and i can even light the LEDs.
The problem is that i dont quite understand why which LED lights up.

I have tried different options like
shiftOut(dataPin, clockPin, MSBFIRST, "1-4")
shiftOut(dataPin, clockPin, MSBFIRST, "something like 1010/0001/111...");
and others

but i cant figure out the pattern, the result always seems so random.
i would expect the first led to light up when i enter 1000, or the second when i enter 0100?
sometimes it works, but with the next combination i.e. 0010 2 Leds light up and im like wtf :o .

so the question is which value addresses which output ?

hope someone can help

Please give your sketch and a schematic (hand drawn schematic is OK).

Please read the forum rules so you know how to post code and attachments correctly.

This "7 Segment 2 Digits Displays " probably has 10 or 12 pins?
8 will be the common A, B,C,D,E,F,G,DP shared between the digits, and then a common anode or cathode for each digit.
So you need to setup the segments for 1 digit, turn on its common anode or cathode, wait a few ms, then then turn the common pin off and repeat the setup/turn on for the other digit. The eye will be tricked into seeing both on thru persistence of vision.

The segments in a display are arranged thus:
A
F B
G
E C
D DP decimal point, or colon, or maybe not even existing.

Make a font array to represent numbers.
Connect Q7-q6-q5-q4-q3-q2-q1-q0 to DP-g-f-e-d-c-b-a

byte fontArray [] = {
0b00111111, // 0   DP-g-f-e-d-c-b-a, 1 represents segment on
0b00000110, // 1
0b01011011, // 2
0b01001111, // 3
//etc
0b01101111, // 9
};

then in loop use the font to light the selected segments
shiftOut (dataPin, ClockPin, MSBFIRST, fontArray[leftDigit]); // look up the font for the digit to be displayed
same for the other side after a few ms
shiftOut (dataPin, ClockPin, MSBFIRST, fontArray[rightDigit]);

Spend a couple bucks at digikey.com or mouser.com and get some modern parts, like TPIC6C595. And current limit resistors so you don't burn up the LEDs. Works just like a 74HC595, but can sink 100mA per output pin. Works great with common anode parts.
TPIC6C595N Texas Instruments | Integrated Circuits (ICs) | DigiKey Marketplace

At 5V power, the 4015 has very little IO current capability. And no latch pin. And you have to add extra wires to make it look like an 8-bit part.

Thanks for the help, appreciate it. Had some time today to try it out and it Works great!
used 2 4015 to control 3 Digits, exactly what i needed.
there are 2 problems though.
first: as you can see in the gif below the 2 digits in the black display show an 8 instead of a 0.
Thats really weird since they are wired the same and use the same code as the display on the left.
any ideas?

second: I need 2 more digitalinputs to control a relay and a switch .... the 3 segment displays used all I/O pins (4x3pins for the shiftreg. + 2 for common Anode [used 5v rail for the first digit since i dont need to switch between 2 digits] )
So i was wondering if i could cascade the 4015 shift registers. I saw this before with the 74HC. Is it possible with the 4015 too?

int ClockpinA = 8;
int DatapinA = 10;
int ResetpinA = 9;

int ClockpinB = 11;
int DatapinB = 13;
int ResetpinB = 12;

int ClockpinC = 0;
int DatapinC = 2;
int ResetpinC = 3;

int ClockpinD = 6;
int DatapinD = 4;
int ResetpinD = 5;

int Anodepin1 = 7;
int Anodepin2 = 6;
int Anodepin3 = 1;

byte fontArrayA [] = {
0B11110010, //0
0B11111111, //1
0B11110000, //2
0B11110000, //3
0B11111100, //4
0B11110000, //5
0B11110000, //6
0B11111011, //7
0B11110000, //8
0B11110000  //9
};
byte fontArrayB [] = {
0B11110000, //0
0B11111100, //1
0B11111010, //2
0B11111100, //3
0B11110100, //4
0B11110101, //5
0B11110001, //6
0B11111100, //7
0B11110000, //8
0B11110100  //9
};


// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(ClockpinA, OUTPUT);  
  pinMode(DatapinA, OUTPUT);
  pinMode(ResetpinA, OUTPUT);
  
  pinMode(ClockpinB, OUTPUT);
  pinMode(DatapinB, OUTPUT);
  pinMode(ResetpinB, OUTPUT);  
  
  pinMode(ClockpinC, OUTPUT);
  pinMode(DatapinC, OUTPUT);
  pinMode(ResetpinC, OUTPUT);
  
  pinMode(ClockpinD, OUTPUT);
  pinMode(DatapinD, OUTPUT);
  pinMode(ResetpinD, OUTPUT);
  
  pinMode(Anodepin1, OUTPUT);
  pinMode(Anodepin2, OUTPUT);
  pinMode(Anodepin3, OUTPUT);
}


void loop() {




digitalWrite(Anodepin1, HIGH);
digitalWrite(Anodepin2, HIGH);
digitalWrite(Anodepin3, HIGH);
  
  for (int i = 0; i < 10; i++)  {
    
    shiftOut(DatapinA,ClockpinA,MSBFIRST,fontArrayA[9-i]);
    delay(5);
    shiftOut(DatapinB,ClockpinB,MSBFIRST,fontArrayB[9-i]);
    delay(5);
    shiftOut(DatapinC,ClockpinC,MSBFIRST,fontArrayA[9-i]);
    delay(5);
    shiftOut(DatapinD,ClockpinD,MSBFIRST,fontArrayB[9-i]);
    delay(500);
  }
   

  
}

First question. You may have wired the displays the same, but they may not be wired the same inside. Look for a code/model number printed on the side of the display and Google for that.

Second question. Yes. You don't need the reset pins, just tie them to ground. Connect the clock pins to the same Arduino pin. Connect the Q4A output to DATA B and Q4B to DATA A on the next chip.

Now the bad news. You may be damaging your Arduino. You need some transistors on those anode pins. Powering 7 or 8 led segments from a single pin is probably going to overload it.

thanks for the quick reply,
its weird but i have searched beofre and cant find a real datasheet online. anyway i cant imagine its wired wrong since all the other numbers are displayed correct i think it must be something else? never mind though, i guess i can figure it out if i put my head to it.

connecting the reset pins to ground is a great idea, gives me the 2 IO pins i needed !
though i thought about using maybe just 1 shift register to control all 3 digits.
I guess that is possible just the same way i control 2 digits with one shift register right now....
no idea why i didnt think of that before^^

I dont understand what you mean by transistors on the anode pins. Do you maybe mean resistors?
i have a few tip120s and a bunch of old electronics i could use to salvage other transistors, but i dont understand what they are supposed to do in this case. Could you maybe explain what you mean, since i want to solder all of this permenantly to a perf board once im done and it would really suck if it will break down after short period of time.

It is hard to help you without a schematic. Hand dawn is OK, as long as it is a proper schematic (not Fritzing breadboard view please, a Fritzing or other schematic). Right now all I can see is 2 x 2-digit 7-seg displays, 2 x 4015 registers, 5 resistors of unknown value and a lot of spaghetti wiring.

I don't think you are close to being ready to solder your components to a board yet. Unsoldering components without damaging them is not easy. Stick with breadboard until you have tested everything.

You say you are controlling 3 digits with two shift registers, but I see no evidence of multiplexing in your code. Do all 3 digits always show the same pattern? Can you display "123" for example?

yeah i understand, but i dont write shematics anymore since I never really know what im ending up with and change my plans all the time by adding or removing stuff.

Would be great if you can just give me a rough idea of what u meant by adding transistors, like the idea behind it. that wouldnt require shematics i guess. (if you insist ill make some :smiley: )

yes i can display 123, not with this specific code but i have written other code that can do this by turning on/off digits for milliseconds as CrossRoads explained it.

Well, it sounds like you might need some PNP transistors, to avoid damaging the Arduino pins by drawing to much current from them. Or maybe not, depending.

ah i think i understand. You mean i place the pnp between an external power supply and the Common Anodes of the 7segs and switch the PNP with the arduino IO pins instead of powering the Segs from the arduino diretly right?
thanks for pointing this out! i read that i can draw a max of 40ma per pin, and the segments seem to draw around 12ma per digit when fully lit according to the datasheet. so thats pretty close to max i guess.

Close to the max? You're funny. Closer to double the max. But your post gives me faith that you are thinking and learning and measuring. Good stuff.

For the transistors I would suggest bc327. A 4K7 resistor between the base and the Arduino pin should do the trick.

I found 5 bc32740 in my old washing mashines controller, perfect! :smiley:
BUT
i cant get it to work the way i want. first i tried the bc32740 with a simple led blink circuit, they work.
then i went on to the segment displays and it didnt work >:(
here is a shematic of how i wired it.

and here is the code i used to test it

int ClockpinA = 8;
int DatapinA = 10;
int ResetpinA = 9;

int ClockpinB = 11;
int DatapinB = 13;
int ResetpinB = 12;

int Anodepin1 = 1;
int Anodepin2 = 2;
int Anodepin3 = 3;


byte fontArrayA [] = {
0B11110010, //0
0B11111111, //1
0B11110000, //2
0B11110000, //3
0B11111100, //4
0B11110000, //5
0B11110000, //6
0B11111011, //7
0B11110000, //8
0B11110000  //9
};
byte fontArrayB [] = {
0B11110000, //0
0B11111100, //1
0B11111010, //2
0B11111100, //3
0B11110100, //4
0B11110101, //5
0B11110001, //6
0B11111100, //7
0B11110000, //8
0B11110100  //9
};


// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(ClockpinA, OUTPUT);  
  pinMode(DatapinA, OUTPUT);
  pinMode(ResetpinA, OUTPUT);
  
  pinMode(ClockpinB, OUTPUT);
  pinMode(DatapinB, OUTPUT);
  pinMode(ResetpinB, OUTPUT);  
  
  pinMode(Anodepin1, OUTPUT);
  pinMode(Anodepin2, OUTPUT);
  pinMode(Anodepin3, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {

//then in loop use the font to light the selected segments


digitalWrite(Anodepin1, HIGH);
digitalWrite(Anodepin2, HIGH);
digitalWrite(Anodepin3, HIGH);
  
  for (int i = 0; i < 10; i++)  {
    
    shiftOut(DatapinA,ClockpinA,MSBFIRST,fontArrayA[i]);
    delay(5);
    shiftOut(DatapinB,ClockpinB,MSBFIRST,fontArrayB[i]);
    delay(500);
  }
   

  
}

I expected the segment display to turn on when i set the Anodepin1/2/3 to High, and turn off when i set it to low since GND to basepin of the PNP switches it right?
but either with High or Low the segments displays 1234...

i was wondering is a low digitalinput/output pin the same as GND or not? If not,how do i control the Base of the PNP ?

It's a PNP, so to switch it on you set the Arduino pin connected to the base to LOW. HIGH switches it off.

yes of course...i know i wrote something different in my previous post...but thats what i did

high or low, nothing changes.

But if you replace the 7 seg with a single led, that works?

This should be similar to your circuit, except that you are using the shift register for the cathodes and the Arduino pins for the transistor bases.

yeah it worked with a single LED,
tks for the shematics i will figure it out somehow i guess, i just use 20k ohm resistors until then.

the code seems to be the bigger problem right now. I know how to display static numbers like 123 and i can also do a counter, but what would be the best way to display something that keeps on changing like a Temperature for example?

i thought about using the switch function to replace each temperature digit with the byte from the byte array maybe and find a way from there... but im quite overwhelmed with this task since im rather new to all of this :smiley:
and i bet that theres an easier way, i searched already but didnt find any good examples. especially since my setup with those 4015 and CA displays is quite uncommon.
If you have a good idea for a combination of functions i would appreciate it.
I also have the opportunity to use 74HCs now, found them in my washing mashine too, smds though but i soldered one to a perf board with pins to use it in my breadboard

pretty proud of that :smiley: but I still prefere to continue with my 4015s, dont like to give up so easy

will let you know if i get the PNPs to work

With 7 seg displays and scrounged parts, you have two main options: multiplex or not. If you have one shift register per digit, you don't need to multiplex or use transistors. If not, you could in theory run 8 digits using only two shift registers and 8 transistors. But they might not be bright enough for use outdoors for example. Multiplexing reduces brightness, and 4015/74595 shift registers can't source or sink enough current to compensate.

yeah,
If i multiplex with one shift register, that would be really cool. But i dont have the skills to code it, and i dont want to copy paste someone elses work.
if i use 3 shiftregister for 3 digits, it will cost me 2 pins each so 6 pins and is less but still difficult to code.
with 10 pins and no shift register i could simply use the SevenSegment library with 3PNPS(which work now btw. problem was a cheap chinese breadboard....different location on the board worked)
i think im gonna continue my project with the library and and use 1 4015 to expand my 4 left IO pins.
which leaves me 2 Inputs and 8 Outputs and thats all i need.
thanks for your help a lot Paul!

You're welcome. But judging by some of the things you said in that last post you still have not understood some of the answers I have given you in this thread. I'm sure you will get it eventually. Good luck.