5. Learning and Application

Share for us

After completing the assembly and installation of the PiSmart Car, you can enjoy the fun of playing and learning at the same time! We have provided a library SunFounder_PiSmart for operations of the PiSmart, which includes abundant functions such as analog value reading, PWM output control, LED Ring control, motor and servo control, and interaction control by STT and TTS. What’s more, there is also a library designed for amateurs, which is convenient for you to use the PiSmart.

For Amateurs


The Amateur library is prepared on the PiSmart platform for users to learn from scratch. It’s a simplified model at entry level, with which you can DIY projects more simply and make human-computer interaction more intelligent. Now let’s check how to use the PiSmart to make an interactive car.  

Step 1: Create a Project

There is a tool for setting up the project automatically on PiSmart. You can create a project named pismart quickly by using this tool. Type in the command:

pi@raspberrypi:~ $ pismart start_project my_pismart

my_pismart is your project name, and you can use any name you like for your project.

The tool will create a project directory my_pismart automatically, and it includes two files:

dictionary.sps  The library file for speech recognition commands; please refer to the related chapter later for details.

my_pismart.py  Main code file of the project.

Note: After the main code of the project is run, some files will be generated automatically in the directory. Files with suffix as .db, .dic, .fsg, and .jsgf are indispensable to the speech recognition library.

Step 2: Modify the Main Code

Change directory (cd) to the project directory and use the nano editor to open the main code file my_pismart.

pi@raspberrypi:~ $ cd my_pismart

pi@raspberrypi:~/my_pismart $ nano my_pismart.py

GNU nano 2.2.6                                                                   File: my_pismart.py
from pismart.amateur import PiSmart
from time import sleep
def setup():
    global my_pismart
    my_pismart= PiSmart()
    # If one of the motor is reversed, change its False to True
    my_pismart.MotorA_reversed = False
    my_pismart.MotorA_reversed = False
def end():
def loop():
    # Erase pass below and add your code here
if __name__ == "__main__":
        while True:
    except KeyboardInterrupt:
[ Read 25 lines ]
^G Get Help   ^O WriteOut    ^R Read File   ^Y Prev Page    ^K Cut Text       ^C Cur Pos
^X Exit       ^J Justify     ^W Where Is    ^V Next Page    ^U UnCut Text     ^T To Spell

You will find that there already exists some code. Here is the structure of the template:

from pismart.amateur import PiSmart

from time import sleep

To import the necessary modules.

def setup():

Put your setup code here, to run once

def end():

Ending function which will clear what’s in setup.

def loop():

Put your main code here, to run repeatedly

if __name__ == “__main__”:

Entrance of the program

When you’re writing code by yourself, generally you only need to modify the contents in setup() and loop(): settings in setup() and the circular process in loop().

Step 3: Run the Main Code

In the main code directory, you can run the code with the sketch python my_pismart.py:

pi@raspberrypi:~/my_pismart $ python my_pismart.py

Before running the code, please use a prop (like the package box) to hold the car, wheels hanging in the air. Since the car is still in debugging, it’s not safe to run it with the incomplete code. Let it run on the road only after the program has been completed.

Now the project is created. Let’s move on to develop functions of the car from easy to difficult.