SPIKE™ Prime with Python

Communicating with Sounds

Students will learn to program different types of sounds.

45 min
Beginner
Years 7-9 or Key Stage 3

Questions to investigate

How can sound help someone to communicate an idea?

Prepare

Check to make sure SPIKE Prime hubs are charged, especially if connecting through Bluetooth.

1. Engage

There are many ways to communicate with each other. Allow students to share some ways that they frequently communicate.

Engage students in a challenge to communicate without talking or writing/texting.

2. Explore

Students will explore how to program sounds.

Each partner in the team will need a matching set of three bricks of three different colors.

  • Ensure that each student in the pair has the same three colors bricks.
  • Partner A will stack the three bricks in any order. For example, if the student’s bricks are green, red, and blue, then the stack might be green on the bottom, red in the middle, and blue on top.
  • Partner A should communicate to Partner B how to build the stack without talking. The simplest approach here would be to show Partner B how to build the stack.

Next, challenge the students to repeat the exercise with Partner B creating the stack. However, this time students cannot show the stack to each other.

  • Ask the teams to come up with a way to communicate with each other using sounds.
  • Demonstrate the idea by saying that the green brick is represented by a clap, the red brick by a snap, and the blue brick by a stomp.
  • Make each sound as you create your stack.
  • Students should create their own sounds for each brick and try to work together to build the stacks.

Discuss with students how sound can be used to communicate other than talking. Examples may include whistles or honking a horn to get someone’s attention, clapping hands to show approval, or a scream that means you are very scared of something.

Creating sounds is a great way to communicate.

Beep, Beep
Investigate producing beep sounds on the hub.

Direct students to open a new project in the Python programming canvas. Ask students to erase any code that is already in the programming area. Students should connect their hub.

Allow students to investigate how sounds can be made using the hub with this sample program.
Provide students with the sample code below. Have students type the code into the programming canvas.

# import the sound
from hub import sound
import runloop

async def main():
    # play a beep for one second
    await sound.beep(400, 1000, 100)

runloop.run(main())

