Salted fish ZTMR example-run script
Connect to the development board
Connect to the computer via a USB cable. After the connection is successful, the development board will power on and enter the boot process. The green LED on the board will turn on and off, indicating that the boot process has been completed.
Open "My Computer", you will find a removable disk named "PYBFLASH", which is the Flash storage space inside the development board. The capacity of the Flash disk is only 95KB. If you need to process large-capacity files, you can insert a TF card to expand the capacity (after inserting the TF card, the development board will first run the TF program).
Open the "PYBFLASH" disk and view the files inside.
file name | Explanation |
---|---|
boot.py | Boot file, which will load the default running program file (main.py by default), it can also set the mode of the board, for example, as a mouse, keyboard, etc. |
main.py | The program files that the default development board runs, mainly according to the settings of the boot.py file |
tpybcdc.inf | Driver files for the development board for serial communication with the computer |
README.txt | About the development board, and some help information |
The device manager finds the installed development board and can see which port is used (eg COM9).
Edit main.py
to open the main.py file using a python editor such as Notepad and IDLE. After opening the file, you will see the following line:
# main.py -- put your code here!
Anyone who has learned Python knows that the line starts with the # character, which means that this is a line of comments. Such a command line will not be executed, and it is only used to provide comment information for the code.
Add two more lines below the comment line, as shown below:
import pyb
pyb.LED(4).on()
The first line indicates the use of the pyb module, which contains all the functions and classes that control the development board.
The second line indicates that the LED class in the pyb module is used to light up the No. 4 LED on the development board:
Reset the development board
To run this small script, you need to save and close the main.py file. When the development board saves the program, the on-board red LED will light up and turn off after about 2 seconds.
Then after pressing the reset button, the green LED will quickly flash and go out, indicating that the development board has restarted.
Then the blue LED stays on, indicating that the script in main.py ran successfully.