← Back to Library
Lesson PlanFreeEN

CyberPi: Data Storage

Description In this lesson, students will explore the data storage components of a computer - in particular, the CPU and memory usage. A computer's CPU and memory usage fluctuate while the operating system handles different tasks. The utilization of memory affects the performance of the CPU and hence the performance of the computer. Students will investigate the relationship between the utilization of memory and the performance of the computer using Python and CyberPi.

Gr. 11–12
CyberPi: Data Storage

Lesson

Overview

Description

Description In this lesson, students will explore the data storage components of a computer - in particular, the CPU and memory usage. A computer's CPU and memory usage fluctuate while the operating system handles different tasks. The utilization of memory affects the performance of the CPU and hence the performance of the computer. Students will investigate the relationship between the utilization of memory and the performance of the computer using Python and CyberPi.

Objectives

  • Features of CPU performance Button, joystick, screen, and LED controls of CyberPi using Python

Before the Lesson

Preparation

For the teacher:

  • Students should have a laptop or device with mBlock 5 installed from here: https://www.mblock.cc/en/download/ (desktop version or cloud-based version) and mBlock Python editor (mLink) installed. Click here to download the Python editor (mLink)

  • One CyberPi with USB-C cable 

  • Pocket shield (optional)

  • Worksheet: Lesson Data Storage

  • Example Program: Lesson Data Storage

  • Refer to the text-based beginner lessons in this bundle for more ways to teach text-based programming without the use of the CyberPi.

Introduction:

  • In this lesson, students will explore the data storage of a computer – in particular, the CPU and memory usage.

  • A computer’s CPU and memory usage fluctuate while the operating system handles different tasks.

  • The utilisation of memory affects the performance of the CPU and hence the performance of the computer.

  • Students will investigate the relationship between the utilization of memory and the performance of the computer using Python and CyberPi.

Review

Warm Up

1. Ask students to have a look at the Task Manager (of the Window System) or the Activity Monitor (of the macOS System) on the computer.

2. Explain the role of the CPU and memory.

  • If students already have a basic understanding of the computer system, briefly review the components of a computer through demonstration – for example, bring computer components (or microcomputers) to the classroom and ask students to identify the name of different parts.

  • However, if this is your students’ first time to learn about computer components, use the above figure (Von Neumann Architecture) to explain each component. Highlight the components as followed:

  • CPU: CPU stands for ‘Central Processing Unit’. It is the chip that contains all the circuitries for performing arithmetic and logic operations and directing data to and from memory.

  • Memory: Like a human brain, computer memory is the storage space in the computer system.

  • Explain the ‘input–process–output’ model of information processing in the computer system.

3. Instruct students to open the Task Manager (of the Window System) or the activity monitor (of the macOS System) and check the CPU usage and memory.

4. Have students fill out the ‘What I Know’ column of the K-W-L chart before the class.

Direct Instruction

Tour of mBlock 5

1. Open the mBlock software or mBlock 5 Web version.

2. Introduce students to the following key areas of the software interface:

Connect the CyberPi

3. Plug the CyberPi into the computer using the included cable. The CyberPi should boot up and the screen will display either the last program uploaded or the Home menu.

4. On the "Devices" tab in mBlock, click the "Add" button. Select CyberPi and click "Ok".

5. Click the "Connect" button. Then, select the USB port and click "Connect".

6. If connected successfully, the button will change to "Disconnect".

7. When you open the editor for the first time you will see these explanations mapping the interface. Encourage students to thoroughly read through it. Below are the screen captures if you ever need to reference them again.

Figure 1: To connect your CyperPi

Figure 2: Creating Projects and Project files (see How to Create, Open, Import, or Export Project Files)

Figure 3: Editing Area

Figure 4: Console Commands to run code and more

Figure 5: Terminal (Console) to display output from Editing Area

Figure 6: Libraries containing example program. Feel free to explore these at your leisure

Figure 7: Click "Tutorials" to view these helpful instructions anytime

Guided Practice

Hands On

Activity 1:

1. Have students read "Activity 1" in the example program

2. Say: Like the Task Manager or Activity Monitor, this program can show you the CPU and memory usage. Look through the scripts and consider how it displays the CPU and memory usage.

3. Ask students to explain the program and draw a flowchart.

4. Ask students to think about the questions below:

  • What is the library for calling functions to monitor the CPU and memory usage?

  • Identify the two variables plotted in the line chart, the function that plots the lines, and the function that set the colour of the line.

5. Students should identify the following functions:

  • The library for retrieving information on running processes and system utilization (such as the CPU and memory usage demonstrated in this example program):

import psutil

  • To retrieve data on the CPU usage:

psutil.cpu_percent()

  • Have students write and run the code below in the Python editor to experience how this function works:

  • To retrieve data on memory usage:

psutil.virtual_memory()

  • Have students write and run the code below in the Python editor to experience how this function works:

6. Explain:

  • This expression returns a set of data about the system memory usage, including the total physical memory, the available memory that can be assigned instantly to processes, the memory usage in percentages, and more.

  • To extract the data that is needed, it is necessary to use the ‘memory.percent’ to select the dataset of the memory usage in percentage.

