Ultrasonic Piezo?

I appear to have an ultrasonic piezo. I can’t hear a thing coming out of it… :wink: Ok, I need a little help. I’m new to piezos. Never thought I’d have a desire to make such god awful noises but Gus has inspired me. I wired it up to an Extender module connected to a Hydra on pin 7 of socket 7 and a button on socket 13 and I run the following code but no sound comes out of the piezo. I’ve validated with an LED that the pin is supplying current. What’s the secret?

This is the piezo I’m using…

Here’s the Gadgeteer code.

        void ProgramStarted()
        {
            Debug.Print("Program Started");

            var piezoModule = piezo.SetupPWMOutput((Socket.Pin)7);

            button.ButtonPressed += delegate
            {
                Debug.Print("Pressed.");
                const float frequency = 16.35f;
                const float period = 1000000 / frequency;
                piezoModule.SetPulse((uint) period, (uint) (period/2));
                Thread.Sleep(3000);
                piezoModule.SetPulse(0, 0);
            };
        }

1000000/16.35 = 61162… so yea, you’re way outside the range of a standard piezo and human ear. Try something around 2000. Why is your frequency constant? Where did 16.35 come from? Isn’t the second parameter of SetPulse the duty cycle? If so, this should have a value of 0-100.

That was my late night attempt at reverse engineering some online code… However, I tried (2000, 50) and (2000,100) and still no go. Could I have damaged the piezo by providing too high of values?

@ Ian

I would go even lower. Concert “A” is 440hz, which is where I’d typically start, since it’s roughly in the middle of the musical scale, and thus almost certain to be reproducible by any speaker or piezo.

Depending on the piezo, it might not be capable of getting as high as 2000hz (I’m speculating here, as I don’t have a ton of piezo experience, but 2000hz is more than 2 octaves higher than concert A, so it’s not inconceivable that a cheap piezo might not get that high). I have a commitment outside the office today, but I’ll try to hook up my piezo over the weekend and see if I can get it to sound at 2000hz. Will let you know.

They’re usually pretty tough. Check the specs on the piezo and see if you’ve got enough power to drive it. They come in a million different configurations (and quality, although adafruit takes care of the latter issue). The cheapos I got from Radio Shack sound best in the 1800-2000 range, high enough to make the dogs run for cover and howl ??? At 440 they sound like a sick bumblebee.

440 didn’t do anything either. I think you may be right about the lack of power. I’m powering it straight off the pin. However, every example I see on YouTube is doing the same thing. Unfortunately, there are zero specs on Adafruit about this part. I may swing by Radio Shack today and pick up a few more varieties to try.

Did you scope the pin?

Note that pin# != pwmpin#

Get rid of the resistor

Unfortunately, I do not currently have a scope.

What do you mean? Socket.Pin #7 of socket #7 is supposed to be PWM0, correct?

Didn’t help.

socket pin7 = IOxxx for example but that is not PWM0.

Can you simply try this fro now the non-gadgeteer way and use PWM0 from PWM class.

Are you sure ? :o Schematics does indeed say that it’s PWM0 (on Hydra, of course). :think:

Edit: I think I understand what you want to say… :hand: In this case, PWM0 is pin PD14, which would translate to (CPU.Pin)110.

I’ll give it a try the non-Gadgeteer way tonight.

Ok. Either I’m doing something wrong or there’s another problem. I suspect the former. I’m trying to create the PWM object for Socket #7 pin #7 (PWM0) trying both of these…


var pwm = new PWM((PWM.Pin)110);
//and for kicks...
var pwm = new PWM((PWM.Pin)0);

in both cases, I get…

Any ideas?

Of course this is not going to work :slight_smile:

You are suing hydra right? Are you using GHI.OSH libs? …the correct libs?

Show your complete code, which should be about 5 lines of code please.

Ah… I knew there was something obvious I was forgetting. I got past the deployment problem but now I’m getting the same result as before - no sound from the piezo. I’m getting power from the pin but no sound from the piezo. So, maybe I’m not getting enough power. I picked up a different piezo from Radio Shack today. It’s supposed to have a range of 3.0 - 7 V. So, I would expect to get something.

I’m going to try the same thing on a Panda now…



using System.Threading;
using Microsoft.SPOT;
using GHIElectronics.OSH.NETMF.Hardware;

namespace HydraPiezoNativeTest
{
    public class Program
    {
        public static void Main()
        {
            Debug.Print("Program started.");
            var pwm = new PWM(PWM.Pin.PWM0);
            pwm.SetPulse(2000, 50);
            Thread.Sleep(3000);
            pwm.Set(0,0);
        }

    }
}

Why set pulse? Just use set!

Woo hoo! I have noise!!! I think the netduino example I started from was using SetPulse so I never really thought to do it otherwise…

Changing the native code to


            var pwm = new PWM(PWM.Pin.PWM0);
            pwm.Set(2000, 100);
            Thread.Sleep(3000);
            pwm.Set(0,0);

solved the problem. Also, changing the same Set() line worked using Gadgeteer code.

However, I tried the piezo I was using last night and still got no sound out of it. So, I suspect it either does require a higher voltage or I’ve somehow damaged it.