Banana Pi Cookbook - Ryad El-Dajani - E-Book

Banana Pi Cookbook E-Book

Ryad El-Dajani

0,0
23,99 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

This book is intended for anybody who wants to learn how they can utilize the capabilities of the Banana Pi to its full potential. It's full of step-by-step guides and detailed descriptions for the whole range of possibilities in a language that is appropriate for computer enthusiasts and experts alike. It would be helpful to have a basic knowledge of Unix-like operating systems or programming, but no prior experience is required as every concept is explained in the appropriate sections.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 233

Veröffentlichungsjahr: 2015

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Banana Pi Cookbook
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
Sections
Getting ready
How to do it…
How it works…
There's more…
See also
Conventions
Reader feedback
Customer support
Downloading the example code
Downloading the color images of this book
Errata
Piracy
eBooks, discount offers, and more
Questions
1. Installation and Setup
Introduction
Banana Pi Overview
Operating systems for the Banana Pi
Android
Linux
Downloading an operating system for the Banana Pi
Getting ready
How to do it…
See also
Setting up the SD card on Windows
Getting ready
How to do it…
Writing an Android image to the SD card on Windows
Writing a Linux distribution image to the SD card on Windows
How it works…
See also
Setting up the SD card on Linux
Getting ready
How to do it…
How it works…
See also
Booting up and shutting down the Banana Pi
Getting ready
How to do it…
Booting up
Shutting down Android
Shutting down Linux
How it works…
See also
2. Administration
Introduction
Determining the IP address and hostname
Getting ready
How to do it…
How it works…
There's more…
Connecting via SSH on Windows using PuTTY
Getting ready
How to do it…
How it works…
There's more…
See also
Connecting via SSH on Unix-like systems
Getting ready
How to do it…
How it works…
There's more…
See also
User maintenance
Getting ready
How to do it…
Adding a new user
Setting a password for a user
Deleting a user
How it works…
There's more…
See also
Searching, installing, and removing the software
Getting ready
How to do it…
Searching for packages
Installing a package
Removing a package
How it works…
There's more…
See also
Updating the operating system
Getting ready
How to do it…
How it works…
There's more…
Wireless network on the Banana Pro
Getting ready
How to do it…
Loading the ap6210 module
Configuring the wireless network with WiFi Config
Configuring the wireless network manually
How it works…
There's more…
3. External Disks
Introduction
Mounting a USB drive
Getting ready
How to do it…
How it works…
There's more…
See also
Mounting an SSD or HDD via SATA
Getting ready
How to do it…
How it works…
Mounting via fstab
Getting ready
How to do it…
How it works…
There's more…
See also
Booting from an external disk
Getting ready
How to do it…
Formatting the drive
Copying the root filesystem and editing uEnv.txt
How it works…
See also
4. Networking
Introduction
Sharing files over the network via Samba
Getting ready
How to do it…
Installing the Samba server
Accessing the Samba share on Windows
Accessing the Samba share on Linux manually
Accessing the Samba share on Linux using fstab
How it works…
There's more…
See also
Setting up a web application
Getting ready
How to do it…
Installing the Nginx web server
Installing the PHP scripting language
Installing the MySQL database server
Installing WordPress
How it works…
There's more…
Setting up PhpMyAdmin
Other technologies
See also
Securing the Nginx web server using SSL
Getting ready
How to do it…
Creating the certificate
Configuring Nginx to use an SSL certificate
How it works…
There's more…
Importing a self-signed certificate on Windows
Importing a self-signed certificate on Linux
See also
Synchronizing files over the Internet
Getting ready
How to do it…
Setting up a Dynamic DNS
Updating the Dynamic DNS hostname
Setting up a port forwarding
Installing ownCloud
How it works…
There's more…
See also
Controlling the desktop remotely using VNC
Getting ready
How to do it…
Installing the VNC server on the Banana Pi
Installing and using a VNC client on Windows
Installing and using a VNC client on Linux
How it works…
There's more…
Adding a SSH tunnel for VNC in PuTTY
Using an SSH tunnel for VNC on Linux
See also
Securing SSH using SSH keys
Getting ready
How to do it…
Using SSH keys in PuTTY
Using SSH keys on Linux
Disabling the SSH password login on the Banana Pi
How it works…
See also
Setting up a UPnP media server
Getting ready
How to do it…
How it works…
There's more…
See also
5. Using the GPIO Pins
Introduction
Lighting up an LED using the gpio command
Getting ready
How to do it…
How it works…
There's more…
The Banana Pi pin layout
The Banana Pro pin layout
Using a GPIO extension board
See also
Programming the LED
Getting ready
How to do it…
Programming the LED with C
Programming the LED with Python
How it works…
Explaining the C code
Explaining the Python code
Using the GPIO input with a pushbutton
Getting ready
How to do it…
Preparing the circuit
Programming the software
How it works…
Explaining the C code
There's more…
See also
6. Multimedia
Introduction
Configuring the audio device
Getting ready
How to do it…
Configuring HDMI pass-through
Configuring analog audio
Testing the audio output
How it works…
There's more…
See also
Getting accelerated video playback
Getting ready
How to do it…
Preparing the building of the required components
Building and activating the hardware-accelerating components
Installing and configuring MPlayer
Installing and configuring VLC media player
How it works…
There's more…
See also
Setting up Kodi
Getting ready
How to do it…
How it works…
There's more…
See also
Setting up an infrared remote control using LIRC
Getting ready
How to do it…
Configuring LIRC to recognize the remote control
Controlling applications using the remote control
How it works…
There's more…
See also
Index

