Using buzzer with shift register

Hello!
Just recently I've started exploring shift registers as a part of my new project. Long story short I have two 7hc595 shift registers, two 7-segment displays and a 5v buzzer (and arduino uno). I successfully daisy chained the shift registers and the numbers are being displayed nicely. I haven't yet connected the buzzer to the last available pin on one of the registers because I am not sure how I am supposed to run it. To my (poor) knowledge, a buzzer uses a square wave of certain frequency to make sounds. Thats what the tone function uses. How do I set the frequency on that register pin if I am not using the tone function (because it needs one pin and shift is using 3)? There are no tutorials on that online just a few people mentioning its possible somehow. I plan on controlling all that with attiny85 so I am low on available pins. Thats why I am considering doing it this way.

Best regards
Me

Me,

There are two kinds of buzzer, passive and active. The passive requires a square wave drive and the active has an internal oscillator so it only needs continuous power applied, in order to sound.

What buzzer do you have? Have you tried using it at all?

Oh yeah sorry I have a passive buzzer. I've used them quite a bit in the past but never with a shift register. Will just using delayMicroseconds and shiftout do the trick?I know I can't use tone function...

Did you try? Please post your sketch in code tags if you want specific advice.

Are you "comfortable" with your code (you understand it), or it's a copy and paste job?

You could use the shift register for an on/off signal into a 2-input AND (or NAND) gate that can then "add" the tone signal (on the 2nd input) for the passive buzzer.

If you want to connect the buzzer directly to the shift register then you have to drive the shift register (using shiftOut() or whatever) at a frequency high enough for the buzzer. You alternate the value of the pin in a cycle 0,1,0 ....
You may need a transistor depending on the shift register and the power requirements of the buzzer.

Sorry for the long reply guys. Here is the code, I took out the parts that have stuff related to other components so I can troubleshoot easily.

int datapin = 11;
int clockpin = 12;
int latchpin = 8;

int dec_digits[12]{252,96,218,234,102,174,190,224,254,238,1,0};

void setup() {
  pinMode(datapin, OUTPUT);
  pinMode(clockpin, OUTPUT);
  pinMode(latchpin, OUTPUT);
}

void loop() {


  digitalWrite(latchpin, LOW);
  shiftOut(datapin, clockpin, LSBFIRST, dec_digits[10]);
  digitalWrite(latchpin, HIGH);
  delayMicroseconds(100);

  digitalWrite(latchpin, LOW);
  shiftOut(datapin, clockpin, LSBFIRST, dec_digits[11]);
  digitalWrite(latchpin, HIGH);
  delayMicroseconds(100);

}

I connected an led to the other remaining pin of the seconds shift register to see if it would work. The led works fine it toggles on off like it should (when delay is set and not delayMicro) but the buzzer is silent.

Sorry, but in order to identify bits in your scheme, we need to see a schematic. At a minimum, we need to know which bit in the shift register is connected to the buzzer, and which are connected to segments. You made that nearly impossible by using decimal numbers for the digits, and not documenting anything.

What do you mean? I see no delay().

Well, it sounds like you have found the right pin on the shift register if a led blinks (when you put a sufficient delay in so you can actually see something).
When you use tone() to drive the buzzer, what frequency do you use? You have to drive the shift register so that one on and one off cycle is equivalent to one wave from tone(). Say the frequency is 1kHz, then that means 500us on and 500us off. So two delayMicroseconds(500) statements in your code.

...and could offer more specific help if I knew which bit in the buffer corresponds to it, nothing concrete can be done without knowing that.

"the remaining pin" means nothing unless you have the circuit in front of you.

You will want to do some bit masking operations. I would love to show you how to do that, but I'm not going to waste time with non-specific advice on that. That will be necessary so the segment and buzzer updates don't conflict.

Sorry I don't know how to make real circuit diagrams yet...
This is the part of the original program I started out with. You can see the bits.

int digits [12][8]{
  {0,0,0,0,0,0,1,1}, // digit 0
  {1,0,0,1,1,1,1,1}, // digit 1
  {0,0,1,0,0,1,0,1}, // digit 2
  {0,0,0,1,0,1,0,1}, // digit 3
  {1,0,0,1,1,0,0,1}, // digit 4
  {0,1,0,1,0,0,0,1}, // digit 5
  {0,1,0,0,0,0,0,1}, // digit 6
  {0,0,0,1,1,1,1,1}, // digit 7
  {0,0,0,0,0,0,0,1}, // digit 8
  {0,0,0,1,0,0,0,1},  // digit 9
  {1,1,1,1,1,1,1,0,},  // led ON
  {1,1,1,1,1,1,1,1,}  // led OFF
};

Okay, I will return when you know how to make real circuit diagrams. Good luck with your project.

Understood. Thanks for help I guess

ShiftOut here is a single byte operation. An int is 2 bytes (with a sign bit). Use single bytes.

Try this

int datapin = 11;
int clockpin = 12;
int latchpin = 8;

uint8_t dec_digits[12] {252, 96, 218, 234, 102, 174, 190, 224, 254, 238, 1, 0};

void setup() {
  pinMode(datapin, OUTPUT);
  pinMode(clockpin, OUTPUT);
  pinMode(latchpin, OUTPUT);
}

int buzzCount;
int digitCount;
const int BUZZMAX = 300; // buzz cycles per digit increment
const int DIGITMAX = 4; // cycle through this many digits for demo

void loop() {
  buzzCount++;
  if (buzzCount >= BUZZMAX) {
    buzzCount = 0;
    digitCount++
    if (digitCount >= DIGITMAX) {
      digitCount = 0;
    }
  }
  uint8_t mask = buzzCount & 1;

  digitalWrite(latchpin, LOW);
  shiftOut(datapin, clockpin, LSBFIRST, dec_digits[5 + digitCount] | mask);
  shiftOut(datapin, clockpin, LSBFIRST, dec_digits[11]);
  digitalWrite(latchpin, HIGH);
  delayMicroseconds(200);
}

You need bypass capacitors on the shift registers.

This does just as well. Even schematics make on KiCad are hard to understand.

This video shows why:

Really? So what are the pin functions on the SR in the Fritzing? Without looking them up?

I never said Fritzing was good.