Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 10 of 10

Thread: Teensy 3.5 driving a piezo buzzer

  1. #1
    Junior Member
    Join Date
    Feb 2017
    Posts
    3

    Teensy 3.5 driving a piezo buzzer

    What is the best way to drive a piezo for trying to use it as a basic lo-fi speaker for playing samples? Which pin type would be best and do I need to make any special electrical provisions for it? Just checking since I am new to Teensy's, but familiar with Arduinos and other MCUs.

  2. #2
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,572
    The current limit of 20 mA will place some constraints there, as does the 3.3V drive. If you find a suitably speced piezo you can direct drive, and even H-bridge it between pins to get ~6v delta voltage but don't believe there is any library for that.

    The Teensy audio library does offer a single channel PWM output.
    https://www.pjrc.com/teensy/td_libs_Audio.html
    which may do what you want, possibly with the addition of a driver to give a voltage step up or by doing a 180 phase invert onto a second pin for a cheaters h-bridge.

    For a slightly better approach you can use the DAC out, possibly with the prop shield or similar class D amp module to give quite reasonable mono sound.

  3. #3
    Junior Member
    Join Date
    Feb 2017
    Posts
    3
    I am looking at this piezo, not sure what the current requirements are though: http://www.digikey.com/product-detai...25-1-ND/935930 I have 5V available as a power source, could I somehow sink it to ground while toggling the pin? It doesn't need to be very loud or high quality, I want to replicate some kind of mechanical ticking noise, like drive access sounds for a computer. I think I tried an H-bridge circuit before, but it seemed to use a significant amount of current. Maybe I set it up wrong, but I would like to keep the design simple. The 180 phase invert sounds interesting, is there somewhere I can find more info on it?

  4. #4
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,572
    Running the piezo off 5V won't help directly, since it will just get a swing from 5V-0v (5V) and 5V-3.3V (1.7) so your piezo only gets 3.3V worth of swing, and some model teensies might blow up just for extra fun (3.5 should be 5V tolerent). If you use a transistor drive you can PWM fine and get a 5V swing, and may be easier than trying to get a 6.6V swing by using pins driven in opisition. When you say that you had tried an H bridge, was that using a driver or just trying to have pins going in oppiste polarity? Getting that without bitbanging would be tricky since things like PWM will most likely be starting the on time together so you would need to hack into the PWM code a bit.

    The 180 inversion I suspect won't work thinking more about it, since it would require the PWM output to be more complex than I suspect it is. For the basic application you are trying suspect getting a 3.3V piezo (which I think the linked one is intended for) and driving it single ended will get you beeps and such. If it's not loud enough then go for more exotic double ended drives later.

  5. #5
    Moderator KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    3,214
    I have done it several different ways.

    When experimenting sometimes I simply hook up the buzzer directly to IO pin and GND. The one I often use(d) in circuit boards is:
    http://www.digikey.com/products/en/a...?k=102-1155-ND

    When I used them on boards I often used it with a transistor, cap... Or I also experimented with simple RC circuit.

    But sometimes I simply jamb the two pins of it into a servo expansion cable and then plug the other side into a board that has RC servo pins. I have one right now while helping someone out up on Trossen Robotics with an AVR board.

    As for generating the sounds. You can use the Arduino tone command. Some of my programs also have my own hacked up code that I can pass in multiple sounds (duration and frequency) and it plays them one after another. My code is real dumb and simply uses delayMicroseconds and digitalWrite to generate the tones...

  6. #6
    Member
    Join Date
    Nov 2015
    Location
    Cold hollow VT
    Posts
    53
    The piezo you linked to is only capable of making a loud tone when 5v is applied across it. I do not think it is suitable to reproduce sounds. You may get a 'ticking' sound from it if you just apply brief pulses of power to it. Try connecting it to a power source and swipe one set of connections together to determine if it makes the 'clicking' sound you require.

  7. #7
    Junior Member
    Join Date
    Feb 2017
    Posts
    3
    I ordered the Teensy 3.5, so I can try out some of these ideas. One concern I have on the software side is generating sounds might not be practical if playing the sound holds up the other more essential operations. This SCSI emulator project got me interested in the Teensy and I thought I could add a mod for some sounds to replicate an old drive. https://hackaday.io/project/18974-tiny-scsi-emulator

    Here's the piezo amp circuit I tried that seemed to use too much power, at least for the battery powered board I was working on. It uses too many components anyway.
    Click image for larger version. 

Name:	PiezoAmp.png 
Views:	503 
Size:	11.6 KB 
ID:	9872

  8. #8
    Senior Member
    Join Date
    Apr 2013
    Posts
    1,572
    If asking about code blocking you probably need to go back and look at the previously mentioned:
    https://www.arduino.cc/en/Reference/Tone
    https://www.pjrc.com/teensy/td_libs_Audio.html
    Audio library is overkill for what you are trying to do, but offers lots of expansion room.

  9. #9
    Member
    Join Date
    Nov 2015
    Location
    Cold hollow VT
    Posts
    53
    Your bias network keeps both Tx's (slightly) on. You need to break the connection at the 4.7k / 4.7k / 1uF junction. add another 1uF from the digital pin to the lower 4.7k and keep the connection of the upper 4.7k to the 1uF cap. That way the Tx's are off and only provide power to the piezo when Digital Pin is switching. Get yourself something like LT Spice to simulate you circuits to figure out where their faults are. It's free and there is a Yahoo users group that is excellent, just like the folks on this forum know their Teensy's.

  10. #10
    There is an excellent and very compact piezo driver and piezo speaker combo build by One Horse on Tindie

    It amplifies from 3.3v (or 5v) at 2x,2x or 3x and implements full +- range with great sound in a smaller size than the smallest piezo speaker

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •