Developing the First Script
Before starting to write code, please ensure that you have completed the preparation of the hardware, firmware, and software environment.
Writing the First Script File
Open VSCode and enter the following string:
print("hello world")
Next, save the written script locally and name the file helloworld.py (only English letters, numbers, and underscores are allowed; Chinese characters and special characters are prohibited).
Next, transfer the edited file to the module via QPYcom and run it.
Transferring the Script File to the Module
Before transferring the script file, ensure that the QPYcom serial port is open.
Method 1: Transfer via Drag-and-Drop
Open QPYcom, click File, then click the button shown in the figure to select the path of the helloworld.py script file.
After selecting the path where the helloworld.py script file is stored, the written script file can be seen on the left side.
Drag the helloworld.py script file from the left side to the usr directory on the right side for transfer. The download progress and result will be displayed in the status bar at the bottom.
The display of helloworld.py in the usr directory on the right side indicates that it has been successfully transferred to the module.
Method 2: Transfer via Tool Buttons
Click the "+" button on the right side to transfer the file.
Locate the written helloworld.py file and click Open in the bottom right corner.
The display of helloworld.py in the usr directory on the right side indicates that it has been successfully transferred to the module.
Method 3: Transfer by Creating a User Project
Click the Download page.
Create a user project (click the "Create" button).
Enter the project name and click "OK".
The created project is displayed on the left side.
In the "User Scripts/Files" area, select the root directory of usr, right-click and select Add File.
After successful addition, the helloworld.py file ready for transfer will be displayed. Click the icon in the bottom right corner
, and options "Download Script" and "Download Firmware" will appear. Select Download Script for transfer.
After successful download, a prompt "File downloaded successfully" will appear.
Executing the Script File
Method 1: Execute the Script via REPL
After opening the serial port, enter the following code on the QPYcom interactive page to execute the script file:
import example
example.exec("/usr/hello world.py") # filePath is the path of the script file to be executed
Method 2: Execute the Script via GUI Tool
On the file page of the tool, select the helloworld.py script file to be executed, then click the
button to run it.
Method 3: Run the Script File via Right-Click Menu
Select the script file and right-click to run it.
The execution result is shown in the figure below
Stop a Running Program
Depending on the type of running script file, there are the following methods to stop it:
| Program name is "main.py" | Program Contains Endless Loop | Program Uses Multithreading | Stop Steps |
|---|---|---|---|
| ✓ | ✓ | ✓ | 1. Press "Ctrl + A" to enter RAW mode 2. Press "Ctrl + D" to restart the QuecPython virtual machine 3. Press "Ctrl + B" to return to normal interaction mode 4. If the above methods are ineffective, please re-download the firmware |
| ✗ | 1. Press "Ctrl + C" to interrupt the program execution 2. If the above method is ineffective, please re-download the firmware |
||
| ✗ | ✓ | 1. Press "Ctrl + A" to enter RAW mode 2. Press "Ctrl + D" to restart the QuecPython virtual machine 3. Press "Ctrl + B" to return to normal interaction mode 4. If the above methods are ineffective, please wait patiently for the program to finish running |
|
| ✗ | 1. Press "Ctrl + C" to interrupt the program execution 2. If the above method is ineffective, please re-download the firmware |
||
| ✗ | ✓ | ✓ | 1. Press "Ctrl + D" to restart the QuecPython virtual machine 2. If the above method is ineffective, please reboot the module |
| ✗ | 1. Press "Ctrl + D" to restart the QuecPython virtual machine 2. If the above method is ineffective, please reboot the module |
||
| ✗ | ✓ | 1. Press "Ctrl + C" to interrupt the program execution 2. If the above method is ineffective, please re-download the firmware or reboot the module |
|
| ✗ | 1. Press "Ctrl + C" to interrupt the program execution 2. If the above method is ineffective, please re-download the firmware or reboot the module |
Common Issues and Precautions
1. No Output When Executing the Script / Prompt "File Does Not Exist"
- Incorrect path spelling: When executing the
execfunction in REPL, the case/spelling of the path and file name is inconsistent with the file in the module; - Wrong file selected for GUI execution: The target script in the
usrdirectory on the right side is not selected, so no actual program runs after clicking the execute button; - Script syntax errors: There are syntax issues in the script (such as missing parentheses, indentation errors), resulting in silent failure with no output during execution.
2. Failed to Download the Script File
- Serial port not ready: The serial port is not opened before download, or the corresponding firmware is not flashed to the development board / firmware flashing fails, resulting in no response from the module;
- Illegal naming/path: The file name contains Chinese characters or special characters, or the local file path is selected incorrectly;
- Improper drag-and-drop operation: The local file is not dragged to the
usrdirectory area of the module on the right side.