Piezo mono

Hey,

i want to rebuild a netduino project on the gadgeteer. OK no problem… think.
I connected a buzzer to my extender modul and want to play my RTTL Ringtones. But there is only a monotone “klick” “klick” “klick” every tone.

I have a Cerberus.

Thought i’m doing wrong, i tried a example:
http://www.tinyclr.com/codeshare/entry/345

But this the same result.

I changed the piezo, its the same.

Here is my code:


using System.Threading;
using Gadgeteer;
using Gadgeteer.Interfaces;
using Microsoft.SPOT;


namespace RingtonePlayer
{
    public partial class Program
    {
        private PWMOutput buzzer;
        private void ProgramStarted()
        {
            Debug.Print("=== Config");
            buzzer = extender.SetupPWMOutput(Socket.Pin.Nine);

            Debug.Print("=== Elvis has entered the building.");

                button.TurnLEDOn();
                buzzer.Set(262, 1);
                buzzer.Set(440, 0);
                Thread.Sleep(250);
                buzzer.Set(294, 1);
                buzzer.Set(440, 0);
                Thread.Sleep(250);
                buzzer.Set(330, 1);
                buzzer.Set(440, 0);
                Thread.Sleep(250);
                buzzer.Set(349, 1);
                buzzer.Set(440, 0);
                Thread.Sleep(250);
                buzzer.Set(392, 1);
                buzzer.Set(440, 0);
                Thread.Sleep(250);
                buzzer.Set(440, 1);
                buzzer.Set(440, 0);
                Thread.Sleep(250);
                buzzer.Set(494, 0.5);
                buzzer.Set(440, 0);
                Thread.Sleep(250);
                buzzer.Set(523, 0.5);
                buzzer.Set(440, 0);
                Thread.Sleep(250);
                buzzer.Set(494, 0.5);
                buzzer.Set(440, 0);
                Thread.Sleep(250);
                buzzer.Set(440, 0.5);
                buzzer.Set(440, 0);
                Thread.Sleep(250);
                buzzer.Set(392, 0.5);
                buzzer.Set(440, 0);
                Thread.Sleep(250);
                buzzer.Set(349, 0.5);
                buzzer.Set(440, 0);
                Thread.Sleep(250);
                buzzer.Set(330, 0.5);
                buzzer.Set(440, 0);
                Thread.Sleep(250);
                buzzer.Set(294, 0.5);
                buzzer.Set(440, 0);
                Thread.Sleep(250);
                buzzer.Set(262, 0.5);
                buzzer.Set(440, 0);
                Thread.Sleep(250);
                buzzer.Set(440, 0);
                buzzer.Set(440, 0);
                button.TurnLEDOff(); 
            
            Debug.Print("=== Elvis has left the building.");
        }
}

Thanks for help

What is your firmware version?

Here is my MFDeploy Result:

[quote]HalSystemInfo.halVersion: 4.2.0.0
HalSystemInfo.halVendorInfo: Microsoft Copyright © Microsoft Corporation. All rig
HalSystemInfo.oemCode: 255
HalSystemInfo.modelCode: 0
HalSystemInfo.skuCode: 65535
HalSystemInfo.moduleSerialNumber: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
HalSystemInfo.systemSerialNumber: FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
ClrInfo.clrVersion: 4.2.0.0
ClrInfo.clrVendorInfo: Microsoft Copyright © Microsoft Corporation. All rig
ClrInfo.targetFrameworkVersion: 4.2.0.0
SolutionReleaseInfo.solutionVersion: 4.2.0.1
SolutionReleaseInfo.solutionVendorInfo: Copyright © GHI Electronics, LLC
SoftwareVersion.BuildDate: May 21 2012
SoftwareVersion.CompilerVersion: 410462
FloatingPoint: True
SourceLevelDebugging: True
ThreadCreateEx: True
LCD.Width: 0
LCD.Height: 0
LCD.BitsPerPixel: 0
AppDomains: True
ExceptionFilters: True
IncrementalDeployment: True
SoftReboot: True
Profiling: False
ProfilingAllocations: False
ProfilingCalls: False
IsUnknown: False[/quote]

@ cyntonix - I think your issue may be that your decimal place is off on the duty cycle. If you want 50% you need to use 50, not 0.5. Check out the following code submission of mine:

http://www.tinyclr.com/codeshare/entry/345

It demonstrates using e-block Piezos with Gadgeteer, so I know it works. :slight_smile:

Hi, looks like you’re setting a duty cycle of 1%, then immediately setting it to zero (off), then waiting - so it clicks then is silenced. Instead, set your frequency with a duty cycle of 50, then do the Thread.Sleep for the duration you want the note to sound, then set it to zero to make it stop. Here’s a function I use:


