CHAPTER 1

image

Your First Bite of Raspberry Pi

This chapter is where we finally get our hands dirty. If you decided to skip the introduction in your eagerness to get up and running, that’s fine; you won’t have missed anything critical for this chapter. However, make a note to pay the introduction a visit in the not too distant future as it gives you a lot of background on the Pi and what makes it so special.

Now, back to dirty hands! We are going to start off by unpacking the Pi and going through the list of things that you need to actually get it up and running. Once we’ve hooked everything up, we’ll then need to sort out something for it to run—in this case, Raspbian Linux (more on this a little later). Once we get Raspbian running, we still need to configure it and some of the options are a little technical and Linux-specific; but don’t fret, we have you covered there, too. To round off the chapter, we will bask in the glow of the Raspbian desktop before heading off to Chapter 2 to see what we can actually do with it.

Your Freshly Baked Pi Arrives

Okay, so the postman has just dropped off your long-anticipated package, and after eagerly ripping away the padded envelope you’re left with a little box, (little being the operative word). You simply can’t help but look into the depths of the envelope to see if there is perhaps something lingering at the bottom. Failing to find anything with a visual inspection, you’ll no doubt proceed to the old faithful approach of turning the envelope upside down and giving it a bit of a shake. Although you might shake loose the packing sheet (somehow they always seem to super glue themselves to the inside), you won’t find anything else.

When you order a Raspberry Pi, this, dear reader, is all that you’re going to get (see Figure 1-1).

9781484211632_Fig01-01.jpg

Figure 1-1. What falls out of the envelope

WHY A PICTURE OF JUST A BOX AND SOME BITS?

The honest reason is because when this is all that turned up, our first thought was that something must have gone missing. Yes, the site tells you when you order that this is all you are going to get, and it really makes perfect sense.

We want to emphasize that this is all you get, and it’s not enough to get your Pi hooked up and in business. You will need other bits and pieces (some or all which you might already have), and it’s important to highlight it right at the beginning. In the next section, we will cover the kit you actually need to get started.

If you have yet to order a Pi (or are waiting for it to turn up in the mail), Figure 1-2 shows one sitting next to a blank DVD.

9781484211632_Fig01-02.jpg

Figure 1-2. A Raspberry Pi next to a blank DVD

Even though the size of the Pi is well known and it comes in such a small box, it isn’t until you actually hold it in your hands that you realize how small it truly is! After “aw-ing” to ourselves (and anyone else who sadly for them happened to be within earshot), we figured it was time to get the show on the road.

And that’s where things came to a somewhat abrupt halt. We had the Pi, but it had only just dawned on us that we didn’t have the faintest idea what we actually needed to make it go. Even though we’re not exactly new to all this, we had let ourselves get caught up in the moment and for whatever reason hadn’t considered that the Pi would need anything special (or at least something that your average geeky type person wouldn’t have hanging around the house).

If you’re not equipped with a cupboard of odds and ends straight out of Dexter’s lab, you might need to pick up a few things. Fortunately, they are all easy to find, and you should be able to pick up everything you need at your local computer shop. If you don’t fancy going on a treasure hunt, many companies are offering starter kits that come with everything you need. Because these kits are rapidly changing, the best way to find what’s available is to go online and search for “raspberry pi starter kit”.

List of Ingredients

To bake your Pi to perfection, you’re going to need the following ingredients:

  • Raspberry Pi
  • Micro USB lead (for power)
  • USB power adapter (also for power)
  • HDMI lead: Type A to Type A (to connect to your monitor or TV)
  • HDMI display
  • Micro SD card: 8 GB to 64 GB (for storage – Class 10 required for Windows IoT)
  • Micro SD card reader
  • USB keyboard and mouse

Micro USB lead

If you happen to have an Android phone or a Kindle sitting about, chances are good that you’ve got a lead that you can reuse to power the Pi. This lead isn’t actually used for transferring data, and although you can draw power from a USB port (you can plug it into your main PC or laptop), you can’t use the USB connection for anything else. The different types of USB connectors are hard to describe if you haven’t already seen one. Take a look at Figure 1-3 for some examples.

Image Warning  Although you could run an original Pi from a USB port with a bit of luck, the Raspberry Pi 2 draws nearly four times the power of the original and as non-negotiated USB only provides a tiny amount of current, you cannot run your new Pi from a USB port. Instead you’ll need a chunky power supply such as those used to charge tablets. Be warned that even if they claim to provide enough power, they might not play nice with your Pi. If your Pi crashes, has trouble connecting to the network or generally has odd behaviour, check your power supply first.

9781484211632_Fig01-03.jpg

Figure 1-3. Different types of USB connectors

The connector you’re interested in is the first one on the left, known as a micro USB. Be careful because on quick inspection, a micro USB plug can easily be mistaken for a mini USB plug (second on the left). The last thing you want to do is make a special trip to the store and then come back only to find out that you picked up the wrong one!

USB Power Adapter

As mentioned above, a normal USB port can power a Model A Pi (the one without built-in Ethernet), but for a modern Pi, you’re going to need something with a lot more bite.

