SOUNDS & SPEAKER
In this project, we introduce the sound library and use it to play notes through the speaker.
Speaker & Audio Cable
Having issues? Check out the Troubleshooting Guide.

The assembled RaspberrySTEM CREATOR Kit has an attached speaker and audio cable, and also a library of functions that allow you to play notes, music and sound effects.

If your audio cable was removed, reattach it now:

  1. Insert the Audio Cable into the audio jack on the Raspberry Pi.

  2. Connect the other end of the Audio Cable to the Speaker Cable (the cable attached the Speaker Assembly). Note: It doesn’t matter which way the three-pronged Audio Cable is oriented.

With the speaker hardware connected, we can start making noise with just a few lines of code...

In this project, we're just going to use the basic functionality of the sound library to play notes in variable durations. Let's start with this code:

If you run this code, you'll hear a single tone play for one second. If you want to change the duration of the note, you can set duration in the play() function, as you see below:

home | prev | next