Banana Pi Cookbook

Banana Pi Cookbook

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: June 2015

Production reference: 1240615

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-78355-244-3

www.packtpub.com

Credits

Author

Ryad El-Dajani

Reviewers

José Manuel Cerrejón González

Kenny Hsu

Michał Piątkowski

Commissioning Editor

Priya Singh

Acquisition Editor

Sam Wood

Content Development Editor

Arwa Manasawala

Technical Editor

Pankaj Kadam

Copy Editor

Laxmi Subramanian

Project Coordinator

Shweta H. Birwatkar

Proofreader

Safis Editing

Indexer

Rekha Nair

Production Coordinator

Manu Joseph

Cover Work

Manu Joseph

About the Author

Ryad El-Dajani is a software engineer and passionate technology enthusiast. He developed an interest in computers when he was 10 years old. Soon thereafter, he began to learn his first programming languages.

After he had completed his training as an IT specialist, he worked on several e-commerce Internet projects. Currently, he is studying business computing and works for a big IT company in Germany, realizing various IT projects based on Java or .NET technologies.

Besides the classic application development, he has professional experience in realizing projects based on web frameworks such as Spring, Play, Symfony, eZ Publish, and Magento. Moreover, he has been excited about all kinds of Unix-like embedded systems since the revolutionary SheevaPlug.

I would like to thank my family for their support during the authoring of this book. Special thanks go to my grandpa, Jürgen, and my uncle, Thomas, who introduced me into the world of computers against the wishes of my parents when I was a child.

Furthermore, I would like to thank the Internet community for spreading their knowledge. Without amazing guys like you, I would have never been able to understand and, in the end, write about the complex technologies surrounding us today.

I am particularly grateful to my beloved girlfriend, Marlene. Without her infinite support, patience, understanding, and cooking skills, I would not have been able to complete this project.

About the Reviewers

José Manuel Cerrejón González is a full-stack freelance software developer based in Huelva, Spain, and a Raspberry Pi, Odroid, and Banana Pi enthusiast. Nowadays, he blogs regularly on his own website at http://misapuntesde.com/ in both Spanish and English, and he has compiled a great Raspberry Pi resource on Google Docs at http://goo.gl/Iwhbq.

