Orangutan plays ring tones!

Some time ago I posted routines to play music using the Orangutan’s buzzer. The Pololu engineers have implemented similar routines for the X-2 controller, but all of these implementations suffer from the drawback that you have to somehow come up with the notes to play! For those not so musically inclined, this is not easy.

Monophonic RTTTL ring tones come to the rescue and they are available on lots of websites, free for the download. I’ve implemented two different routines. They both use timers 0 and 1 and will work on the atmega168. With a little effort, they will work on the atmega8 as well.

Ringtone_long.c was inspired by (and draws heavily from) code posted for the PIC processor by Craig Peacock at BeyondLogic beyondlogic.org/pic/ringtones.htm

Ringtone_long.c decodes a monophonic RTTTL string (read about Ring Tone Text Transfer Language at the website above) and calls a subroutine to play the tune, using timers 0 and 1 as a source of beat and frequency information. Read Craig’s excellent description of how the program works at the link above. You may download my version of the program from here: uoxray.uoregon.edu/orangutan/ringtone_long.c

Example tune array for ringtone_long.c (note the compiler-generated string concatemers):

// AxelF
	const unsigned char static Melody[] =  
	"32p,8g,8p,16a#.,8p,16g,16p,16g,8c6,8g,8f,8g,8p,16d.6,8p,16g,16p,"
        "16g,8d#6,8d6,8a#,8g,8d6,8g6,16g,16f,16p,16f,8d,8a#,2g,4p,16f6,8d6,"
        "8c6,8a#,4g,8a#.,16g,16p,16g,8c6,8g,8f,4g,8d.6,16g,16p,16g,8d#6,8d6,"
        "8a#,8g,8d6,8g6,16g,16f,16p,16f,8d,8a#,2g";
        defaultoctave = 5;
        defaultduration = 4;
        beat_speed = 80;

Ringtone_short.c is much more compact and takes advantage of the “Tune Wizard” that is part of the PICAXE programming editor, free for the download at rev-ed.co.uk/picaxe/ Also download “manual 2” under picaxe data sheets and take a look at the tune command, which explains most things in detail. If you are musically inclined, you may be offended by the bizarre naming convention used for notes and octaves by Rev-Ed!

You must edit the byte array resulting from the Tune Wizard.
-Change the “$” into “0x” to define hex bytes.
-Add a tempo byte at the zeroth element of the array.
-If the array does not contain embedded zero bytes, add a zero byte at the END of the array to signify its end and use strlen() in the “for” loop to detect its end.
-If the array does contain an embedded zero byte (a 1/4 duration C note, “6th” octave), count the bytes in the array and change the “for” loop accordingly.

Better than the Tune Wizard, download about 1000 tune arrays from the Rev-Ed web site!
rev-ed.co.uk/picaxe/ (click on software tab and scroll down the page).

Example tune array for ringtone_short.c:

    // Godfather
    char tune_array[]=
    {10,0x67,0x40,0x43,0x42,0x40,0x43,0x40,0x42,0x40,0x68,0x6A,0xE7,0x67,0x40,0x43,0x42,0x40,
    0x43,0x40,0x42,0x40,0x67,0x66,0xE5,0x65,0x68,0x6B,0xC2,0x65,0x68,0x6B,0xC0,0x60,0x63,0x6A,
    0x68,0x67,0x6A,0x68,0x68,0x67,0x67,0x6B,0xC0,0};

Download ringtone_short.c at uoxray.uoregon.edu/orangutan … ne_short.c

Let me know if any problems arise.
Jim

1 Like