Skip to Content
Circuit Playground: Part 2
Audio: Play File

The Circuit Playground Express has a real speaker! It’s not going to compete with your HiFi stereo, but it can play simple songs and tones.


In this exercise, we will add two sound clips to the board.

To access the speaker, we will need to import the module:

from import cpx

In the file, we can play audio using the cpx.play_file() function. The name of the audio file will go inside the parentheses like so:


In this exercise, let’s output some sound by clicking button A and button B.

Here are some sound clips from Super Mario Bros:

Description Size
Coin 42 KB
Jump 27 KB
Oops 118 KB
Game Over 164 KB

Note: To preview the sound clips, right-click the links above and choose to open the link in a new tab or window.



Download two of the sound files above (right-click and press “Save Link As…”).

And store them in the CIRCUITPY drive:

File Icons

Inside the while loop:

  • If cpx.button_a is pressed, play 1st clip by using cpx.play_file().
  • If cpx.button_b is pressed, play 2nd clip by using cpx.play_file().

Click the Download button to download the file.

Drag and drop the downloaded file into the CIRCUITPY drive on your computer.

Press button A and then press button B. Are there any sounds?

Press Run again when you are ready to move on.

Folder Icon

Sign up to start coding

Already have an account?