Interactive IoT Classroom Quiz System | Learn Python with Graphical Programming for Beginners 13

0 2155 Hard

Classroom quizzes  can help teachers assess the effectiveness of their instruction, as well as student understanding of the concepts taught. To enhance this process, in this lesson we will utilize UNIHIKER's IoT service to develop an interactive classroom quiz system. This system will enable teachers to post questions at any time, providing real-time assessments of student comprehension. 

projectImage

Goal

The teacher end: send quiz questions and collects the students' answers.

The student end: provide an answer when receiving the question from the teacher.

projectImage

Get to Know

1. The concept of threads in programs

2. The knowledge of wireless network services of UNIHIKER

3. How to construct a simple IoT system using two UNIHIKER boards

Preparations

Hardware:

HARDWARE LIST
1 UNIHIKER
1 Type-C&Micro 2-in-1 USB Cable

Software: Mind+

Download address: https://www.mindplus.cc

projectImage

Hands-on Practice

The interactive classroom quiz system consists of two parts: the student end and the teacher end. The student end allows students to answer quiz questions within a limited time frame, while the teacher end can remotely view the students' answers. We will now break down the project into three tasks.

Task 1: Countdown Quiz

In this task, we will learn how to use the UNIHIKER to start a thread and utilize the UNIHIKER's text and button objects to implement a countdown quiz on the student end.

Task 2: Message exchange between the teacher end and student end

In this task, we will learn how to use multiple UNIHIKER boards to construct a simple IoT system, complete the core functions of the project, and enable communication between the teacher end and the student end.

Task 3: Interactive Quiz

After completing message exchange between the teacher end and student end, we will integrate the program from Task 1 and enhance the quiz system to allow for interactive quizzing between them.

Task 1: Countdown Quiz

1. Hardware Connection

Connect UNIHIKER to the computer via a USB cable.

projectImage
2. Software Preparation

Open Mind+, and complete the software preparation according to the figure below.

projectImage

3. Write a Program

The UNIHIKER for the student end serves as a quiz system. Its main function is to complete the quiz within the countdown time. Now, let's implement it together.

(1) Display the question and options

To display the question and options, let's analyze the components of the student end's interface. The entire interface is composed of a countdown, a question, options, option buttons, and the selected answer.

projectImage

Based on the analysis, we can add objects for displaying text and buttons on the screen in order.

Note: To ensure that longer text is displayed completely on the UNIHIKER screen, we can use block The number parameter width of the update object name is to implement automatic line wrapping.

projectImage

Click the option button, and the corresponding answer will be recorded and displayed. Don't forget to use a global variable to record the answer. Taking button A as an example, refer to the implementation method below:

projectImage

(2) Countdown quiz

Now, we can select the answer. Next, we need to add a countdown timer to limit the answering time.

(a) Display countdown

We can use a variable and repeat commands to implement the display of the countdown timer. Specifically, set the variable to decrease by 1 every second, repeat the countdown for the specified number of times and update the countdown display in real time.

projectImage

(b) Countdown quiz

To keep the countdown continuously running while displaying the selected answer, we can use the "thread" command. We can find the Thread object thread 1 start and Thread object thread 1 stopped blocks in "Multithreading" under the "UNIHIKER" category, and use them in combination.

Note: "Thread" is often used to implement multiple functions running simultaneously for a certain period of time. For more information on "thread," see the "Knowledge Base".

projectImage

Now, just execute the block Thread object thread1 start after the interface is displayed, and display the countdown after starting the thread.

projectImage

When the countdown stops, students can’t continue answering. That means the buttons cannot be clicked anymore, we just use Update button object is disabled to implement that.

projectImage

We have now completed the countdown quiz function for the student end. The complete reference code is as follows:

projectImage

4. Run the Program

Click Run, and you can click the option button to select an answer before the countdown reaches 0; When the countdown expires, the buttons turn gray and you cannot select an answer.

projectImage

5. Have a Try

Now, please design simple prompts for your quiz system, and evaluate whether the answer is correct or not after the countdown stops (the correct answer is "B"). You can refer to the interface design below.

projectImage

Task 2: Message exchange between the teacher end and student end

1. Task Analysis

In the interactive classroom quiz system, we need at least two UNIHIKER boards to implement the information transmission between the teacher end and student end. We can use UNIHIKER boards to build an Internet of Things (IoT) system to accomplish this.

