File Analysis

There are two folders under /home/pi: SunFounder_PiCar for controlling motors and steering and SunFounder_PiCar-V for pan/tilt and wireless control. Here look into the code of PiCar-V.

Since too many contents and instructions are involved in the code, we will not cover every detail. For more knowledge about Python 2, Python 3, Django, HTML, and CSS in the programs, you can visit related websites or buy books to learn by yourself. In the following part, we will go through the overall structure and the process in brief.

First, let’s check the files in the code folder:

  • .git is a hidden directory to store all the information of a Git repository; it’s generated automatically after you create the repository.

  • Ball_track is used to let the car follow the red ball.

  • datasheet stores the manual of some chips used in the hardware modules.

  • mjpg-streamer is an open source streaming media library, through which the data of the camera is transferred.

  • Remote_control is to store the code of the web server; it controls the motor and servo of the car based on the API request.

  • .gitignore records the requests of file types to be ignored when the Github repository is synchronized.

  • is automatically generated when you create a project which is a standard necessary document of python package, just leave it there.

  • is a Python script written by Python 2 to configure and detect the I2C connection.

  • install_dependencies, an executable bash script for simple installation and environment configuration.

  • LICENSE, as the name suggests, is a text file of GNU V2 license.

  • and show record some information normally for statement and prompts.

Server Code

The server code is based on Django 1.10 (adapt to the latest release if needed). If you are interested in this, you can visit the Django website Here we will just learn how the web server works.


The code may be updated irregularly on Github to fix bugs and release some functions update. So the code here is the initial version. You can view the updates in the Github repository at:

Open the code directory and check the file by ls:

pi@raspberry:~ $ cd SunFounder_PiCar-V/
pi@raspberry:~/SunFounder_PiCar-V $ ls
datasheet   install_dependencies   mjpg-streamer   remote_control
client       LICENSE show

remote_control is the main code directory of the web server. Open the code directory by cd remote_control, and check the file by ls:

pi@raspberry:~/SunFounder_PiCar-V $ cd remote_control
pi@raspberry:~/SunFounder_PiCar-V/remote_control $ ls
db.sqlite3   remote_control   start static
  • db.sqlite3 is generated when you create a Django project.

  • is the main program of the Django project and is generated when the project is created. It normally does not need to be modified.

  • remote_control includes the main code files.

  • start is a small script written to run sudo python runserver, and servo installation with attribute install just for convenience.

  • static is to store some static pictures on the web.

The Django web server normally runs sudo python runserver to start. The address means the listening address covers all the addresses on the LAN, and the port number is 8000. Here we will just focus on the code in remote_control folder. Go to the directory via cd remote_control:

pi@raspberry:~/SunFounder_PiCar-V/remote_control $ cd remote_control
pi@raspberry:~/SunFounder_PiCar-V/remote_control/remote_control $ ls
driver   \   templates
  • driver stores the drivers of the car.

  • is automatically generated when you create a Django project which is a standard necessary document of python package, just leave it there.

  • is automatically generated and stores the related settings.

  • templates is a Django app for storing the webs in the html format.

  • is generated automatically to configure the URL to associate with the code.

  • is the code for page control which is associated by the URL. It calls the templates to show the page and the driver to control the car.

  • is generated automatically and does not need changes. For more, please visit the official website of Django.

So here is how the code works: Run the main program which will be associated with automatically, to respond to the URL. When you run the web browser like the Chrome to visit http://<rpi_ip_address>:<port> or visit the configured API via the client, the will turn to due to the association of the Then the processes this and returns the templates to the browser. In addition, it will call the driver package on the basis of the parameters set in the browser to control the car.

Now open the folder driver and check:

pi@raspberry:~/SunFounder_PiCar-V/remote_control/remote_control $ cd driver/
pi@raspberry:~/SunFounder_PiCar-V/remote_control/remote_control/driver $ ls   config   \

The driver folder mainly includes the driver modules for controlling the pan and tilt and camera streamer. for controlling the pan-and-tilt.

config stores the calibration data. is the essential file of the package and you can just leave it alone. is a video streaming service based on the MJPG-streamer.

Exit and open the folder templates to view:

pi@raspberry:~/SunFounder_PiCar-V/remote_control/remote_control/driver $ cd ../
pi@raspberry:~/SunFounder_PiCar-V/remote_control/remote_control $ cd templates/   \    migrations     templates

This folder is created by the startapp just for calling the templates conveniently. Therefore, the files have not been changed except for the templates. Open the templates again:

pi@raspberry:~/SunFounder_PiCar-V/remote_control/remote_control/templates $ cd templates
pi@raspberry:~/SunFounder_PiCar-V/remote_control/remote_control/templates/templates $ ls
base.html   cali.html   run.html

There are three HTML files that also consist of layers. The low level base.html stores contents contained on each page such as the <head> of HTML, the overall layout, and contents of the home page by default. The surface layer: cali.html for calibration and run.html to control the car.