How to use the Terminal application and Pi Cap
Learn how to use the Terminal application and Pi Cap
If you are just getting started with the Pi Cap and haven’t heard of the terminal before, then this tutorial is a good place to start. The terminal is an easy interface to work with the Raspberry Pi and Pi Cap. In this tutorial, we give you a short overview of how to use a Raspberry Pi from your personal computer with the terminal and explore SSH. We recommend reading this tutorial in combination with the Set Up Guide.
A Raspberry Pi is essentially a small computer. By connecting it to a screen, you can operate the Pi with a mouse and keyboard, as you would on your personal computer – editing files, clicking through folders and so on. Alternatively, you can do those same things without a mouse, using only a keyboard, by typing commands inside the terminal application. Within the terminal app, you can easily navigate through folders, launch applications and install new packages with different commands.
What if you wanted to use the Raspberry Pi in a standalone installation, without any peripherals attached to it? You can still access the Raspberry Pi’s content, even if you don’t have a desktop or keyboard attached to the Pi, by using SSH. This stands for Secure SHell and you can SSH into your Pi from your personal Windows or macOS computer by using the respective terminal application. On a Windows computer you have to download Putty, whereas, on a macOS system, you can use the built-in Terminal app (we prefer to use iTerm).
When you SSH into a Raspberry Pi, you basically have the terminal application of the Raspberry Pi on your personal computer. Any commands that you enter into your terminal application on your computer are executed on the Raspberry Pi. Ultimately, this allows you, for example, to launch projects on the Raspberry Pi without needing to attach a mouse, keyboard or desktop to it.
SSH into Raspberry Pi
In order to SSH into the Raspberry Pi, your computer and Raspberry Pi need to be connected to the same network. If you have a Raspberry Pi and an ethernet cable, you can simply connect the cable to the Pi. If you have a Pi Zero or don’t have an Ethernet cable, you can connect to the WiFi network. In order to do so, you will probably need to connect the desktop, keyboard, and mouse, after all, only to set up the WiFi.
But once your Pi is connected to the same internet as your personal computer, you can enter “ssh firstname.lastname@example.org” inside the terminal application on your computer. You then need to enter the Pi’s password (which by default is “raspberry”) and then you are presented with the line “pi@raspberrypi:~ $”. This means you have successfully connected to your Pi and your current position is the home directory, marked with an “~”. If you now enter “ls”, you will see all the folders that are located in the home directory.
Edit Pi Cap code
When you install the Pi Cap package, you also get the Pi Cap example code copied onto your Raspberry Pi. The majority of the example code is written in three languages: Python, C++, and Node.js. These are located in their respective folders within the “PiCapExamples” folder.
Let’s run through an example, say you wanted to edit the “touch-mp3.cpp” file. First, you head into the correct directory by entering “cd PiCapExamples/cpp/picap-touch-mp3-cpp/” into your terminal application. You can then edit the file with “nano touch-mp3.cpp”. This will open the text editor. At the bottom of the window you can find all the commands for the text editor, so for example, ‘CTRL + X’ is exiting the editor. Once you have saved any edits and exited the editor, you can execute the edited file by entering “./run” into the terminal. This will compile and run that file.
Note that you don’t need to head into the directory first. If you know which file you want to use and you know where it’s located, you can directly edit it – using, for example, “nano ~/PiCapExamples/cpp/picap-touch-mp3-cpp/touch-mp3.cpp”.
Here at Bare Conductive, we always SSH into our Pi to run programs or edit code. Below are some of the most common commands that we use:
ls – List all of the visible files within the directory (or folder)
cd <directory> – Head into the specified directory, for example, “cd PiCapExamples/”, changes to the “PiCapExamples” folder
nano <file> – Open a text editor, where you can edit a file, for example, “nano touch-mp3.py” allows you to edit the touch-mp3.py file