[SOLVED] Strange behavior with Arduino Uno when using ShiftOut (....

Hi,
I recently started to dig into Arduino and it is really fun.

While progressing through tutorials I experienced a strange behaviour while using the ShiftOut command. LEDs, or 4 Digit (and 1) 7-Segment display where sometimes displaying the right thing, sometimes only partly and sometimes nothing.

I double checked LEDs and display, the 74HC595 (tested 5 different ones) and it leaves me in my opinion with a problem with the Arduino board.

The code example below should show on the 4 digit 7 segments the numbers 0000 till 9999 and then AAAA till FFFF an then repeat.

At the beginning it stays most of the times black for 4-10 seconds, then sometimes (seldom) makes one full run showing everything but most of the times it only shows 3-4 consecutive numbers right and then goes black or shows only parts of the display (like A and B part only of the 7 segment display).

I’ve added a few pictures hoping to convey what I see.
First it shows correctly 1111, then 2222, then 3333, then for short while nothing and then the 4th picture after a while with only A part lit from the 7 segment display.

As I feel this is a Board issue I’m posting it in General Electronics section, please move if wrong… :slight_smile:
Any recommendation I can do to test and find the problem?

Used code:

int data=8;   //74HC595  DS
int latch=9;  //74HC595  STCP
int clock=10; //74HC595 SHCP
int delayTime=500;

unsigned char table[]=
{0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c
,0x39,0x5e,0x79,0x71,0x00};

void setup() {
 pinMode(latch,OUTPUT);
 pinMode(clock,OUTPUT);
 pinMode(data,OUTPUT);
}
void Display(unsigned char num)
{

 digitalWrite(latch,LOW);
 shiftOut(data,clock,MSBFIRST,table[num]);
 digitalWrite(latch,HIGH);
}

void loop() {
 Display(0);
 delay(delayTime);
 Display(1);
 delay(delayTime);
 Display(2);
 delay(delayTime);
 Display(3);
 delay(delayTime);
 Display(4);
 delay(delayTime);
 Display(5);
 delay(delayTime);
 Display(6);
 delay(delayTime);
 Display(7);
 delay(delayTime);
 Display(8 );  << Entered  space as forum software changes this to a smile otherwise :-)
 delay(delayTime);
 Display(9);
 delay(delayTime);
 Display(10);
 delay(delayTime);
 Display(11);
 delay(delayTime);
 Display(12);
 delay(delayTime);
 Display(13);
 delay(delayTime);
 Display(14);
 delay(delayTime);
 Display(15);
 delay(delayTime);
 
}

I also tried to send B11111111 only with a delay in between with shiftout leading to the same strange behavior. Sometimes all segments lit up, sometimes partly some and sometimes none.

I further see that the numbers are “better” shown if I power via 9V than via USB connection. Means with USB I have more often just a black display…

Thanks,
David

EDIT:
used Code tag for easier reading

Hello,

May I ask how you are powering this circuit?

And if possible, do you have a diagram of your complete circuitry?
The more info we have, the easier we can troubleshoot it.

With regards,

Mike

Hi Mike,
Breadboard is powered by Arduino 5v out which is going to 74HC595 Pin 16.

Is there an easy tool to paint the circuit?

But basically the attached circuit with very small changes, i.e. used GND near digital pins and hooked this one first with breadboard GND rail, same for +5V to go first via breadboard + rail. Cathode out from display goes via 220 Ohm each directly to GND rail.

Does this help?

Thanks,
David

Hello David,

