Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Raspberry Pi By Example
Raspberry Pi By Example

Raspberry Pi By Example: Start building amazing projects with the Raspberry Pi right out of the box

eBook
€8.99 €26.99
Paperback
€32.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Raspberry Pi By Example

Chapter 1. Introduction to Raspberry Pi and Python

One can learn about topics in computer science in an easy way with the Raspberry Pi and Python. The Raspberry Pi family of single-board computers uses Python as the preferred development language. Using Raspberry Pi and Python to learn programming and computer science-related concepts is one of the best ways to start your journey in this amazing world of computers that is full of creative possibilities. We will explore these possibilities in this book.

We will commence our journey in this chapter by getting ourselves familiar with the following topics:

  • Single-board computers
  • Raspberry Pi
  • Raspbian
  • Setting up Raspberry Pi
  • Basics of Python
  • Turtle programming with Python

Single-board computers

A single-board computer system is a complete computer on a single circuit board. The board includes a processor(s), RAM, input/output (I/O), and networking ports for interfacing devices. Unlike traditional computer systems, a single-board computer is not modular and its hardware cannot be upgraded as it is integrated on the board itself. Single-board computers are used as low-cost computers in academia, research, and embedded systems. The use of single-board computers in embedded systems is quite prevalent and many individuals and organizations have developed and released fully functional products based on single-board computers.

The Microcomputer Trainer MMD-1 designed by John Titus in 1976 is the first true single-board microcomputer that was based on the Intel C8080A. It was called dyna -micro in the prototyping phase, and the production units were called MMD-1 (short for Mini Micro Designer 1).

Popular single-board computers available in the market include but are not limited to Raspberry Pi, Banana Pro, BeagleBone Black, and Cubieboard. The following images are of the front view of BeagleBone Black, Banana Pro, and Cubieboard 4, respectively:

Single-board computers

Raspberry Pi

The Raspberry Pi is a series of low-cost, palm-sized single-board computers developed by Raspberry Pi Foundation in the UK. The intention behind the creation of the Raspberry Pi is to promote the teaching of basic computer skills in schools, which it serves very well. Raspberry Pi has expanded its footprint well beyond its intended purpose by penetrating the embedded systems market and computer science research.

Note

This is the home page of Raspberry Pi Foundation: http://www.raspberrypi.org.

The Raspberry Pi is manufactured with licensed agreements with Newark element14, RS Components, Allied Electronics, and Egoman. These companies manufacture and sell the Raspberry Pi. The hardware is the same across all manufacturers.

The following table displays the URLs of the manufacturers' websites, where you can shop for Pi and related items online:

Manufacturer

Website

Newark element14

http://www.newark.com

RS Components

http://uk.rs-online.com

Egoman

http://www.egoman.com.cn

Allied Electronics

http://www.alliedelec.com

You can also shop for Pi and the other third-party add-ons at the following links:

Raspberry Pi models

The following are, at the time of writing this, the major models of Raspberry Pi:

  • Model A (not in production; discontinued in favor of the production of later and upgraded models)
  • Model A+ (currently in production and available for purchase)
  • Model B (available for purchase but not in production)
  • Model B+ (currently in production and available for purchase)
  • Raspberry Pi 2 Model B (currently in production and available for purchase)

Note

Check out the Product page of Raspberry Pi at http://www.raspberrypi.org/products/.

Additionally, Raspberry Pi is also available in a more flexible form factor intended for industrial and embedded applications. It is known as Compute Module. A Compute Module prototyping kit is also made available by the foundation.

Note

Check out the following URLs for the Compute Module and Compute Module development kit, respectively:

http://www.raspberrypi.org/products/compute-module/

http://www.raspberrypi.org/products/compute-module-development-kit/

The following table compares the currently available models of Pi:

Raspberry Pi models

The following image shows the top view of the Raspberry Pi Model B front:

Raspberry Pi models

The following image shows the top view of the flip side of Raspberry Pi Model B:

Raspberry Pi models

