RESISTOR PIANO

PIPER MAKE EDUCATOR RESOURCES SERIES

To do this project, you will need a Piper Make Starter Kit. Get yours here:

Code your own guessing game to figure out what number your Pico is thinking of!

To get started, head to Piper Make and hit this icon:

Time: 60 minutes

Age Range: 8+

Difficulty: Advanced

The Resistor Piano provides a deep dive into using resistors and completed circuits to interact with sound in Piper Make. Students will create a panel of resistors and use a jumper wire to “play notes” and create their own musical creations.

Note: There are step by step instructions for the students to follow in the tutorials included in each project on Piper Make. These provide directions both for writing code and for building the electronic circuits. The tutorials are well-defined and most students will be able to follow them with little assistance required.

LEARNING OBJECTIVES

Students will:

 

  • Practice coding loops
  • Review key electronics understandings:
    • Implementing resistors in order to control passage of electrical current
    • Sounds as auditory outputs
  • Practice computational concepts of
    • loops: running the same sequence multiple times
    • events: while a pin’s condition is on or off, another action happens
  • Create programs that use variables to store and modify data.
  • Create programs that include events, loops, and conditionals.
  • Decompose problems into smaller, manageable tasks which may themselves be decomposed.
  • Create programs by incorporating smaller portions of existing programs, to develop something new or add more advanced features.
  • Test and debug a program or algorithm to ensure it accomplishes the intended task.

STANDARDS ALIGNMENT

CA Computer Science Standards

3-5.CS.2: Demonstrate how computer hardware and software work together as a system to accomplish tasks.

3-5.CS.3: Determine potential solutions to solve simple hardware and software problems using common troubleshooting strategies.

3-5.AP.11: Create programs that use variables to store and modify data.

3-5.AP.12: Create programs that include events, loops, and conditionals.

3-5.AP.13: Decompose problems into smaller, manageable tasks which may themselves be decomposed.

3-5.AP.14: Create programs by incorporating smaller portions of existing programs, to develop something new or add more advanced features.

3-5.AP.17: Test and debug a program or algorithm to ensure it accomplishes the intended task.

Math Standards Alignment

5.NF.A.2: Solve word problems involving addition and subtraction of fractions referring to the same whole, including cases of unlike denominators, e.g., by using visual fraction models or equations to represent the problem. Use benchmark fractions and number sense of fractions to estimate mentally and assess the reasonableness of answers.

5.NF.B.3: Interpret a fraction as division of the numerator by the denominator (a/b = a ÷ b). Solve word problems involving division of whole numbers leading to answers in the form of fractions or mixed numbers, e.g., by using visual fraction models or equations to represent the problem.

LANGUAGE OBJECTIVES

CCSS.ELA.L.W.3.8: Recall information from experiences or gather information from print and digital sources; take brief notes on sources and sort evidence into provided categories.

CCSS.ELA.L.W.3.10: Write routinely over extended time frames (time for research, reflection, and revision) and shorter time frames (a single sitting or a day or two) for a range of discipline-specific tasks, purposes, and audiences.

CA ELD.3.C.11: Supporting own opinions and evaluating others’ opinions in speaking and writing

CA ELD.3.C.12: Selecting and applying varied and precise vocabulary and language structures to effectively convey ideas

MICHIGAN INTEGRATED TECHNOLOGY COMPETENCIES FOR STUDENTS (MITECS)

1B-CS-02 Model how computer hardware and software work together as a system to accomplish tasks. Subconcept: Hardware & Software; Practice 4.4

1B-CS-03 Determine potential solutions to solve simple hardware and software problems using

common troubleshooting strategies. Subconcept: Troubleshooting; Practice 6.2

1B-AP-09 Create programs that use variables to store and modify data. Subconcept: Variables; Practice 5.2

1B-AP-10 Create programs that include sequences, events, loops, and conditionals. Subconcept: Control; Practice 5.2

1B-AP-11 Decompose (break down) problems into smaller, manageable subproblems to facilitate the program development process. Subconcept: Modularity; Practice 3.2