7. Explain how to measure and assess the performance of the CPU of the computer.

  • Say: We could use the percentage of the CPU usage as an indicator of the CPU performance. However, it is difficult to assess, because a computer might excel at some tasks but not perform so well at other tasks.

  • Explain: Four factors affect the CPU performance: the number of cores, the clock speed or rate, the cache size, and the type of CPU.

  • Explain the cores: A core is a processing unit of the CPU. The CPU can contain more than one core. Computers nowadays have 4, 6, 8, and even 10 cores. The more cores a computer has, the more power the computer gains to handle tasks at the same time. Yet it does not mean that doubling the number of cores will double a computer's performance or processing speed.

  • Instruct students to use the ‘pustil’ functions to check the number of cores their computers have.

  • Tip: Use the syntax: psutil.cpu_count()

8. Explain the clock speed: The clock speed or rate indicates how fast the CPU can run. This is measured in megahertz (MHz) or gigahertz (GHz). The clock speed describes the number of tasks or activities the CPU can deal with in a second, that is, the frequency of the CPU performance. A computer normally has a maximum clock speed.

  • Instruct students to use the ‘pustil’ functions to read the minimum and maximum clock speed of their computers.

  • Tip: Use the syntax: psutil.cpu_freq()

9. Explain the cache: Cache is a small amount of memory which is a part of the CPU. It is used to temporarily hold instructions and data that the CPU is likely to reuse.

10. Briefly mention the two types of the processor: 

  • There are two types of CPU: Complex Instruction Set Computing (CISC) and Reduced Instruction Set Computing (RISC). The latter type of CPU is usually used in smartphones and tablets. We will explore the two types of CPU in the next lesson.

  • Have students discuss the features of lower and higher CPU performances based on the information mentioned above. Ask them to summarize and fill out the table below:

11. Explain the RAM: 

  • Random Access Memory, or RAM, stores user programs that control what the CPU does including the data used by these programs and the results of operations performed by these programs. RAM is accessible to the user. The memory size of RAM affects computer performance.

  • RAM is a kind of volatile memory. It means that everything stored in RAM is lost when the computer is switched off, even for an instant.

12. Explain the ROM: 

  • Read Only Memory, or ROM, stores the instructions a computer needs to get itself started after the user turns on the power. As its name indicates, ROM cannot be modified by the user, which means the data stored in ROM can only be read by the user.

  • Unlike RAM, things stored in ROM will not be lost when the computer is switched off. The data and instructions are still stored in ROM even when the computer is switched off.

  • Say: The Basic Input Output System is an example of a program that is stored in ROM. The BIOS runs as soon as the power is turned on.

Independent Practice

Try It!

Activity 2:

1. Have students work individually to create a CPU usage alarm based on the example program.

  • Ask students to add control structures and light effects to the example program. Define the thresholds of the alarm and the corresponding alarm indicators. For example, if the CPU usage exceeds a threshold of 70% usage, CyberPi gives a red warning light; if the CPU usage is between 50% and 70%, CyberPi lights up in orange (or amber).

  • Encourage students to program other functions. For example, hint at adding an alarm sound by using the syntax below:

cyberpi.audio.play_tone()’

  • This function can make CyberPi play the sound of a buzzer. The first parameter in the round bracket refers to the buzzer’s frequency range between 20Hz and 5000Hz. Remind students that they should use an appropriate frequency and avoid high-frequency sounds to protect their ears. The second parameter represents the duration of the sound.

cyberpi.audio.play_tone(1047, 0.3)

cyberpi.audio.play_tone(262, 0.3)

  • Remind students that if they want to add a chart title and display it on CyberPi’s screen, they can use the syntax:

cyberpi.chart.set_name()

Note: Students may ignore one thing: the content of the chart title should be a strings variable. The values of the two variables ‘CPU’ and ‘mem_p’ are integers. Students need to debug and convert the data type.

Reflection:

  • Have students fill out the K-W-L chart

  • Remind students to always comment their code, regardless of the simplicity

Extension:

  • Encourage students to further explore computer architecture

  • Ask students to build their own computer:

  • For this task they would research various parts and simulate buying the components they need to build their own computer.

Wrap Up

Wrap-Up & Quick Check

Summary:

1. Summarize features of the CPU performance.

2. Summarize the key points:

  • A multi-core CPU will have a higher performance than a single-core CPU with the same clock speed.

  • A CPU with a high clock speed will process more instructions per second and will, therefore, have a higher performance than the equivalent CPU with the lower clock speed.

  • A larger cache size suggests a higher CPU performance because the CPU will spend less time accessing RAM so programs will execute faster.

Downloadable Material

Example Program

Worksheet

Educational Standards

Ontario - Grade 11-12 - Computer Science

Grade 11 University - Computer Science (ICS3U)

A. Programming Concepts and Skills