The following image shows the top view of the Raspberry Pi Model B+ front:

Raspberry Pi models

The following image shows the top view of the flip side of Raspberry Pi Model B+:

Raspberry Pi models

The following image shows the top view of the Raspberry Pi 2 Model B front. The location of the connectors and important ICs (integrated circuits) on the board is not different from Pi B+:

Raspberry Pi models

We will be using Raspberry Pi 2 Model B throughout this book. However, all the applications and programs in this book will work on all the models of Pi.

Operating systems

The Raspberry Pi primarily uses Unix-like Linux-kernel-based operating systems, such as variants of Debian and Fedora.

Raspberry Pi Models A, A+, B, and B+ are based on the ARM11 family chip, which runs on the ARMv6 instruction set. The ARMv6 instruction set does not support Ubuntu and Windows.

However, the recently launched Raspberry Pi 2 is based on ARM Cortex A7, which is capable of running Windows 10 and Ubuntu (Snappy Core). The following operating systems are officially supported by all the models of Raspberry Pi and are available for download at the download page:

  • Raspbian: We will be using this with Raspberry Pi throughout the book
  • OpenELEC
  • Pidora (Fedora Remix)
  • RASPBMC
  • RISC OS

Note

Windows 10 and Ubuntu are only supported by the recently launched Pi 2.

Raspbian

Raspbian is an unofficial variant of Debian armhf (ARM Hard Float) compiled for hard float code that will run on Raspberry Pi computers. It is a free operating system based on Debian optimized for the Raspberry Pi hardware.

Note

To know more about Raspbian, visit http://www.raspbian.org/.

Setting up the Raspberry Pi

We need the following hardware to set up a Pi.

  • Raspberry Pi 2 Model B (hereafter, this will be referred only as Pi).
  • Power Supply: A micro USB power supply.

    Considering that we are going for slightly power-intensive usage of our Pi (such as connecting Pi Camera, webcam, and third-party sensors for Pi), a 5V 2A power supply is recommended. The micro USB pin is shown in the following image:

    Setting up the Raspberry Pi

    Note

    You can find a similar one online at http://www.adafruit.com/product/1995.

  • A standard USB keyboard
  • A MicroSD card and a MicroSD to SD card converter

    We need a minimum 4 GB Micro SD card.

  • A USB mouse
  • A monitor

    You can use either an HDMI monitor or a standard VGA monitor.

  • A monitor connection cable and converter

    If you are using HDMI monitor, then an HDMI cable will be sufficient. If you are using a VGA monitor, then you need to use an HDMI to VGA converter with a VGA cable. Some special changes need to be made to the /boot/config.txt file if you're using a VGA monitor, which will be explained in the next section.

    Setting up the Raspberry Pi

    Note

    You can find a similar one online at https://www.adafruit.com/products/1151.

  • A Windows, Linux, or Mac OS computer with a MicroSD card reader and an Internet connection

Preparing MicroSD card manually

This is the original way to install an OS into a MicroSD card, and many users, including me, still prefer it. It allows the SD card to be prepared manually before it is used and it allows easier access to configuration files such as /boot/config.txt, which we might have to modify in a few cases before booting up. The default Raspbian image consists of only two partitions, BOOT and SYSTEM, which will fit into a 2 GB card. However, I recommend that you use a minimum 4 GB card to be on safe side. Choosing an 8 GB card will be adequate for most of the applications we are going to develop in this book.

