Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

OZ-Solutions - Sheet Music


  • Please log in to reply
17 replies to this topic

#1 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 18 September 2010 - 05:35 AM

Sources (Places I copied a little from ;) ):
Piezo Buzzer (Netduino Forums)
Notes to Frequencies and Mario Song



If you need help with the implementation of this ask right here.

UPDATE
--------------------------------------------------------------------------

Fixed the Play method - correction provided by Robert Echten (http://forums.netdui...-robert-echten/)

Attached Files

  • Attached File  Sound.cs   5.68KB   165 downloads


#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 18 September 2010 - 04:42 PM

Ooh, I want to play! [literally] If you have more code or instructions to share, I'd love to build it myself as well... Chris

#3 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 18 September 2010 - 08:40 PM

Ooh, I want to play! [literally]

If you have more code or instructions to share, I'd love to build it myself as well...

Chris

Its not quite ready but I will post it soon! I got to do some stuff and I found a second speaker so now I can make a better song... To use the two I'll have to use multi-threading, so I'll be adding that to my class next.

#4 hari

hari

    Advanced Member

  • Members
  • PipPipPip
  • 131 posts

Posted 19 September 2010 - 08:07 AM

I probably should not be posting code this late.
I know of at least one bug (Mission Impossible missed two notes), but I'm too excited not to share.
Source code attached to this post. Excuse the blurry video. I need to go to sleep. Posted Image

Belive it or not, it sounds a little bit better in real life -- less harmonics. Enjoy!

http://www.youtube.com/watch?v=MjprqDe2ftA

Attached Files



#5 Eric Burdo

Eric Burdo

    Advanced Member

  • Members
  • PipPipPip
  • 130 posts

Posted 19 September 2010 - 11:14 AM

Oooh... I think I'm going to have to try this today. I can claim it as a learning experience... I gotta learn PWM anyhow... :)
~ Eric D. Burdo ~ http://brick-labs.com/

Today LED's, tomorrow, the world!!! Well, OK, maybe servos.

#6 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 19 September 2010 - 01:37 PM

I probably should not be posting code this late.
I know of at least one bug (Mission Impossible missed two notes), but I'm too excited not to share.
Source code attached to this post. Excuse the blurry video. I need to go to sleep. Posted Image

Belive it or not, it sounds a little bit better in real life -- less harmonics. Enjoy!

http://www.youtube.com/watch?v=MjprqDe2ftA


Very Nice!

#7 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 19 September 2010 - 03:56 PM

Wow oz. Yet again, great stuff. I wonder if we could add an SD card and MIDI file parser to that and then users could insert an SD card and it would be a "music player"... Chris

#8 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 19 September 2010 - 04:02 PM

Wow oz. Yet again, great stuff.

I wonder if we could add an SD card and MIDI file parser to that and then users could insert an SD card and it would be a "music player"...

Chris


I'd be awesome if I could make my own file format to save these note sequences. I have done it before with a regular C# program, but yeah I would need to save the file with the netduino to an SD card...

Are there any updates on the mega netduino idea?

#9 CwbhX

CwbhX

    Advanced Member

  • Members
  • PipPipPip
  • 85 posts
  • LocationNYC

Posted 09 October 2010 - 02:26 AM

Wow! Nice, looks pretty great! How loud does this thing go? Could you possible make a unique door bell with this? I don't believe mine is working at the moment. I knew I should have brought my Netduino Plus with me I have my breadboard & cables, and several speakers, where I am now. P.S. I remember at a C++ session I went to, one kid made a whole program that just played you simple tunes, it was pretty great :)
-Cwbh

#10 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 09 October 2010 - 03:11 AM

Wow! Nice, looks pretty great!
How loud does this thing go? Could you possible make a unique door bell with this? I don't believe mine is working at the moment.


I knew I should have brought my Netduino Plus with me I have my breadboard & cables, and several speakers, where I am now.

P.S. I remember at a C++ session I went to, one kid made a whole program that just played you simple tunes, it was pretty great :)


The speakers are somewhat loud... I got a speaker from a hallmark birthday card that plays music, and it is much louder than the ones in the video, and piezo buzzers.

I guess you COULD make a doorbell, but it wouldnt be too alarming since the speakers arent that loud. I think if you were to get bigger speakers, and supply them with external power it would be great. I havent figured out the whole supplying extra power and using the PWM ports, so you'll have to ask around.

