How-to live code music using Sonic Pi for Raspberry Pi

How-to live code music using Sonic Pi for Raspberry Pi

sonicpi.jpg

The Sonic Pi programming environment teaches you how to code and turns a low-cost Raspberry Pi into a musical instrument. Sonic Pi is a programming environment that turns a computer into a live synthesiser. It's the brainchild of Dr Sam Aaron at the University of Cambridge Computing Laboratory.

It’s a social project with the vision of inspiring people to recognise that coding is a creative activity. The software is free and open source.

Sam recently demonstrated the project on a Raspberry Pi (Mac and Windows versions are also available) at TEDxNewcastle. He entertained the audience at the University of Newcastle with his live coding skills.

The Raspberry Pi is a £30 credit card-sized computer used to teach computing in schools. It was developed by the Raspberry Pi Foundation, a charity that promotes the study of basic computer science in schools.

I bought one in an initial burst of enthusiasm when it launched it 2012. I set it up as a web device to access Internet-based services but it's been sitting in a desk drawer ever since.

Sam’s session at TEDxNewcastle inspired me to power it up again and tinker with Sonic Pi with Dan, my nine-year-old son.

The appeal is two-fold. Sonic Pi is a pathway to both coding and making music. Sam and his team want to inspire a generation of school children.

Sam said he uses Sonic Pi for live gigs at clubs throughout Europe. This is no exaggeration. You check out music created by the Sonic Pi community on Sam's SoundCloud page.

What you need to set-up a Raspberry Pi

The software installation recommended by the Raspberry Pi Foundation is preloaded with Sonic Pi so setting up a system is relatively straightforward.

Here’s what you need to get started.

  • SD Card – the Raspberry Pi doesn’t have a hard disk. You load and save software and data using a memory card.
  • Display – use a computer or TV display connected via a HDMI or DVI connection. HDMI is the most straightforward.
  • Internet – you need to connect to the Internet for software updates. Connect via an Ethernet cable or by using a Wi-Fi USB device costing around £5.
  • Keyboard and mouse – any device with a USB connector will work.
  • Power supply – use a 5V micro USB supply.
  • Speakers or headphones – the audio will play out via an earphone jack or phono connection. Alternatively use HDMI if your display or TV.

Setting up a Raspberry Pi

Plug in the keyboard, mouse, monitor, and Ethernet cable.

If this is the first time that your Raspberry Pi has been used you’ll need to configure it using an operating system installer called NOOBS.

You can buy a pre-installed NOOBS SD card or download the software and copy it directly to a SD card.

Insert the memory card in your Raspberry Pi and connect the power. This will turn the Raspberry Pi on and boot it up.

NOOBS is pre-installed with a series of operating systems including one called Raspbian. Select this and follow the installation procedure.

Once the installation is complete, and each time you subsequently boot up the Raspberry Pi, you’ll need to enter the username pi and password raspberry.

To load the graphical user-interface you need to enter startx at the command line prompt.

Coding music with Sonic Pi

Sonic Pi is preloaded with the Raspbian operating system. Select Menu > Programming > Sonic Pi.

The interface is simple: there’s a series of coding workspaces with a stop button, a play button and a couple of other functions; an output window; and a help area.

The Raspberry Pi Foundation has published five Key Stage 3 (KS3) lesson plans for ages 11 to 14, to guide teachers and students through the platform. There are also a series of tutorials within the help area.

We were playing music within 60 to 90 minutes of starting out thanks to copy and pasting chunks of nifty code.

The help tutorials guide you through the rudiments of coding (data structures, functions,  loops and variables) and making music (amplitude, chords, pitch, scale, threads and samples).

Carrie Anne Philbin, better known as Geek Gurl on YouTube, has published a really excellent guide to coding Sonic Pi.

You'll want to subscribe to Carrie's channel if you're interested in craft and technology.

The magic really starts when you start editing and compiling on the fly. This turns the Raspberry Pi in a live musical instrument that produces performance music.

I highly recommend Sonic Pi. We’ve had a great few hours coding and making music. It's an incredibly cool way to learn to code.

We’ll return to time and time again.

The not-so-secret Internet diary of a Gen X woman

The not-so-secret Internet diary of a Gen X woman

Why we favourite on Twitter

Why we favourite on Twitter