The following are the instructions for Windows users:

  1. Download the Win32DiskImager installer, which is available at http://sourceforge.net/projects/win32diskimager/files/latest/download and then install it.
  2. Download the installable version of WinZip, which is available at http://www.winzip.com/prod_down.html, and install it.
  3. Go to http://www.raspberrypi.org/downloads and download the latest image of Raspbian. It will be a compressed file in the ZIP format and will need to be extracted.
  4. Extract the ZIP file using WinZip. The extracted file will be in the .img format.
  5. Insert the microSD card into the card reader and plug the card reader into the computer. Many computers nowadays have an inbuilt SD card reader. In this case, you will need to insert the microSD card into the microSD to SD card converter and insert it into the computer's inbuilt SD card reader. MicroSD to SD card converters usually come bundled with microSD cards in the same package. If that's not the case, then you will have to procure it separately.
  6. Run Win32DiskImager.exe and write the image onto the SD card:
    Preparing MicroSD card manually

    You might receive the following message if the card reader's write protection is on:

    Preparing MicroSD card manually
  7. Toggle the write protection notch and try again. You will see the following message:
    Preparing MicroSD card manually
  8. Click on Yes and it will start writing the image file to the microSD card:
    Preparing MicroSD card manually
  9. Once the image is successfully written, it will display the following message:
    Preparing MicroSD card manually

Note

If you are using Linux, then you can find the instructions at https://www.raspberrypi.org/documentation/installation/installing-images/linux.md.

If you are using Mac OS, then you can find the instructions at https://www.raspberrypi.org/documentation/installation/installing-images/mac.md.

If you have an HDMI monitor, then skip this step. This additional step is required only if you are planning to use a VGA monitor in place of an HDMI monitor.

Browse the microSD card on the computer. Locate and open config.txt. We have to edit the file in order to enable proper display on the VGA monitor.

