Running Python Code
This section explains how to do Python programming and run Python code on the WalnutPi. If you have never learned Python, you can first visit the following website to learn the basics:
- Python Basics Tutorial: https://www.runoob.com/python/python-tutorial.html
Running Python in Terminal
Let's first look at how to write and run Python code using the most basic method — the WalnutPi terminal. This method also works for headless (no desktop) systems.
Open the WalnutPi terminal and use the nano editor to create a new Python file:
nano hello_walnutpi.py

Enter the editing interface and type the simplest Python code:
print('hello walnutpi!')

Press Ctrl+X to exit, and you will be prompted whether to save.

Press Y to choose a filename to save. Keep the default and press Enter to confirm.

Use the ls command to see that the hello_walnutpi.py file has been added to the current directory.

You can directly run a Python file using the python command. You can see the code runs successfully and prints "hello walnutpi!"
python hello_walnutpi

You can also type python directly in the terminal to see the current Python version and enter Python interactive mode.

Press Ctrl+Z or Ctrl+C to exit.

Thonny IDE
If you are using the WalnutPi desktop version OS, you can directly use the built-in Thonny IDE for programming, which is very convenient. You need to connect the WalnutPi to a monitor via HDMI and connect a keyboard and mouse.
Open Menu → Development → Thonny
On first run, you will be prompted to select a language. Click "Let's go!" to enter:

Once inside, bring up the file directory for easier viewing. Click View → Files:

You can see a file directory of the current system added to the left side of the IDE:

Next, create a new file:

Type in the editing area:
print('hello walnutpi!')
Then save.

Click the green "Run" button, and the Python code will be executed directly:

Of course, you can also interact with Python directly in the Python terminal at the bottom of Thonny:

You can enable Tab key autocompletion in the editor via the Thonny menu bar Tools → Options for easier development.

Below, after typing led., press the Tab key to autocomplete:

Thonny Remote Connection (Windows-based)
Above, we used Thonny IDE on the WalnutPi system. Similarly, we can use Thonny IDE on Windows to remotely connect to the WalnutPi for Python programming. The WalnutPi system comes pre-installed with an SSH server, allowing remote control via SSH. This method is suitable for remote development using your own computer.
This method is recommended for users who only do Python programming and are accustomed to using a PC. It is also the primary method used in this tutorial chapter.
Thonny IDE Windows version download link: https://thonny.org/
After downloading and installing, open Thonny. First, click View → Files to bring up the file directory.

Next, connect to the WalnutPi via SSH. Click Run → Configure Interpreter:

In the popup configuration interface, configure as shown below:
- Select Remote Python 3 (SSH)
- WalnutPi IP address
- WalnutPi username, enter pi
- Use the default password authentication
- Enter Python3 here (note the capitalization). This is because WalnutPi's
python3(lowercase) has some file permission issues, whilePython3(uppercase first letter) has been pre-configured with the correct permissions.

After configuration, click Run → Stop/Restart Backend to initiate the connection:

Enter the password pi:

Wait until the WalnutPi file system directory appears at the bottom left of Thonny, indicating a successful connection:

You can use Python commands directly in the Python terminal (equivalent to operating on the WalnutPi board):

You can then open a local Windows .py file or a WalnutPi .py file, write the code, and click the Run button to execute the Python code.

You can distinguish local vs. remote files by the title bar above the code area:
[ hello.py ] with "[ ]" indicates a WalnutPi board file (remote file);
hello2.py without "[ ]" indicates a Windows file (local file).

You can upload/download files by right-clicking in the left file directory to transfer between WalnutPi and Windows.

You can enable Tab key autocompletion in the editor via the Thonny menu bar Tools → Options for easier development. The autocompletion content is from the device connected to the interpreter — in the case of remote connection, it will autocomplete from the WalnutPi's Python libraries.

Below, after typing led., press the Tab key to autocomplete:

VSCode Remote Connection (Windows-based)
Thonny, used above, is mainly for Python programming. Some users may prefer VS Code, so here's how to set up remote development with VS Code. The advantage of VS Code is its convenience for multi-language programming.
The VS Code remote method consumes a considerable amount of the WalnutPi's memory. It is not recommended to run other memory-intensive applications on the WalnutPi when using this method.
First, install VS Code. Download: https://code.visualstudio.com/download
After installation, search for the ssh extension in the VS Code extensions panel and install it:

After the extension is installed, open it on the left and click the + button on the right to create a new remote connection:

In the popup box, enter: pi@192.168.2.180. pi is the default WalnutPi username, and the part after @ is the IP address. You can use "sudo ifconfig" to find the WalnutPi's IP address.

Next, choose where to save the information. The default first option is fine:

Then click the "Connect" button at the bottom right:

Next, select "Linux" from the top:

Select "Continue":

Enter the WalnutPi pi user password: pi

Wait for the connection until the WalnutPi IP address appears at the bottom left:

Click position 1 in the image below to view files, then click position 2 to open a folder. At position 3, you can enter your desired path — the default /home/pi is fine. Click OK.

Check the trust option:

After opening, you can see the WalnutPi directory on the left. You can download files from the WalnutPi board or upload files. The right side is the document editing area.

You can create a new WalnutPi terminal for easy command operations:

You can see the familiar terminal appear at the bottom.

The VS Code remote terminal works just like the WalnutPi local terminal. Edit your Python code, then use the python xx.py command to run the Python program.

Logged-in IPs and accounts are saved, so next time you can simply open them in the remote manager:

Troubleshooting: Cannot Connect via SSH
One common scenario: if you have previously used Thonny or VSCode to remotely connect to a WalnutPi, and then the WalnutPi has been re-imaged or its SD card replaced, you need to delete the SSH key information on your computer to reconnect.
For Windows users, this file is located at C:\Users[username].ssh\known_hosts
Open the file, find the current WalnutPi IP, and delete the IP and its key information.

