We’ll be using the Raspberry Pi for all the further exercises throughout the year. If you attend one of the schools we visited in 2016 the hardware will be available to you, but you’ll need to set it up first. This tutorial will show you how.
In this tutorial, you’ll learn how to:
- Hook up all hardware peripherals and turn on the Raspberry Pi
- Install Raspbian, a flavor of Linux designed specifically for the Raspberry Pi, using the NOOBS operating system
- Take your first steps using the Raspberry Pi from the command line
- Find further resources
What should I know about the Raspberry Pi?
The Pi itself
The Raspberry Pi is a special type of embedded system, because unlike many other embedded systems, it is not only a microcontroller – it’s an entire computer. Many microcontrollers are designed with a specific purpose in mind – this is not the case with the Raspberry Pi. Instead, it is a very small computer that can run a full version of an operating system, such as Linux. This is very different from most microcontrollers, which only run a single main program.
Although the Pi is very much like a “normal” computer – it can run almost any program you put on it, including databases, web servers and more traditional desktop applications – it’s closely related to more traditional embedded hardware because it’s very small and has general purpose input/output pins (GPIO). This allows the Pi to connect directly to all kinds of hardware.
There are several different models of Raspberry Pi and all of them are impressively affordable. Each model has strengths and weaknesses in terms of affordability, power consumption, availability of ports, etc. The newest model, the Raspberry Pi Zero, costs only $5 – a little more than 21.25 GH₵ or 3200 CFA!
In Full Stack Embedded 2016 we practiced connecting Raspberry Pis to a few different sensors and hardware peripherals – ultrasonic sensors, LEDs and buzzers. But Pis are able to connect to just about anything – thermometers, motors, you name it. The tutorials in the next few months will show you the details of these connections so that you can connect to any kind of sensor you want. We can’t wait to see what you’ll build on your own!
Linux is a free operating system. This means not only that it doesn’t cost anything – its source codes are open and anybody is welcome to contribute to it in order to make it better. This makes it part of a large family of software that has free licenses, meaning that when you download and use it, you also own it at the same time.
Linux profits from many of the advantages of an open source system – high transparency can contribute to better security and improve performance. Also, because it is not owned by any company, it puts users in control of their own systems, which can protect their privacy and give them more freedom. This is easy to notice if you try to program using Linux – it’s very easy to get down “under the hood” and control the system from the command line, which lets you access the system directly – no windows, registries, etc. between you and the machine. This is one of the reasons that Linux is deployed on most of the world’s smartphones and tablets, more than 90% of its supercomputers, and many other critical systems that need high performance and security (the Large Hadron Collider, the New York Stock Exchange and the air traffic control systems of the world are just a few examples).
This can sound scary to new users, and it is a bit more difficult to learn than pure graphical interfaces. But don’t worry! If you’ve ever used a phone that runs Android, you’ve already used Linux. And there are plenty of Linux distributions that have not only a command line interface, but also a graphical one.
This year we’ll be working with Raspbian, a special distribution of Linux designed specifically for the Raspberry Pi. It comes with all the software you need to get a Raspberry Pi up and running, start a web server, connect to hardware, or anything else you might want to do. It’s also loaded with a few programs that can help you learn to program and use the Raspberry Pi. Its default interface is a command line, but you’ll learn how to start a graphical interface and how to connect to the Raspberry Pi from another computer, such as from your laptop, using SSH.
Homework: Set up your own Raspberry Pi
Collect the equipment you’ll need
If you are working with a conventional Raspberry Pi 1, 2 or 3 you will need a:
- Monitor or TV
- HDMI cable
- USB keyboard
- USB mouse
- Micro-USB power supply
- Micro-SD Card with at least 8 GB disk space
If you are working with a Raspberry Pi 1, you will have no easy option to connect the Pi to the Internet or another network.
If you are working with any variant of the Raspberry 2, you might want to also acquire either an ethernet cable or a wifi dongle in order to connect the Pi to a network.
If you are work with a Raspberry Pi 3, wifi support is built in, but you might want use an ethernet cable in order to connect to it via a wired connection.
If you are working with a Raspberry Pi Zero you will also need a micro-HDMI to HDMI adapter in order to connect the Pi to a screen. You might also want to use a wifi dongle in order to connect the Pi to your network.
Prepare your microSD card
The microSD card is your Pi’s hard drive. In order for the Pi to work, it has to have an operating system installed on it.
The easiest way to get Raspbian on your SD card is to use the New Out Of the Box Software (NOOBS). NOOBS is an easy operating system installer which contains Raspbian. It also provides several alternative operating systems which you can downloaded from the internet and install. You can download it from here. We recommend downloading the offline version of NOOBS, as the file is very large. If you need to install multiple micro-SD cards, you can download it just once and then copy the contents to all of them. The NOOBS LITE installer will download very quickly, but it downloads the operating system you want to install during installation, so if you’re installing multiple Pis you might end up downloading a lot more data than you actually need.
The files in the NOOBS zip file are over 4GB in size. Older zip programs may not be able to work with them. If you are using Linux to unzip the NOOBS archive you shouldn’t have problems. If you’re working with Windows and are unable to unzip the archive, try using 7Zip. Otherwise, if you’re using a Macintosh, try The Unarchiver.
Unzip the contents of the zip file and copy the contents to the microSD card. This step takes a little while. Afterwards, safely remove the SD card from your computer.
Connecting the hardware
Begin by placing your SD card into the SD card slot on the Raspberry Pi. Don’t worry about putting it in wrong – it will only fit one way. Next, plug your keyboard and mouse into the USB ports on the Raspberry Pi. Make sure that your monitor or TV is turned on, and that you have selected the right input (e.g. HDMI 1, DVI, etc). Then connect your HDMI cable from your Raspberry Pi to your monitor or TV.
If you want to connect your Raspberry Pi to the internet, plug an active ethernet cable into the ethernet port, or connect a wifi dongle to one of the USB ports. This isn’t necessary if you have a Raspberry Pi 3 – the wifi adapter is built into the board.
When you’re you’ve plugged all the cables and SD card in correctly, connect the micro USB power supply. This will turn on and boot your Raspberry Pi.
The NOOBS boot screen will show and guide you through the installation process. Follow the instructions on the screen to complete the installation, selecting Raspbian as your operating system. Afterwards, the Pi will reboot and you can log into the command line. The username is
pi and password is
Working with the Raspberry Pi
Booting the Pi
Booting the Raspberry Pi is easy – just connect it to all the peripherals and a power source, liked described above, and it will turn on automatically.
Working on the command line
When the Pi boots, it shows a large number of text detailing how it starts up. What you are seeing on the screen is the Pi reporting what hardware it finds, the services it’s starting, etc. After everything’s done, it will display the login prompt, which is simply a line of text:
Enter your username here (if you haven’t changed it, it’s
pi) and press Enter. On the next line, you will be prompted for your password. If you haven’t changed that, it’s
When you successfully log in, the Pi will display a few lines of text about its operating system and then another prompt. It looks like this:
Now you can enter commands. Once you press Enter, they are executed. If you type in a command that doesn’t work, don’t worry – the Pi will do its best to tell you what went wrong and you will return to the command prompt.
The command line is structured as follows:
pi– This tells the name of the user you are logged in as. If you switch users, this name will change too.
raspberrypi– This is the name of the computer you’re logged into. If you changed the Pi’s host name during setup, or if you do that at a later time, this name changes.
~– This shows the directory that you’re working in. ~ is a special symbol which means that you’re working in the user’s home directory. Don’t worry, you’ll understand this better in the months to come.
Try using some of the following commands:
cd– Change directory. This moves your session between different directories.
ls– List files and directories and can tell you more information about them.
cp– Copy files
mv– Move files
mkdir– Create a new directory
touch– Create a file or updates its last modified date.
rm– Remove files and directories from the file system.
pwd– Show the current working directory
nano, vi– Text editors that work on the command line.
If you want to find out more about how a command works, try typing its name followed by
--help. This calls up its short help description. If you want more detailed information, type
man followed by the command’s name. This will call up the program’s so-called “man pages” – Linux terminology for the program’s manual. You can also try searching for help about the command in the Internet – if you just type it into a search engine you’ll find all kinds of resources about it.
Raspbian comes with hundreds of programs already installed, so try as much as you can! If you want a program that does a specific thing, try searching for that function in the Internet by searching for e.g. “convert pictures in Linux” or “changing pdf files from command line”.
Starting the graphical interface
Working on the command line is fun and fast, and if you find yourself repeating tasks there it’s easy to turn those into a script or program. However, you may also want to work with the Pi using its graphical interface. You can start it with the command
This starts the Pi’s X server and lets you work with a graphical interface, like on most computers you’re used to.
Shutting down the Pi
You can shutdown graphically by using the windows or, if you’re working on the command line, by using the command
sudo shutdown now
sudo means that you are performing that command with administrative privileges. You’ll have to enter the password for the Pi’s administrator, which is
raspberry if you haven’t changed it.
If all else fails, you can always unplug the Pi. This isn’t a good idea under normal circumstances and it will stop whatever your Pi’s doing right then – which might corrupt files on your file system or break your system. But it works as a last resort.
If you’ve done all these things and want to learn more, try some of the following things!
Read more about the Raspberry Pi
Change the main user’s password
You can do this with the command
passwd. If you type in this command it will give you prompts that you can follow in order to change the password.
Set up your own user name
You can do this with the command
useradd. If you’re not sure how to use it, try reading the manpages with
or reading a tutorial (here’s an example).
Connect the Pi to your wifi network
Connect to the Pi from another computer
In order to do this you’ll need to activate secure shell (SSH) access on your Pi and then connect to it using an SSH client from the operating system on the computer you want to use to access the Pi with. If the computer you’re using to access your Pi is running Linux, you can do this with the SSH command. If you’re accessing the Pi from a Windows computer, a Macintosh, or an Android or Apple device, search the Internet for an appropriate client.