Review the code with students to identify what sections of the code tell the software what to do (importing the speaker), what portions of the code tell the hub what to do (beep), and what portions are just notes to the programmer (# green sections).

Ask students to identify areas that they could change to play different sounds. Encourage students to try different numbers.

Allow students to share the new sounds they have created by changing the numbers. Ask students to identify what the number 400, 1000 and 100 represents in the code. Explain that the number 400 represents the frequency, the number 1000 represents the length of time in milliseconds and the number 100 represents the volume.

Debugging
Ask students to replace the number 400 (frequency) with a number lower than 100. Discuss what happens.

Note: Students may have already discovered this on their own. Discuss as it becomes relevant.

# import the sound
from hub import sound
import runloop

async def main():
    # play a beep for one second
    await sound.beep(100, 1000, 100)

runloop.run(main())

Students will encounter that even though there isn’t an error shown, you cannot hear any beep.
• Ask students to explain what happened.

Play a Song
Challenge students to take what they learned in their investigation to add additional lines of code to create a song. Students should add several additional lines of code with different sounds to make a song.

Guide students to reference the sound options through the Speaker section in the Knowledge Base and select beep(). This guide will provide a range of numbers to use in the code to make different sounds as well as some guidance on errors. Allow students time to explore as time allows.

Here is a sample song for students that might struggle.

# import the speaker
from hub import sound
import runloop

async def main():
    # play a song
    await sound.beep(400, 1000, 100)
    await sound.beep(450, 500, 100)
    await sound.beep(500, 1000, 100)

runloop.run(main())

3. Explain

Allow students to share their final song programs with each other and explain what their code shows.

Ask them questions like:

  • What libraries need to be imported?
  • How did you add additional lines to your code?
  • What does each line of code in your program represent?
  • What was challenging about this task?
  • Where did you run into errors in programming? How did you fix or debug them?

Explain to students that the numbers included in the beep code are a float type because they can be whole numbers or include decimals. For example, the seconds could be set for 1.5 to be more exact.

4. Elaborate

Playing Sounds
Investigating playing pre-recorded sounds.

Explain to students that in addition to playing beeps, the hub can also be programmed to play pre-set sounds such as a cat’s meow or a dog barking. Have students look at the code they have been working with and consider how to change this code to play a pre-set sounded hub rather than just a beep.

Help students recognize that they will still need to import the sound module. Students will need to know what pre-set sounds are available. Students can locate all the available sounds in the play sound word block. Students can access these later.

Ask students to create a code to investigate how sounds can be made by using the sample program Below. Prompt students to either copy this code to the programming canvas or type it in by modifying their existing project.

import runloop
from app import sound

async def main():
    await sound.play('Cat Meow 1')

runloop.run(main())

Troubleshooting tip: Ensure students are bringing in the proper libraries to program both parts of the challenge. For additional debugging information, reference the Knowledge Base.

Note: Because the sounds are coming from the device and not the hub, ensure the speakers on the device are turned on.

Discuss with students what is different about this code than the code for playing beeps. Students should see that the sounds are based on names and not numbers.

Students should recognize that the sound is coming from their device (app) and not the hub. Prompt students to think about why. When they import speaker, it allows the beeps to be heard. When they import sound, it allows sounds to be heard through the device.

Ask students why they think a “1” is located after the words cat meow. In this case, the 1 is to differentiate between other similar sounds Cat Meow 2 and Cat Meow 3. The number is part of the string or name for that variable. Ask students if they remember what a string is. You may need to review this term.

Allow students to try other sounds by changing the code from ‘Cat Meow 1’ to ‘Triumph’ or ‘Doorbell1”. Prompt students to reference a word block lesson to locate the available sounds.

Challenge students to try different sounds from the library of options provided to create a pattern. Allow students to share their sounds with other groups.

Discuss with students how they can use sounds to communicate in a variety of ways.

5. Evaluate

Teacher Observation:
Discuss the program with students. Ask students questions like:

  • How does programming beeps differ from programming sounds?
  • Where do you hear the sound when the beep plays?
  • Where do you hear the sound when the sound plays?

Self-Assessment:
Have students answer the following in their journals:

  • How can you use beeps and sounds to communicate?
  • What characteristics of a good teammate did I display today?
  • Ask students to rate themselves on a scale of 1-3, on their time management today.
  • Ask students to rate themselves on a scale of 1-3, on their materials (parts) management today.

Teacher Support

Students will:

  • Describe the function of hardware and software.
  • Program sounds and beeps and learn how to debug a simple program.
  • Create a sound pattern.
  • SPIKE Prime sets
  • Device with SPIKE App installed
  • Student journal

CSTA
2-CS-02
Design projects that combine hardware and software components to collect and exchange data.

2-AP-13
Decompose problems and subproblems into parts to facilitate the design, implementation, and review of programs.

2-AP-16
Incorporate existing code, media, and libraries into original programs, and give attribution.
2-AP-19 Document programs in order to make them easier to follow, test, and debug.

CCSS ELA
SL.8.1
Engage effectively in a range of collaborative discussions (one-on-one, in groups, and teacher-led) with diverse partners on grade 8 topics, texts, and issues, building on others' ideas and expressing their own clearly

SL.8.4
Present claims and findings, emphasizing salient points in a focused, coherent manner with relevant evidence, sound valid reasoning, and well-chosen details; use appropriate eye contact, adequate volume, and clear pronunciation

RST.6-8.3
Follow precisely a multistep procedure when carrying out experiments, taking measurements, or performing technical tasks

L.8.6
Acquire and use accurately grade-appropriate general academic and domain-specific words and phrases; gather vocabulary knowledge when considering a word or phrase important to comprehension or expression

Vocabulary
Debug
Communicate