Index>Robot Kit>Alter All in One Kit for RPi>Lesson 24 The Program to Start Automatically
No related product information!

Lesson 24 The Program to Start Automatically

1038

24.1 Set The Specified Program to Run Automatically at Boot

This section only introduces the auto-run method used by our products. If you need more information about the Raspberry Pi auto-run program, you can refer to this document from itechfythe document Auto-Run.

If you have used the operation steps of 3.5 or 3.6, then the script program has been configured to automatically run the program at startup. In this chapter, we explain how to set a program to start automatically at startup from scratch.

First we use the following code to create a new startup.sh:

sudo touch //home/pi/startup.sh


Edit startup.sh

sudo nano startup.sh


Write the following content in startup.sh, where python3 is followed by the program you want to run automatically. Note that you must use an absolute path here. Let's take webServer.py as an example.

#!/bin/sh

sudo python3 [RobotName]/server/webServer.py


After Ctrl + X To exit editing. Press Y Save. Enter Confirm and exit editing.

Give startup.sh permissions, where *** is the Linux permission code, we do not recommend the use of permissions such as 777, but for novices 777 can avoid many account and permissions problems, of course, you can also set it to 700 , So that only the owner can read, write and execute startup.sh, you can learn more about Linux permissions through this article from maketecheasier the article link Understanding File Permissions.

sudo chmod 777 //home/pi/startup.sh


Edit rc.local to configure the script to run automatically

sudo nano /etc/rc.local


Add the following content under fi in the original document, save and exit:

//home/pi/startup.sh start


Of course, you can also replace the above script file path with other scripts you want to run automatically.


24.2Change The Program That Starts Automatically

After step 7.1, you can already set the program to run automatically at boot. If you want to change the program to run automatically at boot, just edit startup.sh:

sudo nano //home/pi/startup.sh


For example, if we want to replace webServer.py with server.py, we only need to edit the following:

Replace

sudo python3 [RobotName]/server/webServer.py

with

sudo python3 [RobotName]/server/server.py

Save and exit so that the robot will automatically run server.py instead of webServer.py the next time the robot is turned on.

server.py is a socket server used when using pythonGUI. We do not recommend it to novices here, because you need to manually install a lot of dependent libraries in the computer that controls it to allow the GUI to communicate with it normally. It is recommended to use the WEB application to control the Raspberry Pi robot.