Index>Robot Kit>DarkPaw Spider Robot Kit for RPi>Lesson 4 How to View or Edit Code on a Raspberry Pi

Lesson 4 How to View or Edit Code on a Raspberry Pi

5937

Lesson 4 How to View or Edit Code on a Raspberry Pi

 

For convenient use, we usually do not connect peripherals such as mouse, keyboard, and monitor to the Raspberry Pi. Since the Raspberry Pi is installed inside this robot, often with peripherals, the efficiency of programming and testing will be greatly affected. To achieve better results, here we introduce a method of programming the Raspberry Pi.

 

4.1 For Mac

 

A third-party software Putty will be used for this method. For detailed instructions, refer to 3.6.2 Remotely logging in to the Raspberry Pi system.

Putty is a terminal software to remotely control Raspberry Pi (need to enable SSH).

Operation Steps

1. Run Putty, type in the IP address of your Raspberry Pi and click open. Enter your user name and password – with the initial user name: pi, password: raspberry.

2. Type in "ls" to show the files to be edited or viewed.

wps89.jpg 

3. Type in "sudo nano <file path>" to view or edit a file, as shown below:

sudo nano adeept_darkpaw/server/LED.py

wps90.jpg 

wps91.jpg 

4. Exit. Press Ctrl + X on your keyboard to exit if nothing is changed. Otherwise press Y and Enter key to save and exit.

4.2 For Windows

 

A third-party software MobaXterm will be used for this method. For detailed instructions, refer to 3.6.2 Remotely logging in to the Raspberry Pi system.

MobaXterm is a terminal software to remotely control Raspberry Pi (need to enable SSH).

To run MobaXterm, firstly create a new session. Click Session in the upper left corner, and pop-up window will be shown. Click SSH, fill in the IP address of the Raspberry Pi next to Remote host, and click OK. The default user name of the Raspberry Pi is pi and the password is raspberry. When you type in the password, it doesn't display anything on the screen, yet it doesn't mean you aren't entering anything. Press Enter after typing to log into the Raspberry Pi, and MobaXterm will remind you to save your password.

wps92.jpg 

If the user name and password are correct, you can change the user name and password, which is recommended to do for security reason, according to the prompt in the terminal.

After the successful login, MobaXterm will automatically save the conversation. Next time to connect to the Raspberry Pi, you only need to double click on the left side of the IP address to log in. But if the IP address of the Raspberry Pi was changed, you need to start a new dialogue.

After a successful login, the left column will be replaced with a file transfer system, which allows you to interact with the system inside the Raspberry Pi. To return to session selection, just click Sessions.

You can transfer programs written on other devices to the Raspberry Pi by simple drag and drop and control the Raspberry Pi in the terminal to execute the program, or transfer files in the Raspberry Pi to other devices by dragging.

If you want to use another IDE to edit files in Raspberry Pi, just look for the file in the file transfer system on the left side of the MobaXterm, right-click on the file, click Open with… and select the IDE desired. After editing, press CTRL+S to save the file and it will be automatically synchronized to the Raspberry Pi. 

wps93.jpgwps94.jpg 

However, when you use MobaXterm's file transfer system to edit files in the Raspberry Pi, you need to pay attention to the permissions problem. Since the file transfer system does not have root permissions, when prompted to save after editing the file, the "Permission denied" error will fail the saving. You need to use the following command to give the edit permission to MobaXterm:

sudo chmod 777 [FileName]  

For example:

sudo chmod 777 adeept_darkpaw/server/LED.py

When granting permission, where *** is the Linux permission code, we do not recommend to use the permission 777; but to novice, 777 can avoid many account and permission problems. Surely  you can also set it to 700, so that only the owner can read, write and execute. Learn more about Linux permissions through the maketecheasier article at this link:

https://www.maketecheasier.com/file-permissions-what-does-chmod-777-means

If you encounter any problems, please contact us by email: support@adeept.com