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
Learning Raspberry Pi
Learning Raspberry Pi

Learning Raspberry Pi: Unlock your creative programming potential by creating web technologies, image processing, electronics- and robotics-based projects using the Raspberry Pi

Arrow left icon
Profile Icon Serge Schneider Profile Icon Shah
Arrow right icon
$9.99 $39.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.7 (3 Ratings)
eBook Apr 2015 258 pages 1st Edition
eBook
$9.99 $39.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m
Arrow left icon
Profile Icon Serge Schneider Profile Icon Shah
Arrow right icon
$9.99 $39.99
Full star icon Full star icon Full star icon Full star icon Half star icon 4.7 (3 Ratings)
eBook Apr 2015 258 pages 1st Edition
eBook
$9.99 $39.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m
eBook
$9.99 $39.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

Learning Raspberry Pi

Chapter 2. Developing Web Applications

Modern web technologies allow web pages to be used as full-featured applications to replace traditional programs. The most important of these is AJAX, which allows a page to communicate with the server and dynamically alter web page elements. In this chapter, you will learn the basics of web development by creating a simple web page, changing its visual appearance, and making it interactive. Then, you will learn how a web server can serve dynamic pages generated by Python, before putting all of these skills together to create a media player and radio station that you can access from anywhere. We will cover the following topics in this chapter:

  • Adding page content with HTML
  • Customizing the visual appearance
  • Adding interactivity with JavaScript
  • Simplifying scripts with jQuery
  • An introduction to Python
  • Creating an Internet radio station

Getting started with HTML, JavaScript, and jQuery

In the previous chapter, you were introduced to Raspberry Pi and installed LAMP server on your Raspberry Pi. You also installed WordPress to host your personal website/blogs. So, how do you create your blog/website? This section will give a high-level overview of HTML, CSS, JavaScript, and jQuery.

Tip

If you are familiar with HTML, CSS, JavaScript, and jQuery, you might want to jump directly to the An introduction to Python section. You can get the source code from the book website.

Adding page content with HTML

HTML is used by the web browser to display content. To get started, replace /srv/www/index.php with the index.html file, which contains the following code:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Hello world</title>
</head>

<body>
  <h1>Hello World!</h1>
  <p>This is a <em>simple</em><abbr title=
  ...

An introduction to Python

So far, only the client side of a web application or website has been covered. However, the bulk of the work is usually done on the server, rather than in the browser. Python is an excellent language to handle the backend of web applications and it is very well supported on Raspberry Pi. Moreover, it is the official programming language suggested by Raspberry Pi Foundation. Apart from web development, Python can also be used to develop desktop and command-line applications or games and to the interface of the Raspberry Pi to the real world. This makes it easy to create a web application to display sensor data, or to control the Raspberry Pi.

Python code can be tested directly by running the python command to enter the Python shell. Within the shell, statements can be entered directly. In order to exit the shell, enter quit() or press Ctrl + D. To run the code as a proper program, enter it into a file with the .py extension. The program can then be executed by running...

Creating an Internet radio station

Although the previous example had no practical applications, it introduced most of the concepts needed to make something useful. To put the skills together in a more interesting way, the next example will show you how to create your own Internet radio station. A screenshot of the piMusic interface is shown here:

Creating an Internet radio station

The piMusic interface

The aim is to develop a site to play music stored on your Raspberry Pi from anywhere. This will integrate a small file browser that will allow you to browse your music collection and click a file to play it. Clicking Home will return to the top of the music folder, whereas Up will go up one directory level. Instead of playing individual files, clicking Radio will allow you to play a radio station, which you can manage from your Raspberry Pi.

First, create and enter a directory for the new Flask application as follows:

$ mkdir -p ~/piMusic/static/music
$ mkdir ~/piMusic/templates
$ cd ~/piMusic/templates

Creating the user interface...

Deploying Flask applications

As mentioned earlier, running Flask applications by directly launching the script works for testing, but is extremely unsafe and slow. In order to use nginx as the server for Pi MusicBox, the following needs to be added to the server block of the nginx site's configuration file (/etc/nginx/sites-available/pisite):

location = /piMusic { rewrite ^ /piMusic/; }
location /piMusic { try_files $uri @piMusic; }
location @piMusic {
include uwsgi_params;
    uwsgi_param SCRIPT_NAME /piMusic;
    uwsgi_modifier1 30;
    uwsgi_passunix:/tmp/uwsgi.sock;
}

For consistency, the Pi MusicBox directory should be moved to /srv.

Next, uWSGI needs to be installed and configured. You can think of it as the glue that will connect your application to nginx. You can install it by running this:

# apt-get install uwsgi uwsgi-plugin-python

Then, create the app configuration file /etc/uwsgi/apps-available/piMusic.ini as follows:

[uwsgi]
plugins = python
socket =  /tmp/uwsgi.sock
module...

Summary

In this chapter, an important set of technologies for web development was covered and an application that takes advantage of them was developed. The skills gained here can be used to create rich web applications to control Raspberry Pi and attach hardware remotely.

In the next chapter, you will get introduced to Raspberry Pi electronics and some of the electronics components that you will use later in this book. Using this knowledge, you will develop a digital clock, an e-mail notifier, and an alarm clock.

Left arrow icon Right arrow icon

Description

If you have a passion for technology and want to explore the world of Raspberry Pi, then this book provides you with all the tools and information you are looking for. Although being familiar with basic programming concepts is useful, you can still learn a lot from this book as a wide variety of topics are covered.

Who is this book for?

If you have a passion for technology and want to explore the world of Raspberry Pi, then this book provides you with all the tools and information you are looking for. Although being familiar with basic programming concepts is useful, you can still learn a lot from this book as a wide variety of topics are covered.