Fortunately, the sheer number of devices that have adopted USB as a means of charging means that you can get mains adapters really cheaply and easily. As far as which adapter to get, that really comes down to personal choice. However, as the Model B requires 800 ma without anything else plugged into it and you always want to have a bit of room for expansion, you probably should aim to get an adapter that can provide at least 1000 ma (or 1 amp) and preferably 2000ma (2 amp). From our highly scientific tests (wandering around numerous shops and squinting at packaging labels), it seems that 1000 ma is actually the most common rating. We did come across some rated at 500 ma and although that’s enough for most USB devices, it isn’t enough for your needs.

HDMI Lead

Over the past few years, HDMI has become the de facto standard in connecting a myriad of devices to both monitors and TVs. This is really handy because it means that if a device supports HDMI, it can be easily connected to any display that supports it. This might not sound all that impressive, but it wasn’t too long ago that TVs and monitors were very separate things and usually there was no direct way to connect, say, a computer to a TV or a VCR to a monitor (although interestingly if you go back 20 years, all home computers connected directly to the TV (for example, the Commodore 64 or Spectrum)). Of course, you could get special hardware, and some higher-end devices did offer a range of different connectors, but as a rule, the two worlds didn’t really mix.

Fortunately, the Pi uses HDMI, so we can ignore the irritations of the past. To connect your Pi to a display, you will need a "Type A to Type A" lead. Type A is the size you will find in the back of your TV or monitor; all you have to do is find a lead for connecting some device via HDMI to a TV and where both ends are the same size. Most consumer electronics use Type A, so if you have an Xbox 360 or your laptop has HDMI, chances are you already have a lead of the correct type.

HDMI Capable Display

You probably saw this one coming, but you’re going to need some sort of display that supports HDMI. As it has been widely adopted over recent years, practically every new TV comes with one or more HDMI ports and most new monitors do as well. These days, it’s fairly common to see three or four ports on a TV because you’ll need that many to hook up all your new digital devices.

It’s pretty easy to determine whether your TV or monitor supports HDMI. All you have to do is look for a physical HDMI port. You are much more likely to find it on your TV rather than your monitor, but many of even the more basic monitors these days seem to support it.

In our case, it turned out that our aging monitor didn’t support HDMI, although the TV in the living room did. Of course, it being the main TV meant that people wanted to watch TV on it and admittedly we were not looking forward to sitting cross-legged on the floor in front of a big TV, trying to convince a Pi to boot. In the end, we decided to get a new monitor that supported it. Although we could have bought a DVI converter, we decided we couldn’t pass up on the opportunity to get a new shiny toy.

If you can’t reuse your TV or computer monitor, you should be able to get your hands on a basic TV or monitor that supports HDMI quite easily.

Micro SD Card

Most computers use a hard drive of some sort as their primary form of storage. Even laptop-sized disks are larger than the Pi, and although the newer solid state disk (SSD) models draw very little in the way of power, they would certainly drastically increase the amount of power your Pi would need. Fortunately, we have an alternative. Rather than using something heavy duty like a hard disk, we can instead borrow technology that cameras have been using for many years: flash memory. Although the cards can’t match a hard disk for space or for performance, they are exceptionally good for power usage and despite being smaller than their erstwhile cousins; 64 GB (the maximum for your Pi) is still a reasonably impressive amount and probably more than you will need for your Pi.

Micro SD cards are standardized so there isn’t too much more to say about them. You do want to get a high-performance card if you can (often referred to as Class 10) but they ultimately all do the same job. That said, we have heard of some micro SD cards that haven’t worked with the Pi, but if you stick to a well-known brand you get a class 10 card, you should be fine. Linux is pretty tolerant on the performance of the card, but it seems that Windows 10 IoT is very picky. We could only get it to work on Class 10 SD, and this seems supported by Microsoft’s latest documentation. If you want to try out Windows, you will definitely need a Class 10 SD card.

As there are lots of different types of memory cards floating about these days, Figure 1-4 shows what an micro SD card actually looks like.

9781484211632_Fig01-04.jpg

Figure 1-4. SD card with micro SD and adapter

The card on the far left is your typical SD card; on the far right is a micro SD card. They have become pretty popular for use in smartphones (particularly Android-based phones), and because most phones come with small cards (in terms of storage space), it’s not unusual to either buy a larger card or have one thrown in as part of your phone package. If you happen to have one of these floating about, you can use it with your Pi.

Micro SD Card Reader

Now that you have your micro SD card, you need some way to actually use it. The Pi has you covered and has a micro SD card slot built right in. However it doesn’t actually have any other storage on the device, so it’s effectively a blank slate until you insert an SD card with something useful (like Linux) installed on it. The thing is, to put Linux on the card, you need a device that’s already up and running that can also read and write to the card. This is a classic Catch-22 situation. Even if you could borrow someone else’s card with Linux already installed, you couldn’t simply swap out the cards because as soon as you do that, you won’t have Linux anymore!

Again, thanks to the proliferation of digital cameras, many computers come with card readers built in. Many (often dubbed as media PCs) come with a whole range of slots for various different card types. So chances are you already have a way to read the card. If you don’t have a reader already, you can pick up any cheap multicard reader from your local computer store. They’re generally inexpensive and will support lots of different types of cards. Just make sure that it has a micro SD card slot (often hidden on a different side for some reason) before you hand over your hard-earned cash! For reference, the adapter we are using looks like the one in Figure 1-5.