        void Beep(int freq, int duration)
        {
            piezo.Set(freq, 50);
            Thread.Sleep(duration);
            piezo.Set(freq, 0);
        }

So you could either try that (e.g. Beep(262,250):wink: or fix your code by moving all the calls to buzzer.Set(440, 0) after the Thread.Sleeps, and scale up all the non-zero second parameters (where you’ve currently got 1 or 0.5) by a factor of 100.

Edit - beaten to it about the scaling, the placement of the Set(440,0) is still important though!

RorschachUK

Thanks all for reply,

i get a System.ArgumentException on first line with .Set:
buzzer.Set(440, 50);

Debugger only says “Information”: dutyCycle

I think its only able to set a dutyCircle under 1… intellisense says it :slight_smile: (See Screenshot)

Here is the German Message in the Screenshot.

And here the Output:

[quote]Eine Ausnahme (erste Chance) des Typs “System.NotSupportedException” ist in Microsoft.SPOT.IO.dll aufgetreten.
Der Thread ‘’ (0x2) hat mit Code 0 (0x0) geendet.
Warning: socket 8 is not compliant with Gadgeteer : Cpu pin 4 must be specified for socket of type D
Warning: socket 8 is not compliant with Gadgeteer : Cpu pin 5 must be specified for socket of type D
Using mainboard GHI Electronics FEZCerberus version 1.1
=== Config
Eine Ausnahme (erste Chance) des Typs “System.ArgumentException” ist in Gadgeteer.dll aufgetreten.
Eine nicht behandelte Ausnahme des Typs “System.ArgumentException” ist in Gadgeteer.dll aufgetreten.

Zusätzliche Informationen: dutyCycle[/quote]

Ah yes - in this respect NETMF 4.2 is different to 4.1, as I learned yesterday with an error with the Motor Driver module. So the values of 1 and 0.5 might be OK - in which case it’s just the placement of the lines with duty cycle of 0 which were wrong (should be after the thread.sleep). Or, you could fix my Beep routine for NETMF 4.2 by changing the 50 for 0.5.

Hi cyntonix,

PWM in 4.2 does use the 0-1 duty range. The range is in essence 0 to 100% but in decimal format. We discovered that the sound will not come out if it is at an even 100. Reformatting your code gave a scaled result (the tune is a note scale) :slight_smile: . Try this and see what happens:


            //button.TurnLEDOn();
            buzzer.Set(262, 0.75);
            //buzzer.Set(440, 0);
            Thread.Sleep(250);
            buzzer.Set(294, 0.75);
            //buzzer.Set(440, 0);
            Thread.Sleep(250);
            buzzer.Set(330, 0.75);
            //buzzer.Set(440, 0);
            Thread.Sleep(250);
            buzzer.Set(349, 0.75);
            //buzzer.Set(440, 0);
            Thread.Sleep(250);
            buzzer.Set(392, 0.75);
            //buzzer.Set(440, 0);
            Thread.Sleep(250);
            buzzer.Set(440, 0.75);
            //buzzer.Set(440, 0);
            Thread.Sleep(250);
            buzzer.Set(494, 0.25);
            //buzzer.Set(440, 0);
            Thread.Sleep(250);
            buzzer.Set(523, 0.25);
            //buzzer.Set(440, 0);
            Thread.Sleep(250);
            buzzer.Set(494, 0.25);
            //buzzer.Set(440, 0);
            Thread.Sleep(250);
            buzzer.Set(440, 0.25);
            //buzzer.Set(440, 0);
            Thread.Sleep(250);
            buzzer.Set(392, 0.25);
            //buzzer.Set(440, 0);
            Thread.Sleep(250);
            buzzer.Set(349, 0.25);
            //buzzer.Set(440, 0);
            Thread.Sleep(250);
            buzzer.Set(330, 0.25);
            //buzzer.Set(440, 0);
            Thread.Sleep(250);
            buzzer.Set(294, 0.25);
            //buzzer.Set(440, 0);
            Thread.Sleep(250);
            buzzer.Set(262, 0.25);
            //buzzer.Set(440, 0);
            Thread.Sleep(250);
            buzzer.Set(440, 0);
            //buzzer.Set(440, 0);
            //button.TurnLEDOff();

@ Aron - Thanks for the heads-up…didn’t realize that had changed in 4.2. Something to watch out for, since I have a number of robotic projects on the agenda for this month. :slight_smile:

I’ve updated my codeshare entry with a note regarding the new duty cycle format.

It would have been easier if PWM raised an exception fro anything more than 1.

Here are my first Step for my Musicboard…

http://www.youtube.com/watch?v=9fsC-giIvuY

But think Im doing it not completly correct, because thats only short not loud pieps.
In your example the noise is louder.

My Project can be found here:
https://dl.dropbox.com/u/76092/RingtonePlayer_2012-06-14.zip

Thanks for all

Nice! The only thing that is missing is a fog machine! :smiley:

Yep, a fog machine :slight_smile:

Here the second version. Fog machine is coming in 2.0 :slight_smile:

Here the project:
https://dl.dropbox.com/u/76092/RingtonePlayer_2012-06-15.zip

Suggstestions are welcome.

Greets
Johann

Sweet

Loved the Zelda theme.