4.1. Fundamental Software Tools
This section will guide you through the installation and usage of all the fundamental tools and programs that we will need to complete the project.
4.1.1. Python3
Python3 is the main programming language we will be using to configure and control our rover, here is how to install it on your Raspberry Pi 5 !
Turn on your Raspberry Pi, log into it and open a terminal by doing either:
CTRL-ALT-t
Windows key, search “terminal”, ENTER
Now enter the following commands into the terminal:
# Make sure your packages are up to date
sudo apt update && sudo apt upgrade -y
# Install python3
sudo apt install python3 -y
You now have access to the python3 executable which will run any python code you give to it. You can find where the apt package manager installed that python3 file by running:
which python3
This will probably return /usr/bin/python3
. This means that the
python3 executable is installed on your system and you can execute it no
matter which directory you are currently in.
Hint
/bin/ directories are not the trash! They are where the binary files are stored. Binary files are files made of 1s and 0s that your CPU can directly execute. Try opening one up, you will just see gibberish.
The PATH
system variable stores a long list of all directories of
binary files (…/bin/) that are known by your operating system.
When you execute any program from your terminal:
my-new-cool-program
Your OS will search inside all of the directories in your
PATH
variable to find the my-new-cool-program
file.
If you are curious, you can see what is inside the PATH
system variable by running:
echo $PATH
The which
program that you executed a few lines above searches all the
places in the PATH
and tells you in which one your program resides.
In our case, python3
resides in /usr/bin/
.
Therefore, you can now execute that python3 file by running:
python3
This python3 executable file works in two different ways:
- Python Live Interpreter
You call python3 with no arguments:
python3
and it will launch the live python interpreter. This transforms your terminal into a python environement where you can type any python code.
- Python Script Execution
Or you can run the file with a single argument, the name of your .py python script:
python3 my-python-script.py
. In this case, the python3 executable will run the code in your script and then return to the terminal.
# To enter the python live interpreter
python3
# To run a python script
python3 my-python-script.py
Let’s do a hello-world example in both cases.
# Launch python live interpreter
python3
# Print "Hello World!" to the terminal
print("Hello World!")
# Exit the interpreter
CTRL-D
# Make a new .py in the current foler from the terminal
touch my-script.py
# Check it really appeared
ls
# Open it with the nano text editor
nano my-script.py
# Type in
print("Hello World!")
# Save your changes with
CTRL-o ENTER
# Exit the nano text editor with
CTRL-x
# Check the contents inside the file by printing them out
cat my-script.py
# Execute the python3 program and pass your file as an argument
python3 my-script.py
Hint
Congratulations, you now know how to write python scripts!!


Please signal any mistake to: errata@microver.ch