1B-AP-12 Modify, remix, or incorporate portions of an existing program into one’s own work, to

develop something new or add more advanced features. Subconcept: Modularity; Practice 5.3

1B-AP-15 Test and debug (identify and fix errors) a program or algorithm to ensure it runs as intended. Subconcept: Program Development; Practice 6.1, 6.2

 

Core Content Standards

 

Math Standards Alignment

5.NF.2: Solve word problems involving addition and subtraction of fractions referring to the same whole, including cases of unlike denominators, e.g., by using visual fraction models or equations to represent the problem. Use benchmark fractions and number sense of fractions to estimate mentally and assess the reasonableness of answers.

5.NF.3: Interpret a fraction as division of the numerator by the denominator (a/b = a ÷ b). Solve word problems involving division of whole numbers leading to answers in the form of fractions or mixed numbers, e.g., by using visual fraction models or equations to represent the problem.

 

Language Objectives

 

Michigan ELA, Grade 3-8, Research, 8: Recall information from experiences or gather information from print and digital sources; take brief notes on sources and sort evidence into provided categories.

Michigan ELA, Grade 3-8, Range of Writing, 10: Write routinely over extended time frames (time for research, reflection, and revision) and shorter time frames (a single sitting or a day or two) for a range of discipline-specific tasks, purposes, and audiences.

 

WIDA ELD Standards

ELD-SI.K-3.Argue:

  • Ask questions about others’ opinions
  • Support own opinions with reasons
  • Clarify and elaborate ideas based on feedback
  • Defend change in one’s own thinking
  • Revise one’s own opinions based on new information

 

ELD-SC.2-3.Argue.Interpretive:

Interpret scientific arguments by

  • Identifying potential evidence from data, models, and/or information from investigations of phenomena or design solutions
  • Analyzing whether evidence is relevant or not
  • Distinguishing between evidence and opinions

CONCEPTS

Students will use variables, conditionals, values, loops, lists and sounds.

PARTS

Raspberry Pi Pico, breadboard, charging cable, five M2M Jumper Wires, ten 330 Ω Resistors

GPIO SETUP

OVERVIEW OF STEPS

Step 1: Let's make music!

We are going to build a musical instrument using your Pico, a few wires, and a lot of resistors! Do you remember using resistors in the Blink and Traffic Light tutorials?

A Resistor is used to limit the flow of electricity. One of the ways we can use resistors is to divide a voltage. If we use a lot of resistors, we can make something that has a bunch of different voltages - and that's what we will use to tell the Pico and your computer what notes to play!

Click NEXT to get started!

Step 2: An important note

Before you build your circuit, please look at the drawing below.

When you "play" your resistor piano, you will touch one end of the green wire to the resistor leads marked with numbers in the drawing below.

There are two areas where you should NOT touch the green wire. They are marked with the yellow triangle symbol:

Touching the green wire to the areas marked with the yellow triangles ⚠️ will cause a short circuit and could damage your Pico module.

Your Pico has a protection circuit, but it's best not to take an unnecessary risk.

Click NEXT.

Step 3: Get your stuff

Let’s start by gathering our supplies. You’ll need your Pico and breadboard, ten 330 Ω resistors, and five jumper wires.

The jumper wires don't have to be the same color as the ones in the diagrams - you can use any color wires that you have.

Click NEXT to start building your circuit!

Step 4: Build it

Let's build the circuit! Use the diagram below to place 10 resistors on the breadboard. Start in the lower-right corner, and insert them from right to left.
Make sure that the lead of one resistor is in the same breadboard row as the lead of the next one.

Even though you are putting 10 resistors into your circuit, your piano will only play 9 notes. Don't worry, we'll explain why later.

After all ten resistors are inserted, connect one of the black jumper wires from the right-most resistor's right lead to a pin in the GROUND rail at the top of the breadboard. Then, connect another black jumper wire from a GROUND pin on the Pico to the GROUND rail at the top of the breadboard.

Next, connect the red jumper wire from the left-most resistor's left lead to the Pico's 3.3V pin.

