# Piezo Ring Tones with Raspberry Pi

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/023/681/medium800/components_piezo-rttl.png?1425497401)

The ringtone text transfer language ( **RTTTL** ) is a way to represent music data for play on older mobile phones. &nbsp;The format was created by Nokia for thier phones, but it also works with GPIO pins and a piezo buzzer.

This project shows how to use the Raspberry Pi's GPIO pins to play RTTTL on a piezo buzzer. &nbsp;This project was inspired by existing RTTTL implementations, but differs from those in that its user interface is Web enabled.

The application, written in Java, starts an HTTP server. &nbsp;The HTTP server presents the user interface via HTML. &nbsp;The user interface provides a list of built-in RTTTL ditties&nbsp;available for play. &nbsp;The application's interface also accepts user-provided RTTTL sequences, via its on-the-fly input controls.

# Piezo Ring Tones with Raspberry Pi

## Assembly

This guide assumes a Raspberry Pi, with network access, is available.

Need help setting up a network-enabled Raspberry Pi? &nbsp;If so, check out these [awesome Raspberry Pi tutorials](../../../../category/learn-raspberry-pi "awesome Raspberry Pi tutorials").

Assembling this project involves&nbsp;connecting a piezo buzzer's leads to Raspberry Pi GPIO pins.

Connecting a piezo buzzer to the Raspberry Pi is a blast, but don't be alarmed. &nbsp;It is also easy to do.

&nbsp;Here is a wiring diagram for this project:

