Shop OBEX P1 Docs P2 Docs Learn Events
Propeller and piezo — Parallax Forums

Propeller and piezo

computer guycomputer guy Posts: 1,113
edited 2008-02-01 22:18 in Propeller 1
Hi everyone,

What is the easiest way to connect a piezo speaker up to a propeller chip?
The piezo I have is 5v.


Thank you smile.gif

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Check out my robot using the propeller RECONAUTOR
If you like my avatar then check this out Propeller Domed Sticker

Comments

  • OzStampOzStamp Posts: 377
    edited 2008-01-31 08:06
    Hi

    I would use a transistor like a 2n3904 or bc337 or similar with a 1K base resistor.
    These are NPN transistor..

    Supply the piezo speaker with 5VDC on 1 wire and the other wire switch it to GND

    Driving it direct from an output pin might work but the volts is a little low..

    Your stuff left today as well to DeniL.... cheers Ron
  • computer guycomputer guy Posts: 1,113
    edited 2008-01-31 08:15
    Thanks Ron,

    That sounds like a good idea.

    @OzStamp

    Just to illustrate how sparse electronics shops are around here I will tell you a quick story.

    I walked into Jaycar in Shepparton the other day and asked if they had any variable resistors and they said no so I asked for some wire ties and they said they had none of them either.

    So I might have to source a 2n3904 transistor online.
    It is a shame, I only ordered some electronics online the other day. cry.gif

    Thanks smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
  • deSilvadeSilva Posts: 2,967
    edited 2008-01-31 09:33
    To boost the voltage swing you can connect the piezo to two Propeller pins, alternating their polarity, This will give 4 fold power U2/R
  • computer guycomputer guy Posts: 1,113
    edited 2008-01-31 10:05
    deSilva,

    Thank you, however four-fold power sounds like it would be complex to implement. smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2008-01-31 21:55
    computer guy,

    You can't drive a piezo with an open collector configuration without some sort of leakage resistor across the piezo.
    The reason is because the piezo crystal behaves like a capacitor...· In open collector mode, it charges, but is not allowed to discharge.

    See this link below for some alternative 1 pin examples...

    http://forums.parallax.com/showthread.php?p=464410

    Note:
    The two transistor inverter solution is designed for 5V operation, and needs different valued resistors to work at 3.3V

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • computer guycomputer guy Posts: 1,113
    edited 2008-01-31 22:28
    Beau,

    wouldn't it be easier to just add a leakage resistor?

    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2008-01-31 22:48
    computer guy,

    You could, but you wouldn't get the volume you would from deflecting the crystal in both directions.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • computer guycomputer guy Posts: 1,113
    edited 2008-01-31 22:50
    Beau,

    I have used the piezo with the BS2 before with plenty of volume.
    Wouldn't this get the same volume, or at least close to?

    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
  • Beau SchwabeBeau Schwabe Posts: 6,559
    edited 2008-01-31 22:58
    computer guy,
    ·
    Sorry, I misread your original post... for some reason I thought you wanted more volume.
    ·
    OzStamp's solution is fine, just place a resistor (1K to 4.7K) in parallel with the piezo in addition to what he mentioned.

    deSilva's solution will also work, just fine and is capable of boosting the volume.· Just drive 2 pins 180 deg out of phase.
    ·




    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 1/31/2008 11:03:29 PM GMT
  • computer guycomputer guy Posts: 1,113
    edited 2008-01-31 23:05
    Ok, Thanks Beau will do. smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2008-01-31 23:19
    If you use one of the Propeller's built-in counters, driving two pins 180 degrees out of phase is a slam dunk. Just use the "NCO differential" mode (%00101). You can key the piezo on and off via DIRA and adjust the frequency via FRQx.

    -Phil
  • computer guycomputer guy Posts: 1,113
    edited 2008-01-31 23:49
    Phil,

    Thank you however I am happy with the circuit that Ron and Beau have provided.
    I am just wanting to drive a piezo from 3.3v.

    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2008-02-01 01:14
    If you used deSilva's technique and Phil's suggestion it is loud, easy to implement and there is no circuit as such just connect two pins to the piezo and it IS being driven by 3.3v.

    I don't understand your comment:

    "Thank you, however four-fold power sounds like it would be complex to implement"

    4 fold power means 4 times more power.

    Graham
  • computer guycomputer guy Posts: 1,113
    edited 2008-02-01 03:44
    Graham,

    I understand what four-fold power is.
    I just mean in terms of writing code that can alternate the pins and still generate the desired frequency on the piezo.

    Thank you smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
  • Graham StablerGraham Stabler Posts: 2,507
    edited 2008-02-01 18:48
    Why should alternating the pins be hard, say you code it with an XOR to toggle the pins, start with one pin high and the other low and they will then always be opposite.

    Or do as Phil suggests and use a counter, in differential mode the pins will automatically be opposite. Not sure how to proceed, then have a look at the app note and ask a question when you get stuck.

    Graham
  • computer guycomputer guy Posts: 1,113
    edited 2008-02-01 22:18
    Graham,

    I am happy with the volume I am getting, so the circuit that I have works fine for me.

    Thank you anyway smile.gif

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Check out my robot using the propeller RECONAUTOR
    If you like my avatar then check this out Propeller Domed Sticker
Sign In or Register to comment.