Book Image

Raspberry Pi Sensors

By : Rushi Gajjar
Book Image

Raspberry Pi Sensors

By: Rushi Gajjar

Overview of this book

Table of Contents (16 chapters)
Raspberry Pi Sensors
Credits
About the Author
Acknowledgements
About the Reviewers
www.PacktPub.com
Preface
Index

Setting up for the first time


Following your recent purchase of the RasPi, you now have to make it ready to work for you. In this section, we are going to install an operating system on which our RasPi will run. The most popular, stable, and widely used operating system for RasPi is the Wheezy-Raspbian.

The Raspbian runs on an open platform, Debian Linux. Why are we going to use Raspbian instead of directly using Linux and other flavors of Linux? Simply because Raspbian has all device drivers written for the RasPi. In brief, the device driver is a program that gives the details of the hardware to the running operating system and supports the user interface to take/give commands from/to the hardware. As our RasPi has different hardware than a personal computer or general-purpose computer, the modified operating system is needed to completely use all resources on the hardware. It is best for those who want to follow the default standards.

You can download the Wheezy-Raspbian install file (known as an image file) from the Raspberry Pi foundation's website at http://downloads.raspberrypi.org/raspbian_latest. If you want to install the GUI-free flavor of Linux (Direct CLI), you can try Arch Linux. It can be downloaded from the ArchLinuxArm web page at http://archlinuxarm.org/os/ArchLinuxARM-rpi-latest.tar.gz.

Installing the operating system

We need some essential components to successfully start up the RasPi. Note that this subsection is for those users who are using the RasPi for the first time and have not purchased the preloaded SD card. If you have installed the operating system on your SD card, then you can skip this section, or just look at the procedure to help your friend who has just brought a new RasPi.

Purchasing your SD card

When you buy a RasPi module, it may or may not be sold with an SD card. If your RasPi did not come with an SD card, then the minimum size you should get is 4 GB. RasPi doesn't have any on-board memory, so purchasing an SD card is the only way to get data storage as well as an operating system. I have an 8 GB SD card for my RasPi, and it works well and is sufficient for doing almost all projects.

Tip

For server applications, if you require more space, then an SD card with higher space will be useful.

Downloading the required software

Once you have an SD card, you are ready for this step. These steps are broadly explained in my personal blog too, which you can visit at http://rushigajjar.blogspot.in/2014/03/setting-up-raspberry-pi-for-first-time.html.

Let's see the procedure for different operating systems.

Windows

These things need to be kept in mind while working on Windows:

  • Format the SD card: Use the SD Card Association's tool (www.sdcard.org/downloads) to format/wipe your old data from the SD card. Use of the SD formatter provides optimal performance for your memory cards compared to the generic formatting facilities provided by your computer's operating system.

  • Write the image of the OS on an SD card: The downloaded Raspbian OS will be written from a raw disk image to a removable device using the popular and free tool, Win 32 Disk Imager (sourceforge.net/projects/win32diskimager/). Follow the steps on the screen, and you can easily write an image of Raspbian on your SD card. Once you are done with this process, jump to the next section.

Mac OS X

The following things need to be kept in mind while working on Mac OS X:

  • Download software to write the image of the OS on an SD card: There are multiple tools available for Mac OS X users such as ApplePi-Baker, PiWriter, and Pi Filler. PiWriter is a CLI-based tool, whereas ApplePi-Baker and Pi Filler are GUI-based tools. Pi Filler is recommended to be used because it is simpler and faster than other tools. It can be downloaded from http://ivanx.com/raspberrypi/files/PiFiller.zip.

  • Write the image on the SD card: Insert an SD card, locate or choose the downloaded image in the tool, and erase the SD card in the automatically popped-up menu. Select the continue button to write the image on the SD card.

Linux

These things need to be kept in mind while working on Linux:

  • Unzip the downloaded image: If you are using a GUI-based Linux OS on your desktop computer, open the download folder and unzip the OS by right-clicking on Extract Here.

  • Download the software to write the image of the OS on an SD card: You can install image writer from the Ubuntu Software Center. Open Software Center and search for ImageWriter. Insert the SD card in your desktop and follow the GUI (click on the Write to Device button) to locate and write the image on your SD card.

Expanding the root filesystem

Now, it's time to start the RasPi for the first time. After the process of writing an OS on the SD card, insert the SD card into the slot available on the RasPi. Connect the display (or TV) through an RCA or HDMI connection, and power up the RasPi by connecting a power supply to the micro USB connector. You will be able to see the configuration screen. Directly select the expand_rootfs option (from the keyboard connected through the USB of the RasPi) and wait for some time to complete the background process. When you write the image on the SD card, everything is in a compact bundle, where it needs to be expanded for the RasPi's complete operation. Expanding the root filesystem (expand_rootfs) resizes the partitions in the SD card and allows us to utilize the memory space in it. By this point, you should restart your RasPi.

Tip

Before powering up the RasPi using the micro USB cable, the SD card must be inserted and the HDMI cable must be attached. RasPi reads the signals coming through HDMI to check the display connection. If the display is not available at the first point of startup, it disables the HDMI interface and streaming to optimize performance.

Logging in to the RasPi

When the RasPi restarts, you will be able to see many pieces of code running on the screen. Don't panic! It's a normal process that goes on in the RasPi. When it becomes stable, it will prompt you to enter the username and password. By default, the username and password are pi and raspberry respectively.

Tip

Note that while you are writing your password, you will not be able to see anything coming on the screen; don't worry. Welcome to the Linux world!

Once you've entered the correct password, you will be able to see the CLI with pi@raspberrypi~$on your screen, monitor, or TV, which is now ready to take commands from you. Aye, aye, captain!

Opening the desktop

Enter the startx command as pi@raspberrypi~$startx and press Enter. Now you have a white screen with the Raspberry Pi logo and a GUI that looks similar to our personal desktop computers. Take a bite!

So, we saw an easy and compact guide for setting up the RasPi for the first time. We'll now add more functionality to our RasPi by providing an Internet connection for it. A computer is incomplete without an Internet connection, and so is our RasPi. This is something we need to solve, especially as we can directly download useful libraries and applications on the RasPi through the internet.