#11 Robert Echten

Robert Echten

    New Member

  • Members
  • Pip
  • 3 posts

Posted 17 November 2010 - 03:45 AM

Hi Omar,

Just had a look at your player for a little holiday project I'm working on and found that some notes couldn't be heard (I guess the same thing happens with the two notes you claim to have missing in the Mission Impossible ringtone).

After some investigation, what I found was that your PlayNote method allows the duration to be longer than the period, which I understand is not allowed. If I understand it correctly PWM sets a period (the total time of one cycle in the square wave) and the duration is the total time in that period that it's ON).

This means that the duration should therefore be less than the period. However, if you make the duration the same as the period or slightly less, it still drops off (you can still hear it, but only faint). I found that a max duration of 95% of the period worked well for me. I changed your PlayNote method as follows:
        public static void PlayNote(uint frequencyInHertz, uint durationMilliseconds)
        {

            if (frequencyInHertz != 0)
            {
                uint timbre = 50; // 50% = perfect square wave.
                pwm.SetDutyCycle(timbre);

                uint period = (uint)1000000 / frequencyInHertz; // 1000,000 instead of 1,000 because SetPulse duration is in microseconds, not in milliSeconds.

                //Duration needs to be less than the period. To make sure we have at least some sound, make sure we stay below 95% of the period:
                double maxDuration = 0.95*period;
                uint duration = (uint)(durationMilliseconds <= maxDuration ? durationMilliseconds : maxDuration);
                Debug.Print("Frequency -> " + frequencyInHertz + ", Period -> " + period + ", durationMilliseconds -> " + durationMilliseconds + ", Max Duration -> " + maxDuration + ", duration -> " + duration);
                pwm.SetPulse(period, duration);
            }

            //-- Wait for note (or silence) to play out, then be quiet --
            Thread.Sleep((int)durationMilliseconds);
            pwm.SetDutyCycle(0);
        }
Hope this helps. If anyone has some suggestions or want to tell me I'm completely wrong, please feel free. I'm an experienced .Net developer, but new to Netduino/electronics, so...

Robert :-)

#12 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 17 November 2010 - 03:10 PM

Hi Omar,
...
Hope this helps. If anyone has some suggestions or want to tell me I'm completely wrong, please feel free. I'm an experienced .Net developer, but new to Netduino/electronics, so...

Robert :-)



I'll update my code once I get home. Thanks for the corrections.

#13 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 18 November 2010 - 12:15 AM


Hope this helps. If anyone has some suggestions or want to tell me I'm completely wrong, please feel free. I'm an experienced .Net developer, but new to Netduino/electronics, so...

Robert :-)


I am about to post update, I think you have a pretty solid explanation there.... you are probably right, and if it worked better for you, then I should post the improved code.

Thanks again
-Omar

#14 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 18 November 2010 - 12:37 AM

Wow! Nice, looks pretty great!
How loud does this thing go? Could you possible make a unique door bell with this? I don't believe mine is working at the moment.


I knew I should have brought my Netduino Plus with me I have my breadboard & cables, and several speakers, where I am now.

P.S. I remember at a C++ session I went to, one kid made a whole program that just played you simple tunes, it was pretty great :)


Are you still trying to do this? I found out how it can be done.
Use some 'audio grade' transistors to supply the bigger speakers with the proper voltage. If you still want to do that I can help you.

#15 VincentA

VincentA

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts
  • LocationIndia

Posted 02 January 2011 - 07:48 AM

this one worked really nice!!! Thanks Omar! heres few other tunes http://www.ez4mobile...atone/rtttf.htm My favorite is "Knight Rider"

#16 Charles

Charles

    Advanced Member

  • Members
  • PipPipPip
  • 192 posts

Posted 02 January 2011 - 05:21 PM

Nice PWM project Oz! I love it!

#17 Dezorian

Dezorian

    Member

  • Members
  • PipPip
  • 24 posts

Posted 02 March 2011 - 04:11 PM

Wow oz. Yet again, great stuff.

I wonder if we could add an SD card and MIDI file parser to that and then users could insert an SD card and it would be a "music player"...

Chris


I'm very interested in this feature as well!

#18 Omar (OZ)

Omar (OZ)

    Advanced Member

  • Members
  • PipPipPip
  • 564 posts

Posted 02 March 2011 - 09:47 PM

I'm very interested in this feature as well!

I should get started on that then :) thanks for your interest.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.