9781484211632_Fig01-05.jpg

Figure 1-5. Multicard reader (micro SD reader is on the left edge near the bottom)

USB Keyboard and Mouse

Last but not least is the good old keyboard and mouse. Advanced as the Pi is, it doesn’t yet have telepathy so you’re going to need some way to control it. This is common sense, but with modern computers often coming with a wireless keyboard and mouse and a fair few of those using Bluetooth with no USB adapter (even some with an adapter have been known to cause problems), you might find that your current keyboard and mouse just won’t work with your new toy (no Bluetooth on the Pi, I’m afraid). There’s really no need to go into any detail here as any standard keyboard and mouse will do, and this is mostly a reminder to check what you actually have before you go out to buy your Pi-making ingredients to avoid untold frustration when you get home and find you’re completely stuck.

Whew, We’re Done!

Finally we have everything we need! Hooking all this stuff up to your Pi is very easy, especially as each item has a unique shape so it will fit into only one slot (see Figure 1-6 for the finished Pi).

9781484211632_Fig01-06.jpg

Figure 1-6. A fully loaded Pi

If you put everything together, plug in the power, and turn on your TV you should see… a completely black screen.

Don’t Panic!

When your PC or laptop boots, there is a piece of software called the BIOS that kicks everything off for you. It tests the memory, sets up a basic display, and allows all your devices to initialize. On some machines (notably those from Apple) the machine will have an EFI instead of a BIOS. For all intents and purposes (at least from our point of view), they’re basically equivalent. Regardless of the technology used, it is this system that finally hands control over to your bootloader, the piece of software responsible for starting your operating system.BIOSs are by nature very noisy, and if you get something wrong it will either bleep a lot (with some magic number code that you can only find in the BIOS manual that you threw in the bin 3 years ago) or display some helpful yet cryptic message on the screen. In short, it may not do what you want, but at least you know that your computer is still alive. Although it has a little red LED "on light", the Pi won’t do a thing unless it has a bootable operating system on its SD card. If you were expecting some sort of splash screen or other sign of life (hands up; we know we were), you’re out of luck (and probably thinking you have a dead Pi).

Now that you know what you need to restore the Pi to life (a bootable operating system) it’s time to move on to Phase 2 of our master plan and get us some Linux!

Linux

As this is a book for beginners, we’re going to take the time to talk a little about Linux, where it came from, what’s special about it and some of the little gotchas that trip people up from time to time. If you already know this stuff (or simply don’t care), feel free to skip to the next section “Downloading NOOBS.” For those who want a quick refresher, just keep on reading.

What Is Linux?

Ah, this simple question opens a big can of worms that many people go out of their way to avoid. The reason is that in technical terms, Linux means one thing but in general speech, it tends to mean something else. When talking about operating systems in general, we see Microsoft Windows and Apple OSX to be discrete, whole things. If you say “I run Windows,” everyone knows what you’re talking about. With Linux, it’s a bit different.

Linux is just an operating system kernel, which means that it handles all the low-level bits and pieces such as handling device drivers, and providing easy access to networks and hard disks. What actually makes Linux usable is all the software that is wrapped around it. Not much trouble there, but it starts to get complicated when you realize that people have differing opinions about what software should be wrapped around it. There are no simple or minor opinions when it comes to computing!

As this software is open source, and anyone can put it together in pretty much any way they like, people have been able to build their own Linux distributions. This is an operating system with Linux at its core, but with the surrounding ecosystem set up to match the goals of the people who built it. For example, Red Hat Enterprise Linux (RHEL) is built to be robust, supportable, and stable over long periods of time. Fedora, on the other hand, is released every 6 months or so and has the latest and greatest of everything in each build. Gentoo requires that you build your software from source (so it can be completely optimized for your machine), and Debian goes to great lengths to remain stable and secure at the cost of introducing new features.

OPEN SOURCE

In the olden days, when computers cost millions of dollars, it was the machine itself that sold, not the applications that ran on it. It was common practice for a company to write software for you, in order to get you to buy their machine. It wasn’t until computers became commodity items that suddenly the value was in the software, and companies moved to start protecting the software they’d written. One way to do this is to provide the software ready to use without the source code (which is effectively the blueprint on how to make the software). This meant that you couldn’t change the software or make improvements to suit your changing needs.

Many people believe that software should always come with the source code so that people can make changes. Open source revolves around the idea of people being able to freely exchange, modify, and improve software collectively. This can only be done when the source code is provided freely and permission is given (through an open source license) to make those changes.

Entire books can and have been written on this topic, but you can find a presentation on this topic that Peter gave at his university a few years ago: http://www.youtube.com/watch?v=c-1LQIGh6cI

So which one is best? Well, that depends on your needs! There’s no perfect distribution; just the best fit for a particular job. For the Pi, the official and supported platform is Raspbian, which is based on the Debian distribution. Because it is supported and because it’s the easiest to use (and quite likely the fastest to get updated and fixed when things go wrong), we’re going to stick to using Raspbian in this book. If you do fancy something a little different, Brendan Horan’s book (also from Apress), Practical Raspberry Pi will show you in great depth how to install Fedora and (if you’re feeling particularly brave) how to make a custom build of Gentoo!

