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.


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.

3 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.

  2. Schools and programs provide academic and social support to help students succeed with the demanding coursework.
    Most children who exhibit violent or aggressive behaviors suffer from low self
    esteem and self image. Laurel Springs School is an accredited, college prep private school
    offering distance learning programs and teacher services for students in grades K-12.

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