completely missunderstood shiftregister?

Hi,

I'm stuck with this for weeks now, and whatever I do, I always get a unwanted result :confused:

first i thought something is broken, but now I think I'm just an idiot.. so please help me not to stay one :slight_smile:

So I have this UTC U74HC595AG-Shiftregister and 8 LEDs conntected to it.. I want to control each LED individually. I understood, that when I have:

LED 1 - OFF
LED 2 - OFF
LED 3 - OFF
LED 4 - OFF
LED 5 - OFF
LED 6 - OFF
LED 7 - OFF
LED 8 - OFF

and I want to get only the LED 2 and LED 6 on.. I would have to push

00100010 into it.. is that correct?

because whatever I push via shiftOut() into it.. it seems like only the first digit is beeing processed..

so what am I doing wrong? please help, I haven't sleep for days now, because that f*cks me up :confused: .. I am completely confused.

and I want to get only the LED 2 and LED 6 on.. I would have to push

00100010 into it.. is that correct?

Yes.

So post your code and a schematic so we can see what you are doing wrong.

Grumpy_Mike:
Yes.

So post your code and a schematic so we can see what you are doing wrong.

Hi,

sorry, I am in office@work after another sleepless night.. i will post the shematic and full code in the evening.. but for now..

so according to the example above.. I would do

shiftOut(..., ...., LSBFIRST, B00100010);

is that correct? Or would I have to do something like

shiftOut(..., ...., LSBFIRST, 0);
shiftOut(..., ...., LSBFIRST, 1);
shiftOut(..., ...., LSBFIRST, 0);
shiftOut(..., ...., LSBFIRST, 0);
shiftOut(..., ...., LSBFIRST, 0);
shiftOut(..., ...., LSBFIRST, 1);
shiftOut(..., ...., LSBFIRST, 0);
shiftOut(..., ...., LSBFIRST, 0);

oO

Of course the first. If you looked up the shiftOut() you would have seen it shifts out a whole byte.

And it's partly preference and partly better (because then you're not limited to 8-bit) but use 0b00100010 as notation instead of B00100010.

Depending on how things are labled you might have to do MSBFIRST instead of LSBFIRST

Hi again..

so here is my shematic


(or https://circuits.io/circuits/3885162-the-unnamed-circuit/)

(.. by the way,.. when I start the simulation in autodesk, the IC breaks .. oO .. why?? .. could that be my problem?)

anyway.. when I do for example:

int DS_pin = 4;
int STCP_pin = 6;
int SHCP_pin = 5;

void setup() {
  pinMode(SHCP_pin, OUTPUT);
  pinMode(STCP_pin, OUTPUT);
  pinMode(DS_pin, OUTPUT);

  digitalWrite(SHCP_pin, LOW);  
  shiftOut(DS_pin, STCP_pin, MSBFIRST, 0b00001111);
  digitalWrite(SHCP_pin, HIGH); 
  }
void loop(){
   
}

it shifts me one byte.. why one? .. shouldn't it light me up LED1, LED2, LED3 and LED4 ?

second question.. about reset-pin of the IC:
..when I now execute the code once more, it like shifts the one LED into the chain.. so do I understand it correctly, that if I want to display various states on demand, I would have to

  1. reset the register
  2. fill it again with the states that I want

??

so here is my shematic

No it is not. It is a physical layout diagram, it is a bit useless for telling if you have the correct wires.

Also you have:-

  1. No resistors on your LEDs - that is going to burn something, maybe that is why it is not working.
  2. No supply decoupling on that shift register chip. - You NEED a 0.1uF ceramic capacitor between the power and ground of that chip as close to the chip as possible with the capacitor's leads cut as short as possible.

Hi

oh okay, I understand .. I will post a real shematic when I am back home.

But, is my understanding of shiftOut() correct? or could it be, that the missing resistors and capacitors lead to that false behaviour ?

is my understanding of shiftOut() correct

Yes.

could it be, that the missing resistors and capacitors lead to that false behaviour

Yes. No decoupling leads to erratic behavior, http://www.thebox.myzen.co.uk/Tutorial/De-coupling.html

no resistors might have burnt out the outputs of the chip.

Hi

thank you for the link. I have wired it like you said, but still with same result

I do:

void loop(){
    digitalWrite(SHCP_pin, LOW);  
    shiftOut(DS_pin, STCP_pin, MSBFIRST, 0b00000001);
    digitalWrite(SHCP_pin, HIGH);  
    
    delay(500);
  
    digitalWrite(SHCP_pin, LOW);  
    shiftOut(DS_pin, STCP_pin, MSBFIRST, 0b00000000);
    digitalWrite(SHCP_pin, HIGH);
    
    delay(500);   
}

this does this

why can't I fill the whole IC with values.. then fill the whole IC with other values?

Try

    digitalWrite(STCP_pin, LOW); 
    shiftOut(DS_pin, SHCP_pin, MSBFIRST, 0b00000001);
    digitalWrite(STCP_pin, HIGH);
int STCP_pin = 6;
int SHCP_pin = 5;

Is it possible you have these two pins swapped?

Try

int STCP_pin = 5;
int SHCP_pin = 6;

Grumpy_Mike:
Try

    digitalWrite(STCP_pin, LOW); 

shiftOut(DS_pin, SHCP_pin, MSBFIRST, 0b00000001);
   digitalWrite(STCP_pin, HIGH);

Mike, I'm pretty sure you are correct: 595 latches on the rising edge. Found this out recently when using one to drive the D0-D7 inputs of a ks0108 display. It's Enable pin latches, very conveniently, on the falling edge, so I was able to use the same Arduino pin for both purposes.

Hi,

it works now :smiley: .. thank you soooo much!! :))