When the Linux kernel first debuted in the early 1990s, no one really appreciated the huge impact it would have on the world of computing. Open-source software had already been around for a long time before this, and countless tools for the UNIX platform had already been released (such as the awesome GCC compiler). However, they were just tools and software packages. They still needed a proprietary operating system to run (the only kind available at the time). To be fully compatible with the open-source ethos, what was needed was an open-source kernel to power these systems and this is what Linux delivered. While many will talk about how this brought freedom and hope to the world of computing, we will save you from that particular lecture (although admittedly there is quite a bit of truth to it) and simply say that it was the Linux kernel that really brought open source to the eyes of the general public.

Now that the world has Linux, what exactly can we do with it? Almost anything we like—such as installing it for free on our Pi.

Introducing NOOBS

At this point in the first edition of the book, we were off to download a Raspbian image file. Back then all of the different Pi distributions were distributed as image files. All you had to do was download the image of interest and write it out to your SD card.

Well, it’s not just the Pi’s hardware that has improved over the last couple of years. Today you can download a Pi installer that is even easier to set up and provides a whole list of operating systems to choose from (although we will still be using Raspian, check out the “Why Raspbian” sidebar).

NOOBS was developed as an easy way for Pi users to be able to pick an operating system and install it with the least amount of hassle and headache. For seasoned users, writing out an SD card wasn’t much hassle, but it is a pretty alien thing to do for most users. It also meant understanding how imaging works and the difference between copying a file and writing it out as an image.

With NOOBS this is a thing of the past. First, instead of downloading an image file, you download a zip file, something almost everyone is familiar with these days. You then extract the contents of that zip file directly onto an SD card. And, well, that’s it, you’re done! Simply pop out the SD card, boot your Pi and you’re off.

So how does this work? Well, on your average PC, you need to have things set up just so, so that the BIOS can find the operating system and boot it. The Pi is different in that it doesn’t come with firmware in the traditional sense and instead loads everything from the SD card. This makes it a bit slower to start up, but makes it very easy for the Pi foundation to update things that otherwise would need special tools to update. So instead, the Pi looks for a specific file on the SD card and simply executes that. In the case of NOOBS, you’re running an installer, and from there, you can pick which operating systems you’d like to install – all through a nice graphical interface!

The two NOOBS

There are two versions of NOOBS that you can download. The first is the full installer, simply called NOOBS and the second is NOOBS lite. The only material difference between them is that NOOBS comes with Raspbian and NOOBS lite doesn’t come with anything. Remember, NOOBS is an installer not an operating system itself and so it needs to have a means of retrieving whichever operating system you’re interested in. In all cases, if you don’t want Raspbian, NOOBS will go online and download the release from the Internet. If you do want Raspbian (and honestly, you probably do) then you might as well get the full version of NOOBS. If on the other hand you’re only interested in the other operating systems, there is absolutely no benefit in downloading the full version and you should instead stick to NOOBS lite.

Downloading NOOBS

Whatever version of NOOBS takes your fancy, you can get it by going to the Raspberry Pi download site shown in Figure 1-7.

https://www.raspberrypi.org/downloads/

9781484211632_Fig01-07.jpg

Figure 1-7. Pick your NOOBS

As we mentioned previously, there are two versions available for download. If you’re following along with this book, then we highly suggest you choose the full version of NOOBS as you’re going to want to install Raspbian. You could admittedly still do this with NOOBS lite, but if you want to install a number of Pi’s for example you’d have to effectively download Raspbian each time you do the install.

WHY RASPBIAN?

As you can see from the download page, there are numerous distributions to choose from, and especially if you’ve used Linux elsewhere you might be tempted to pick something other than Raspbian. However, before you download that exotic distribution, you should know that the majority of people using a Pi run Raspbian—and as such most of the support, blog posts, and tutorials (not to mention this book) are all based on it. This means if you pick something else, you might find it much harder to get help if something doesn’t go quite according to plan.

The other more subtle issue is that the Raspberry Pi is an ARM-based device. It doesn’t quite work the same way as your PC does. For example, the Pi doesn’t have a PCI bus, so any tools that expect there to be one (and there are more than a few) just won’t work. There are also quite a few gotchas for these other distributions, and they might not be as well maintained as Raspbian. In short, you will be taking on much more work if you don’t pick Raspbian to start out.

Getting NOOBS onto Your SD Card

“Getting Raspbian onto your SD card isn’t as easy as simply copying across the file.” – That’s how we started off this section in the first edition. Today however, it is exactly as easy as copying across the files to an SD card. First though we need to make sure your SD card is ready for use. For this example we’re going to use Windows as that’s what most people will be using. However if you’re using a Mac, the process is basically the same and you’ll probably have no trouble following along.

First let’s insert the SD card. Under “This PC” we can see the card has been detected (Figure 1-8):

9781484211632_Fig01-08.jpg

Figure 1-8. Freshly inserted SD card

Now this is a card that was literally taken straight from its packaging (seriously, I’m still oozing blood from trying to rip it out of its “easy open” packaging). As you can see it has no files on it, an important perquisite for installing with NOOBS (Figure 1-9):