What you will learn

  • Get to grips with the basics of Linux administration, along with the inner workings of Linux distributions
  • Develop a web interface that can be used to upload selected files and create playlists
  • Discover how to connect your Raspberry Pi to the real world using analog inputs
  • Build your own remotecontrolled robot
  • Get to know about different image processing operations
  • Explore troubleshooting tips and tricks
  • Create your own Twitterenabled Raspberry Pi camera

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Apr 24, 2015
Length: 258 pages
Edition : 1st
Language : English
ISBN-13 : 9781783982837
Vendor :
Raspberry Pi
Category :
Languages :
Concepts :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Apr 24, 2015
Length: 258 pages
Edition : 1st
Language : English
ISBN-13 : 9781783982837
Vendor :
Raspberry Pi
Category :
Languages :
Concepts :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.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
$199.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
$279.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 $ 136.97
Raspberry Pi Blueprints
$48.99
Raspberry Pi Android Projects
$38.99
Learning Raspberry Pi
$48.99
Total $ 136.97 Stars icon
Banner background image

Table of Contents

8 Chapters
1. Getting Started with Raspberry Pi Chevron down icon Chevron up icon
2. Developing Web Applications Chevron down icon Chevron up icon
3. Introduction to Electronics Chevron down icon Chevron up icon
4. Getting into Robotics Chevron down icon Chevron up icon
5. Introduction to Image Processing Chevron down icon Chevron up icon
6. Image Processing Algorithms Chevron down icon Chevron up icon
7. Troubleshooting, Tips/Tricks, and Resources for Advanced Users 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 Half star icon 4.7
(3 Ratings)
5 star 66.7%
4 star 33.3%
3 star 0%
2 star 0%
1 star 0%
CWJ Koster Jun 01, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book just takes you a bit further on what you can do with a Raspberry Pi. It is a great way to learn more and generate ideas on what to make with your Raspberry Pi. The subjects are chosen well and give a broad range of projects. Although the projects are simple they are good starting points for staring your own projects. Learning Raspberry Pi is a good book with lots of information to start experimenting even more with your Raspberry Pi.
Amazon Verified review Amazon
Heleen Durston Jun 06, 2015
Full star icon Full star icon Full star icon Full star icon Full star icon 5
“Learning Raspberry Pi” by Samarth Shah is not the introductory book to the Raspberry Pi that you might think from the title. The book is meant for someone who already has some experience with the device and is looking to expand their knowledge of what’s possible. The book assumes that you have a model B Raspberry Pi and the special camera that was designed especially for the Raspberry Pi which you usually have to buy separately. Additional hardware is required to complete some of the exercises in the book. The book begins by explaining how to set-up your Raspberry Pi and use New Out Of the Box Software (NOOBS) to load the Linux operating system on the device. Once this is done all sorts of wonderful things are possible! Each chapter in the book covers different projects that you can complete with your Raspberry Pi (usually some extra pieces of equipment). The second chapter discusses how you can set-up a web server and create web pages with the Python computer language and Wordpress. By the end of the chapter you can have your own music station running from the Raspberry Pi.The third chapter does a brief explanation of basic electronics and then helps you create your own digital clock and finally an actual alarm clock. This all requires extra parts that you would need to purchase separately. On a side note I got my Raspberry Pi in the form of a kit (many of which are available online) that came with several pieces of extra equipment including diodes, resistors, etc. Most of what you need for the clock is contained within that kit.The fourth chapter covers robotics, one of my favorite aspects of having a Raspberry Pi. The projects in this chapter definitely require you to purchase extra equipment including the special Raspberry Pi camera. Three separate projects are created and then these three are combined together to make a robot. Lots of scripting in Python is required to make each part of the robot work.The next chapter is about image processing and some of the amazing things that can be done with the camera and your Raspberry Pi. The OpenCV image processing software is used to let you manipulate pictures that you capture with the camera. You also learn how to take time-lapsed pictures and how to set-up a Twitter controlled camera.Chapter six dives into software algorithms that can help with the image processing. Details are given on how to set-up facial recognition and even object tracking. So your Raspberry Pi can be set-up to be a surveillance camera of sorts. How cool is that?!! All of this takes patience and determination but is achievable with the details provided in the book.The book ends with some tips for using the Raspberry Pi as well as help with common problems that can occur. Resources for more advanced projects are listed and author provides his email address so that you can tell him of any Raspberry Pi problems you may have.This is a very interesting book and is great for someone who has completed a couple of projects from the Raspberry Pi website. Many hours of enjoyment and learning can be had from following the projects provided in this book.
Amazon Verified review Amazon
Dustin Marx Jun 12, 2015
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
"Learning Raspberry Pi" starts with introductory details regarding Raspberry Pi, but quickly broadens and deepens in its coverage. It provides more lower-level details than one might expect in a "Learning..." book."Learning Raspberry Pi" covers subjects as diverse as Linux commands, web development with Python and HTML5 technologies, a nice introduction to electronics, robotics, and two chapters on image processing. I really liked the final chapter's collection of miscellaneous tips and tricks for dealing with common issues one might run into when working with a Raspberry Pi.Although "Learning Raspberry Pi" does provide introductory coverage of these different technologies, it also goes into depth on some of the topics, particularly image processing. On many of the topics, the book provides just enough introductory information to get going on the subject and additional research might be warranted for deeper learning. There are several highly detailed projects that illustrate the covered concepts.The images and screen snapshots in "Learning Raspberry Pi" are clear and helpful in understanding the concepts. The code listings are comprehensive and are black text on white background with no line numbers and no color syntax.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.