Time to complete: 5-10 mins; Level of Difficulty: Beginner
If you haven’t used a Raspberry Pi before, you migh be wondering what all the fuzz is about. Whereas we cannot cram everything this little device can do in a single tutorial, we can certainly highlight how easy it is to get it running. We’ll go over the few necessary components to get up and running, particularly choosing an Operating System and installing it onto the Pi’s ‘hard drive’!
The Raspberry Pi
The first questions everyone asks when hearing about the Raspberry Pi are:
What is it?
First and foremost the Raspberry Pi is a computer much like any desktop or laptop. Just as any other computer in the market, the Raspberry Pi runs an Operating System that allows users to perform any common tasks such as browsing the internet, making spreadsheets and text documents, watching high-definition (up to 1080p!) video, and even playing videogames.
However, compared to other computers the Raspberry Pi features a tiny form factor and a remarkably low price tag. This fantastic single-board computer was developed to enable people of all ages and technical backgrounds to explore computing and learn programming. Whereas it was initially targeted at middle-and high-school students in the UK, it quickly became widely adopted around the world from all corners of the electronics market, from the hobbyist to the commercial and industrial.
What does it do?
As mentioned before, the Raspberry Pi is capable of carrying out typical computer tasks. However, unlike others, this single-board computer has the ability to interact with the physical world. That is, without the need of expensive equipment like Data Acquisition devices or Programmable Controllers, we can use a Raspberry Pi to communicate with external sensors, actuators, and other 'low-level' devices. This unique feature enables users to build a wide range of projects, from music machines and fart detectors to weather stations and tweeting birdhouses!
We've made a detailed video of the process described below, which guides you step by step through the process:
Before diving into all the fun things that can be done with the Raspberry Pi, we need to do a little prepping. Depending on what package or bundle you purchased with your Raspberry Pi, you may or may not have received a pre-programmed SD Card. The SD Card is the Hard Disk Drive (HDD) of the Raspberry Pi, and it holds the Operating System files that run when we apply power and boot up the system.
There's nothing special about the SD Card needed so any microSD (for current models A+, B+, 2, and 3) or standard SD Card (for the older A and B models) should work. Over the next few steps we'll show you how to turn an SD Card into a Hard Disk Drive for the Raspberry Pi. We recommended that you use a card with at least 8GB of capacity.
If you already have a microSD Card formatted with an Operating System, you can skip ahead to the step: Booting up your Raspberry Pi. Otherwise, you'll need both the card and a standard desktop or laptop computer to complete the next few steps.
Choosing an Operating System
Different than most standard Mac or PCs, the Raspberry Pi offers a set of Operating Systems that allow us to dedicate this little device to a particular application. The majority of the options are versions (distributions) of the GNU/Linux Operating System, and most of them are specifically tailored to a specific purpose such as running a Media Center (e.g., using OpenELEC) or a Music Generator (e.g., using Sonic Pi).
For the purpose of this lesson, we'll be using the Raspbian distribution, however, you can always keep a bunch of Operating Systems on different microSD Cards, and interchange them when necessary!
If you haven't already, start downloading the Operating System image file for the Raspbian distribution, which we'll use later in the "Writing an OS Image File to the SD Card" step. It is available at the Raspberry Pi Foundation's website: http://www.raspberrypi.org/downloads/
Formatting the microSD Card
Now, we need to prepare the microSD Card for writing an Operating System image file to it. We'll run a quick format in order to erase its contents and also to choose an appropriate File System.
Note that you should use an microSD Card exclusively for your Raspberry Pi, thus choose either a spare or new one. Also, double-check the contents of the card and back up any files you'd like to preserve.
Mac OS X
- Insert the microSD card to a corresponding port on your computer, you can use a USB MicroSD Card Reader/Writer if needed.
- Open the Disk Utility application (hint: press Command+Space Bar to use Spotlight to search for the application).
- On the left side where all the disk devices are listed, select the microSD Card that you've connected. In our case is the 7.89 GB APPLE SD Card... option, yours might be different.
- Click the
Erasetab next to the
MS-DOS (FAT)from the
Formatdrop down options (if not selected by default).
- Click the
Erasebutton near the bottom right corner of the window.
Writing an OS Image File to the SD Card
Now that we have downloaded the Raspbian image file and successfully formatted our microSD card, we are ready to write the image file onto it.
Mac OS X
We'll use a command-line interface on our Macs for this process. The commands listed below can be copy-pasted onto your terminal directly. Remeber to hit the enter/return key after entering the commands.
Open the Terminal application (hint: press Command+Space Bar to use Spotlight to search for the application), and enter the command:
This command lists all storage devices currently available in the system. From the list we can identify the microSD Card inserted on the previous step.
In our case, the microSD Card inserted in my computer has been listed as
/dev/disk2. Depending on your system, the numbering might be different (e.g.,
/dev/disk3). You can identify the correct one from the name assigned to the card and from its listed storage capacity (8GB in our case).
Next, we unmount the card, which dettaches its filesystem from the currently accessible filesystem of our computer. Amongst other things, this stops any pending read/write operations to the card:
diskutil unmountdisk /dev/disk2
We then locate the Raspbian image file that we downloaded earlier Typically, it should be inside the Downloads directory. The download is usually a zipped file (.zip extension), which by using the Finder application, navigating to the Downloads directory (or wherever it's been downloaded), and double-clicking on it. Take note of where the file lives in your system as the path will be needed for the next operation.
The next command is highly dependant on a few things. First, the path of the image file might change because a new version is released (so the file itself will be named differently) or because you downloaded the file to a different directory. More importantly, remember that the system path of your microSD Card (
/dev/diskN) might be different!
To write the image file to our microSD card we use the disk dump utility. It allows us to copy byte-for-byte the image file from our computer's filesystem to the filesystem on the microSD Card:
sudo dd if=~/Downloads/2015-02-16-raspbian-wheezy.img of=/dev/diskN bs=2m
This process, which is different than copying or drag-and-dropping the image file, will take a few minutes. Notice that issuing the command without
sudo will result in a
Permission denied error, as writing image to disks requires by default superuser (root) privileges. Once it's finished, you will get a confirmation message as shown below.
After the writing is completed, we can eject the card from the computer and use it with our Raspberry Pi! To eject the card we can use either using the shortcut icon in Finder or by right-clicking on the Desktop icon of the microSD Card. Alternatively, we can enter the command:
sudo diskutil eject /dev/rdiskN
Remember to change
rdiskN for your own setup as described earlier in this tutorial.
Booting up your Raspberry Pi
We’re now ready to start using our Raspberry Pi as a desktop computer! Before moving forward, we'll need to gather the necessary peripherals (keyboard and mouse) and a video monitor that will be used with the Raspberry Pi.
We place the microSD Card in the metal socket found on the underside of the Raspberry Pi board. The contacts of the microSD card should be facing downward (towards the board) and inward (towards the connector itself). We also need to ensure that the card is securely in place by gently pushing down on it until hearing a ‘click’.
Before applying power, we need to connect the keyboard, mouse, USB Wi-Fi adapter (optional), and video monitor. We can then connect the Raspberry Pi to a 5V USB Micro-B Power Supply. After power is applied, text output from the boot-up process will be shown on the screen. Towards the end of the boot-up process, the raspi-config screen will come up (shown below). This allows us to configure important options for the operation of the Raspberry Pi:
You can explore all the different options, but 3 that we typically recomend you go over are:
- 1 Expand Filesystem: this allows the Operating System to access a bigger storage space of the memory card.
3 Enable Boot to Desktop/Scratch: by default Raspbian boots to a terminal where we can start a Desktop Environment by issuing the command
startx. If you rather boot directly to the Desktop Environment, use this option.
- 4 Internationalisation Options: by default the keyboard option for the Raspberry Pi is set to a British layout. Use this option to change it (if needed). You can also select the preferred Time Zone for the system clock.
After making these changes you'll need to reboot the system; note that a few of the options might ask you to do it during the configuration process. If you've selected to boot onto the Desktop Environment, the next time your Raspberry Pi boots up you should somthing similar to the image below at the end of the boot-up process:
Otherwise, you'll see a login console login screen. In such case there'll be a text prompt asking for a username. The default username for the Raspbian image is pi whereas the default password is raspberry. After successfully login in, you can always start the Desktop Environment by running the command:
Mac OS X
- Writing to the microSD Card takes too long!
When writing the Raspbian image file to the microSD card you may notice that the process takes more than just a few minutes. If the diskdump (
dd) command takes longer than 15 minutes, you can stop it by hitting Control+C on your keyboard. Try re-formatting the SD Card (remember to select FAT as the format) and writing the image file once again.
- Getting a "Disk is busy" error when attempting to write the image file
Writing to the filesystem of your own computer will have catastrophic results, so please make sure that you're attempting to write to the correct filesystem! That is, that you're choosing the correct device for the output file (
Typically on OS X
rdisk0 is the main Hard Disk Drive of your computer, and sometimes even
rdisk1 will also correspond to an internal drive. If you're unsure, you can always list the devices (using
diskutil list) before and after connecting the microSD Card to the computer's port. The microSD Card will not be listed in the first attempt, but it will be shown on the second one so you'll know for sure under what rdisk it's listed.
- Getting a "File not found" error when attempting to write the image file
This occurs when the wrong path to the image file is entered. Here are a few things to try:
- Please ensure that the file has finished downloading to the expected directory (in our case, we used the Downloads directory located inside the User's Home directory).
- Use Finder to navigate to said directory, and ensure that the name of the file matches the one being used in the command.
- At the time of this writing the file name is 2015-02-16-raspbian-wheezy.img which is bound to change for the next version of Raspbian.
- Getting a "Permission Denied" error when attempting to write the image file
This error typically occurs if we haven't included
sudo at the beginning of the command, or we have mistyped our password. Note that nothing will be 'echoed' on screen while we type the password, nonetheless when we hit enter/return after entering it (if the entry is valid) the command will execute correctly.