By default, the commented options (which have # at the beginning) are disabled. We are enabling this option by uncommenting this line, that is, by removing # from the beginning of the commented line. This is what you need to do:

  1. Change #disable_overscan=1 to disable_overscan=1.
  2. Change #hdmi_force_hotplug=1 to hdmi_force_hotplug=1.
  3. Change #hdmi_group=1 to hdmi_group=2.
  4. Change #hdmi_mode=1 to hdmi_mode=16.
  5. Change #hdmi_drive=2 to hdmi_drive=2.
  6. Change #config_hdmi_boost=4 to config_hdmi_boost=4.
  7. Save the file.

Booting up our Pi for the first time

Let's boot up our Pi for the first time with the microSD card:

  1. Insert the microSD card into the microSD card slot of the Pi.
  2. Connect the Pi to the HDMI monitor. If you are connecting the VGA monitor, connect it using the HDMI to VGA converter.
  3. Connect the USB mouse and the USB keyboard.
  4. Connect the Pi to a power supply using the micro USB power cable. Make sure the power is switched off at this point.
  5. Check all the connections once and then switch on the power supply of the Pi.

At this stage, our Pi will start booting up. You will see a green light on the Pi board blinking. This means that it's working! Now, there are few more things we need to do before we can really start using our Pi. Once it boots up, it will show the desktop as follows:

Booting up our Pi for the first time

Once the desktop is visible, go to Menu | Accessories | lxterminal. Then, type sudo raspi-config. A text-based menu, such as the following, will appear:

Booting up our Pi for the first time

Perform the following steps. We need to use arrow keys and the Enter key to select options in the text-based menu. Press Enter to select a menu item. Also, we can use the Tab key to directly go to the Select and Finish buttons:

  1. Select Expand Filesystem.
  2. In Boot Options, select B4 Desktop Autologin, as shown in the following screenshot:
    Booting up our Pi for the first time

    Note

    The default username is pi and the password is raspberry. We need it when we don't choose any of the preceding autologin options. We can change this password from the second option in the raspi-config menu.

    We can also choose to boot to the console by selecting any of the first two options in the preceding menu. The default shell of Raspbian is Bash. We can confirm it by typing the following command:

    echo $SHELL
    

    We can always go to the graphical desktop from the Command Prompt by typing the startx command in the console.

  3. Go to Internationalisation Options | Change Timezone.
  4. Go to Internationalisation Options | Change Keyboard Layout | Change it to US (the default is UK).
    Booting up our Pi for the first time
  5. Select Enable Camera.
  6. Select Advanced Options.
  7. Under this option, select Memory Split and enter 64MB for GPU.

This option decides how much RAM is used by the GPU (Graphics Processor Unit). The more RAM is allocated to the GPU, the more intensive graphics processing can be done. 64 MB is a good value for most graphics purposes.

Once all these options are modified, select Finish. This will prompt for a reboot of the Pi. Choose Yes and let it reboot. Once rebooted, it will automatically take us to the Raspbian Desktop again.

You can always invoke the raspi-config tool from Command Prompt with the following command and change the settings:

sudo raspi-config

Shutting down and rebooting Pi safely

In the Raspbian menu, there are options to shut down and reboot the Pi.

If we click on the following Menu button on the desktop, it will display multiple options:

Shutting down and rebooting Pi safely

The following image shows the last option:

Shutting down and rebooting Pi safely

If we click on the preceding option, the following window will appear:

Shutting down and rebooting Pi safely

Also, from Command Prompt LXTerminal, we can shut down Pi safely by issuing the following command:

sudo shutdown –h now

An alternative command for this is as follows:

sudo halt

You can reboot Pi with the following command:

sudo reboot

Updating the Pi

Now we have a working Pi running on the Raspbian OS. Let's update our Pi. Make sure you have a working wired or wireless Internet connection with reasonable speed for this activity:

  1. Connect your Pi to an Internet modem or router with an Ethernet cable or plug in the Wi-Fi dongle to one of the USB ports.
  2. Run the following command to restart the networking service:
    sudo service networking restart
    
  3. Make sure that your Raspberry Pi is connected to the Internet by typing the following command:
    ping –c4 www.google.com
    
  4. apt (Advanced Package Tool) is the utility used to install and remove software in Debian and its variants. We need to use it to update our Pi software.
  5. Run the following commands in a sequence:
    • sudo apt-get update: This command synchronizes the package list from the source. Indexes of all the packages are refreshed. This command must be issued before we issue the upgrade command.
    • sudo apt-get upgrade: This command will install the newest versions of all the already installed software. Any obsolete packages/utilities are not removed automatically. If any software is in its newest version, then it's left as it is.
    • sudo rpi-update: This command is used to upgrade the firmware. The kernel and firmware are installed as a Debian package, and so they will also get updates. These packages are updated infrequently after extensive testing.
    • sudo reboot: This will reboot the computer.

Getting started with Python

Python is a high-level general-purpose programming language. It supports multiple programming paradigms, such as object-oriented programming, imperative programming, functional programming, procedural programming, aspect-oriented programming, and metaprogramming. It has a dynamic type system, automatic memory management, and a large standard library to carry out various tasks. It emphasizes code readability, and its syntax allows you to carry out tasks in fewer lines of code than other programming languages, such as C or C++.

Python was conceived and implemented by Guido van Rossum at CWI in the Netherlands as a successor to the ABC language, capable of exception handling and interfacing with the Amoeba operating system platform. Van Rossum is Python's principal author, and he continues to have the central role in deciding the direction of Python. He has been endowed with the title benevolent dictator for life (BDFL) by the worldwide Python community.

The core philosophy of the Python programming language is mentioned in this URL: https://www.python.org/dev/peps/pep-0020/; its first few lines are as follows:

"Beautiful is better than ugly.

Explicit is better than implicit.

Simple is better than complex.

Complex is better than complicated.

Flat is better than nested.

Sparse is better than dense.

Readability counts."

Python is the preferred programming language for the Raspberry Pi family of computers. Its interpreter comes preinstalled with Raspbian, and there is no need for any additional installation to get started with code. It is recommended that you have chapter wise directories for the code examples presented in this book, as shown in the following diagram:

Getting started with Python

Let's get started with Python. Open Raspbian's Command Prompt LXTerminal. It is located as a shortcut on the taskbar. Alternately, we can find it by navigating to Menu | Accessories | Terminal. We can start Python in interactive mode by typing python in the prompt and then pressing the Enter key. It will take us to the Python interactive shell, as follows:

Getting started with Python

Now type the following lines and press Enter:

print "Hello World!"

The output will be as follows:

Python 2.7.3 (default, Mar 18 2014, 05:13:23) 
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> print "Hello World!"
Hello World!

Congrats! We have started with Python programming. The interactive mode of Python is suitable for small programs. Press Ctrl + D to exit the interactive shell. For large and code-intensive projects, it's recommended that you use Python in script mode. In this book, we will be using Python in script mode unless specified explicitly. Let's look at how to use Python in script mode.

Create a subdirectory, book, in the /home/pi directory for the code examples in this book. We can do this with mkdir book (by default, we are be in the /home/pi directory). Then, navigate to this recently created directory with the cd book command. We can verify our current directory with the pwd command. It returns the current directory as follows:

pi@raspberrypi ~ $ mkdir book
pi@raspberrypi ~ $ cd book
pi@raspberrypi ~/book $ pwd
/home/pi/book
pi@raspberrypi ~/book $ 

As discussed earlier, we need to keep the code of each chapter in separate directories for better organization. Now, create the chapter01 directory for this chapter in the current book directory using mkdir chapter01. Navigate to this with cd chapter01. At the beginning of each chapter, we are required to create a directory for the chapter under /home/pi/book for the code examples of that chapter.

We will now create a script file for our code and run it.

Use the Nano text editor to create and edit script files. If we type nano prog1.py, then Nano will open prog1.py for editing if it already exists in the current directory; otherwise, it will create a new file with the name prog1.py. You can exit the Nano editor by pressing Ctrl + X.

Note

You can find more information about nano at http://www.nano-editor.org/.

Alternatively, you can use the Leafpad text editor. We can find it by navigating to Menu | Accessories. Or, we can invoke it from Command Prompt with the leafpad prog1.py command.

Finally, you can also use vim, but you will need to install it by running the following command:

sudo apt-get install vim

Note

This is the link for an interactive tutorial on vim: http://www.openvim.com/.

Let's write the same Python code and run it as a script. Write the following code with Nano, Leafpad, or vim, and save it as prog1.py:

print "Hello World!"

To run the preceding program, use the python prog1.py command, and the output will be as follows.

We will run all the other Python programs in this book in the same way.

Let's try some more examples to have more hands-on Python.

The following is the iterative program to calculate the factorial of a given positive integer:

def fact(n):
    num = 1
    while n >= 1:
        num = num * n
        n = n - 1
    return num

print (fact(10))

In the preceding program, def fact(n) is a user-defined function that accepts an argument. The logic used to calculate the factorial of a positive integer follows the definition and the function returns a calculated factorial. The last line of the program calls the factorial function and prints the returned output as follows:

pi@raspberrypi ~/book/chapter01 $ python prog2.py 
3628800

The following is an iterative program for the Fibonacci series:

def fib(n):
    a=0
    b=1
    for i in range(n):
        temp=a
        a=b
        b=temp+b
    return a

for i in range (0,10):
    print (fib(i))

The preceding program prints the first 10 numbers in the Fibonacci series. A more "Pythonic" way of writing the same program, which eliminates the use of a temporary variable, is as follows:

def fib(n):
    a,b = 0,1
    for i in range(n):
        a,b = b,a+b
    return a

for i in range(0,10):
    print (fib(i))

The output of both of the preceding programs is the same and is as follows:

pi@raspberrypi ~/book/chapter01 $ python prog4.py 
0
1
1
2
3
5
8
13
21
34

Turtle programming with Python

Turtle graphics is one of the best ways to learn programming for beginners. Originally, it was part of the Logo programming language, which was primarily used to introduce programming in schools. Python has the turtle module, which is an implementation of the same functionality provided by the original turtle. We can write programs with this module in a procedural as well as object-oriented way.

In Python, when we need to access a module that is not part of the current code, we need to import it. Over the course of the book, we will be importing various modules as and when needed, which will provide us with specific functionalities.

Let's get started with importing the turtle module, as shown here:

import turtle

The following code creates objects for turtle and the screen classes, respectively:

t=turtle.Turtle()
disp=turtle.Screen()

We will use the t.color() function with which we can set the pen and fill color, as follows:

t.color("black","yellow")

We will call the t.begin_fill() and t.end_fill() functions to have our shape filled with a fill color:

t.begin_fill()
t.end_fill()

The code to draw an actual shape we need will be in between these two function calls, as follows:

t.begin_fill()
while 1:
    t.forward(100)
    t.left(190)
    if abs(t.pos())<1:
        break
t.end_fill()
disp.exitonclick()

In the preceding code, t.forward() is used to move the turtle forward a specified distance, and t.left() is used to rotate the turtle left by 190 degrees. t.pos() returns the current coordinates of the turtle.

Finally, we use disp.exitonclick() to close the current output window when we click on the exit button.

Note

At the start, the turtle cursor is at (0,0) and is pointed toward the positive direction of the x axis (facing right).

The output of the program will be a cursor drawing the desired shape progressively, and it helps the programmer understand how the program is actually working. The final output of the preceding program is as follows:

Turtle programming with Python

Note

Detailed documentation for the turtle API can be found at https://docs.python.org/2/library/turtle.html.

Next, we will learn the concept of recursion. In terms of programming, recursion means calling the same block of code within itself. For a procedural and modular style of programming, this stands for calling a function or method within itself. Usually, this is done to break a big problem into similar problems with smaller input sizes and then collect the output of all these smaller problems to derive the output of the big problem. One of the best ways to see recursion at work is to visualize it using a turtle. We will now write a program to draw a fractal tree using recursion.

First, we start by importing the required libraries, as follows:

import turtle
import random

We need the random library for the randint() function, which returns a random integer in the provided range. This is needed to make our generated tree seem different every time. Then, we will define a function to draw a part of the tree recursively:

def fractal_tree(b_len,t):
    if b_len > 5:
        temp=random.randint(1, b_len)
        temp_angle = random.randint(1, 25)
        t.forward(temp)
        t.right(temp_angle)
        fractal_tree(b_len-10,t)
        t.left(2 * temp_angle)
        fractal_tree(b_len-10,t)
        t.right(temp_angle)
        t.backward(temp)

In the preceding program, we are calling the same function twice in order to draw the further branches of the tree. If the b_len parameter is less than or equal to 5, then it will be a leaf (which means that the function will not be called again); else, the recursion will continue. We are randomizing the angle and length of the movement of the turtle while drawing the branches here; otherwise, the tree will be symmetrical, which is very unlikely in real life. The combination of t.forward(), t.backward(), t.left(), and t.right() ensures that at the end of each function call, the turtle cursor is at the same position as where it started.

Finally, we write the routine to call this recursive function:

t=turtle.Turtle()
disp=turtle.Screen()
t.left(90)
t.up()
t.backward(100)
t.down()
t.color("green")
fractal_tree(120,t)
disp.exitonclick()

The cursor does not draw the movements between the t.up() and t.down() function calls. In the preceding code, we are moving the cursor downward by 100 positions so that the tree should fit in the turtle graphics window. When we call fractal_tree() with 120 as the argument, it takes more than 30 minutes due to the high degree of recursion. The output of the preceding program is as follows:

Turtle programming with Python

Summary

In this chapter, we learned about the background of Raspberry Pi and Python. We understood the details of the different models of Pi. We learned how to set up the Raspberry Pi for programming. We also performed some hands-on Python programs. Then, we learned some graphics programming with the turtle library. This got us started with the Pi and the Python programming language, which we will be using throughout the rest of the book.

In the next chapter, we will learn how to play and program minecraft-pi.

Left arrow icon Right arrow icon

Key benefits

  • Explore the vast range of opportunities provided by Raspberry Pi and other hardware components such as a webcam, the Pi camera, and sensors
  • Get hands-on experience with coding, networking, and hardware with the Raspberry Pi platform
  • Learn through ample screenshots that offer a play-by-play account of how to implement Raspberry-Pi-based real-life projects

Description

Want to put your Raspberry Pi through its paces right out of the box? This tutorial guide is designed to get you learning all the tricks of the Raspberry Pi through building complete, hands-on hardware projects. Speed through the basics and then dive right in to development! Discover that you can do almost anything with your Raspberry Pi with a taste of almost everything. Get started with Pi Gaming as you learn how to set up Minecraft, and then program your own game with the help of Pygame. Turn the Pi into your own home security system with complete guidance on setting up a webcam spy camera and OpenCV computer vision for image recognition capabilities. Get to grips with GPIO programming to make a Pi-based glowing LED system, build a complete functioning motion tracker, and more. Finally, get ready to tackle projects that push your Pi to its limits. Construct a complete Internet of Things home automation system with the Raspberry Pi to control your house via Twitter; turn your Pi into a super-computer through linking multiple boards into a cluster and then add in advanced network capabilities for super speedy processing!

Who is this book for?

What's the best way to learn how to use your Raspberry Pi? By example! If you want something exciting to do whilst getting to grips with what your Pi can offer, this is the book for you. With both simple and complex projects, you'll create a wide variety of cool toys and functions with your Raspberry Pi - all with minimal coding experience necessary.

What you will learn

  • Set up your Raspberry Pi and get it ready for some interesting real-life projects
  • Work with images, videos, webcams, and the Pi camera and create amazing time-lapse videos
  • Explore the amazing world of Minecraft Pi
  • Get to know how to use PiGlow for GPIO programming
  • Interface your Pi with Grove Sensors and implement IoT applications
  • Build your own cluster with Raspberry Pi
  • Understand the networking and network programming fundamentals

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 22, 2016
Length: 294 pages
Edition : 1st
Language : English
ISBN-13 : 9781785285066
Vendor :
Raspberry Pi
Category :
Languages :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Apr 22, 2016
Length: 294 pages
Edition : 1st
Language : English
ISBN-13 : 9781785285066
Vendor :
Raspberry Pi
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 104.97
Internet of Things with Python
€41.99
Raspberry Pi By Example
€32.99
Python Programming with Raspberry Pi
€29.99
Total 104.97 Stars icon
Banner background image

Table of Contents

16 Chapters
1. Introduction to Raspberry Pi and Python Chevron down icon Chevron up icon
2. Minecraft Pi Chevron down icon Chevron up icon
3. Building Games with PyGame Chevron down icon Chevron up icon
4. Working with a Webcam and Pi Camera Chevron down icon Chevron up icon
5. Introduction to GPIO Programming Chevron down icon Chevron up icon
6. Creating Animated Movies with Raspberry Pi Chevron down icon Chevron up icon
7. Introduction to Computer Vision Chevron down icon Chevron up icon
8. Creating Your Own Motion Detection and Tracking System Chevron down icon Chevron up icon
9. Grove Sensors and the Raspberry Pi Chevron down icon Chevron up icon
10. Internet of Things with the Raspberry Pi Chevron down icon Chevron up icon
11. Build Your Own Supercomputer with Raspberry Pi Chevron down icon Chevron up icon
12. Advanced Networking with Raspberry Pi Chevron down icon Chevron up icon
13. Setting Up a Web Server on the Raspberry Pi Chevron down icon Chevron up icon
14. Network Programming in Python with the Pi Chevron down icon Chevron up icon
A. Newer Raspberry Pi Models Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Full star icon 5
(1 Ratings)
5 star 100%
4 star 0%
3 star 0%
2 star 0%
1 star 0%
Eugenio M. Sep 28, 2016
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Es un libro que recomiendo para los que quieran hacer cosas diferentes con una Raspberry. No es el tipico libro que se basa en los GPIO y las 200 paginas hablan de lo mismo. Este es diferente y me dió la idea de como solucionar un problema de comunicación entre diferentes RPI.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.