Sonic Pi is a programming language created for the Raspebrry Pi to use sound and music to teach programming skills in Schools that is fun and educational.

Sonic Pi is based on the Ruby programming language which through programs like Kids Ruby gives a fun and easy introduction to programming for children and beginners.

Sonic Pi has been developed to be used on a Raspberry Pi computer as part of the KS3 introductory Computer Science classes in Schools.

The programming window consists of three main areas; a programming window, program text output and and error window. Getting started is as simple as entering the command play with a note number and then selecting play. "Beep"


To play a simple sequence of notes use the sleep command so there is a short delay before the next note. Sleep 0.25 pauses for a quarter of a second. Sleep 0.5 paused for half a second.


The notes range from 0 to 254 and relate to the frequencies used by MIDI synthesisers. 0 is low pitched and 254 is high pitched. The useful range relates the the Piano keyboard from 21 through to 108.Midi Numbers for a Piano Keyboard


 As with other programming languages there are loops and variables available so you can make more complex sequences of notes without having to write out each note.


Example of a loop with two notes going up the scale of notes, the second note is set 20 above the first.

Click the link to see what it sounds like SonicPi example Loop MP3

 This uses the while end loop. While a $note has a value less then 81, run the code beween while and end.

After each play, sleep sequence $note is increased by 1 with the line $note +=1. When $note is equal to 81 the loop is no longer run and the next command after end is read. As there is no command after end the program stops.

$note is a varible I have made up and given the starting value of 50. Nearly anything could have been used such as: note abc, $abc, boogywoogy

The $ is not required in this example but helps to highlight it is a varible.


More complex programs can be written that show off the type of thing SonicPi can do once you get the hang of programming it.

This programs by Robin Newman give a good example of what can be done with Sonic Pi.

Bach-Minuet.txt which sounds like this Bach-Minuet-SonicPi.mp3

 To play this in SonicPi dowload the text file to a Raspberry Pi. Then open the file in a text editor like leafpad and then copy all the text. Load SonicPi and right click in a blank window and select paste.


For more information about SonicPi including a KS3 scheme of work for use in schools visit the SonicPi webasite at










Add comment