In this IoT system, the teacher end for storing, transmitting and receiving quiz-related data acts as the server. And we can control the sending of questions and display the received answers at the teacher end using the UNIHIKER screen, which means the teacher end functions as a mobile terminal, while the student end used for answering questions is a smart terminal.

projectImage

After analyzing the roles of the two UNIHIKER boards in the IoT system, we need to configure the UNIHIKER networking, enable SIoT services, and do other preparations before programming to achieve data transmission between the student end and teacher end.

2. Preparations

To achieve data transmission between the student end and teacher end, the UNIHIKER boards of both ends need to be connected to the same network. In addition, to access their SIoT service using PC, the PC also needs to be connected to the same network. Next, we will configure the networks of the PC, the teacher-end UNIHIKER, and the student-end UNIHIKER separately, and then enable the SIoT service on the teacher-end UNIHIKER.

(1) Network configuration

First, connect the PC to the router or mobile hotspot (2.4G Wi-Fi needs to be used);

projectImage

Next, connect one of the UNIHIKER to the PC using a USB cable and open the browser. Enter "10.1.2.3" in the address bar to enter the UNIHIKER service page. Click "Network Settings" and you can click "Scan" in the "Connect Wi-Fi" section to find the wireless network that the PC just connected to. Then select the corresponding Wi-Fi name, type the password, and then click "Connect" to wait for the connection to be successful.

Note: For more information on UNIHIKER Networking Settings, see "Knowledge Base".

projectImage

After completing the above steps, unplug the USB cable and configure the network for the other UNIHIKER similarly.

Finally, power on both boards at the same time to keep them in a powered-on state.

Note: There are three ways to power on UNIHIKER boards: using a power adapter with USB or Type-C output, a power bank with USB or Type-C output, or USB port of PC.

Next, we need to enter the Home menu of both UNIHIKER boards separately and view their IP addresses in Network Info to check if the connections are successful.

projectImage

If the IP addresses of the two boards have the same first three parts, it means that they are in the same local area network. Now we can choose one of the UNIHIKER boards as the server and enable the SIoT service. In this project, the UNIHIKER board with an IP address of 192.168.1.210 is selected to enable the SIoT service as the server, and the other UNIHIKER board with an IP address of 192.168.1.254 is used as the intelligent terminal.

projectImage

(2) Enable SIoT service

At this point, you can open the SIoT service in the Home menu of the UNIHIKER board serving as the server, just like in Lesson 11, or you can directly enter its IP address in the browser to set up or view the SIoT service.

projectImage

(3) Connect to Mind+ remotely

Since we will program both UNIHIKER boards next, we need to open two Mind+ files, name them "teacher end" and "student end" respectively, and use the UNIHIKER board IP address to remotely connect each.

projectImage
3. Write a Program

The preparation work has been completed, and now we can start programming to implement the task of exchanging answer messages between the teacher end and the student end.

(1) Teacher end

The teacher end needs to implement two functions: sending the start answering command and receiving student answers. We can set a "Send" button and a receive text display object for easy viewing.

projectImage

We can use the MQTT-py module to set up, connect, and subscribe to two topics: "Startanswering/Answer" used to send the correct answer to the student end and control the start of answering; "answer/1" used to receive answers from the student end.

projectImage

Next, you can refer to the method of sending and receiving messages in Lesson 11, press the button to send the correct answer as the message for start answering, and then receive and display the student message. The complete teacher-end program is as follows:

projectImage

(2) student end

The student end can receive the start answering message from the teacher end and can also send their own answers to the server. You can refer to and copy the code from the "teacher end" to the "student end" and modify the prompt text and the sending/receiving topics accordingly to complete it.

To copy a large block of code across files, you can use the "Backpack" function in Mind+.

projectImage

Open the "Backpack," drag all the code from the "teacher end" into the backpack area, and save the current file.

projectImage

Now, open the Mind+ file where you want to paste the code, click on "Backpack," and find the copied code. You can drag the code to the script area to complete the paste operation.

projectImage

Now, you can copy the code from the "teacher end" file to the "student end" and modify the sending/receiving content and corresponding topics accordingly to complete the student-end code. The sample code is as follows:

projectImage
4. Run the Program

Check the remote connection status of the student and teacher ends, run the teacher end first, then run the student end to simulate the entire answering process and observe the running situation.

Note: If the teacher or student end cannot receive messages due to "network restrictions," you can try running the program again or changing the wireless network.

