Recent

Author Topic: Buzzer to raspberry pi 2  (Read 13680 times)

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Buzzer to raspberry pi 2
« on: April 29, 2016, 06:03:40 pm »
Hello guys, I bought a buzzer for my raspberry pi 2.
Now comes the difficult, after connecting how do I let him make a sound?

Thanks for the help
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Buzzer to raspberry pi 2
« Reply #1 on: May 02, 2016, 09:25:24 am »
Any suggestions? No one has ever done this with Lazarus?
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: Buzzer to raspberry pi 2
« Reply #2 on: May 02, 2016, 10:02:45 am »
A buzzer is like a switch. It "clicks" every time you turn it on or off. To make it buzz, do that very fast.

First you have to find out how it is connected. If it is simply connected between +3.3V and a GPIO pin, use a library for that, a timer, and just swap the state:

Code: Pascal  [Select][+][-]
  1. procedure MyTimerOnTimer(Sender: TObject);
  2. begin
  3.   MyTimerPin := not MyTimerPin;
  4. end;
  5.  

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Buzzer to raspberry pi 2
« Reply #3 on: May 02, 2016, 10:07:55 am »
for my buzzer I have three cables

Yellow: in
Red: vcc
Black: gnd

The gpio is the raspberry pi 2. Tell me about what you want to pin gpio I put them so we reason with the same data.

Also refer to a library. To what are you referring to?

Thanks
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: Buzzer to raspberry pi 2
« Reply #4 on: May 02, 2016, 10:27:14 am »
GPIO Library.

If it has three wires, it has a built-in resonator, so you only have to turn it on once to get it buzzing, you don't need a timer.

mig-31

  • Sr. Member
  • ****
  • Posts: 305
Re: Buzzer to raspberry pi 2
« Reply #5 on: May 02, 2016, 10:36:31 am »
You should use a buzzer with voltage supplied by Rasberry Pi. Default is 3.3V.  Connected +3.3V and GND pins to your buzzer.
Lazarus 2.2.6 - OpenSuse Leap 15.4, Mageia 8, CentOS 7

Thaddy

  • Hero Member
  • *****
  • Posts: 14157
  • Probably until I exterminate Putin.
Re: Buzzer to raspberry pi 2
« Reply #6 on: May 02, 2016, 10:47:12 am »
You should use a buzzer with voltage supplied by Rasberry Pi. Default is 3.3V.  Connected +3.3V and GND pins to your buzzer.
Yup, but that's not all:
Given is:
Yellow: in   // this controls buzzing or not (hi or low), choose any suitable pin from the GPIO
Red: vcc    // is the 3.3V pin, use a hot pin, there are at least two depending on your Pi
Black: gnd// is ground.

Some buzzers just require red and black, though, as suggested. Yellow should bring down vcc as well.
If the buzzer itself is dumb, you can use a pull-up resistor for that between the yellow pin and vcc. See: http://www.seattlerobotics.org/encoder/mar97/basics.html
« Last Edit: May 02, 2016, 11:07:12 am by Thaddy »
Specialize a type, not a var.

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Buzzer to raspberry pi 2
« Reply #7 on: May 02, 2016, 03:24:59 pm »
Thanks for the suggestions. I did a little test but does not work. I attach the test source and the photos of how I connected the buzzer to 2 pi raspberry.

Strangely me error:
Error mapping gpio registry

Thans
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

xinyiman

  • Hero Member
  • *****
  • Posts: 2256
    • Lazarus and Free Pascal italian community
Re: Buzzer to raspberry pi 2
« Reply #8 on: May 02, 2016, 03:25:26 pm »
My connection
Win10, Ubuntu and Mac
Lazarus: 2.1.0
FPC: 3.3.1

SymbolicFrank

  • Hero Member
  • *****
  • Posts: 1313
Re: Buzzer to raspberry pi 2
« Reply #9 on: May 02, 2016, 03:50:41 pm »
Do you have a multimeter? First, find two pins with 3.3V and one with 0V. Connect the black cable to 0V and the red to 3.3V. You should hear silence. Now connect the yellow to 3.3 as well, and you should hear a buzz.

No? Ok, some more explanation.

You want to power something. That requires that those pins can deliver that power. Power supply pins can do that, processor pins cannot. So, you want the red cable connected to a power supply pin.

The easy way to test this, is that the power on the red and yellow pins has to stay above 3.3V when connected. If it drops, it was a processor pin and not a power supply pin.

When you found the right pins and the buzzer makes noise, it is time to program a pin. Write and execute your program and measure if the voltage on the pin switches between 0 and 3.3V. If it did, use that for the yellow cable.

If it still doesn't work, you need a pull-up resistor, like Thaddy posted. Start with 10k, if that doesn't work, try 4.7k.

If it still doesn't work, post specs.
« Last Edit: May 02, 2016, 04:49:57 pm by SymbolicFrank »

Thaddy

  • Hero Member
  • *****
  • Posts: 14157
  • Probably until I exterminate Putin.
Re: Buzzer to raspberry pi 2
« Reply #10 on: May 02, 2016, 04:58:28 pm »
Do you have a multimeter? First, find two pins with 3.3V and one with 0V. Connect the black cable to 0V and the red to 3.3V. You should hear silence. Now connect the yellow to 3.3 as well, and you should hear a buzz.

Correct for test... But not correct for programming... Don't, plz, don't (if by chance they are parallel you have a lot more than you want) connect two hot lines, Use a switch line. There are plenty.
The correct way to test is connect the yellow wire to the red wire, connect to hot and black to earth. If you're not deaf, disconnect immediately. It is not easy to blow up a buzzer, but you can.... :) <i did that, many moons ago>
Specialize a type, not a var.

 

TinyPortal © 2005-2018