Discover millions of ebooks, audiobooks, and so much more with a free trial

Only $11.99/month after trial. Cancel anytime.

Raspberry Pi Essentials
Raspberry Pi Essentials
Raspberry Pi Essentials
Ebook404 pages2 hours

Raspberry Pi Essentials

Rating: 0 out of 5 stars

()

Read preview

About this ebook

About This Book
  • Utilize the exciting capabilities of the Raspberry Pi to build unique audio, video, and robotic designs
  • Get familiar with the bare essentials of basic programming and hardware tasks on the Raspberry Pi
  • Learn the Raspbian OS and its standard applications with the help of this easy-to-follow, quick-reference guide
Who This Book Is For

Programmers new to the Raspberry Pi and novice programmers with little to no experience with micro board computing will find the book useful. A basic knowledge of programming languages in general will prove useful for a better understanding of the topics.

LanguageEnglish
Release dateApr 28, 2015
ISBN9781784396923
Raspberry Pi Essentials

Related to Raspberry Pi Essentials

Related ebooks

Hardware For You

View More

Related articles

Reviews for Raspberry Pi Essentials

Rating: 0 out of 5 stars
0 ratings

0 ratings0 reviews

What did you think?

Tap to rate

Review must be at least 10 words

    Book preview

    Raspberry Pi Essentials - Jack Creasey

    Table of Contents

    Raspberry Pi Essentials

    Credits

    About the Author

    About the Reviewers

    www.PacktPub.com

    Support files, eBooks, discount offers, and more

    Why subscribe?

    Free access for Packt account holders

    Preface

    What this book covers

    What you need for this book

    Who this book is for

    Conventions

    Reader feedback

    Customer support

    Downloading the example code

    Downloading the color images of this book

    Errata

    Piracy

    Questions

    1. Getting Started with Raspberry Pi

    Let's get started

    Unboxing the Raspberry Pi

    Configure power for Pi

    Local display, keyboard, mouse, or remote headless access

    Selecting a screen

    Connecting VGA displays

    Getting your SD Card ready

    Booting the Raspberry Pi for the first time

    It's time to power up the Pi

    No video on initial boot

    Final installation configuration

    A quick tour of the desktop

    Instructions for downloading all project files

    Summary

    2. Configuring the Raspberry Pi Desktop and Software

    Hardware and software networking configuration

    Client reservations for Ethernet and wireless

    Configuring the Raspberry Pi desktop and software

    Keeping the development environment up to date

    Setting up a screensaver

    Manually locking your session

    Desktop and file manager accelerators

    Adding root privileges to the PCManFM file manager

    Programming on the Raspberry Pi

    Developing with Bash shell scripts

    Project 1 – Building a talking clock with a Bash script

    Creating project files and directories

    Building a talking clock with Python 3

    Summary

    3. Raspberry Pi and Cameras

    Connecting cameras to the Raspberry Pi

    PiCam and PiNoIR

    Webcams

    Project architecture for the Raspberry Pi security camera

    Features and limitations of the cameras

    Testing camera capability

    Viewing CPU resource for the luvcview application

    Verifying the PiCam operation

    Controlling data storage for video

    Testing the data storage limit

    Project 1 – Running raspivid as a background service

    Project 1a – Creating a Bash script to drive raspivid

    Testing the picam.sh script

    Project 1b – Creating a movement detector with a USB camera

    Test the webcam installation

    A final word on resolution and frame rate for movement detection

    Project 2 – Combining the webcam movement detector and the PiCam camera

    Project 3 – Creating a simple Python GUI for the security application

    Summary

    4. Raspberry Pi Audio Input and Output

    Audio quality and bandwidth

    Audio capability on the Raspberry Pi

    Limited headphone output

    Understanding the ALSA configuration

    Configuring the default device for ALSA

    Configuring the Raspberry Pi to support high-quality sound

    Project 1 – Installing an advanced audio playback application

    Building an Internet radio based on VLC and Raspberry Pi

    Project 2a – Running VLC in the background for the Internet radio

    Starting VLC automatically at reboot

    Project 2b – Designing a playlist file for the Internet radio

    Chapter 4 supplemental materials

    Project 2c – Parsing the playlist file for the Internet radio

    Project 2d – Implementing a Python text interface to VLC

    Project 3 – Implementing a TKinter GUI for the Internet radio

    Running tktest.py

    Creating a clock in the radio UI

    Running tkradio.py

    Recording sound files on the Pi

    Summary

    5. Port Input and Output on the Raspberry Pi

    Understanding Raspberry Pi digital input and output ports

    Using breakout boards with the Raspberry Pi

    Driving LEDs as output indicators

    Python LED demo

    TKinter LED demo

    Block 1 – initialization

    Block 2 – on/off buttons

    Block 3 – monostable function

    Block 4 – loop flash

    Block 5 – PWM flash

    Block 6 – TKPWM flash and toggle tkrun

    Block 7 – start the application

    TKinter switch demo

    Block 1 – the activity indicator

    Block 2 – the Edge switch detector

    Block 3 – the Event switch detector

    Adding a physical switch interface to the Internet radio

    Project 1 – Add a switch interface to the Internet radio

    Summary

    6. Driving I2C Peripherals on the Raspberry Pi

    Getting started with I2C

    Understanding address fields

    Driving RC servos

    Raspberry Pi software requirements for SMBus

    Programming the PCA 9685 to drive a servo

    PCA 9685 addressing and registers

    Project 1 – Python control of a PWM board driving RC servo motors

    Code block 1 – imports, constants, and variables

    Code block 2 – I2C access functions

    Code block 3 – the PCA9685 specific code

    Code block 4: the test code

    Other demo code

    Summary

    7. Going Mobile with Raspberry Pi

    Remote access to the Raspberry Pi

    Using PuTTY remote access

    Installing PuTTY on Microsoft Windows

    Remote access from Linux and OSX

    Testing your remote session from a PC or Mac

    Battery power systems

    Selecting regulators

    Measuring Raspberry Pi project current

    Potential battery power solutions

    Adafruit PowerBoost 1000 Basic

    Adafruit PowerBoost 500C

    Power banks as an alternative mobile power system

    Project 1 – Selecting a project battery capacity

    Summary

    8. Creating a Raspberry Pi Line-following Robot

    Implementing a line-following robot

    Line-following robot architecture

    Software architecture

    Software module functions

    Implementing rbuttons.py

    Downloading rbuttons.py and test-buttons.py

    Implementing rcam.py

    Installing the pip manager

    Installing the pip package manager

    Installing Pillow

    Downloading rcam.py

    Implementing rwheel.py

    Downloading rwheel.py and test-rwheel.py

    Implementing navigate.py

    Downloading navigate.py

    The steering methodology

    Open loop servo control

    Analyzing camera data

    Steering algorithm

    Time to build the mobile system

    Checking wireless connectivity

    Line-following robot

    Assembling the robot

    How to bring up your robot

    Navigating the robot

    Summary

    Index

    Raspberry Pi Essentials


    Raspberry Pi Essentials

    Copyright © 2015 Packt Publishing

    All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

    Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

    Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

    First published: April 2015

    Production reference: 1230415

    Published by Packt Publishing Ltd.

    Livery Place

    35 Livery Street

    Birmingham B3 2PB, UK.

    ISBN 978-1-78439-639-8

    www.packtpub.com

    Credits

    Author

    Jack Creasey

    Reviewers

    P Ashwin

    Scott Gibson

    Yegor Yefremov

    Werner Ziegelwanger

    Commissioning Editor

    Julian Ursell

    Acquisition Editor

    Sonali Vernekar

    Content Development Editor

    Siddhesh Salvi

    Technical Editor

    Rohith Rajan

    Copy Editor

    Sarang Chari

    Project Coordinator

    Nidhi Joshi

    Proofreaders

    Safis Editing

    Paul Hindle

    Kevin McGowan

    Dan McMahon

    Indexer

    Tejal Soni

    Graphics

    Sheetal Aute

    Production Coordinator

    Aparna Bhagat

    Cover Work

    Aparna Bhagat

    About the Author

    Jack Creasey has been in the technology industry for more than 30 years, the last 15 years as a Senior Program Manager in hardware and software design. His expertise includes designing, developing, and teaching IT courseware. He is an avid inventor and holds 13 patents in hardware and software design.

    After retiring early from the computing industry, Jack avidly participates in social network groups that share his passion for next generation technology solutions.

    About the Reviewers

    P Ashwin is a Bangalore-based engineer who wears many different hats depending on the occasion. He graduated from IIIT Hyderabad in 2012 as a Master of Technology in Computer Science and Engineering. He has a total of 5 years of experience in the software industry where he worked in different domains, such as testing, data warehousing, replication, and automation. He is very well versed in DB concepts, SQL, and scripting with Bash and Python. He has earned professional certifications in products from Oracle, IBM, Informatica, and Teradata. He's also an ISTQB certified Tester.

    In his free time, he volunteers for different technical hackathons and social service activities. He was introduced to Raspberry Pi in one of the hackathons and he's been hooked on it ever since. He writes a lot of code in Python, C, C++, and Shell on his Raspberry Pi B+ cluster. He's currently working on creating his own Beowulf cluster of 64 Raspberry Pi 2s.

    Scott Gibson is an Electrical Engineer from Ottawa, Ontario Canada. He works as a software developer in the wireless telecommunications industry as well as a consultant specializing in embedded hardware and software development.

    Scott has a passion for all things technical with particular interest in projects that cross between software, hardware, and mechanical engineering. Scott runs the website www.thegreatgeekery.com documenting some of his personal projects as well as contributions to the open source community.

    Werner Ziegelwanger (MSc) has studied game engineering and simulation and got his master's degree in 2011. His master's thesis was published with the title Terrain Rendering with Geometry Clipmaps for Games by Diplomica Verlag. His hobbies are programming, games, and all kinds of technical gadgets.

    Werner worked as a self-employed programmer for many years and mainly did web projects. At that time, he started his own blog (http://developer-blog.net), which is about the Raspberry Pi, Linux, and open source technologies.

    Since 2013, Werner has been working as a Magento developer and head of programming at mStage GmbH, an e-commerce company focused on Magento.

    www.PacktPub.com

    Support files, eBooks, discount offers, and more

    For support files and downloads related to your book, please visit www.PacktPub.com.

    Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at for more details.

    At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

    https://www2.packtpub.com/books/subscription/packtlib

    Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can search, access, and read Packt's entire library of books.

    Why subscribe?

    Fully searchable across every book published by Packt

    Copy and paste, print, and bookmark content

    On demand and accessible via a web browser

    Free access for Packt account holders

    If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view 9 entirely free books. Simply use your login credentials for immediate access.

    This book is dedicated to my wife, April. Without her dedication and support this book would not exist.

    April provided encouragement to start the project, and acted as the Instructional designer and editor once underway.

    Her patience and input as we built the learning objectives helped us meet most of the deadlines, and significantly enhanced the materials.

    I can only hope she will perform this function again for the next book.

    Preface

    The Raspberry Pi is a low-cost, highly capable computer system about the size of a deck of cards that can use a standard-sized keyboard, monitor, and mouse. This book will show you how to use this amazing little machine to design and configure your own development environment, build really cool hobby projects, and gain expertise in project design and development. You will also learn how to take advantage of existing open source tools, applications, and scripts.

    It doesn't matter whether you are new to the hobby project world or you are an experienced DIY maker; from the very first chapter, we guide you through complex software and hardware concepts. This book uses a project-based learning design, from setting up a graphical desktop interface to driving a line-following robot; you learn what you need to know when you need it.

    As you complete the projects, you will build on what you learn in the chapters and continue to expand your expertise, using complex computing solutions for your Raspberry Pi.

    What this book covers

    Chapter 1, Getting Started with Raspberry Pi, introduces the features of the Raspberry Pi and its peripherals. You will build your own Raspberry Pi system and configure the base OS.

    Chapter 2, Configuring the Raspberry Pi Desktop and Software, continues with the configuration of a Raspberry Pi project development environment based on the use of graphical desktop applications. You will build a talking clock using a Raspberry Pi sound card.

    Chapter 3, Raspberry Pi and Cameras, explores the configuration of the Raspberry Pi to support various video solutions. You will create a camera-based movement detection system with PiCam and USB cameras, using Bash Shell and Python 3 scripts.

    Chapter 4, Raspberry Pi Audio Input and Output, examines audio capability and the configuration of the Raspberry Pi to support high-quality sound. You will build an Internet radio and stereo audio system using VLC.

    Chapter 5, Port Input and Output on the Raspberry Pi, explains digital I/O configuration. You will experiment with LEDs as output indicators and sensing switches to make improvements to the Internet radio.

    Chapter 6, Driving I2C Peripherals on the Raspberry Pi, describes the characteristics of I2C protocols and the extensive I2C interface support built into the Raspberry Pi. You will build an RC servo control program.

    Chapter 7, Going Mobile with Raspberry Pi, explores wireless access from the command-line to a remote Raspberry Pi and battery power systems. You will configure remote access to a Raspberry Pi.

    Chapter 8, Creating a Raspberry Pi Line-following Robot, builds upon projects completed in previous chapters to design the architecture for a Raspberry Pi-driven robot. You will construct a line-following robot using PiCam as the line sensor.

    What you need for this book

    The content was based on:

    NOOBS Version 1.4.0, released on February 18, 2015

    Raspbian (Debian Wheezy) Version 7.8 (Linux Kernel 3.18), released by RaspberryPi.org on February 16, 2015

    For details, visit http://www.raspberrypi.org/downloads/.

    Who this book is for

    Raspberry Pi Essentials is intended for hobbyists and academic project designers and developers who have minimal experience with programming languages and hardware designs. Don't worry if you are new to computing, this book will coach you through cool projects that ensure you build expertise and competence. Since the Raspberry Pi is an inexpensive computing solution, you can easily build a very cost-effective and flexible graphical desktop environment to develop your hobby projects.

    Conventions

    In this book, you will find a number of text styles that distinguish between different kinds of information. Here are some examples of these styles and an explanation of their meaning.

    Code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles are shown as follows: You will often see the Wi-Fi configuration utility referred to in configuration guides as the wpa_supplicant GUI user interface.

    A block of code is set as follows:

    [Desktop Entry]

    Encoding=UTF-8

    Type=Application

    Name=Screenlock

    Name[en_GB]=Screenlock

    Icon=kscreensaver

    When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

    [Desktop Entry]

    Encoding=UTF-8

    Type=Application

    Name=Screenlock

    Name[en_GB]=Screenlock

     

    Icon=kscreensaver

    Any command-line input or output is written as follows:

    sudo apt-get update

    New terms and important words are shown in bold. Words that you see on the screen, for example, in menus or dialog boxes, appear in the text like this: Clicking the Next button moves you to the next screen.

    Note

    Warnings or important notes appear in a box like this.

    Tip

    Tips and tricks appear like this.

    Reader feedback

    Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or disliked. Reader feedback is important for us as it helps us develop titles that you will really get the most out of.

    To send us general feedback, simply e-mail <feedback@packtpub.com>, and mention the book's title in the subject of your message.

    If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide at www.packtpub.com/authors.

    Customer support

    Now that you are the proud owner of a Packt book, we have

    Enjoying the preview?
    Page 1 of 1