MIDI Song on Raspberry Pi W/ Piezo Speaker


I pulled a piezo speaker from an old desktop computer that I had. These things can run directly off the GPIO or you can add a resistor to lower the volume if necessary. I connected the speaker to pin GPIO18 (PWM) and GND.

I then used a modified version of the code presented here on the third post. I do not take any credit for writing this code.

http://www.raspberrypi.org/phpBB3/viewtopic.php?f=44&t=20559

What the poster did not mention was that “tone 60″ is equivalent to MIDI middle C. From there you can figure out what value most of the major notes are. Then you can create a little song by expanding upon that script which is what I have done. I did it line by line which is likely the laziest and most inefficient method. Instead an array could have been used or an input file to be parsed. You can also change the time length of each note but I just left most of them 0.1 seconds.

There are more efficient ways of doing it, but I was working with what I had for my first go at the GPIOs.

I get my GPIO breakout and breadboard this week, so I will play around more.

About these ads

2 responses to “MIDI Song on Raspberry Pi W/ Piezo Speaker

  1. * A sitemap to navigate your website is helpful for visitors to access main pages.
    The website speed test at Secret Search Engine Labs will analyze
    how fast a page on your site is loading and give you tips on how to improve it.
    Besides placing advertisers ads on your Blog, you can also
    make money Blogging by placing Google Adsense into your Blog.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s