![](https://cdn-learn.adafruit.com/assets/assets/000/023/606/medium800/components_wiring-diagram_bb.png?1425252611)

Connect one of piezo leads to ground on the Raspberry Pi. &nbsp;The other piezo lead goes to GPIO pin 22. &nbsp;It is the 8th pin&nbsp;down, in the left column, from the end closest to the SD card slot.

# Piezo Ring Tones with Raspberry Pi

## Software

## System Requirements

Java 8 is a requirement for this project. &nbsp;The latest version of Raspbian, the recomended OS for this projet, comes pre-bundled with Java 8.

Don't have Java 8 on the Raspberry Pi? &nbsp;Then use these commands to install or update:

`sudo apt-get updatesudo apt-get upgradesudo apt-get install oracle-java8-jdk`

## Application

The application software for this project&nbsp;is distributted as an executable JAR file.

Download the JAR and copy it&nbsp;to the Raspberry Pi.

[pisoundo-0.0.1-SNAPSHOT-jar-with-dependencies.jar](https://learn.adafruit.com/system/assets/assets/000/023/642/original/pisoundo-0.0.1-SNAPSHOT-jar-with-dependencies.jar?1425404617)
If you are not familiar with copying files over the network to a Rasspberry Pi, then see these links for details:

- [easiest way](https://blog.adafruit.com/2015/02/27/the-easiest-way-to-transfer-files-between-raspberry-pi-and-pc-ubuntu-or-windows-raspberry_pi-piday-raspberrypi/ "easiest way to transfer files")
- [remote copy](https://blog.adafruit.com/2014/03/21/how-to-remotely-copy-files-to-and-from-your-raspberry-pi-raspberry_pi-piday-raspberrypi/ "remote copy")&nbsp;(also easy)

With the JAR file copied over, issue this at the Raspberry Pi's command line interface:

`sudo java -jar pisoundo-0.0.1-SNAPSHOT-jar-with-dependencies.jar`

Replace **pisoundo-0.0.1-SNAPSHOT-jar-with-dependencies.jar** with whatever you named the JAR file when copying to the Raspberry PI.

Verify the server application is running and accessible. &nbsp;Browse to this URL, from a device on the same network where the application is running.

**http://raspberry-pi:2110/ui/index.html**

Notes:

- The ' **raspberry-pi'** part of the URL should be replaced with the actual IP or hostname of the Raspberry Pi.  
  
- Keep the port number in the URL.

# Piezo Ring Tones with Raspberry Pi

## Usage

If everthing went well in the **Software** section, then you should see the following user interfae in the browser:

![](https://cdn-learn.adafruit.com/assets/assets/000/023/639/medium800/components_user-interface-screen-shot.png?1425399268)

## &nbsp;Built-In RTTTLs

The screenshot above shows the list of built-in RTTTL sequences. &nbsp;Play a ditty by clicking on its name in the list.

## Playing other RTTTLs

Play other&nbsp;RTTTLs on the-fly! &nbsp;Click the 'On-the-Fly' link at the top right of the UI.

![](https://cdn-learn.adafruit.com/assets/assets/000/023/640/medium800/components_user-interface-on-the-fly-link.png?1425400188)

This brings up a input text box and 'Play' button.

![](https://cdn-learn.adafruit.com/assets/assets/000/023/641/medium800/components_user-interface-on-the-fly.png?1425400782)

Copy and paste an RTTTL sequence in the textbox, then click the 'Play' button.

An RTTTL sequence is something like:

- **PEANUTS:d=4,o=5,b=160:f, 8g, a, 8a, 8g, f, 2g, f, p, f, 8g, a, 1a, 2p, f, 8g, a, 8a, 8g, f, 2g, 2f, 2f, 8g, 1g**  
  

- **Austin Powers Theme:d=4,o=5,b=140:a#, 8c#6, 8a#, 8d#6, 8c#6, 8a#, a#, 8a#, 8a#, 8f, g#, 8a#, 8f, g#, 8a#, 8f, g#, 8a#, g#, 8a#, 8a#, 8g#, 8a#, 8c#6, 8d#6, 8c#6, f6, f6, 8g#6, f6, 8g#6, 8a#6, 8a#6, 8a#6, 8g#6, 8f6, 8d#6, 8c#6, 8g#, 8a#, 8f, 8g#, 8f, g#, 8a, a#**

The 'Resources' section has a link to more RTTTL selections. &nbsp;

# Piezo Ring Tones with Raspberry Pi

## Going Further

## Customize the Built-In RTTTLs

Bring down the source code for the project.

`git clone https://github.com/onebeartoe/media-players.git`

The built-in selections are updated/modified by editing the **BuiltInSongs.java** file. &nbsp;

The path to that file, under the cloned github project, is:

**path-to-github-clone/media-players/pi-ezo/src/main/java/org/onebeartoe/media/piezo/ports/rtttl/BuiltInSongs.java**

Open and edit this file with your favorite text editor.

The actuall RTTTL data is stored in the elements of the String array variable named&nbsp; **songData**.

To add RTTTL sequences, place a comma character after the last one, followed by the RTTTL data in double quotes.

So if the RTTTL array data looked like this before adding a sequence:

```auto
private final String[] songData =
{
"The Simpsons:d=4,o=5,b=160:c.6,e6,f#6,8a6,g.6,e6,c6,8a,8f#,8f#,8f#,2g,8p,8p,8f#,8f#,8f#,8g,a#.,8c6,8c6,8c6,c6",
"Indiana:d=4,o=5,b=250:e,8p,8f,8g,8p,1c6,8p.,d,8p,8e,1f,p.,g,8p,8a,8b,8p,1f6,p,a,8p,8b,2c6,2d6,2e6,e,8p,8f,8g,8p,1c6,p,d6,8p,8e6,1f.6,g,8p,8g,e.6,8p,d6,8p,8g,e.6,8p,d6,8p,8g,f.6,8p,e6,8p,8d6,2c6"
};
```

Then the RTTTL array data would&nbsp;look like this after adding a sequnce:

```auto
private final String[] songData =
{
"The Simpsons:d=4,o=5,b=160:c.6,e6,f#6,8a6,g.6,e6,c6,8a,8f#,8f#,8f#,2g,8p,8p,8f#,8f#,8f#,8g,a#.,8c6,8c6,8c6,c6",
"Indiana:d=4,o=5,b=250:e,8p,8f,8g,8p,1c6,8p.,d,8p,8e,1f,p.,g,8p,8a,8b,8p,1f6,p,a,8p,8b,2c6,2d6,2e6,e,8p,8f,8g,8p,1c6,p,d6,8p,8e6,1f.6,g,8p,8g,e.6,8p,d6,8p,8g,e.6,8p,d6,8p,8g,f.6,8p,e6,8p,8d6,2c6",
"MissionImp:d=16,o=6,b=95:32d,32d#,32d,32d#,32d,32d#,32d,32d#,32d,32d,32d#,32e,32f,32f#,32g,g,8p,g,8p,a#,p,c7,p,g,8p,g,8p,f,p,f#,p,g,8p,g,8p,a#,p,c7,p,g,8p,g,8p,f,p,f#,p,a#,g,2d,32p,a#,g,2c#,32p,a#,g,2c,a#5,8c,2p,32p,a#5,g5,2f#,32p,a#5,g5,2f,32p,a#5,g5,2e,d#,8d"
};
```

&nbsp;Save the changes.

Next, repackage the application for distribution to the Raspberry Pi. &nbsp;At a command line window, change directories to the directory where the github project was cloned. &nbsp;Then issue the following command:

`mvn package`

This will create an executable JAR file, at this location:

**path-to-github-clone/media-players/pi-ezo/target/pisoundo-0.0.1-SNAPSHOT-jar-with-dependencies.jar**

Copy this updated JAR to the Raspberry Pi, and run as before to see the updated list of built-in RTTTLs.

# Piezo Ring Tones with Raspberry Pi

## Resources

- [Piezo on Raspberry Pi using C](http://computers.tutsplus.com/articles/creating-a-speaker-for-your-raspberry-pi-using-a-piezo-element--mac-59336 "Piezo on Raspberry Pi using C")&nbsp;(helped with wiring and the pin number in the software)  
  
- [RTTTL on Arduinno](http://electronics.flosscience.com/Home_LE/unit-9---lets-make-some-noise/rtttl "RTTTL on Raspberry Pi using C")&nbsp;(source of the Java port)  
  
- [More RTTTL Tones  
  
](http://www.picaxe.com/RTTTL-Ringtones-for-Tune-Command/ "More RTTTL Tones")
- [RTTTL on Wikipedia  
  
](http://en.wikipedia.org/wiki/Ring_Tone_Transfer_Language "RTTTL on Wikipedia")
- [Source Code](https://github.com/onebeartoe/media-players "Project Source Code")  
  
- [Development Builds](https://onebeartoe.ci.cloudbees.com/job/media-players/ "Project Development Builds")


## Related Guides

- [How to Build a Testing Jig](https://learn.adafruit.com/how-to-build-a-testing-fixture.md)
- [Humidity and Temperature Monitor with E-Ink Display](https://learn.adafruit.com/humidity-and-temperature-monitor-redux-e-ink-display.md)
- [Adafruit IO Time Tracking Cube](https://learn.adafruit.com/time-tracking-cube.md)
- [Gemma M0 Vibration Sensor Motion Alarm](https://learn.adafruit.com/motion-alarm.md)
- [CircuitPython Libraries on Linux and Google Coral](https://learn.adafruit.com/circuitpython-on-google-coral-linux-blinka.md)
- [Annoy-O-Matic Sound Prank Device](https://learn.adafruit.com/annoy-o-matic-sound-prank-device.md)
- [LLM Agent Embodiment Kit](https://learn.adafruit.com/llm-agent-embodiment-kit.md)
- [Spy Theme Playback Device](https://learn.adafruit.com/spy-theme-playback-device.md)
- [Using Piezo Buzzers with WipperSnapper](https://learn.adafruit.com/using-piezo-buzzers-with-wippersnapper.md)
- [Storage humidity and temperature monitor](https://learn.adafruit.com/storage-humidity-and-temperature-monitor.md)
- [Getting Started with Raspberry Pi Pico and CircuitPython](https://learn.adafruit.com/getting-started-with-raspberry-pi-pico-circuitpython.md)
- [Adafruit IO Home: Security ](https://learn.adafruit.com/adafruit-io-home-security.md)
- [PowerWash Simulator Nozzle Controller](https://learn.adafruit.com/powerwash-simulator-nozzle-controller.md)
- [CircuitPython 101: Basic Builtin Data Structures](https://learn.adafruit.com/basic-datastructures-in-circuitpython.md)
- [Interactive Gift Box](https://learn.adafruit.com/interactive-custom-gift-box.md)