now that the standard shiftOut() is working.. i try to find out, why shiftPWM is not working correctly..

when I do a:

shiftPWM(0,100,0,0);

..it should light me up the first LED in slight red.. correct?
but it lights me up the first LED in red.. and the second LED in green(?)

also when I do

void setup() {
  Serial.begin(9600);
  ShiftPWM.SetAmountOfRegisters(3);
  ShiftPWM.SetPinGrouping(8);
  ShiftPWM.Start(75, 255);  
}

void loop() {
    ShiftPWM.SetAll(0);
    delay(500);
    
    ShiftPWM.SetRGB(0,100,0,0); 
    delay(500);
    
    ShiftPWM.SetRGB(0,0,100,0);  
    delay(500);
    
    ShiftPWM.SetRGB(0,0,0,100); 
    delay(500); 
}

it does this: ShiftPWM - Problem - YouTube

shouldn't it light up the first LED in red.. then in green.. then in blue?

Are you sure you have not mixed up the clock and latch pin like you did in the software shift out case?
Note that you need to use specific pins for this libiary, you can't fix things in software. So you need to show us how you have wired your shift registers.

Grumpy_Mike:
Are you sure you have not mixed up the clock and latch pin like you did in the software shift out case?

I have tried swapping the pins.. but

Grumpy_Mike:
Note that you need to use specific pins for this libiary, you can't fix things in software. So you need to show us how you have wired your shift registers.

oh.. okay.. I need to try that out.
maybe for my understanding.. why do I have to use the pre-configured pins? i mean, i do not use SPI(?)

i mean, i do not use SPI(?)

You might not but the shiftPWM libiary does. Look at the example program and you will see that it has a couple of lines at the start saying what pins you should use with what models of Arduino.

It says:-

// Clock and data pins are pins from the hardware SPI, you cannot choose them yourself if you use the hardware SPI.
// Data pin is MOSI (Uno and earlier: 11, Leonardo: ICSP 4, Mega: 51, Teensy 2.0: 2, Teensy 2.0++: 22)
// Clock pin is SCK (Uno and earlier: 13, Leonardo: ICSP 3, Mega: 52, Teensy 2.0: 1, Teensy 2.0++: 21)