He has also contributed to the community with a project called PiKISS (Pi Keeping It Simple, Stupid!) that you can download from GitHub (https://github.com/jmcerrejon/PiKISS).

Although this is the first book he has reviewed, he has written other articles for the press, such as ODROID Magazine.

You can follow him on Twitter at https://twitter.com/ulysess10.

To my daughter, Laura: I hope to see your smile every morning for a long time.

Kenny Hsu is a Linux system administrator, database administrator, and web developer who has over 7 years of experience. He has executed projects in a broad range of technologies, including Java, Spring Framework, jQuery, MySQL, MariaDB, Ubuntu, Debian, and so on. He is also an open source contributor. This year, he has written some dev board-related tutorials for beginners (who are interested in Banana Pi, Cubieboard, and OpenWRT router), in Chinese. He is also a native Chinese speaker residing in Taiwan.

Some of the tutorials he wrote earlier this year are as follows:

OpenWRT wr841n mod (https://github.com/annbigbig/wr841nd-memo)Cubian memo (https://github.com/annbigbig/cubian_memo)

If you can speak Chinese, you can interact with him directly in Chinese. He would be very glad to talk to you. You can follow him on Twitter at @annbigbig and you can also e-mail him at <[email protected]>.

This is my first book with Packt Publishing, and I am very glad to meet you.

My dear kitten called PaPa passed away in summer 2013. He was a 17-year-old white Persian kitten, and I will always miss him.

Michał Piątkowski is a young freelancer, who always tries to develop his potential. Although he mainly programs in Java, he is also interested in C and C++, especially where microcontrollers are concerned. Moreover, he is fascinated by Banana Pi and Raspberry Pi projects. He devotes his spare time to robotics and electronics. On the Internet, he can be found as Axandar or @Axandar29 on Twitter.

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 <[email protected]> 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 PacktCopy and paste, print, and bookmark contentOn 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.

Preface

Packed with recipes for the Banana Pi, solving the most common real-world problems, viewers get a practical assistance to avoid difficulties.

Full of supportive guides, this book is designed to help you build and expand your device into a versatile box. Any computer enthusiast can quickly learn how to become a Banana Pi expert, while not requiring skills in programming or Linux. Banana Pi Cookbook will allow you to use the technology start from the very beginning, through the daily usage and maintenance, up to setting up a WordPress from scratch, sharing files using Samba or ownCloud, blinking an LED, or playing 1080p videos.

What this book covers

Chapter 1, Installation and Setup, introduces the Banana Pi device. It also explains which distributions are available and how to download and install a Linux distribution. Moreover, we present Android as a contrast to our upcoming Linux adventure.

Chapter 2, Administration, introduces the reader to the most common tools to administrate their fresh Linux installation. We will connect remotely using SSH from Windows (using PuTTY) and Linux (using the command-line SSH application). Besides user modification (adding a new user, changing passwords, and so on), we will also cover basic maintenance tasks, such as searching and installing a new software, updating the system using the distributions package manager, and so on.

Chapter 3, External Disks, covers all about external disk drives. We will connect and mount USB drives and HDD drives using the SATA interface and explore the possibility of switching the root filesystem to and boot from an external drive.

Chapter 4, Networking, presents recipes for common networking tasks using the Banana Pi. One of the key strengths of the device is the fast Ethernet and wireless (Banana Pro) adapters it provides—especially combined with the fast SATA interface—which is the base of powerful network applications.

Chapter 5, Using the GPIO Pins, introduces the GPIO pins. We will light up an LED using the shell. Furthermore, we will build a simple circuit, including a pull-up resistor and control an LED with a button. To achieve this, we will introduce the C programming language with the WiringPi library and the Python scripting language with the RPi.GPIO library.

Chapter 6, Multimedia, covers configuring the two audio outputs (line out and HDMI). We will discuss and solve the hardware acceleration problem by compiling important components and using these mentioned components to build video players and Kodi. The configuration of a remote control using LIRC is also covered.

What you need for this book

The following is a list of things that you'll need to follow along with the recipes of this book:

A Banana Pi and/or a Banana ProAn SD cardAn SD card readerA 5V USB power supplyA network connection (Ethernet and/or WiFi on Banana Pro)An HDMI or a composite connection for displayA USB keyboard and a mouseA Windows or Linux operating systemAn external HDD/SSD plus a power supply and a SATA connection for Chapter 3, External DisksA breadboard and various electrical components for Chapter 5, Using the GPIO Pins

Who this book is for

This book is intended for anybody who wants to learn how they can utilize the capabilities of the Banana Pi to its full potential. It's full of step-by-step guides and detailed descriptions for the whole range of possibilities in a language that is appropriate for computer enthusiasts and experts alike. It would be helpful to have a basic knowledge of Unix-like operating systems or programming, but no prior experience is required as every concept is explained in the appropriate sections.

Sections

In this book, you will find several headings that appear frequently (Getting ready, How to do it, How it works, There's more, and See also).

To give clear instructions on how to complete a recipe, we use these sections as follows:

Getting ready

This section tells you what to expect in the recipe, and describes how to set up any software or any preliminary settings required for the recipe.

How to do it…

This section contains the steps required to follow the recipe.

How it works…

This section usually consists of a detailed explanation of what happened in the previous section.

There's more…

This section consists of additional information about the recipe in order to make the reader more knowledgeable about the recipe.

See also

This section provides helpful links to other useful information for the recipe.

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: "The commands used in the next steps assume that your SD card is recognized as /dev/mmcblk0."

A block of code is set as follows:

allow-hotplug wlan0 iface wlan0 inet manual wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

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

$ sudo cp interfaces interfaces.backup

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: "Choose the write mode Startup and click on Format to Normal."

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 <[email protected]>, 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 a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files from your account at http://www.packtpub.com for all the Packt Publishing books you have purchased. If you purchased this book elsewhere, you can visit http://www.packtpub.com/support and register to have the files e-mailed directly to you.

Downloading the color images of this book

We also provide you with a PDF file that has color images of the screenshots/diagrams used in this book. The color images will help you better understand the changes in the output. You can download this file from https://www.packtpub.com/sites/default/files/downloads/2443OS_ColorImages.pdf.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you could report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/submit-errata, selecting your book, clicking on the Errata Submission Form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded to our website or added to any list of existing errata under the Errata section of that title.

To view the previously submitted errata, go to https://www.packtpub.com/books/content/support and enter the name of the book in the search field. The required information will appear under the Errata section.

Piracy

Piracy of copyrighted material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works in any form on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at <[email protected]> with a link to the suspected pirated material.

We appreciate your help in protecting our authors and our ability to bring you valuable content.

eBooks, discount offers, and more

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 <[email protected]> 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.

Questions

If you have a problem with any aspect of this book, you can contact us at <[email protected]>, and we will do our best to address the problem.

Chapter 1. Installation and Setup

This chapter will cover the following recipes:

Downloading an operating system for the Banana PiSetting up the SD card on WindowsSetting up the SD card on LinuxBooting up and shutting down the Banana Pi

Introduction

The Banana Pi is a single-board computer, which enables you to build your own individual and versatile system. In fact, it is a complete computer, including all the required elements such as a processor, memory, network, and other interfaces, which we are going to explore. It provides enough power to run even relatively complex applications suitably.

In this chapter, we are going to get to know the Banana Pi device. The available distributions are mentioned, as well as how to download and install these distributions. We will also examine Android in contrast to our upcoming Linux adventure.

Thus, you are going to transform your little piece of hardware into a functional, running computer with a working operating system. You will master the whole process of doing the required task from connecting the cables, choosing an operating system, writing the image to an SD card, and successfully booting up and shutting down your device for the first time.

Banana Pi Overview

In the following picture, you see a Banana Pi on the left-hand side and a Banana Pro on the right-hand side:

As you can see, there are some small differences that we need to notice. The Banana Pi provides a dedicated composite video output besides the HDMI output. However, with the Banana Pro, you can connect your display via composite video output using a four-pole composite audio/video cable on the jack.

In contrast to the Banana Pi, which has 26 pin headers, the Banana Pro provides 40 pins. Also the pins for the UART port interface are located below the GPIO headers on the Pi, while they are located besides the network interface on the Pro.

The other two important differences are not clearly visible on the previous picture. The operating system for your device comes in the form of image files that need to be written (burned) to an SD card. The Banana Pi uses normal SD cards while the Banana Pro will only accept Micro SD cards. Moreover, the Banana Pro provides a Wi-Fi interface already on board. Therefore, you are also able to connect the Banana Pro to your wireless network, while the Pi would require an external wireless USB device.

Besides the mentioned differences, the devices are very similar. You will find the following hardware components and interfaces on your device.

On the back side, you will find:

A20 ARM Cortex-A7 dual core central processing unit (CPU)ARM Mali400 MP2 graphics processing unit (GPU)1 gigabyte of DDR3 memory (that is shared with the GPU)

On the front side, you will find:

Ethernet network interface adapterTwo USB 2.0 portsA 5V micro USB power with DC in and a micro USB OTG portA SATA 2.0 port and SATA power outputVarious display outputs [HDMI, LVDS, and composite (integrated into jack on the Pro)]A CSI camera input connectorAn infrared (IR) receiverA microphoneVarious hardware buttons on board (power key, reset key, and UBoot key)Various LEDs (red for power status, blue for Ethernet status, and green for user defined)

As you can see, you have a lot of opportunities for letting your device interact with various external components. In the upcoming chapters, we are going to explore most of the possibilities in detail.

Operating systems for the Banana Pi

The Banana Pi is capable of running any operating system that supports the ARM Cortex-A7 architecture. There are several operating systems precompiled, so you are able to write the operating system to an SD card and boot your system flawlessly. Currently, there are the following operating systems provided officially byLeMaker, the manufacturer of the Banana Pi.

Android

Android is a well-known operating system for mobile phones, but it is also runnable on various other devices such as smart watches, cars, and, of course, single-board computers such as the Banana Pi.

The main advantage of running Android on a single-board computer is its convenience. Anybody who uses an Android-based smartphone will recognize the graphical user interface (GUI) and may have less initial hurdles. Also, setting up a media center might be easier to do on Android than on a Linux-based system.

However, there are also a few disadvantages, as you are limited to software that is provided by an Android store such as Google Play. As most apps are optimized for mobile use at the moment, you will not find a lot of usable software for your Banana Pi running Android, except some Games and Multimedia applications. Moreover, you are required to use special Windows software called PhoenixCard to be able to prepare an Android SD card.

Because of the mentioned disadvantages, this book will show you how to get Android up and running, but focus on Linux-based distributions in the next chapters.

Linux

Most of the Linux users never realize that they are actually using Linux when operating their phones, appliances, routers, and many more products, as most of its magic happens in the background. We are going to dig into this adventure to discover its possibilities when running on our Banana Pi device.

The following Linux-based operating systems—so-called distributions—are used by the majority of the Banana Pi user base and are supported officially by the manufacturer:

Lubuntu: This is a lightweight distribution based on the well-known Ubuntu using the LXDE desktop, which is principally a good choice, if you are a Windows user.Raspbian: This is a distribution based on Debian, which was initially produced for the Raspberry Pi (hence the name). As a lot of Raspberry Pi owners are running Raspbian on their devices while also experimenting with the Banana Pi, LeMaker ported the original Raspbian distribution to the Banana Pi. Raspbian also comes with an LXDE desktop by default.Bananian: This too is a Debian-based Linux distribution optimized exclusively for the Banana Pi and its siblings.

All of the aforementioned distributions are based on the well-known distribution, Debian. Besides the huge user base, all Debian-based distributions use the same package manager Apt (Advanced Packaging Tool) to search for and install new software, and all are similar to use. In the upcoming recipes, we are going to use Raspbian. However, most recipes will be valid for the other Debian-based distributions.

There are still more distributions that are officially supported by LeMaker, such as Berryboot, LeMedia, OpenSUSE, Fedora, Gentoo, Scratch, ArchLinux, Open MediaVault, and OpenWrt. All of them have their pros and cons or their specific use cases. If you are an experienced Linux user, you may choose your preferred distribution from the mentioned list, as most of the recipes in this book are similar to, or even equally usable on, most of the Linux-based operating systems.