9781484211632_Fig01-09.jpg

Figure 1-9. The card is empty

So far so good, now all we need to do is open the NOOBS zip file and extract the content directly into this disk. If you haven’t done anything special, your browser will download NOOBS into your “Downloads” folder. You’re looking for an icon that looks like this (Figure 1-10):

9781484211632_Fig01-10.jpg

Figure 1-10. What you’ll see in Explorer

When you double click to open it, (assuming you haven’t installed a different application to handle zip files such as WinZip) you’ll see what looks like a normal folder with files in it (Figure 1-11):

9781484211632_Fig01-11.jpg

Figure 1-11. The contents of the NOOBS zip file

Now we just need to extract it. If you click on “Extract” you will get a pop up menu. You can ignore the stuff on the left, you want the “Extract All” icon that’s on the right Figure 1-12):

9781484211632_Fig01-12.jpg

Figure 1-12. Extract all

If you’ve followed the steps so far, you’ll be ahead of the game at this stage because you’ll have a nice clean SD card plugged into your computer already. In the earlier example, we showed you that our SD card had been picked up as “E:”. We hit browse and selected our SD card and you should do the same. When it goes back to the main screen it will only show the device name, which in our case is of course “E:” (Figure 1-13):

9781484211632_Fig01-13.jpg

Figure 1-13. Extract everything to the SD card

Once you’ve chosen your SD card you can press the Extract button. Windows will give you a nice pretty progress bar. If your computer is anything like ours, this will take a bit of time so now might be a good time to get and grab that coffee. In total it took about five minutes for Windows to extract all the files to the SD card. We are using a class 10 card for this, so if you’re using a slightly older card (say a class 4) then you might find that it will take quite a bit longer (Figure 1-14):

9781484211632_Fig01-14.jpg

Figure 1-14. This can take a while to copy, but at least it’s pretty!

When finished it will open your SD card and show you the files. All being well it should be exactly the same as what we saw in the zip file earlier. If you see something similar to the following screen grab then you’re in business. All that’s left now is to actually try and boot your Pi with it (Figure 1-15):

9781484211632_Fig01-15.jpg

Figure 1-15. What your SD card should look like after you’re done

Okay, so that was a little bit tedious, but trust us, this is a lot easier than the old approach that we had to use. So without further ado, let’s see if we can book up your Pi (Figure 1-13)!

First Boot

Finally it’s time too boot up your Pi! Armed with our freshly imaged SD card, we can finally get started. Plug in your keyboard, mouse, and monitor, and slot your SD card into your Pi. All you have to do now is attach the power lead and you’re good to go! All being well, you should initially see a screen like Figure 1-16.

9781484211632_Fig01-16.jpg

Figure 1-16. The Pi’s first boot—it lives! If you can see something similar, congratulations, your Pi is up and running! You can skip to the next section. If not, there are a few common things that might have gone wrong

The first thing to check is whether your Pi has a nice red glowing power LED. Now we know this sounds obvious, and we know that it’s probably the first thing you checked, but not checking it is also the most common mistake to make. If your desk looks anything like ours, you will have a fair collection of cables draped about. It’s not too much of a stretch to see how you might have plugged in the wrong cable or that the cable you’re using isn’t actually plugged in to a live power source (some laptops, for example, turn off USB power when they go to sleep). Either way, this is what you should check first because if you did make a mistake, only you will know about it. This is much better than having an extended discussion on the forums trying to get help only to then realize that whoops! you forgot to plug it in.

The second thing to check is whether you have selected the right input on your TV or monitor. Most TVs have multiple inputs these days, and monitors often as not don’t default to HDMI (ours doesn’t), even if that is the only input signal they are receiving. Obviously, we can’t tell you exactly how to fix or check this one as it all depends on the equipment you’re using. However, it should be fairly easy to flick through the different inputs to see whether or not your Pi turns up. In one interesting case, even though on the TV the port clearly said HDMI2, the Pi was actually visible on HDMI3. We have no idea why, but had we thought to flick through the inputs before fiddling with the Pi, we could have saved ourselves a fair bit of grief.

The third thing to check is that the SD card is fully inserted into its slot. The Pi will quite literally do nothing unless it can find the card and boot from it, so if all you’re getting is a black screen, this could well be the reason. If you are sure the card is inserted properly, but you’re still not having any luck, it might be that something went wrong when you copied the files to the card. In that case, flip back to the last section and have another go at it. If you still aren’t getting anywhere and you’ve checked that everything is all plugged in nicely, you have the right input on your monitor, and you have a happily glowing power LED, then it’s probably something more onerous. Unfortunately, without being there with you to look at your poorly Pi, we can’t really give any more specific advice. Fortunately, you’re not alone; there are lots of people on the Raspberry Pi discussion forums who are ready to help out. To visit the forum, go to www.raspberrypi.org and click the Forum link (just below and to the left of the Raspberry Pi logo). This will get you to the main forum page; the particular board you’re looking for is Basic Usage and Setup under Using the Raspberry Pi.

Installing Raspbian with NOOBS

After a short time, you should see NOOBS start up and start initializing itself (Figure 1-17):

9781484211632_Fig01-17.jpg

Figure 1-17. NOOBS setting itself up

