Nokia RTTTL Music With C and a Raspberry Pi

Play Simple Songs with a Piezo Speaker

·

2 min read

This is a simple project for sending Nokia's RTTTL (RingTone Text Transfer Language) to a buzzer in a Raspberry Pi.

This code will compile a single binary that will send the frequencies to the buzzer.

Hardware

  • Raspberry Pi Model B
  • Passive Buzzer 5v. (Computer Speaker)
  • Cables.

It’s important that your buzzer is a passive one, if it beeps when you feed it with 3.3V then it is not a passive one and this project will not work properly.

Software

Deps

First must install the dev packages:

$ sudo apt -y install gcc g++ make automake git

Then install WiringPi dev files:

$ git clone https://github.com/WiringPi/WiringPi.git
$ cd WiringPi
$ ./build

Make sure to add your user to the gpio group.

$ sudo usermod -aG gpio <username>

Schematics

You can connect the buzzer to the GPIO 4 (positive) and the other to the ground. Or change it in pin.h.

circuitbasics.com/how-to-use-buzzers-with-r..

Song

You can select a song in song.h. There is a bunch of sample songs too inside docs/songs. (Got from picaxe.com/rtttl-ringtones-for-tune-command). This song will play if you do not give any arguments to the program.

Compilation

Once you configured your PIN and SONG you can compile with:

$ make build

It will generate a new binary named tune. This binary can be executed and will play the SONG. Maybe can be used on login? or startup sound?.

A binary is included in this repo if you want to avoid compilation.

Play

Now you can play using the command ./tune.

Example:

$ cat docs/songs/mix1/adams.txt | xargs ./tune

Similar Projects

If you want more complex tunes you can use en.wikipedia.org/wiki/Music_Macro_Language instead of en.wikipedia.org/wiki/Ring_Tone_Text_Transf...

See: cubeatsystems.com/tinymml/faq.html

Composers

LICENSE

BSD 2-Clause License

Credits

Made with by Ninjas.cl.