A1. Data types and Expressions

  • A1.1 use constants and variables, including integers, floating points, strings, and Boolean values, correctly in computer programs;

  • A1.3 use assignment statements correctly with both arithmetic and string expressions in computer programs;

  • A1.4 demonstrate the ability to use Boolean operators (e.g., AND, OR, NOT), comparison operators (i.e., equal to, not equal to, greater than, less than, greater than or equal to, less than or equal to), arithmetic operators (e.g., addition, subtraction, multiplication, division, exponentiation, parentheses), and order of operations correctly in computer programs;

A3. Subprograms

  • A3.1 demonstrate the ability to use existing sub- programs (e.g., random number generator, substring, absolute value) within computer programs;

A4. Code Maintenance

  • A4.1 demonstrate the ability to identify and correct syntax, logic, and run-time errors in computer programs;

  • A4.2 use workplace and professional conventions (e.g., naming, indenting, commenting) correctly to write programs and internal documentation;

  • A4.3 demonstrate the ability to interpret error messages displayed by programming tools (e.g., compiler, debugging tool), at different times during the software development process (e.g., writing, compilation, testing);

  • A4.4 use a tracing technique to understand pro- gram flow and to identify and correct logic and run-time errors in computer programs;

  • A4.5 demonstrates the ability to validate a program using a full range of test cases.

B. Software Development

B1. Problem-solving Strategies

  • B1.2 demonstrate the ability to solve problems independently and as part of a team;

B2. Designing Software Solutions

  • B2.1 design programs from a program template or skeleton (e.g., teacher-supplied skeleton, Help facility code snippet);

  • B2.2 use appropriate vocabulary and mode of expression (i.e., written, oral, diagrammatic) to describe alternative program designs, and to explain the structure of a program;

  • B2.4 represent the structure and components of a program using industry-standard program- ming tools (e.g., structure chart, flow chart, UML [Unified Modelling Language], data flow diagram, pseudocode);

  • B2.5 design user-friendly software interfaces (e.g., prompts, messages, screens, forms).

C. Computer Environments and Systems

C1. Computer Components 

  • C1.1 relate the specifications of the internal components of a computer (e.g., CPU, RAM, ROM, cache, hard drive, motherboard, power supply, video card, sound card) to user requirements;

  • C1.2 relate computer specifications (e.g., processor type, bus speed, storage capacity, amount of memory) to user requirements, using correct terminology;

  • C1.3 relate the specifications of common computer peripheral devices (e.g., printer, monitor, scanner, keyboard, mouse, speakers, USB flash drive) to user requirements;

  • C1.4 identify the computer components involved in executing programming operations (e.g., assignment statements store a value in RAM, arithmetic operations are performed in the CPU).

Grade 11 College - Computer Science (ICS3C)

A. Programming Concepts and Skills

A1. Data Types and Expressions

  • A1.1 use constants and variables, including integers, floating points, strings, and Boolean values, correctly in computer programs;

  • A1.3 use assignment statements correctly with both arithmetic and string expressions in computer programs (e.g., numStudents = 4 + 2, name = “Devi”);

  • A1.4 use Boolean operators (e.g., AND, OR, NOT), comparison operators (i.e., equal to, not equal to, greater than, less than, greater than or equal to, less than or equal to), arithmetic operators (e.g., addition, subtraction, multiplication, divi- sion, exponentiation, parentheses), and order of operations correctly.

A2. Control Structures and Simple Algorithms

  • A2.3 Demonstrate the ability to write algorithms with nested structures.

A3. Code Maintenance

  • A3.2 demonstrate the ability to correct syntax, logic, and run-time errors in computer programs;

  • A3.3 use workplace and professional conventions (e.g., naming, indenting, commenting) correctly to write programs and internal documentation;

  • A3.4 demonstrate the ability to interpret error messages displayed by programming tools (e.g., compiler, debugging tool), at different times during the software development process (e.g., writing, compilation, testing);

  • A3.5 demonstrate the ability to validate a program using test cases.

B. Software Development

B2. Designing Software Solutions

  • B2.1 design a simple program from a program template or skeleton (e.g., teacher-supplied skeleton, Help facility code snippet);

  • B2.2 use appropriate vocabulary and mode of expression (i.e., written, oral, diagrammatic) to describe alternative program designs and to explain the structure of a program;

  • B2.3 write subprograms (e.g., functions, procedures) that perform one well-defined task and use parameter passing and appropriate variable scope (e.g., local, global);

  • B2.4 use industry-standard programming tools (e.g., structure chart, flow chart, UML [Unified Modelling Language], data flow diagram, pseudo- code) to represent the structure and components of a computer program;

  • B2.5 design user-friendly software interfaces (e.g., prompts, messages, screens, forms).

C. Computer Components

  • C1.1 describe the functions and features of the internal components of a computer (e.g., CPU, RAM, ROM, cache, hard drive, motherboard, power supply, video card, sound card);

  • C1.2 use correct terminology to describe computer features and specifications (e.g., processor type, bus speed, storage capacity, amount of memory);

  • C1.3 describe the functions and features of common computer peripheral devices (e.g., printer, monitor, scanner, keyboard, mouse, speakers, USB flash drive);

Grade 12 Computer Science - Coming Soon!