You can see in this screenshot that NOOBS already knows about Raspbian and the icon on the right (an SD card) tells you that the operating system is already on the card and ready to be used. Now in theory what should happen next is that you should see a screen that looks like this (Figure 1-18):

9781484211632_Fig01-18.jpg

Figure 1-18. NOOBBS detected lots more operating systems to install

NOOBS has gone online and found a number of alternative operating systems that you can install. Rather than an SD card icon, these have an Ethernet connector, showing that they are available “on the network” – in other words you need to download them. Now the reason we said “in theory” is because we couldn’t get this to work out of the box for us. In fact we had to fiddle around with IP addresses and all sorts in order to get the installer to actually detect the online operating systems. In fact what we got was this (Figure 1-19):

9781484211632_Fig01-19.jpg

Figure 1-19. NOOBS network init failed

Fortunately we’re using the full version of NOOBS so it really doesn’t matter that we can’t get online to download the rest of the operating systems. We expect this is a problem either with our Pi or our set up, and it’s probably something you’re not going to see yourself. That said we wanted to mention it in case it did crop up and reassure you that you can still get Raspbian installed even with this problem.

Okay, let’s actually start the installation process! All you have to do is tick the box to the left of Rasbian and press the “Install” button (Figure 1-20):

9781484211632_Fig01-20.jpg

Figure 1-20. Time to install Raspbian

You’ll get a final warning that this is going to erase the SD card, but that’s something of a moot point because you had to erase the card to get NOOBS on there in the first place. Still it’s always a good idea to double check, even though you’re totally sure everything will be fine (Figure 1-21):

9781484211632_Fig01-21.jpg

Figure 1-21. Last chance to back out

Once you’ve clicked on Yes, NOOBS will start installing Raspbian and all you have to do is wait. You’ll be treated to some useful information screens (which we won’t reproduce here for obvious reasons) and again, it might be time to top up that coffee mug as copying large amounts of data to and from the same SD card is a slow process, class 10 SD card or not (Figure 1-22).

9781484211632_Fig01-22.jpg

Figure 1-22. Raspbian is installing

And finally, everything is installed (Figure 1-23):

9781484211632_Fig01-23.jpg

Figure 1-23. Finally everything is installed

Now it’s time to reboot your Pi. This time when it restarts, NOOBS will be gone and it will be replaced with Raspbian. It’s taken a fair bit of time to reach this stage, but it’s worth it we promise!

When it starts up (for real this time) you should see something like this (Figure 1-24):

9781484211632_Fig01-24.jpg

Figure 1-24. Finally Raspbian is booting!

Configuring Your Pi

After the torrent of incomprehensible text (though we’re sure it means something to someone) you should end up at the configuration shown in Figure 1-25. This is where we’ll configure your Pi for general use so that next time you turn it on, you will be greeted with a nice desktop rather than some chunky text.

We are only going to cover the basic configuration options here (and you can always go back and change them once you’ve got your Pi up and running) as we want to get you in front of a working computer as soon as possible.

9781484211632_Fig01-25.jpg

Figure 1-25. First boot: time to configure your Pi!

Expanding the Filesystem

The first option of interest is “Expand Filesystem”. When you install Raspbian directly from a disk image, it only takes up a small amount of space. The developers don’t know how big your SD card is, and no one wants to download a 16GB or larger image just so they can take full advantage of the space on their card. To deal with this, Raspbian supports expanding the disk once it has been installed, allowing the full amount of space to be used. However, this is something NOOBS already takes care of for you, so if you do try this option you’re likely to see this message (Figure 1-26):

9781484211632_Fig01-26.jpg

Figure 1-26. The filesystem is already expanded if you used NOOBS

The reason we’re mentioning it here is that at some point you might decide to install directly from an image, and if you do, you definitely want to use this option!

Booting to Desktop

The next option allows us to configure what mode the Pi will boot in. In the next chapter we’ll be taking you on a brief tour of the desktop and for most of the topics in the book we make the assumption that you’re actually sat in front of the Pi. With that in mind we want to boot to the desktop. So, select this option and then from the list on the next page select “Desktop Log in as the user ‘pi’” (Figure 1-27):

9781484211632_Fig01-27.jpg

Figure 1-27. Boot to the desktop

Changing User Password

Next we’re going to change the password for the pi user account. This is the account you’ll be using throughout the book, and for most people this will be the only account you’ll ever need on your Pi. At the moment though the password is set to raspberry and as it is the default, it means that anyone can log in to your Pi. While securing your Pi against unauthorized intruders is probably not top of your list of priorities, it is still good practice to change this just in case. Later on, you might make your Pi available via the Internet and in your excitement you might forget that you didn’t actually get around to changing the password. Bad things will happen. So let’s take the opportunity to make the switch now. Highlight “Change User Password” and press Enter, and you’ll see something like Figure 1-28.

9781484211632_Fig01-28.jpg

Figure 1-28. Changing your password

The configuration tool will execute the standard passwd command when you press enter, which is why you’re looking at a text prompt rather than a prettier menu. Just enter your new password (remember that it is case-sensitive: HeLLo is not the same as hello or Hello) and press Enter. For security reasons, the password won’t be shown on the display and it won’t show any stars to let you know you’ve actually typed something. You will then get prompted to enter your password again (Figure 1-29); after you press Enter, and you will get the acknowledgement shown in Figure 1-30. Press Enter again and you’ll be back at the main menu.