Then, connect the blue jumper wire from the second resistor's left lead to the A2 pin of the Pico.

Finally, connect one end of the green jumper wire into the same breadboard row as the black jumper wire and the right-most resistor.

Once you've built your circuit, click NEXT.

Step 5: So many resistors

Why are there so many resistors? It's because we are using them as a big voltage divider:

The image above shows a few different voltage dividers. When ground is connected to one end and a voltage is connected to the other, the junctions in between each resistor will be at a fraction of the voltage from one end of the voltage divider to the other end of the voltage divider.

Look carefully at the image above. If the circuit has two resistors, the junction will be at 1/2 of the voltage. If there are five resistors in the circuit, then the first junction will be 4/5 of the voltage.

Click NEXT.

Step 6: Analog inputs

You may have noticed that one of the jumper wires was connected to a GPIO pin named A2. The "A" stands for analog.

Most of the pins on the Pico are digital. this means that when they are set as an input, they can only tell if the voltage coming into the pin is closer to 3.3 volts (ON) or closer to 0 volts (OFF). An analog pin can read any voltage between 0 and 3.3 volts.

This means that we can connect it to our voltage divider and read all of the different voltages that our voltage divider makes!

Let's try it out! Build the program below by dragging out a start block, a repeat forever block, a print block, and a read voltage from block and connecting them together. Set the wait time in the repeat forever block to 0.5 seconds:

You can delete the "_" block. Then, set the pin variable on the read voltage from block to A2.

Click NEXT.

Step 7: Test it out

Click on the CONSOLE tab at the bottom of the workspace to open it.

Then, click CONNECT and START to run the testing program.

The console will start displaying numbers - try touching the green wire to the leads of the resistors:

When you touch the green wire to each point, the console will show a different value. Do you see the pattern yet?

If you touch the green wire to the lead labeled (1) in the image above, the console should show 0 (or something very close to it). This is because when you make that connection, you are connecting pin A2 to 0V (ground).

When you touch the green wire to lead (2), your console should show approximately 1.7.

This is because you are making a voltage divider with pin A2 in the middle between 3.3V and 0V.

Lead (3) should show approximately 2.2. 2/3 of 3.3V is 2.2.

Lead (4) should show approximately 2.5. 3/4 of 3.3V is 2.5.

Do you see the pattern yet? Click NEXT.

Step 8: Making the connection

Go ahead and click STOP if your program is still running.
Did you notice that the values in the console match what we learned about voltage dividers?

Our circuit can detect different values from our voltage divider, but the numbers are hard to use. The good news is that we can do a little bit of math to make them easier to use!

Click NEXT to find out how.

Step 9: Subtraction to the rescue!

If we do a little bit of subtraction, we can make the value from pin A2 easier to use.

The voltage of our circuit is 3.3V. All we have to do is take 3.3V minus the value from pin A2:

Click NEXT.

Step 10: Build the blocks

We can use blocks from the Logic and Values menus to do a little bit of math.

First, pull the read voltage from pin block out of the print block.

Drag out a _ + _ block from the Logic menu and place it in the print block. Then, grab a 0 block from the Values menu and place it into the left side of the _ + _ block.

Place the read voltage from pin block into the right side of the _ + _ block. Finally, change the "+" (plus) to a "-" (minus), and change the 0 to 3.3:

If you run your program, the CONSOLE will show these approximate values when you touch the green wire to the different resistor leads:

Lead (1) → 3.3Lead (2) → 1.65Lead (3) → 1.10Lead (4) → 0.83Lead (5) → 0.67

We are getting closer, but with a little more math, we can actually see which lead the green wire is touching.

Click NEXT to find out how.

Step 11: Divide and conquer!

You might have noticed that the bottom part of the fraction is actually the number of the lead the green wire is touching. Touching the green wire to lead (1) is 1/1 of 3.3V, lead (2) is 1/2 of 3.3V, and lead (3) is 1/3 of 3.3V.

