Getting Started with Raspberry Pi
So I have had Raspberry Pi for around three years now, but I never had a chance to write something about it. Now that the Raspberry Pi Model B+ and Raspberry Pi 2 Model B are released, I thought I should have done more justice to the one I have, and here it comes! I am using Raspberry Pi Model B for this post, but it should be good for any model.
And before you start thinking that this is an obsolete tutorial, please note that the Raspberry Pi Foundation will keep Model B in production as long as there’s a demand for it. This is meant to continue to support the industrial customers.
A brief introduction to Raspberry Pi (henceforth abbreviated as RPi) can be found here. The first thing that you would want to do with your RPi is to install and run an operating system (OS) on it. But even before that, you might as well know how it should be connected. Check out this cool video from Raspberry Pi’s website.
- Things you’ll need
- Using NOOBS to Install OS
- Manual Installation of OS Images
- Setting up your Raspberry Pi
- First Boot
Things you’ll need
Things you’ll need in this tutorial are:
- Raspberry Pi (Model A, B or B+) – any model will work for this.
- Micro-USB adapter and cable – to power up the RPi. The power adapter should be able to provide at least 5 volts 750 mA current. The RPi is rated a minimum of 750 mA, but if you intend to hook up power consuming devices to the USB ports (like keyboard, mouse), I would suggest you to go for at least 1 A, whereas 2 A is recommended. You can go for your phone’s charger as well. I am using my HTC One’s charger rated at 5 volts 2 amps.
- SD card (for Models A and B) – at least 4 GB (8 GB or more recommended, up to 32 GB) to install and store the OS image.
- MicroSD card (for Model B+) – at least 4 GB (8 GB or more recommended, up to 32 GB) to install and store the OS image.
- Ethernet cable – an RJ-45 10/100 CAT5e LAN cable for internet connection. This is needed if you are going for network-based NOOBS installation. Otherwise it is not needed for this tutorial, but it is recommended.
You’ll need the following things for this tutorial, but they are optional for all the future posts.
- HDMI (to HDMI/DVI) cable – this is to connect a display device (like monitor, TV, TFT/LCD screens). You must not forget that RPi is a computer after all, and computers need a display device.
- RCA analog cable – this is to be used only if you wish to connect your “old” home TV to your RPi.
- Keyboard and mouse – to connect to your RPi computer. Try to go for smaller ones that consume less power.
- SD/MicroSD card reader – to connect SD card to your computer to install the OS image into it. These days many computers come with one such already built in, so check it out first. Once you install your OS, you wouldn’t need it again.
Things that are optional are:
- Powered USB hub – in case you are planning to connect more than two USB devices. It is recommended that you go for a power USB hub rather than an un-powered one since more devices will demand more current.
- Case – for protection and making your RPi look fancy.
- Audio device – if you aren’t connecting your TV via HDMI, then you’ll be missing out on the audio. For that, the RPi has an on-board 3.5 mm audio jack, to which you can connect your headphones, earphones, speakers, or even your home theater system! This is purely optional, we are not demonstrating any audio applications in this tutorial, but you are encouraged to try it out!
But I don’t have a monitor/TV! What do I do?
Good question! I was stumped with the same thing when I was starting off. The answer is really simple. You can log into your RPi remotely via SSH and view the desktop environment by running a VNC server on your RPi. You’ll be able to use your PC to view the desktop of your RPi, use your PC’s keyboard/mouse to control your RPi, as well as share your PC’s internet connection with your RPi. Wait for my next post and I’ll show you how!
Using NOOBS to Install OS
The simplest and fastest method to get up and running with your RPi is to use the New Out Of Box Software (aka NOOBS). It formats and partitions your SD card and installs your desired OS on it. It is a little too simple to discuss it here. The Raspberry Pi Foundation has created an amazing video for this, which I decided to share rather than writing about it. Check it out! You can download the latest version of NOOBS from here.
Manual Installation of OS Images
To install OS images manually, you would need to get hold of them in the first place. At the present, you can find pre-built images of six OS which you can download from here. Apart from these, you can also build a custom Linux image for your RPi, which is outside the scope of this post (we’ll dedicate a post on how to build custom Linux image for RPi using the Yocto project soon).
The steps discussed here can be used for any of the OS images, but for the purposes of this tutorial, we will download and install the Raspbian (Debian Wheezy) image onto an SD card and then boot the RPi with it. At the time of writing this post, the latest image is the
2014-06-20-wheezy-raspbian.img. So download the zip file from the downloads page and then extract it. Make sure you download the latest version available, especially if you want to run them on the new RPi Model B+. Older versions wouldn’t work on it.
As mentioned on their Wiki page, Debian does not support RPi’s ARM11 CPU. The Raspbian OS has been modified and built exclusively for the RPi and includes updated versions of some software and some non-free third party packages pre-installed (like Oracle Java and Wolfram Mathematica).
The entire installation process can be categorized into the following steps. The steps are the same whether you’re using Linux, Mac or Windows, however the methodology is a little different for Windows.
- Download OS image.
- Unzip the file.
- Format your SD/microSD card.
- Find out the mounted disk ID.
- Write the .img file to the disk ID.
If you are using Windows to transfer the OS image to the SD/microSD card, then there’s a GUI called Win32 Disk Imager that you can use. Here are the steps:
- Download the OS .zip file and extract it using your favorite unzip tool (like Winzip, 7zip, or Windows native unzip tool, etc). Upon extracting you should have the .img OS image.
- Insert your SD/microSD card into your card reader. It’s always recommended to format the card first to FAT32 file system (FAT16 won’t work).
- Once your card is formatted, it should mount on its own. Go to My Computer and note the drive letter number assigned to your card.
- Download and install Win32 Disk Imager application. It is a freeware and can be downloaded from here, and then open it. If it shows an error, just click OK and continue.
- Browse to the image file, choose your SD card device, and click “Write”. Check out the screenshot below. And that should be it. The write process could take a while, so be patient!
If you are using Linux or Mac to prepare your SD card, then we use the dd command line tool. It should be pre-installed. There are a couple of GUI applications available these days as well, but it’s always beneficial to learn to use the dd tool.
As usual, the first step would be download and unzip the OS image. You can unzip it using the GUI or command line, anything is fine. In linux, you can unzip by typing the following in the terminal window:
For me, it was the following:
This unzips the approx 800 MB .zip file into a 3 GB .img file. This is the reason I asked you to go for a minimum 4 GB SD card. Screenshot is attached below.
The next step is to determine where your SD is being mounted. The trick is simple – we list all the disks before and after inserting the SD card. The disk added to the list will be the one assigned to the SD card.
In order to list the disks mounted, type in your terminal window:
In Linux you would see something like this–
If you’re using a Mac, you would see something like this–
Next, insert your SD card and then type in the command again. You would see something like this for Linux and Mac–
You can clearly see that an extra line has been added to the listing. This is the one that refers to your SD card.
On a Linux system, the file system could be listed as
/dev/mmcblkxxx, whereas on a Mac, it could be listed as
/dev/diskxsxxx. I think it’s a good time to take a detour and discuss about Unix file systems. If you are familiar with Unix file system notation, then please skip to the next section.
In Unix based OS (like Linux and Mac), there’s no letter drive number associated to any disk or it’s partition. Every disk exists as a file in the
/dev directory and is mounted somewhere else.
For instance, on Linux various disks are assigned the
sdxy notation, where
x refers to the disk and
y refers to the partition. Example,
/dev/sdb refer to two separate disks (like hard disk and SD card). And if it shows up as
/dev/sda2, it means that the
sda disk has two partitions –
In some Linux distributions (like Ubuntu), all the disks follow the
sdxy notation, whereas in some (like Mint), hard disks and removable drives show up as
sdxy whereas multimedia cards like SD cards show up as
/dev/mmcblk1, etc. and their partitions (if any) show up as
/dev/mmcblk0p2. Whatever the case may be, the basic idea remains the same, which I hope you have understood.
In case of Mac, all the disks show up as
/dev/disk4s1. The earlier one refers to the second partition of
disk0 and the latter one refers to the first partition of
disk4. The underlying concept is the same.
Another important thing that is worth noting is that even though the disk file exists in
/dev directory, the disk is mounted somewhere else. In the screenshots attached above, you can note that the SD card is mounted at
/media/max/Untitled in Linux and at
/Volumes/ABC in Mac. The names “Untitled” and “ABC” are the names of the disk. This means that all the files contained by the SD card can be accessed from these locations. This is totally different from
/dev/disk4s1, which are supposed to be used only by the OS kernel in order to issue commands like read, write, open, close, etc. to the SD card.
Also, note that the disk on which the OS is running is always mounted as root directory
Let’s get back…
Next step is to unmount the partition (do not eject the disk, just umount it. You can do this from the disk utility GUI or from the terminal as follows (replace
disk4s1 with your disk number). Also note that in Mac, the command is
unmount whereas in Linux it is
umount (not unmount).
For Linux: umount /dev/mmcblk0 For Mac: unmount /dev/disk4s1
The next step is to run the
dd. Here is how you run it:
dd bs=4M if=<path-to-name-of-distribution>.img of=/dev/xxxxxx
bs stands for “block size”. We choose the block size as 4 MB, which should work most of the times. If it doesn’t, choose
if stands for “input file”, which should be the full path to the .img file that you downloaded. If you are in the same directory, you can simply type the name of the .img file.
of is the “output file” where
dd should copy the image file, which should be the entire disk file (not any partition of it). So, if you have your SD card mounted at
/dev/sdb1, you should write to
/dev/sdb. If it is
/dev/mmcblk0p1, it should be
/dev/mmcblk0. If it is
/dev/disk4s1, it should be
And of course, this command requires root level privileges. So if you aren’t logged in as root, you’ll need to type in
sudo before the command.
For me, I had to type in the following–
For Linux: sudo dd bs=4M if=2014-06-20-wheezy-raspbian.img of=/dev/mmcblk0 For Mac: sudo dd bs=4M if=2014-06-20-wheezy-raspbian.img of=/dev/disk4
Again, this operation takes a while, and there’s no feedback from
dd. So it might appear frozen for some time (sometimes more than 5 minutes). Don’t fret, go make yourself a cup of coffee, drink it, relax and come back!
On a Mac, if the above operation fails, try replacing
rdiskx. And if it reports an error like
dd: bs: illegal numeric value, replace
4m. This should help.
Once this is done, type in the following command to ensure that the write cache is flushed and it’s safe to unmount your device–
Setting up your Raspberry Pi
That’s it! You’re all set to set up your RPi now! Setting up your RPi is easy. Just follow these steps:
- Insert your SD/micro-SD card into the slot at the back of your RPi. This should always be the first step (recommended). Never ever remove it from the RPi as long as it is powered up!
- Connect one end of the HDMI cable to your RPi, the other end to your monitor/TV.
- Connect one end of the Ethernet cable to your RPi, the other end to your modem/router/PC.
- Connect the keyboard and mouse to the USB ports directly.
- Connect any other peripheral you wish to connect (could be any other USB device, camera module, audio device, or any other circuit/device connected to the GPIO pins).
- Connect the micro-USB power supply. This should always be the last step. And your RPi starts booting up! Rejoice! :)
The following video by the Raspberry Pi Foundation shows you how to do the same.
A connected Raspberry Pi looks something like this–
The first boot of Raspberry Pi takes some time since it initializes and configures some things. If it is Raspbian, it also displays you the
raspi-config software configuration menu, something like this–
You can set some parameters if you want. I would suggest you to expand the file system to fill up the entire space in your SD card and enable SSH. The SD image written by
dd and/or the Win32 Disk Imager is only for 3 GB. If you have an SD card of capacity 8 GB, you would like to expand the file system to utililze the entire space. You would be asked to reboot your RPi after this. The reboot would take some time as well since it needs to resize the root file system.
So while I was doing this, I recorded a video as well. It is not professional by any means, but it should still show you what to do and how to do.
Once the reboot is successful, you should see the RPi asking for you to login. If you don’t already know, your login id is
pi and password is
raspberry. In Linux terminal, when you type in the password, it usually doesn’t show up on screen. This could be baffling if you aren’t familiar with Linux. Don’t worry, just go ahead and type in the password. It will accept it! :)
And when you can see the following, it means that you have successfully logged into your RPi! Woohoo! Congrats!
Raspbian GNU/Linux 7 raspberrypi tty1 raspberrypi login: pi Password: ... some messages ... pi@raspberrypi ~ $
Starting your Desktop Environment
The Raspbian comes in with LXDE (Lightweight X Desktop Environment) as its default desktop environment. To start that, simply type in
startx in the console in front of you.
This should start the visual GUI desktop for you, and you should see something like this–
Beautiful! Isn’t it! And cute too! :) Go ahead, play around with it! If you have your Ethernet cable connected, then you can browse internet using the Midori browser.
Opening Raspberry Pi Software Configuration Tool (raspi-config)
You can open the RPi Software Configuration Tool from the terminal as well. Go to LXTerminal and type in the following–
This will reopen the same configuration tool that you encountered during your first boot.
Shutting Down your Raspberry Pi
One last thing that you should know is how to turn off your RPi. Definitely disconnecting the power supply directly is not the way to go. If you haven’t noticed already, there’s a Shutdown icon on the desktop. Double click it and it asks for your confirmation.
You can Log Out from the desktop environment by clicking on the little red power button on the bottom left of the LXDE’s screen. But this DOES NOT shut down your RPi. It merely closes the desktop environment, that’s it.
Alternatively, you can also shut down using the terminal. Go to LXTerminal (or the console if you don’t have LXDE running), and just type–
And if you wish to restart your RPi, type–
So yeah, that’s pretty much it to get started with your Raspberry Pi! We learned how to transfer the image of your desired OS to your SD/microSD card using Windows, Mac and Linux. This can be done either using NOOBS or manually. The manual process can be categorized into five major steps–
- Download OS image.
- Unzip the file.
- Format your SD/microSD card.
- Find out the mounted disk ID.
- Write the .img file to the disk ID.
Then we had a quick walk-through of what happens when you boot up your RPi for the first time. We learned how to access and change settings using the software configuration tool raspi-config. More importantly, we learned how to turn off your RPi as well!
So that’s it for now folks! In the next post, we’ll learn how we can log into RPi remotely and still view the desktop environment! Subscribe to stay tuned! And if you have any questions, there’s always a comment box down below. Please refrain from posting codes since they will be deleted anyways. Be smart, use pastebin.com to share codes! Thanks for reading! :)
Written by Mayank Prasad (aka Max)
Last updated on July 22, 2014.