9781484211632_Fig01-29.jpg

Figure 1-29. Enter your password

9781484211632_Fig01-30.jpg

Figure 1-30. Password changed successfully

Setting some International Options

One of the nice things about Linux is that it has really good support for internationalization and makes it (relatively) easy to customize your install to match your requirements. There are a number of items that we can configure as you can see in Figure 1-31. As you set each option, you will be taken back to the main menu, so to change the next setting, just select the internationalization menu again:

9781484211632_Fig01-31.jpg

Figure 1-31. International Settings menu

First up is configuring your locale. By telling Linux where you are in the world, it can determine useful things such as the separator between numbers and which currency symbol to use. For example, in the United States we might write 1,000.00, but in many places in Europe it would be written as 1.000,00. Either way for maximum comfort and to ensure that everything just looks right, we need to set the locale. Highlight the “Change Locale” option and press Enter.

You’ll now be presented with an extensive list of different locales to choose from (see Figure 1-32). The first two letters in the name specify the language while the second pair of letters specifies a regional difference. For example, en_US would be English customized for US users but en_GB would have settings specific to English speakers in the UK. You should select the language and country pairs that most closely match your needs and choose them by pressing the spacebar. You probably want both the ISO-8859 and the UTF-8 versions. If you decide to hedge your bets and select all locales, be warned that you will be in for quite a wait as the Pi generates all the locale settings for you. In fact, we tried this option and after waiting ages for just two locales to be generated, we got fed up and pulled the plug. After you select the locales you want, press the Tab key once to highlight the OK button and then press Enter to move to the next screen (after the locales have been generated see Figure 1-33). Here you’ll need to pick the locale you want to use by default (see Figure 1-30). Once you have made your choice, highlight it and press Enter. You’ll then see the locale generation process (see Figure 1-34) and after that has completed (it really can take a while) we’re once again back at the main configuration page.

9781484211632_Fig01-32.jpg

Figure 1-32. Picking your locale

9781484211632_Fig01-33.jpg

Figure 1-33. Select the default language

9781484211632_Fig01-34.jpg

Figure 1-34. Generating locales

Changing the Time Zone

The “Change Timezone” option does pretty much what it says. After selecting this option, you’ll be shown a list of regions (shown in Figure 1-35). In this case, we were configuring Pete’s Pi, so we selected Asia. The next screen will give you a chance to fine-tune your selection and pick your country or city (see Figure 1-36). Once you’ve found the closest match to you, select the option and press Enter.

9781484211632_Fig01-35.jpg

Figure 1-35. Pick your region

9781484211632_Fig01-36.jpg

Figure 1-36. Pick your closest city

Configuring the Keyboard

The next option of interest is “Configure Keyboard”. By default, Raspbian assumes a UK keymap, but chances are you will want something else. Be warned, though, that Raspbian knows a huge number of keyboards, and the sheer quantity can be confusing. For instance, do you know if you have a generic 104 key keyboard or is it actually a 105 key version? We weren’t sure either, so we stuck with the default: the Generic 104 key PC shown in Figure 1-37.

9781484211632_Fig01-37.jpg

Figure 1-37. Choosing your keyboard type

If you can find your exact model, by all means feel free to select it. If you aren’t sure, you’re probably best off following our lead and sticking to the default. Once you have settled on your keyboard of choice, press Enter to move through to the next screen.Now we get to choose which keymap we want to use. By default, it lists various UK keymaps (as shown in Figure 1-38), but if you aren’t lucky enough to own a British keyboard, move the bar down to Other, press Enter, and then scroll through the list to find something more suitable for your needs. Once you’ve found the right keyboard, again just press Enter to move on to the next screen.

9781484211632_Fig01-38.jpg

Figure 1-38. Choose your layoutIf you’re not sure what to select from the menu (shown in Figure 1-39), you’re not alone

For most people, the keyboard defaults will be fine because they will include any special key combinations that your particular keymap already offers. This is one of those times when if you need to make a change, you probably already know why and what to choose. If you are in any doubt, just leave the default selected and press Enter. Now you will see another menu that looks suspiciously like its predecessor (shown in Figure 1-40), at least in terms of knowing what to pick. Again you probably already know if you need to change anything here; if you’re not sure, you should just select the default by pressing Enter.

9781484211632_Fig01-39.jpg

Figure 1-39. Customize your keyboard configuration

9781484211632_Fig01-40.jpg

Figure 1-40. Customize your keyboard some more

The next menu (shown in Figure 1-41) only really means anything to old-school Linux users. Back in the day, if your GUI decided to crap out on you, you could effectively “reboot” the session by holding down Ctrl + Alt + backspace. As the GUI has become more stable, and Linux has become more mainstream, this feature is more often than not disabled. We haven’t had to make use of it for years, although we do happen to think it is quite useful. The default is No, and this is probably what you want. You can always go back and change this later if you find yourself craving this particular feature. To pick the default (and finally return to the main menu), just press Enter.

9781484211632_Fig01-41.jpg

Figure 1-41. Do you want to enable the X server kill switch?