All we have to do is get the bottom number of the fraction by itself. We do that by dividing 3.3 by our value:

Click NEXT to learn how we will do this in our program.

Step 12: A few more blocks

First, pull the 3.3 - read voltage from blocks out of the print block.

Drag out a round block from the Values menu and place it into the print block.
Drag out a _ + _ block from the Logic menu and place it in the round block. Then, grab a 0 block from the Values menu and place it into the left side of the _ + _ block.

Then, change the "+" (plus) to a "÷" (divide by), and change the 0 to 3.3. Finally, place the 3.3 - read voltage from blocks into the right side of the _ ÷ _ block:

Now, when you run your program, the CONSOLE will show which lead the green wire is touching.

Cool, right? One more thing - what is the value in the CONSOLE when the green wire is not touching any of the resistor leads? Make a note if it because we are going to need to know that for later.

Click NEXT.

Step 13: Save it for later

Now that we know what lead is being touched with the green wire, it's time to use that to play different notes.

Let's start by making storing which resistor lead is being touched by the green wire into a variable.

Click the Variables menu and create a variable named "note played".

Drag out the set note played to block into the repeat forever loop. Then, pull the blocks from the inside of the print block out and place them in the set note played to block. Finally, delete the empty print block:

Click NEXT.

Step 14: Make a list

Now it's time to make a list of notes that can be played. Click on the Variables menu can then click the Create variable button. Name your new variable "note list".

Drag out the set note list to block and place it right after the start block. Then, grab a create list with block from the Lists menu and drag it into the set note list to block:

Our circuit can play 9 different notes, so let's add more blanks to our list.

Click the blue gear icon. Drag item blocks into the stack of item blocks until there are 9 of them. Then, click theblue gear icon to close the block's menu:

Click NEXT.

Step 15: Add notes

Now we are ready to add notes to the list.

Click the Values menu to open it. Near the bottom of the list, there is a note block. Drag 9 of those blocks into the list you created in the last step.

Then, click on the variable of each note block and choose a different note for each block:

The create list block is huge! Since it takes up so much space, it makes it a bit tricky to work with our program - so let's make it smaller!

Right-click the create list block and choose "Collapse Block".

If you need to make it bigger again so that you can make changes to it, you can always right-click it again and choose "Expand Block".

Click NEXT.

Step 16: Loop in a loop

Remember a few slides back when we noticed what number the program showed when the green wire was not touching a resistor lead?

10 or 11, right? Basically, our program should only play a note if the note played variable is less than 10.

We want our program to keep reading the A2 pin until we the note we play is less than 10, and if it is less than 10, exit the loop.

Drag an if _ = _ block from the Logic menu and connect it below the set note played block inside of the repeat forever block. Change the "=" to a ">".

Grab a note played block from the Variables menu and drag it into the left side of the _ > _ block. Drag a 0 block from the Values menu and place it into the right side of the _ > _ block. Change the value to 9.
Set the repeat forever block's wait time to 0. Grab the repeat forever block and pull it away from the set note list block.

Then, grab another repeat forever block from the Loops menu and connect it to the set note list block. Finally, put the first repeat forever block into the new one:

Click NEXT.

Step 17: Almost there

Let's add the block that will play our notes.

Drag out a play sound block from the Sounds menu and connect it after the inside repeat forever block.

Drag out an instrument block from the Sounds menu and place it into the play sound block. Finally, delete the note block in the instrument block's pitch input:

Click NEXT.

Step 18: Play that note!

Since we made a list of notes earlier, we can tell the Pico to play a note from that list using the in list _ get block from the Lists menu.

Drag that block out and place it in the pitch input of the instrument block.

Grab a note list block from the Variables menu and place it in the left side of the in list block. Then, grab a note played block from the Variables menu and place it in the right side of the in list block.

Finally, change the wait time of the outside repeat forever block to 0.15 seconds.

Click NEXT.

Step 19: Make music!

Now click START and touch the green wire to the resistor leads. Is your Resistor Piano playing beautiful music?

Click EXIT to return to the home screen and try out more tutorials!