Raspberry Write Your First Program Hello World!
Just as a young child learns to crawl before they walk, programmers learn how to output “Hello, world" as the first step in learning a new language. Now, let's take a look at how to write your first program.
First, connect Pico to the computer using a USB cable; then, open Thonny, and click on the “restart back-end process" button on the toolbar. If you successfully connect Pico to your computer, you will see the MicroPython version information and device name returned by Pico in the Shell area.
After connected, click on the Shell area and type the instruction:
print("Hello, World!")
print() is a common function used as a printout. When you need to output some data to the Shell, you can use this function.
When you press ENTER after you type the instruction, you’ll see the execution result of the input instruction is displayed in the Python Shell area, which means, the message “Hello, World!" is printed out in the Python Shell area.
Now let's try to type the same instruction in the script area. When you press ENTER this time, nothing happens — except that a new, blank line is created in the script.
To make your program in the script work, you'll have to click the “Run current script" button in the toolbar.
If you are running a new program that has never been saved, then when you click the “Run current script" button, Thonny automatically shows you a menu with two options — save the program to “This computer" or “Raspberry Pi Pico". You can choose where to store the program according to your own needs. Once your program is saved, you'll see the execution result of the program in the Shell area.
·Note·
Where should I save the program?
To be honest, there's no definitive answer. Where you save your program depends on your needs. If you want to show your program to your friends, you should save it to your Pico and take it with you. If you simply want to save the program for later use, just save it to your computer.
The next time you want to open your saved program, click the “open" button on the toolbar to find the corresponding program.