Enable Camera

This menu lets you enable the camera. This specifically refers to the camera provided by the Pi Foundation and doesn’t affect other cameras such as USB webcams. This is set to Disable by default but you can Enable it here if you happen to have one. We haven’t included a screenshot here as there really isn’t anything to see.

Add to Rastrack

Rastrack is an unofficial project that asks for voluntary registrations to help see where the Pi’s are being used around the world. As the blurb says in Figure 1-42, this is just for a bit of fun, but many people don’t particularly want their Pi to be tracked. Fortunately Rastrack is opt-in so you can completely ignore it unless you want to take part.

If you do want to take part, simply follow the simple screens that ask for some details. Once you’ve entered everything, they will be submitted to Rastrack and you’ll be returned to the main menu.

9781484211632_Fig01-42.jpg

Figure 1-42. Register on Rastrack

Overclock

Enthusiasts have long enjoyed overclocking their CPUs, that is, making them run faster and hotter than they were designed for. The Pi supports this too and many people consider it perfectly safe. However we recommend against it as if the Pi isn’t fast enough for what you need out of the box, then you probably shouldn’t be using a Pi to do whatever it is that you’re doing.

If on the other hand you really really want to make your Pi go faster, you can select one of the speeds from this menu (Figure 1-43):

9781484211632_Fig01-43.jpg

Figure 1-43. How fast would you like to go?

Advanced features

We’re not going to go through each of these menu items and for many if not most people, the majority of these items will never be used. The only one of interest to us is the memory split. For reference here’s what the menu looks like (Figure 1-44):

9781484211632_Fig01-44.jpg

Figure 1-44. Advanced options

Allocating Memory

The “Memory Split” option needs a bit of explanation. Your Pi has two main processors: the CPU (or central processing unit) and the GPU (or graphics processing unit). The CPU is responsible for the general running of your machine, and the GPU is responsible for handling the display and provides features such as 2D and 3D acceleration as well as hardware support for decoding high-quality video streams. A GPU is dedicated to handling graphics (for the most part) and cannot perform the role of a CPU. However, it does mean that if the CPU can offload all the complex graphics work to the GPU, the CPU doesn’t have to be quite so powerful. By having both, the Pi keeps the costs and power requirements nice and low but without sacrificing much in the way of performance.

So far so good; but what does that have to do with splitting memory? The Pi 2 comes with 1GB of RAM in total and it needs to supply both the CPU and GPU. As the GPU is effectively an independent unit, it needs its own allocation of memory. Rather than having dedicated memory for both, it is possible to split the 1GB between the two processors. By default, the Pi allocates only a small amount for the GPU. This is ideal if you want to use the Pi as a server or you never plan to attach a display to your Pi. If you’re not using graphics, allocating additional memory to the GPU is somewhat pointless.

On the other hand, if you plan to use your Pi as a mini desktop computer or to display high-quality movies, you’re going to want as much memory allocated to the GPU as you can get away with (which in the case of the Pi 2 means allocating 256MB for the GPU). It would be difficult to anticipate how everyone will want to use their Pi, and apart from adding more memory to the Pi itself (and raising the cost) there is no easy solution. Fortunately, we have the ability to choose how we want to allocate the memory ourselves.

For general usage and “getting started”—type tasks, we recommend you allocate 64MB to the GPU. To set this up, select the memory_split option from the menu, press Enter, and you’ll have something similar to Figure 1-45. Type in the memory split that you want and then press Tab to highlight the OK button and then press Enter.

9781484211632_Fig01-45.jpg

Figure 1-45. Choose your memory split

At Last! It’s Configured!

Wow, we finally made it to the end! After all that effort, you can now reboot the Pi and (finally) start using it! Press the Tab key twice to highlight the Finish button and press Enter. Your Pi should shut down and then reboot. After all that effort (and a bit more waiting while the Pi boots up), you should finally be at a pretty graphical display that should look something like Figure 1-46.

9781484211632_Fig01-46.jpg

Figure 1-46. At long last, we have a desktop!Congratulations!

You now have a fully functional Raspberry Pi! If you don’t end up with a pretty desktop, you might need to tweak your configuration a little. At the login prompt, you can log in with the username pi and the password you set during the install. If you then run the following you will be able to change the settings (“Boot behaviour” is the option you want to change):

$ sudo raspi-config

You can also try starting the graphical interface manually with this:

$ startx

Summary

This chapter has taken you from getting your hands on your Pi all the way through getting it up and running. We deliberately took it slow and covered all the basics as it’s always the so-called simple things that trip people up (us included!). We looked at what comes in the box (and more importantly what doesn’t) and provided a shopping list of all the things you’ll need to bake your Pi.

We then touched briefly on Linux—what makes a distribution and why we decided to stick with Raspbian for this book. We then covered how to download NOOBS and get it on your SD card.

Armed with a fully loaded card, we fired up the Pi and walked through the initial setup and configuration process that ultimately ended with us looking at the very pretty Raspberry Pi logo in the middle of an equally impressive desktop.

In the next chapter, we’ll start to explore your new desktop. We give you a quick tour of what comes with Raspbian out of the box, and we finish up by showing you how you can tweak and customize it to suit your needs.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.195.101