I'm not sure about this, but I think the problem could be a power issue. You say it works ok for showing the numbers from 1111 to 3333 and then you get problems. If you add up the numbers of LED'S of the 7 segment display that are lit and multiple that by 20mA you are drawing allot of current from the Arduino. Each pin out has a current limit of 40mA (some people claim it's 20mA, but the datasheet says 40mA) Besides this protection there is another protection in place from the voltage regulator of 500mA. This could be the one limiting your current here David. Do you have a separate power supply for the display of 5 volts? Try using that before you start looking for other possible causes. Remember to connect the GND together.

I really hope this helps David,

Yours,

Mike

panadero:
Hi Mike,
Breadboard is powered by Arduino 5v out which is going to 74HC595 Pin 16.

Is there an easy tool to paint the circuit?

But basically the attached circuit with very small changes, i.e. used GND near digital pins and hooked this one first with breadboard GND rail, same for +5V to go first via breadboard + rail. Cathode out from display goes via 220 Ohm each directly to GND rail.

Does this help?

Thanks,
David

Concerning software to create wiring diagrams.
Fritzing is what most of us use.
http://fritzing.org/home/

I question whether the Arduino UNO clone is able to supply enough voltage and current to the LED display.
My suggestion would be to supply operating voltage to the Arduino UNO clone and the breadboard separately.

Tie all the grounds together. This is easiest on the breadboard.

Use two separate 5volt pwr supply.

I do not know if I still have the parts to replicate your circuit.
I will have to check on that.

Thanks for the the link to fritzing, the software I started to use 2 weeks ago has a very large learning curve.

The rest of your reply with all respect is the same as I suggested. I can't replicate the circuit since I only have 2 7 segment displays.

Sincerely yours,

Mike.

Mikeb1970:
Thanks for the the link to fritzing, the software I started to use 2 weeks ago has a very large learning curve.

The rest of your reply with all respect is the same as I suggested. I can't replicate the circuit since I only have 2 7 segment displays.

Sincerely yours,

Mike.

I was writing my post in reply to the user probably at the same time you were writing your.
I did not see nor read your post.
This does happen in the forums.

I am not sure what you point it though.

I wanted to thank you for the link, since I have been looking for something like this for a very long time. I just got excited.

So, many thanks :slight_smile:

Hi Mike, Artisticforge,
I did the following, still not working 100%:

  1. Connected a power supply module to the breadboard and remove the +5 V from Arduino to the breadboard. Still kept all GND connections (from Arduino board and power supply module) to connect to each other. Power supply module is connected to a 9V (max 1500mA) power supply.

Still not 100%

  1. I also hooked up a 7v 0,420mA max (biggest I have…) power supply to the Arduino board. Still not 100%.

I also switched both w/o much success (Breadboard & Arduino board powered via power supplies.

  1. I disconnected from 4 digit segment the resistors on pin 6,8 & 9 to reduce power consumption by only lighting first digit. Still not 100%. By the way, full lit (incl. dot) it consumes < 14mA per digit.

  2. I reduced power consumption further by only driving the A segment of the first digit with:

  if (i<1) {
  shiftOut(data,clock,MSBFIRST,B00000001);
  i++;
  } else {
  shiftOut(data,clock,MSBFIRST,B00000000);
    i=0;
  }

in my Display routine, still not continues blinking…

With that it stays black for maybe 30 seconds after reset via button on board, then blinks a few times like expected and then black again to repeat after a while. Sometimes it works for only 1 or two blinks, sometimes for 15-25 blinks…

Is there a way to check the output directly on the pins of what shift out is sending?

I tried it by hooking to pin 8,9 & 10 an LED and 220 Ohm resistor each. nothing else.
The LED assigned pin 8 (data) blinked like morse code → guess OK
The LED assigned pin 9 (latch) stayed on the whole time. When I entered a delay between setting this pin to LOW and then HIGH I could see a short blink → guess OK as well
The LED assigned to pin 10 (clock) stays dark. Could be that the clock frequency is too high for the LED to light up?

Any ideas?

Thanks,
David

panadero:
Hi Mike, Artisticforge,
I did the following, still not working 100%:

  1. Connected a power supply module to the breadboard and remove the +5 V from Arduino to the breadboard. Still kept all GND connections (from Arduino board and power supply module) to connect to each other. Power supply module is connected to a 9V (max 1500mA) power supply.

Still not 100%

  1. I also hooked up a 7v 0,420mA max (biggest I have…) power supply to the Arduino board. Still not 100%.

I also switched both w/o much success (Breadboard & Arduino board powered via power supplies.

  1. I disconnected from 4 digit segment the resistors on pin 6,8 & 9 to reduce power consumption by only lighting first digit. Still not 100%. By the way, full lit (incl. dot) it consumes < 14mA per digit.

  2. I reduced power consumption further by only driving the A segment of the first digit with:

  if (i<1) {

shiftOut(data,clock,MSBFIRST,B00000001);
  i++;
  } else {
  shiftOut(data,clock,MSBFIRST,B00000000);
    i=0;
  }




in my Display routine, still not continues blinking....

With that it stays black for maybe 30 seconds after reset via button on board, then blinks a few times like expected and then black again to repeat after a while. Sometimes it works for only 1 or two blinks, sometimes for 15-25 blinks.....


Is there a way to check the output directly on the pins of what shift out is sending?

I tried it by hooking to pin 8,9 & 10 an LED and 220 Ohm resistor each. nothing else.
The LED assigned pin 8 (data) blinked like morse code --> guess OK
The LED assigned pin 9 (latch) stayed on the whole time. When I entered a delay between setting this pin to LOW and then HIGH I could see a short blink --> guess OK as well
The LED assigned to pin 10 (clock) stays dark. Could be that the clock frequency is too high for the LED to light up?

Any ideas?

Thanks,
David

You are still not providing enough power to the circuit.

I use 5v 2amp pwr supply for Arduino boards.

you need to get some better pwr supplies.

artisticforge:
Concerning software to create wiring diagrams.
Fritzing is what most of us use.
http://fritzing.org/home/

[soapbox]
No we don’t.
We tolerate it…
Circuit.jpg
This diagram conveys ;

  • No Pin names
  • Uses pictures of components instead of proper symbols
  • Does not allow proper component and wiring layout to show power flow and signal flow.
  • It is a picture.

A hand drawn “schematic” is more informative.
A picture of the OPs project is more informative as it shows the OPs wiring.

google ExpressPCB download

[/soapbox]
Tom… :slight_smile:

Hi,
Can you post a picture(s) of your project so we can see your component layout.

  1. Connected a power supply module to the breadboard and remove the +5 V from Arduino to the breadboard. Still kept all GND connections (from Arduino board and power supply module) to connect to each other. Power supply module is connected to a 9V (max 1500mA) power supply.

How big was the 5V supply to the display?

It sounds like you have a wiring problem, not all protoboards make good connections.

Please try this example.

http://osoyoo.com/2017/08/08/arduino-lesson-4-digit-7-segment-led-display/#4.2
Its the last example on the page.

Tom... :slight_smile:

Thanks all for your help

While reproducing Tom's sketch I saw that 74HC595 PIN 10 MR was set to +5V with his example.
After reading specs I noticed that I was continuously resetting the chip as I had not connected it (as also visible in the circuit I uploaded) and this chip had MR active on LOW.... (or at least it was in an uncontrolled state ...)

Further leanings from this thread --> I need a stronger PSU / keep mA consumption in mind

I was going to repurpose on old computer power supply when I found a 12V 3000mA PSU which I have now connected to my Arduino board. My sketch is now working w/o power supply on the breadboard but will change this in near future by creating a power station out of the computer power supply to drive everything :slight_smile:

Further learning --> I will never write "no wiring problem...." :slight_smile:

I am glad you found the problem and were able to solve it. It has been on my mind, to bad I couldn't reproduce your circuit though. I do think it's very smart of you to get more powerful PSU's.

I wish you much fun in the future David.

Yours,

Mike

Why are people obsessed with running LEDs at 20mA? This is usually the MAX current, not the sensible normal! There is absolutely no need unless you are trying to make a flashlight with them! Also note without any resistor they will pull a lot more than 20mA before burning out. In the case of an LED multi-segment display this can be a matter of seconds.

For indication you only need about 4mA and can run they through 470Ohm resistors. For most bread boards I use 1K resistors on LEDs and 1 or 2mA.

I built a similar circuit at the weekend to the OP. With tiny little blue LEDs on 470Ohm resistors they are still blinding to look directly at. Estimate them pulling 4mA.

If you have a dozen or more LEDs dropping the current they use by a factor of 5 makes a significant impact on your power demands.