SPIKE™ Prime with Python

Testing for Trouble

Investigate strategies for troubleshooting hardware issues

90-120 min.
Intermed.
Year 5 to 8

Questions to investigate

• How do engineers identify and repair hardware and software problems within a design?

Prepare

• Ensure SPIKE Prime hubs are charged, especially if connecting through Bluetooth.
• Reference for troubleshooting the model is available at https://education.lego.com/en-us/lessons/prime-invention-squad/broken#Planitem2

Engage

(Group Discussion, 5 minutes)

Discuss with students what type of machines can make an exact cut repeatedly, so all pieces are the same. A CNC [computer numerical control] machine is programmed to make the same repetitive cuts. For example, a laser cutter cuts plastic, wood, or cardboard into exact shapes.
• Allow students to research what CNC machines are and how they are used.
• Ask students to name objects that they believe are made with a CNC machine.

Watch the video to get an idea of what the CNC machine they will build should do. https://education.lego.com/en-us/lessons/prime-invention-squad/broken#building-tips

Discuss with students what is wrong with the machine in this video. Ask students questions like:
• How do you know when something is not working right?
• What is your first reaction when something breaks?
• How can we figure out where the problem lies?

Explore

(Small Groups, 45 minutes)

Students will build a CNC machine to investigate troubleshooting design issues or hardware issues.

Direct students to the BUILD section in the SPIKE App. Here students can access the building instructions for the CNC Machine model. Ask students to build the model. The building instructions are also available at https://education.lego.com/en-us/support/spike-prime/building-instructions listed as Broken.

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.

Test the Model
Students will identify that there are hardware issues when trying the sample code.

Review this sample code to run the CNC machine together as a group. Discuss the code as a group and identify any potential errors in the code. Students should note that there don’t appear to be any errors in the program.

Ask students to type this program into the programming canvas. Ask students to run the program to test it for errors.

from hub import button, port
import runloop
import motor

def right_button_pressed():
    return button.pressed(button.RIGHT)

def left_button_pressed():
    return button.pressed(button.LEFT)

async def main():
    while True:
        #feed the paper
        await runloop.until(right_button_pressed)
        await motor.run_for_degrees(port.C, 1000, 500)

        #cut a square and a rectangle
        await runloop.until(left_button_pressed)
        await motor.run_for_time(port.A, 1500, -500)

        # These 4 blocks should 'cut' a square.
        await motor.run_for_degrees(port.A, 400 , 500)
        await motor.run_for_degrees(port.C, 575, 500)
        await motor.run_for_degrees(port.A, -400 , 500)
        await motor.run_for_degrees(port.C, -575, 500)

        # These 4 blocks should 'cut' a rectangle.
        await motor.run_for_degrees(port.A, -60, 500)
        await motor.run_for_degrees(port.C, -800, 500)
        await motor.run_for_degrees(port.A, 400, 500)
        await motor.run_for_degrees(port.C, 1600, 500)
        await motor.run_for_degrees(port.A, -400, 500)
        await motor.run_for_degrees(port.C, -800, 500)

runloop.run(main())

Allow students time to run the program. Notice the machine is not working properly. The machine is supposed to help you “cut” (draw) parts.

Discuss together as a group if the problem is with the hardware/model or the program. Ask students questions like:
• What is not working?
• How does the model move? Does it seem to be moving correctly?
• Did you receive any errors in the console or see any indication that the program was not working?

Students should recognize that there is an issue with the model not the program.

Identify and troubleshoot design problems.
Work together to identify the problems. Look at the machines and see how it behaves versus what you think it will do. Have students write the issues found in their journals or on chart paper. Encourage students to use these steps:
o Identify the problem.
o Take a close look.
o Observe how the model behaves verses what you think it should do.
o Brainstorm solutions.
o Make one change and test the model (run the program). Did it help?
o You may ask other teams for help as needed.

Prompt students as needed to start identifying the problems. Ask students questions like:
• Do you think the paper is moving the way it should?
• Is the pencil able to make the marks needed to represent the cuts?
• Does the model seem to be stable?

Note: there are four issues to identify and fix.
1. A paper feeder wheel is missing, causing the Y axis to not work properly.
2. The top of the CNC machine isn't correctly attached to the bottom.
3. The paper feeder gears are inverted, causing the paper to enter the CNC too quickly.
4. The pencil carriage isn't affixed, causing the X axis to work improperly.
Note: The Broken Lesson shows hints for what is wrong with the model. https://education.lego.com/en-us/lessons/prime-invention-squad/broken#Planitem0

Select one issue to investigate together as a group. Consider starting with the paper moving too fast. Brainstorm ideas for fixing the problem together. How can you slow the movement down without changing the program? Prompt students to look at how the gears are working and consider how to change them to slow the paper movement.

Explain

(Whole Group, 15 minutes)

Discuss the program with students and why it does not seem to be working correctly.
Ask students questions like:
• What do you notice about the CNC machine when you run the program?
• How do you know it is a hardware problem?
• Why is testing your design important?
• How did you determine the issue was with the model and not the program?
• What parts of the machine do not seem to be working?
• As engineers, what is the first step we should take in fixing the machine? (Identifying problems; if more than one problem has been discovered, then deciding which problem to repair first.)

Elaborate

(Small Groups, 25 minutes)

Allow students additional time to finish troubleshooting the model.

Ask the students to brainstorm solutions to the remaining issues. Allow students to retest the model running their program as needed to help troubleshoot the hardware.

After students have identified different issues, ask different groups to work on fixing the problems. Each group should share their fixes with other groups to ensure the CNC machine will work as needed. Students should retest their models to ensure they are working properly.

Share all solutions together as a group after the models are working correctly.

Evaluate

(Group Exercise, 15 minutes)

Teacher Observation:
Discuss the program with students.  Ask students questions like:  
• How does testing help identify issues that need troubleshooting?
• How can you tell the need to troubleshoot hardware and not software?
• What are ways you can troubleshoot hardware issues?

Self-Assessment
Have students answer the following in their journals: 
• What did you learn today about troubleshooting hardware issues?
• 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:
• Identify and repair a hardware problem in a design.

• SPIKE Prime Set
• Device with SPIKE App installed
• Student journal
• Pen or marker (one per team)
• Printed worksheet for Broken Lesson (one per team; link to document)

CSTA
2-AP-10 Use flowcharts and/or pseudocode to address complex problems as algorithms.
2-AP-13 Decompose problems and subproblems into parts to facilitate the design, implementation, and review of programs.
2-AP-17 Systematically test and refine programs using a range of test cases.
2-AP-19 Document programs in order to make them easier to follow, test, and debug.