projectImage

Task 3: Interactive Quiz

1. Write a Program

Now, we can send messages between the teacher and student ends, but this is not yet a complete quiz system. Next, we will combine Task 1 and Task 2 to improve the functionality of the teacher and student interfaces and complete the interactive quiz task.

(1) Design interfaces of the teacher end and student end

In the interactive classroom quiz system, the teacher interface contains the question and the "Start answering" button. We can directly copy the question and option code from Task 1 using the "Backpack" function, modify and add the student answer text object as needed to complete the interface.

projectImage

The student end needs to display the quiz interface after receiving the control message from the teacher end, that is, the student end only displays the waiting prompt at first. The complete quiz interface will be displayed after receiving the message from the teacher end. Of course, you can also directly copy and modify the code from Task 1.

projectImage

(2) Countdown quiz for student end

In Task 1, we used a thread to implement the countdown effect when the program started running. However, in the quiz system, the countdown should start after the student receives the answer message from the teacher. Therefore, we can use the "Correct answer" sent by the teacher as a flag to start the countdown. That is, set Correct answer to "", if MQTT topic="Startanswering/Answer" then Correct answer is assigned to MQTT message. At this time, the countdown starts when "Correct answer" is not "". To continuously check the value of Correct answer, remember to execute forever command.

projectImage

Finally, we only need to set up the result judgment and send the student's selected answer at the student end to help the teacher obtain the student's quiz status. The complete reference code for the teacher and student ends is as follows:

projectImage
projectImage
projectImage
2. Run the Program

Check the remote connection of Mind+, and run the teacher end and student end programs separately. For the teacher end, click "Start answering" to send the correct answer, wait for the student to answer the question, and receive the student's answer. For the student end, when receiving the "Start answering" message from the teacher end, the student should read and answer the question.

projectImage

Knowledge Base

1. Threads in programs

A thread is a task that a program is performing during runtime. It should be noted that the task here refers to a series of codes with a certain execution order, which can be compared to "line". When a program has only one task, it is usually called a single-threaded program, such as plotting visualization charts learned in the previous lesson. However, when multiple tasks need to be executed simultaneously in a program, the program needs to use multiple threads to simultaneously complete multiple sub-tasks. We call the thread that has been running from the beginning to the end the main thread, and the other sub-tasks are called sub-threads.

projectImage

You can understand single-threaded and multi-threaded processes using cooking at home. When there is only one stove, you need to steam the eggs first and then stir-fry the vegetables. The two dishes can only be made in order, which is relatively inefficient. But when there are two stoves, you can complete the task of stir-frying while steaming the eggs, which improves efficiency.

There are three commands related to UNIHIKER and thread operations, located in the "Multithreading" under UNIHIKER category. You can use the Thread object thread1 start to start a thread, the Thread object thread1 stopped to end the specified thread, and Execute when the thread object thread1 starts to implement sub-thread tasks.

projectImage

In addition, since starting and running threads will take away main thread time, the more threads used, the slower the program execution, and even cause the program to freeze. Therefore, it is recommended to use it with caution.

2. Wireless network module on UNIHIKER

UNIHIKER comes with a Wi-Fi & Bluetooth module RTL8723DS 2.4G & 4.0, with the corresponding antenna located on the upper left side of the board.

projectImage

When there is a wireless network (or mobile network hotspot), you can connect to the WiFi hotspot service by accessing the "UNIHIKER service page settings" to complete tasks such as accessing the network or building IoT.

In addition, when there is no wireless network, UNIHIKER can also enable network hotspot services. Although it cannot access the Internet, other UNIHIKER boards or wireless devices can connect to this hotspot to build the IoT. To enable the UNIHIKER wireless hotspot mode, you need to enter the "UNIHIKER Home menu", press button B, find and enter "Hotspot", check and enable "Hotspot". After it is enabled, the wireless network account (SSID) and password (PASS) will be displayed.

projectImage

3. Command Learning

In this project, we mainly learn threads and button enable/disable commands. Next, we will study them in detail.

projectImage

Challenge

Please refer to the content of this lesson and add multiple student terminals to answer questions. Additionally, design multiple interfaces for student answer selection on the teacher terminal, as well as the evaluation of the correctness of the answers.

projectImage
icon Lesson 13. IoT Classroom Quizzing System code.rar 1.48MB Download(2)
License
All Rights
Reserved
licensBg
0