0% found this document useful (0 votes)
22 views77 pages

Get (Ebook) Introduction to IoT with Machine Learning and Image Processing using Raspberry Pi by Shrirang Ambaji Kulkarni, Varadrah P. Gurupur, Steven L. Fernandes ISBN 9781138543522, 1138543527 free all chapters

The document promotes the ebook 'Introduction to IoT with Machine Learning and Image Processing using Raspberry Pi' by Shrirang Ambaji Kulkarni and others, detailing its focus on utilizing Raspberry Pi for applications in machine learning and image processing. It outlines the book's structure, including chapters on Raspberry Pi fundamentals, Python programming, machine learning, and image processing, aimed at enhancing usability in various fields such as healthcare and security. Additionally, the document provides links to download the ebook and other related titles available on ebooknice.com.

Uploaded by

metzzaina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views77 pages

Get (Ebook) Introduction to IoT with Machine Learning and Image Processing using Raspberry Pi by Shrirang Ambaji Kulkarni, Varadrah P. Gurupur, Steven L. Fernandes ISBN 9781138543522, 1138543527 free all chapters

The document promotes the ebook 'Introduction to IoT with Machine Learning and Image Processing using Raspberry Pi' by Shrirang Ambaji Kulkarni and others, detailing its focus on utilizing Raspberry Pi for applications in machine learning and image processing. It outlines the book's structure, including chapters on Raspberry Pi fundamentals, Python programming, machine learning, and image processing, aimed at enhancing usability in various fields such as healthcare and security. Additionally, the document provides links to download the ebook and other related titles available on ebooknice.com.

Uploaded by

metzzaina
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 77

Visit https://ebooknice.

com to download the full version and


explore more ebooks

(Ebook) Introduction to IoT with Machine Learning


and Image Processing using Raspberry Pi by Shrirang
Ambaji Kulkarni, Varadrah P. Gurupur, Steven L.
Fernandes ISBN 9781138543522, 1138543527
_____ Click the link below to download _____
https://ebooknice.com/product/introduction-to-iot-with-
machine-learning-and-image-processing-using-raspberry-
pi-11380832

Explore and download more ebooks at ebooknice.com


Here are some recommended products that might interest you.
You can download now and explore!

(Ebook) Biota Grow 2C gather 2C cook by Loucas, Jason; Viles, James


ISBN 9781459699816, 9781743365571, 9781925268492, 1459699815,
1743365578, 1925268497

https://ebooknice.com/product/biota-grow-2c-gather-2c-cook-6661374

ebooknice.com

(Ebook) IoT Machine Learning Applications in Telecom, Energy, and


Agriculture: With Raspberry Pi and Arduino Using Python by Puneet
Mathur ISBN 9781484255490, 1484255496

https://ebooknice.com/product/iot-machine-learning-applications-in-
telecom-energy-and-agriculture-with-raspberry-pi-and-arduino-using-
python-50195440
ebooknice.com

(Ebook) Matematik 5000+ Kurs 2c Lärobok by Lena Alfredsson, Hans


Heikne, Sanna Bodemyr ISBN 9789127456600, 9127456609

https://ebooknice.com/product/matematik-5000-kurs-2c-larobok-23848312

ebooknice.com

(Ebook) SAT II Success MATH 1C and 2C 2002 (Peterson's SAT II Success)


by Peterson's ISBN 9780768906677, 0768906679

https://ebooknice.com/product/sat-ii-success-
math-1c-and-2c-2002-peterson-s-sat-ii-success-1722018

ebooknice.com
(Ebook) Natural Language Processing Recipes: Unlocking Text Data with
Machine Learning and Deep Learning Using Python by Akshay Kulkarni,
Adarsha Shivananda ISBN 9781484273500, 1484273508

https://ebooknice.com/product/natural-language-processing-recipes-
unlocking-text-data-with-machine-learning-and-deep-learning-using-
python-34204404
ebooknice.com

(Ebook) Raspberry Pi 3 Cookbook for Python Programmers: Unleash the


potential of Raspberry Pi 3 with over 100 recipes by Tim Cox, Dr.
Steven Lawrence Fernandes ISBN 9781788629874, 1788629876

https://ebooknice.com/product/raspberry-pi-3-cookbook-for-python-
programmers-unleash-the-potential-of-raspberry-pi-3-with-
over-100-recipes-7217158
ebooknice.com

(Ebook) Raspberry Pi Image Processing Programming: With NumPy, SciPy,


Matplotlib, and OpenCV by Ashwin Pajankar ISBN 9781484282694,
1484282698

https://ebooknice.com/product/raspberry-pi-image-processing-
programming-with-numpy-scipy-matplotlib-and-opencv-44512010

ebooknice.com

(Ebook) Natural Language Processing Recipes: Unlocking Text Data with


Machine Learning and Deep Learning Using Python by Akshay Kulkarni,
Adarsha Shivananda ISBN 9781484273517, 9781484273500, 1484273508,
1484273516
https://ebooknice.com/product/natural-language-processing-recipes-
unlocking-text-data-with-machine-learning-and-deep-learning-using-
python-34204734
ebooknice.com

(Ebook) Sensor Projects with Raspberry Pi: Internet of Things and


Digital Image Processing by Guillermo Guillen ISBN 9781484252987,
1484252985

https://ebooknice.com/product/sensor-projects-with-raspberry-pi-
internet-of-things-and-digital-image-processing-23627084

ebooknice.com
Introduction to IoT with
Machine Learning and
Image Processing using
Raspberry Pi
Introduction to IoT with
Machine Learning and
Image Processing using
Raspberry Pi

Shrirang Ambaji Kulkarni


Varadraj P. Gurupur
Steven L. Fernandes
MATLAB® is a trademark of The MathWorks, Inc. and is used with permission. The MathWorks
does not warrant the accuracy of the text or exercises in this book. This book’s use or discussion of
MATLAB® software or related products does not constitute endorsement or sponsorship by The
MathWorks of a particular pedagogical approach or particular use of the MATLAB® software.
First edition published 2020
by CRC Press
6000 Broken Sound Parkway NW, Suite 300, Boca Raton, FL 33487-2742
and by CRC Press
2 Park Square, Milton Park, Abingdon, Oxon, OX14 4RN
© 2020 Taylor & Francis Group, LLC
CRC Press is an imprint of Taylor & Francis Group, LLC
International Standard Book Number-13: 978-1-138-54352-2 (Hardback)
International Standard Book Number-13: 978-1-351-00666-8 (eBook)

Reasonable efforts have been made to publish reliable data and information, but the author and
publisher cannot assume responsibility for the validity of all materials or the consequences of their
use. The authors and publishers have attempted to trace the copyright holders of all material
reproduced in this publication and apologize to copyright holders if permission to publish in this
form has not been obtained. If any copyright material has not been acknowledged please write and
let us know so we may rectify in any future reprint.
Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced,
transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or
hereafter invented, including photocopying, microfilming, and recording, or in any information
storage or retrieval system, without written permission from the publishers.
For permission to photocopy or use material electronically from this work, access www.copyright.com
or contact the Copyright Clearance Center, Inc. (CCC), 222 Rosewood Drive, Danvers, MA 01923, 978-
750-8400. For works that are not available on CCC please contact [email protected]
Trademark notice: Product or corporate names may be trademarks or registered trademarks, and
are used only for identification and explanation without intent to infringe.
Contents

Authors, vii

CHAPTER 1 ■ Introduction 1

CHAPTER 2 ■ Raspberry Pi Unraveled 7

CHAPTER 3 ■ Python and Its Libraries for Machine Learning 19

CHAPTER 4 ■ Machine Learning 81

CHAPTER 5 ■ Introduction to Image Processing 125

BIBLIOGRAPHY, 151

INDEX, 153

v
Authors

Dr. Shrirang Ambaji Kulkarni is a prolific learner, author, and faculty


member with 18-plus years of experience in the field of Computer Science
and Engineering. He is currently working as an Associate Professor at
the National Institute of Engineering in the Department of Computer
Science and Engineering, Mysore, India.

Dr. Varadraj P. Gurupur is an distinguished faculty member and


researcher in the field of Health Informatics. He has authored many
research articles in reputed journals. He is currently working as an
Associate Professor at the University of Central Florida in the Department
of Health Informatics, Florida, USA.

Dr. Steven Lawrence Fernandes is a high-profile researcher in the field


of Image Processing. He is currently working as Post-Doctoral Fellow at
the University of Central Florida in the Department of Computer Science
and Engineering, Florida, USA.

vii
CHAPTER 1

Introduction

I n the last three decades, technology has changed the way we live our
lives. This happens to be a universally accepted truth. In this book, we
attempt to illustrate the use of a new technology that has changed the
world of communication, computing and computing education. Interest-
ingly, the name of this technology coincides with that of a famous dessert
named Raspberry Pie. Raspberry Pi is a single board computer developed
in the United Kingdom. Incidentally, the organization that started this is
known as the Raspberry Pi Foundation. This was first launched in
the year 2012.
By the year 2015, Raspberry Pi had gained wide-scale popularity. One of
the key features of this technology was its size and adaptability. In some
strange ways, Raspberry Pi was the panacea the world of technology was
dreaming of. To build on this idea of a tiny computer, one must consider
the fact that more than a decade ago you would have computer programs
running on desktops wired to electromechanical systems that would use
them. The advent of the Raspberry Pi enables the community of technology
developers to innovate handheld devices than can encompass the power of
regular computers. Our intention in writing this book is twofold: a) we
want to provide a basic understanding of how a Raspberry Pi can be used
for simple applications, and b) we want to provide fundamental informa-
tion on how a Raspberry Pi can be used to advance innovations in machine
learning and image recognition.
While providing fundamental information on Raspberry Pi, we will
help students comprehend the necessary information required to develop

1
2 ■ IoT using Raspberry Pi

applications and devices. These devices and applications can have a wide
range of applications such as networking devices, using devices and
applications related to privacy and security, creating medical applications
and developing sensors. The authors believe that this range of applica-
tions will help the scientific community adapt Raspberry Pi for use in
some of their projects and thereby enhance its usability.
Additionally, the authors are attempting to present information on
how Raspberry Pi can successfully implement machine learning and
image processing. The information presented in this book will help the
community of researchers synthesize new scientific methods, algo-
rithms, devices and other forms of technology into a wide range of
application domains. The authors envision Raspberry Pi advancing the
development of science and technology across various user domains
such as medicine, security, communication, and the military. Last but
not least, it is our attempt to have this book used as study material for
courses teaching students about using Raspberry Pi. It is our under-
standing that Raspberry Pi can be used extensively in healthcare informa-
tion systems.
In this book, the authors present a transformative interdisciplinary
perspective of Raspberry Pi usage. This idea is based on the philosophy of
transformative transdisciplinary perspective presented by the founding
fathers of Society for Design and Process Science [1]. This philosophy is
based on bringing about a positive transformative change to one domain
by making changes or improvements in another. This philosophy is
applicable to Raspberry Pi because rapid improvements in Raspberry Pi
and its applicability will facilitate and create a rostrum for improvements
in all the domains in which this device can be used. One example will be
the implementation of machine learning algorithms that can aid image
processing. In this book, the authors have dwelled on some of the
fundamental programming concepts that are needed for image analysis
and machine learning. This is another very important reason this book is
needed for its targeted audience.
While we engage ourselves in recognizing the importance of the Rasp-
berry Pi, it is also important to note that Raspberry Pi has competitors or
alternatives available in the market. A brief summary of these alternatives is
listed in Table 1.1.
This book is divided into five chapters. The first chapter provides some
introductory material on Raspberry Pi and a brief introduction to the
Introduction ■ 3

TABLE 1.1 A List of Raspberry Pi Alternatives Available as of 2019 [2]


Raspberry Pi Model Brief Description

Odroid XU4 Compatible with a few prominent versions of Linux operating


system and comparable to Raspberry Pi 3
UDOO Bolt Works well with desktop applications
ASUS Tinker Board Works with versions of Linux operating system and Chrome
LattePanda Alpha Unlike many alternatives; supports windows 10 and uses an
Intel Core M3 processor
Banana Pi M64 Works with a wider range of operating systems
RockPro 64 A powerful 64 bit CPU
BeagleBone Black Developed by Texas Instruments in collaboration with
Newark element 14
Libre Computer AML- Suitable for image processing
S905X-CC Le Potato
MinnowBoard Turbot Its small size and affordability make it a viable competitor for
the Raspberry Pi.
Odroid H2 Suitable for game streaming and video applications
Arduino Useful for applications involving robotics

authors. The second chapter explains different types of Raspberry Pis and
provides the reader with important information on the slots and other
necessary elements of the Raspberry Pi. An explanation on these elements
or parts is essential from a usability perspective. It also provides instruc-
tions on installing the operating system Raspbian [3] on Raspberry Pi.
Additionally, it provides some information on peripheral devices and the
ways in which they can be used with the Raspberry Pi.
The importance of using Raspbian dwells in the idea that installing and
using this operating system is a necessary step in the synthesis of systems
and applications. Raspbian is a freely available operating system for the
Raspberry Pi. It is important to note that Raspbian is not affiliated with the
Raspberry Pi Foundation. Raspbian is a community-funded development
effort as was the case in the early days of the Linux operating system.
Interestingly, Raspbian is a Linux distribution built with the Linux operating
system. Raspbian was first released in the year 2012.
The third chapter explains the elements of Python programming [4]
that are essential with respect to using Raspberry Pi. Here the authors
dwell on esoteric programming details that are needed for successful
Raspberry Pi application. These details include matrix operations, Cholesky
4 ■ IoT using Raspberry Pi

decomposition and modifying data frames. It is important to note that


data manipulation and analysis have become critical in today’s world of
artificial intelligence and big data. Raspberry Pi provides the much-
needed hardware for manipulating big data. The authors understand this
need and provide some basic information on the development of systems
for data manipulation using the Raspberry Pi. Chapter 3 contains neces-
sary program snippets with illustrations of expected outcomes. One of the
critical objectives of this illustration is to help the reader with machine
learning application development using the Raspberry Pi. These applica-
tions can be applied to smart phones, wearable devices, farming devices
and other IoT applications.
Chapter 4 dwells on details with respect to programming machine-
learning systems. The authors explore required approaches for splitting
data sets into test and training sets essential for machine learning algo-
rithm implementations. We use health informatics examples to explain
how machine learning can be implemented using the Raspberry Pi. This
chapter provides the reader with necessary information on synthesizing
expert systems, developing knowledge banks and performing knowledge
curation.
Machine learning implementation is explained with several examples,
programing snippets and figures associated with the outcome of their
implementation. Implementation of machine learning is important in
many domains including health informatics, where machine learning
has been extensively used to predict healthcare outcomes and diagnoses
and for genetics and bioinformatics. Machine learning and big data
analytics have been helpful in predicting the early onset of diseases.
Additionally, the possibility of the development of a disease or disorder
later in life can be predicted with the application of bioinformatics
based on the information derived from human genomes. The integra-
tion of Raspberry Pi into portable biomedical devices enhances the
possibility of computation.
Finally, chapter 5 deals with image processing using the Raspberry Pi.
Here the authors provide many program snippets and associated out-
puts, thereby delineating details that are necessary for the reader to use
the device to perform image-processing algorithms. In recent times, it
has been observed that image processing and machine learning associ-
ate well. Thus, the authors provide information on machine learning
and image processing in this book. With the advent of the Raspberry Pi,
Introduction ■ 5

the size of the computational device for image processing is reduced


while at the same time it improved the available computability. This
aids the development and synthesis of real-time sensors in need of
advanced processing.
The authors have extensive experience in research and development
of science and technology. Dr. Shrirang Kulkarni has a Doctoral degree
in Computer Engineering; he started his career in research by exploring
and developing technologies for ad hoc wireless networks. He further
identified other areas of science and technology in which his fundamental
approaches could be used, thereby expanding on the transdisciplinary and
transformative nature of his research. He now works on research projects
that involve using the Raspberry Pi for developing machine learning
techniques for healthcare. Additionally, Dr. Kulkarni has written several
books that have attained national attention in India. It is also important
to mention that he has been involved in teaching engineering students
for the last 18 years.
Dr. Steven Fernandes is a well-accomplished researcher in the area of
Internet of Things (IoT), machine learning, image processing and the
design and development of intelligent systems. He has published more
than 40 articles in reputable journals. Additionally, he has served as
a guest editor for several special issues. Dr. Fernandes has been involved
in teaching engineering students in India and the United States for
about a decade.
Finally, Dr. Varadraj Prabhu Gurupur is currently serving as an
Associate Professor with the Department of Health Management and
Informatics at the University of Central Florida. Dr. Gurupur has more
than 100 publications, including a book, chapters, journal articles,
abstracts, conference papers and published reviews. He has worked on
several projects funded by agencies such as the National Science Foun-
dation and the National Institutes of Health. He has been actively
involved with the Institute of Electrical and Electronic Engineers for
over a decade. Additionally, he has been honored with several national,
regional and state level awards in the United States for his accomplish-
ments in the area of Health Informatics. Dr. Gurupur received his
Master’s in Computer Science in the year 2005 and Doctor of Philoso-
phy in Computer engineering in 2010 from the University of Alabama
at Birmingham.
6 ■ IoT using Raspberry Pi

REFERENCES
[1] Society for Design and Process Science Official Website [Online]. Available:
www.sdpsnet.org/sdps/. Accessed: 09/24/2019.
[2] Electromaker [Online]. Available: www.electromaker.io/blog/article/10-
best-raspberry-pi-alternatives. Accessed: 09/24/2019.
[3] Raspbian [Online]. Available: www.raspbian.org/RaspbianImages
[4] S.A. Kulkarni, Problem Solving and Python Programming, YesDee Publish-
ers, Chennai, India, 2017.
CHAPTER 2

Raspberry Pi Unraveled

2.0 RASPBERRY PI
Raspberry Pi is an Advanced RISC Machines (ARM)-processed, credit-
card sized computer. It was developed by the Raspberry Pi Foundation
in the United Kingdom (UK).

ARM stands for Advanced RISC Machines. The company specia-


lizes in building processors based on Reduced Instruction Set
Computers (RISC) architecture. RISC machines emphasize the
use of registers and smaller instructions and thus can achieve
higher speeds with the ability to execute millions of instructions
per second. The smaller size of ARM processors’ low power
consumption makes them most suitable for miniaturized devices
like the Raspberry Pi.
The latest model (Raspberry Pi 3 B+) uses 1.2 GHz ARM
Cortex – A53 Broadcom BCM 2837 Processor. The significant
difference is the quad-core ARM Cortex A53 (ARMv8) cluster,
which works at 1.2 GHz, making it 50% faster than the Raspberry
Pi 2 model.

2.1 TIMELINE OF RASPBERRY PI MODELS


A brief timeline of various base Raspberry Pi models released to date
follows.

7
8 ■ IoT using Raspberry Pi

Year: 2012 Year: 2013


Model: Raspberry Pi Model B Model: Raspberry Pi Model A
Size: 85.60 mm × 56.5 mm Size: 85.60 mm × 56.5 mm
CPU: ARM1176JZF-S; 32 bit CPU: ARM1176JZF-S 32 bit
GPU: Broadcom VideoCore IV @ 250 MHz GPU: Broadcom VideoCore IV @ 250 MHz
Speed: 700Mhz Single-Core CPU Speed: 700Mhz Single-Core CPU
RAM: 512MB RAM RAM: 256 MB RAM

Year: 2014 Year: 2015


Model: Raspberry Pi Compute model Model: Raspberry Pi Zero
Size: 67.6 mm × 30 mm Size: 65 mm × 30 mm × 5 mm
CPU: ARM1176JZF-S 32 bit CPU: ARM1176JZF-S 32 bit
GPU: Broadcom VideoCore IV @ 250 MHz GPU: Broadcom VideoCore IV @ 250 MHz
Speed: 700Mhz Single-Core CPU Speed: 1 GHz Single-Core CPU
RAM: 512 MB RAM RAM: 512 MB RAM

Latest Raspberry Pi Model


Year: 2018
Model: Raspberry Pi 3 Model B+
Size: 85mm x 56mm x 17mm.
CPU: Cortex-A53 (ARMv8) 64-bit
GPU: Dual Core VideoCore IV GPU@400 MHz
Speed: 1.4GHz 64-bit quad-core ARM Cortex A53 CPU
RAM: 1GB RAM

2.2 COMPONENTS OF A RASPBERRY PI MODEL 3


A brief component layout of Raspberry Pi Model 3 is illustrated in Figure 2.1.
The model we considered in this book is Raspberry Pi 3 V 1.2

2.2.1 General Purpose Input-Output Pins (GPIO) Pins


There are 40 general purpose input-output pins (GPIO) pins on the
Raspberry Pi board as illustrated in Figure 2.2. These pins help the
Raspberry Pi connect to the real world. With the help of these pins,
the Raspberry Pi can help you control physical devices like motors,
extension boards and LEDs.
The pins on the left side of the board are numbered using odd numbers
from 1 to 39; the right side uses even numbers from 2 to 40. The GPIO
pins are numbered in two nomenclatures. One is the GPIO numbering
Raspberry Pi Unraveled ■ 9

FIGURE 2.1 Raspberry Pi Model 3.

FIGURE 2.2 GPIO Pins.

and the other is the physical numbering. The GPIO numbering refers to
the Broadcom numbering on System on Chip, whereas the physical
numbering refers to the 40 pins specified on the Raspberry Pi Board.

2.2.2 Broadcom BCM283 7 64bit ARMv7 Quad Core Processor


At the center of the Raspberry Pi is an ARMv7 Quad Core Processor
with 1GB of RAM, which works at 1.2 GHz. The miniature size of the
processor is noticeable. The Quad-Core nature of the processor at the
rate of 1.2 Ghz makes it 50% faster than the Raspberry Pi 2. Coupled
10 ■ IoT using Raspberry Pi

with GPU, the Raspberry Pi can work wonders in number-crunching


situations.

2.2.3 Micro USB Slot


The Micro USB power connector supplies power to the Raspberry Pi
board. This is illustrated in Figure 2.3.
The Raspberry Pi board is powered by 5v DC supply. To turn the
Raspberry Pi on/off you need to turn this power supply on/off.

2.2.4 High Definition Multimedia Interface (HDMI) Port


The Raspberry Pi provides a high definition multimedia interface
(HDMI) output port. This is illustrated in Figure 2.4.
The HDMI port allows the Raspberry Pi to connect to a monitor. For
monitors that support only o video graphics array (VGA) you need an
HDMI to VGA connector cable. With the support from GPU, the
Raspberry Pi can support 1080p video and that could be truly outputted
from an HDMI port.

2.2.5 Audio Jack


For listening to sound, the Raspberry Pi provides a 3.5 mm audio jack. This
is illustrated in Figure 2.5. You can plug earphones into this audio jack.

FIGURE 2.3 Micro USB Slot.


Raspberry Pi Unraveled ■ 11

FIGURE 2.4 HDMI Port.

FIGURE 2.5 Audio Jack/Port.


12 ■ IoT using Raspberry Pi

2.2.6 Universal Serial Bus (USB) Ports


The Raspberry Pi 3 model provides four universal serial bus (USB)
ports. This is illustrated in Figure 2.6.
The USB ports allow for the connection of a mouse and a keyboard.
However, connecting devices indirectly to the Raspberry Pi through a
USB hub minimizes the power drawn.

2.2.7 Ethernet Socket


The Raspberry Pi provides an Ethernet socket. This is illustrated in Figure 2.7.
The Ethernet cable, with its RJ-45 connector, allows a router to be
connected to the Raspberry Pi. Thus, a router with dynamic host
configuration protocol will allow your Raspberry Pi to connect to the
Internet. However, Raspberry Pi also supports built-in Wi-Fi and Blue-
tooth connectivity.

2.2.8 Micro-SD Card Slot


Raspberry Pi provides an onboard micro-SD card slot. This is illustrated
in Figure 2.8.

FIGURE 2.6 USB Ports.


Raspberry Pi Unraveled ■ 13

FIGURE 2.7 Ethernet Port.

FIGURE 2.8 SD Card Port.


14 ■ IoT using Raspberry Pi

For the Raspberry to boot through its operating system, it needs


the operating system to reside on the SD card. This is essential, as
Raspberry Pi does not have a hard-drive like in a laptop or desktop.

2.3 RASPBIAN OPERATING SYSTEM


The soul of a computer system is its operating system. The preferred
operating system for Raspberry Pi is Raspbian. Raspbian is based on
Debian, which is a Linux-based operating system highly customized for
Raspberry Pi hardware. The popular versions of Raspberry Pi are Wheezy,
which is based on Debian 7, Jessie, which is based on Debian 8, and Stretch,
based on Debian 9. The operating system considered in this book is Jessie.
The Jessie version of Raspberry Pi focused on making the desktop
more comfortable for end users. The LibreOffice suite was included in
the Jessie version. This helps users write documents, prepare PowerPoints
and work with Excel spreadsheets and databases. All of these are compa-
tible with Microsoft Windows. The Jessie version comes bundled with
BlueJ, a Java development environment for beginners, and Scratch, a
programming language for beginners. The graphical user interface pro-
vided for Raspbian is the Lightweight Desktop Environment or LXDE.

2.3.1 Operating Systems Available for Raspberry Pi


Let us discuss some of the operating systems available for Raspberry Pi,
shown in Table 2.1.

2.4 TO CONNECT RASPBERRY PI 3 TO MONITOR


Step 1: Connect a monitor to Raspberry Pi via HDMI and a keyboard
and mouse via a USB.
Step 2: Install an Operating System.
Step 2.1: Use new out-of-box software (NOOBs) available at
(https://www.raspberrypi.org/downloads/).
Step 2.2: Extract the NOOBs downloaded.
Step 2.3: The downloaded NOOBS file must be copied into a
formatted SD card. (SDHC card >2GB and ≤ = 32 GB
follows FAT 32). NOOBs will install Raspbian on the SD
card at the initial boot.
Raspberry Pi Unraveled ■ 15

TABLE 2.1 Operating System supporting Raspberry Pi


Raspbian
• Raspberry Pi Foundation recommended OS
• A very user friendly desktop environment
• Comes with a lot of pre-installed software
LibreELEC
• Designed to support Kodi-powered media center
• Can be paired with the KODI Remote App
• Can build a small home theater
Windows 10 IoT Core
• Provides integration with Visual Studio
• Supports both ARM and X86 architectures
• Supports development of connected devices
RISC OS
• Performance is key and is emphasized by the designers
• Comes with an archived file, which is unto 4MB, a very small size
• Provides better drag-and-drop options

Step 3: raspi-config
$ sudo raspi-config

You will see the following screen (Figure 2.9). Choose the interfacing options.

FIGURE 2.9 Choosing Interfacing Options.


16 ■ IoT using Raspberry Pi

Press Enter to move into an option and arrow keys to move up/down.
Tab to select the options like <finish>.

Step 3.1: Change the user password. The default login is pi and
password is raspberry.
Step 3.2: Enable boot to Desktop.
Step 3.3: Internationalization options
Step 3.3.1: Change-locale: select a language.
Step 3.3.2: Change time zone.
Step 3.3.3: Change keyboard layout. QWERTY is the
default.

Post successful configuration; the Raspberry Pi environment will look as


shown in Figure 2.10.

FIGURE 2.10 Raspberry Pi Desktop.


Raspberry Pi Unraveled ■ 17

2.5 APPLICATIONS OF IOT


According to Gartner[1], by 2020 there will be around 2.6 billion
connected devices. This clearly indicates a potential host of
applications.

1. Smart Home: The Smart Home is the most potent application for
IoT. You can control air conditioners, refrigerators, microwave
ovens, lighting and entertainment systems through IoT-based con-
trol systems.
2. Wearable devices: Monitoring human health parameters like heart-
beat, blood pressure and other vitals is possible through wearable
IoT devices. The constraint on these devices is that they must be
small and energy efficient.
3. Farming: Farmers are at times challenged to monitor crops and
livestock at remote farm areas. Now this is possible through IoT.
Also, detecting diseases of crops and water usage can be controlled
through IoT devices.
4. Industrial IoT: It has been now realized that IoT has a host of
applications across different industries like manufacturing, oil and
gas and energy. IoT helps industries in the automation and optimi-
zation of resources.

EXERCISES
1. Show how to make a headless Raspberry Pi installation.
2. Explain why Secure Shell (SSH) is disabled from Raspberry Pi 3
onwards.
3. What type of file system is preferred on the SD card used for
uploading the Raspberry Pi operating system?
4. Discuss the various operating systems available for Raspberry Pi
along with their advantages and disadvantages.
18 ■ IoT using Raspberry Pi

5. Write a note on the most recent industrial applications of Raspberry


Pi as Industrial IoT.

REFERENCE
[1] Gartner, https://www.gartner.com/en/newsroom/press-releases/2019-08-
29-gartner-says-5-8-billion-enterprise-and-automotive-io, 2019.
CHAPTER 3

Python and Its Libraries


for Machine Learning

3.1 INTRODUCTION
Python is one of the most popular languages for Machine Learning. One
of the dominant reasons for the popularity of Python is its rich support
of libraries (see Table 3.1).

TABLE 3.1 Libraries for Python


Python Library Usage

NumPy Mathematical applications


SciPy Scientifics Computing
Pandas Data Analysis
Matplotib Data Visualization
Scikit-learn Machine Learning

3.2 PYTHON
3.2.1 What Is Python?
• Python was proposed by Guido van Rossum in the late 1980s.
• It is a simple but powerful high-level programming language.
• It supports procedural and object-oriented concepts.
• Python code is interpreted rather than compiled.

19
20 ■ IoT using Raspberry Pi

3.3 A TYPICAL PYTHON PROGRAM

FIGURE 3.1 A Typical Python Program.

FIGURE 3.2 Output of a Typical Python Program.


Python and Its Libraries for Machine Learning ■ 21

Thus, we now see a typical Python program, which computes the


square root of every element of a given matrix. A Python program typically
begins with an import statement. The import statement includes Python
modules that provide a programmer with various library functions. In
the mentioned program we have used library functions like map(),
split() and sqrt(). Python follows strict rules for code indentation.
The inner for loop is indented a few more spaces than the outer for
loop is.

3.4 PYTHON KEYWORDS


Keywords are reserved words and cannot be used as names for identi-
fiers or programmer-defined variables. The keywords are listed in the
keyword module and can be printed as seen in Figure 3.3.

FIGURE 3.3 Python Code to Display Keyword List.

3.5 PYTHON VARIABLE


• A python variable must begin with a letter (a – z, A – B) or
underscore (_) followed by letters, numbers or underscore.
• Python variables are case sensitive.

mean valid variable


1_mean invalid variable
mean_new@ invalid variable
_new_mean valid variable
22 ■ IoT using Raspberry Pi

3.6 COMMENTS IN PYTHON


Python provides two types of comments. This is as shown as comments.
py in Figure 3.4.

FIGURE 3.4 Python Program to Demonstrate Comments.

FIGURE 3.5 Output of comments.py.

In Figure 3.5, we observe that comments are ignored by the Python


interpreter.

3.7 PYTHON DATA TYPES


Variables in Python are typeless. Python supports dynamic typing, and
the variable type is decided at runtime Python data types can be
categorized as shown in Table 3.2.
Python and Its Libraries for Machine Learning ■ 23

TABLE 3.2 Python data types


Python Data Types

Numeric int
long
float
complex
bool
Sequence str
list
tuple
Sets set
frozen set
Mapping dict

To determine the data type of the variable use the type() function in
Python. Python program: datatype.py as illustrated in Figure 3.6.

FIGURE 3.6 Python Program to Demonstrate Different Data Types.


24 ■ IoT using Raspberry Pi

FIGURE 3.7 Output of datatype.py.

3.8 PYTHON OPERATOR PRECEDENCE


The Python operator and precedence are given in Table 3.3.

TABLE 3.3 Python Operator Precedence and Associativity


Operator Highest Associativity
** Right-to-left
~+− Left-to-right
* / % // Left-to-right
+− Left-to-right
>> << Left-to-right
& Left-to-right
^| Left-to-right
<= < > >= Left-to-right
<> == != Left-to-right
= %= /= //= −= += *= **= Right-to-left
is is not Left-to-right
In not in Left-to-right
not or and Lowest Left-to-right
Python and Its Libraries for Machine Learning ■ 25

3.8.1 Evaluate the Following Python Expression


2 + 3 * 4//5 − 17
Step 1: (3*4) = 12
Step 2: 12//5 = 2 (Integer division)
Step 3: 2 + 2 = 4
Step 4: 4−17 = −13
Ans = −13

3.8.2 Evaluate the Following Python Expression


2**3+4//7−6*9
Step 1: (2**3) = 8
Step 2: 4//7 = 0 (Integer division)
Step 3: 6 * 9 = 54
Step 4: 8 + 0 = 8
Step 5: 8−54 = −46
Ans = − 46

3.9 CONDITIONAL CONSTRUCTS IN PYTHON


Conditional constructs are used in Python to take action based on certain
conditions. The conditions can involve comparison expressions or arith-
metic expressions, and their outcome is either True or False.
Structure of IF-ELSE Statement in Python
if condition1:
statement 1
elif condition2:
statement 2
else:
statement 3
26 ■ IoT using Raspberry Pi

Example: Consider the following description


0–1: baby
1–2: toddler
2–12: child
13–17: teenager (14 = early teens)
18 +: adult
Python program:if_elif_stmt.py is illustrated in Figure 3.8.

FIGURE 3.8 Python Program to Demonstrate if elif Statements.

FIGURE 3.9 Output of Python Program if_elif_stmt.py.


Python and Its Libraries for Machine Learning ■ 27

3.10 TERNARY OPERATOR IN PYTHON


The syntax for Python’s ternary operator is as follows.
a if test else b

FIGURE 3.10 Python Program to Demonstrate Use of Ternary Operator.

FIGURE 3.11 Output of Python Program to Demonstrate Ternary Operator.

3.11 LOOPING CONSTRUCTS IN PYTHON


At times when certain statements are to be executed repeatedly, loops
are useful. Thus, the statements are executed continuously until some
conditions are met.

3.11.1 While Loop


A while loop is an entry-controlled loop. Thus, the loop is entered only if
the entry condition is satisfied. There may be a counter that keeps count
of the number of time the loop is executed and finally when a certain
threshold is reached, the loop terminates. The syntax is as follows
28 ■ IoT using Raspberry Pi

while expression:
statement
The while loop iterates as long as the condition is True. The Statement
can be a single statement or block of statements.
Example: Python program while_loop.py as seen in Figure 3.12.

FIGURE 3.12 Python Program to Demonstrate while loop.

FIGURE 3.13 Output of while_loop.py.

3.11.2 For Loop


The for loop in Python iterates over a given range of values. The syntax
of the for loop is as follows
for item in sequence:
print item
Example: Python program – for_loop.py as illustrated in Figure 3.14.
Python and Its Libraries for Machine Learning ■ 29

FIGURE 3.14 Python Program to Demonstrate for_loop.py.

FIGURE 3.15 Output of Python Program for_loop.py.

To perform a similar iteration using the for loop in the reverse


manner, consider the program for_loop_reverse.py.

FIGURE 3.16 Python Program to Demonstrate for loop in the Reverse Manner.
30 ■ IoT using Raspberry Pi

FIGURE 3.17 Output of Python Program for_loop_reverse.py.

3.11.3 Else in Combination with While and For Loop


The else condition with while loop activates when the while entry condition
become False. For example, consider the Python program illustrated in
Figure 3.18.

FIGURE 3.18 Python Program to Demonstrate else in Combination with


while loop.
Python and Its Libraries for Machine Learning ■ 31

FIGURE 3.19 Output of Python Program for else with while loop.
The else statement is clubbed with the for loop in the case in which the
for loop has been exhausted by iterating with all elements in the sequence.
For example, consider the Python program illustrated in Figure 3.20.

FIGURE 3.20 Python Program to Demonstrate else in Combination with for loop.

FIGURE 3.21 Output of Python Program for Else with for loop.
32 ■ IoT using Raspberry Pi

3.12 STRINGS IN PYTHON


Strings are contiguous set of characters enclosed by double quotes in
Python.
Example: “Hello”
“Raju”
The concatenation of two strings is performed with the “+” operator.
Example a = “Good” and b = “Morning”. Then a+ b will give Good Morning.
The operator “in” returns True if the given character is in the string.
The operator “not in” returns True if the given character is not in the
given string. Example G in Good returns True and G not in Morning
returns True.

3.12.1 String Built-in Methods


Following are some of the commonly used string methods

a. len(string) returns the length of the string.


Example: len(“morning”)
Output: 7
b. lower() converts uppercase letters into lowercase.
Example: str= “HELLO”
print str.lower()
Output: hello
c. find() finds whether the string is there in a string or in a substring
of the string.
find(sub, start = 0, end = len(string))
Example: str= “morning”
str.find("r",0,len(str))
Output: 2
d. replace() replaces the old string with a new string and returns the
updated string.
replace(old, new, max_occurrence)
Example: str="Good Morning"
str.replace("Morning", "Evening",1)
Output: 'Good Evening'
Python and Its Libraries for Machine Learning ■ 33

e. split() method provides a way to split a string into small substrings


separated by a delimiter. The output is a list.
Example: str="Winning is everything"
str.split()
Output: ['Winning', 'is', 'everything']

3.13 LIST IN PYTHON


A list is comma-delimited values enclosed in square brackets. Example
lst = ['a', 'b', 'c', 'd']. The Python program list_op.py illustrates in Figure
3.22 an example of list.

FIGURE 3.22 Python Program to Demonstrate an Example of list.

FIGURE 3.23 Output of Python Program list_op.py.

3.13.1 List Methods


• len(list) gives the length of the list.
lst=['a', 'b', 'c', 'd']
34 ■ IoT using Raspberry Pi

len(lst)
Output: 4
• list.reverse() reverses the elements of the list.
lst=['a', 'b', 'c', 'd']
lst.reverse()
lst=['d', 'c', 'b', 'a']
• list.sort() sorts the elements of the list in ascending order.
lst=['d', 'c', 'b', 'a']
lst.sort()
lst= ['a', 'b', 'c', 'd']

3.14 TUPLES IN PYTHON


Tuples are sequences similar to lists except that they are immutable
(i.e., they cannot be changed and they use parentheses). Example tup=
('a', 'b', 'c', 'd')

• len(tuple) gives the length of the tuple.


tup=('a', 'b', 'c', 'd')
len(tup)
4
• max(tuple) returns the max value in a tuple.
tup=(1,2,3,4)
max(tup)
4
• min(tuple) returns the min value of the tuple.
tup=(1,2,3,4)
min(tup)
1

3.15 DICTIONARIES IN PYTHON


Dictionaries are key value pairs separated by “:” and enclosed in curly
braces. Example dict ={'a': 'apple', 'b': 'ball', 'c': 'cat', 'd': 'dog', 'e': 'elephant'}
Python and Its Libraries for Machine Learning ■ 35

3.15.1 Methods on Dictionaries


• dict.items() returns dictionary as key/value pairs.
print dict.items()
[('a', 'apple'), ('c', 'cat'), ('b', 'ball'), ('e', 'elephant'), ('d', 'dog')]
• dict.keys() returns the dictionary’s keys only.
print dict.keys()
['a', 'c', 'b', 'e', 'd']
• dict.values() returns the dictionary’s values only.
print dict.values()
['apple', 'cat', 'ball', 'elephant', 'dog']

3.16 PYTHON FUNCTIONS


A user-defined function in Python is defined with the def keyword.
A function can accept parameters and return a value.

FIGURE 3.24 Python Program to Demonstrate a Function That Can Accept and
Return a Value.

FIGURE 3.25 Output of Python Function Program.


36 ■ IoT using Raspberry Pi

3.17 NUMPY INTRODUCTION


NumPy is an abbreviation that stands for numerical python. It is a
fundamental python package useful for performing data analysis and
supporting machine-learning algorithms. As datasets for machine learning
algorithms come from a variety of sources and follow different formats, it
becomes quite challenging to process the same. These datasets may include
images, text or sound clips. These data sources for processing are visualized
as numerical arrays. Thus, NumPy as a python package supports huge
capabilities for array processing. NumPy also provides the following
functionalities:

• ndarray, which supports high-dimensional arrays with superior


performance capabilities.
• Mathematical functions to support operations on entire arrays as
a single unit.

It provides support for linear algebra operations and allows Python code
to interact with C and C++.
How to use NumPy
The convention is to use NumPy with the command as illustrated in
Figure 3.26.

FIGURE 3.26 Usage of NumPy module.

If you see the above screen, the execution of import numpy as np


resulted in the interpreter prompt ⋙; this means that the NumPy
package is installed correctly.
Random documents with unrelated
content Scribd suggests to you:
I took his advice, accepting at the same time the somewhat
battered silver flask which Bobby lugged out hastily from an inside
pocket. It was full of neat brandy, and, having gulped down a
generous mouthful, I proceeded to give them a compressed but
faithful description of the evening's entertainment. The whole recital
only occupied a short while, for in spite of its amazing nature neither
of them attempted to interrupt me.

"So you see what comes of not keeping your appointments,


Robert," I finished. "The diamonds have gone; here am I with a
cracked collar-bone, and——"

A sudden sound attracted our attention, and we all three turned


round abruptly. Christine was standing at the head of the staircase,
with her hand on the banister. Dressed in an old sailing jersey of
mine, with a pair of white flannel trousers rolled up over her bare
feet and ankles, she presented such a delightfully unexpected
picture that for perhaps a couple of seconds none of us moved or
spoke.

"Let me introduce you," I said. "Christine, this is Bobby, and this


is Inspector Campbell. I have just been telling them how you saved
my life."

She came down the staircase, and with a simultaneous movement


both my companions started forward to meet her. Bobby, however,
arrived first.

"Put it there," he exclaimed, burying her slender hand in his huge


brown fist. "I told Jack he'd got a prize-packet, and, by God! it's the
truth."

Campbell's greeting was a shade more formal

"You're a very gallant young lady, miss, and I'm proud and
honoured to make your acquaintance."
With shining eyes Christine looked from one to the other of them.

"I knew that you wouldn't fail us," she said. Then, coming
towards me, she added eagerly: "But what are we waiting for? Why
don't we start at once?"

I got up from my chair.

"Christine's right," I cried. "How about your launch, Bobby? Has


anything gone wrong with her?"

"Gone wrong with her!" he echoed indignantly. "Of course it


hasn't."

"Then why were you late?" I demanded.

"I was kept for an hour at that cursed office. There was some
Admiralty business that had to be attended to."

Christine turned to him, her face alight with excitement.

"We have still time." she said. "If we can catch them up before
they get to Holland——"

She was interrupted by Campbell.

"She's talking sense, the young lady," he exclaimed. "They can't


be very far ahead of us, and there's twenty thousand pounds reward
if we get the stones."

"It's my uncle's life I'm thinking of," declared Christine


passionately.

Campbell made an obvious effort to appear sympathetic.

"Never fear, miss," he rejoined. "We'll bring him back to you and
the diamonds as well."
"I am coming too," said Christine quietly.

The Inspector stared at her in dismay.

"But, my dear young lady——" he began.

"You may as well save your breath, Campbell," I remarked. "If


three hundred yards of water can't stop Miss de Roda——"

"Why the blazes shouldn't she come?" demanded Bobby


indignantly. "She's got more pluck and grit than all the rest of us put
together."

"Have it your own way," returned Campbell. "I'm thinking there'll


be some bloody work before we get the bracelets on Dr. Manning,
but if you choose to run the risk—" He broke off with a shrug of his
shoulders, and Bobby stepped forward, glancing down at Christine's
bare feet.

"Haven't you got any shoes?" he asked. "You can't go through the
shrubbery like that."

"Yes, I can," she replied. "I've done it already."

"Well, I'm hanged if you'll do it again," he retorted. "You're all cut


about and bleeding as it is. You hop up on my back like a sensible
girl."

He stooped down, and, without making any fuss or protest,


Christine at once accepted the proffered lift.

Campbell's grim eyes watched her appreciatively.

"You stick close to me, Commander," he said. "I'll go ahead of you


with the light, and then you can see where you're putting your feet.
I wouldn't have you drop that lass, not for a twenty pound note."
He produced an electric torch from his pocket, and switching on
the current, led the way out into the garden. Bobby followed, with
Christine on his back, and, just waiting to close the door, I hurried
after them and ranged myself alongside of Campbell.

There was very little mist left, and the moon, although
occasionally obscured by clouds, was now shining brightly. We
passed through the iron gate and entered the shrubbery, where I
showed them the broken wire which had been the cause of my
downfall. Then, step by step, we moved cautiously forward along the
winding path, until a glimmer of light in front of us showed that the
trees were coming to an end.

As we emerged on to the saltings Christine slipped lightly to her


feet.

We could see the launch lying out in the tideway, and a dark
figure, silhouetted sharply against the water, standing on guard over
a small dinghy.

"There's Jenkins!" said Bobby, in a relieved whisper.

At the sound of his voice the sailor wheeled round quickly; and
then, seeing us advancing across the grass, drew himself up to the
salute.

"Anything happened?" enquired Bobby.

"All quiet, sir," came the curt answer.

"In you get," continued Bobby, motioning us towards the dinghy.

He turned to Jenkins, who was moving away to unhitch the


painter.

"We've got to catch that launch, Jenkins," he said, "the one we


saw coming out from the opposite shore. She's making for
Rotterdam, and no matter if we break the blasted engines we're
going to overhaul her before she gets there."

"Very good, sir," returned Jenkins indifferently.

He waited until we had scrambled in, and then, unfastening the


rope, took his place at the oars. Two or three strokes brought us
alongside, where Bobby held the boat steady while we clambered on
board over the low iron railing.

I shepherded Christine and Campbell to the cockpit, and, leaving


them there, lent what assistance I could to the others in the task of
getting under way.

Within five minutes of our feet touching the deck the anchor was
hauled in, and we were heading out into the open estuary, with the
black water rippling past our stern.

Bobby, who had taken the wheel, signalled to me to come aft.

"You'll find a pair of night glasses in the cabin," he observed.


"You'd better go up into the bows and keep a look-out."

I nodded. "If you've got such a thing as a spare gun," I said, "I'll
borrow that too."

"There are a couple of Webleys about somewhere," he replied.


"Ask Jenkins for them and give the other one to Campbell."

I dropped down the narrow hatch, and, having discovered the


glasses, made my way forward to where Jenkins was busy with the
engines. He left them for a moment, to reappear with a brace of
useful-looking revolvers, and thus equipped I crawled back to the
cockpit.

I found Christine and the Inspector sitting side by side, apparently


on the most friendly terms.
"Here you are, Campbell," I said, offering him his choice. "I
promised you a bit of shooting, and the odds are that you'll get it."

With a significant gesture the detective tapped his hip.

"Not for me, thank you," he replied. "If Dr. Manning wants to
argue I've got an old friend here who'll do all the talking that's
necessary."

Christine stretched out her hand.

"I'll take the other one," she announced.

Campbell made an attempt to interfere, but he was too late to be


effective.

"You needn't worry about me," said Christine reassuringly. "I


know how to use a revolver."

"I'm not surprised to hear it, miss," was the answer. "All the
same, if it comes to a shooting match, the proper place for you is in
the cabin."

"He's right, Christine," I added. "For heaven's sake keep under


cover when we run alongside."

She looked up at me eagerly.

"You think we shall catch them, then?"

"Of course we shall," I answered. "It's not likely that they can do
more than twenty, and Bobby can knock nearly forty out of this old
jigger." I squeezed her hand comfortingly in the darkness.

"I'm going up forward now to keep a look-out for them," I


continued. "As soon as you hear me let off a yell you'll know that
they're in sight."
With surprising tact Campbell turned away his head, and, having
taken full advantage of the opportunity, I swung myself up on to the
deck and started off in the direction of the bows.

We were now racing through the water at a tremendous speed,


the whole frail shell quivering and rocking beneath the powerful beat
of the engine. On either side a great rolling wave curved away from
the ship's stern, and behind us a broad wake of white foam gleamed
and tossed in the fitful light of the moon.

I crept forward to the end of the deck, and, crouching down in


the angle of the railing, stared long and steadily through my glasses.

As there was no sign of our quarry it was clear that she was
already round the point. Manning had doubtless seen Bobby's launch
returning up the estuary and had wasted no time in getting away
from "The Laurels" directly he had discovered Christine's flight. At
the lowest computation he must now be at least six miles ahead of
us. Provided the moonlight held, however, he would still be in sight
by the time he reached the bar, and I glanced anxiously at heavy
masses of cloud which were gathering ominously from the south-
east.

On we went, the water becoming rougher every minute as we


forced our way into the trough of the incoming tide.

Bit by bit the coast opened out on our right, until at last we were
almost opposite the big clump of trees which marks the extreme end
of the southern shore.

Clutching the rail to steady myself, I once more raised my glasses.


Then, in a lather of spray and foam, we suddenly shot out into full
view of the sea, and at the same moment a wild, involuntary shout
broke from my lips.

There, not half a mile ahead of us, was the launch. She was lying
broadside on under the full light of the moon, and one glance was
sufficient to show me she had broken down. Even at that distance I
could make out two figures working frantically at the engines and
another huddled shape in the bows.

"We've got 'em!" roared Bobby, above the throb of the pistons.

He spun over the wheel, and, swinging round like a greyhound on


the trail, we leaped seaward straight for our helpless prey.

I found Campbell standing beside me, a revolver gripped in his


hand.

"If there's any sign of trouble," he said quietly, "shoot at once.


You keep your eye on Craill and I'll look after Manning."

I had rather it had been the other way on, but there was no time
for arguing.

Even as he spoke I saw Manning fling down his useless spanner,


and, wiping his hands coolly with a piece of cotton waste, step up
into the stern. Craill followed, his evil, scowling face in strange
contrast to the smiling calm of the other.

Slackening speed at just the right moment, Bobby brought us


alongside with masterly precision.

Campbell leaned forward, his eyes fixed grimly on the pair of


them.

"It's no use, doctor," he said, "your luck's out this time."

With a ghastly sound, half-way between a sob and a scream, the


gaunt figure of de Roda rose suddenly from the deck. A torrent of
Spanish curses burst from his throat, and, dropping the bag of
diamonds which he was still holding, he staggered to the side,
shaking his fists at us in a frenzy of maniacal rage.
I heard a low cry of anguish beside me, and, as I half turned
round, I saw Manning and Craill whip out their revolvers.

I think we must all have fired simultaneously. The only thing I


actually remember is a blinding crash in my head as I pitched
forward against the rails.

*****

For a little while I thought that I was still dreaming. Then the low
murmur of voices became so persistent that at last, with a
tremendous effort, I managed to open my eyes.

"What's that?" I demanded.

There was the scrape of a chair, and the next moment Bobby and
Christine were standing beside the bed.

"It's all right, old lad," said the former soothingly. "We're both
here."

I looked up in bewilderment. I had a vague feeling that I was


back in my cabin on the Neptune and that somehow or other Bobby
ought to be Ross.

"Some blighter pushed me into the dock," I said irritably.

Then, with the same startling abruptness as before, a wave of


memory surged through my aching brain.

"Good Lord!" I cried, starting up. "Where am I? What's


happened?"

Christine sat down beside me, and very tenderly took my hand in
hers.

"You are back on the island, dear, in your own room. There's
nothing to be anxious about or worried over. It's all finished, and we
are just here together—you and I and Bobby."

I let my head sink back on the pillows.

"I remember now," I said. "I stopped a bullet, didn't I? I've a sort
of recollection of seeing a lot of stars, and after that everything's a
blank."

Bobby seated himself on the other side of my couch.

"This is splendid," he remarked. "You'll be asking for a whisky and


soda before we know where we are."

Christine leaned forward and rearranged the pillows.

"Tell me," she whispered, "is your head hurting you very much?"

I put my hand to my forehead and found it encircled by a wet


bandage.

"It's aching a bit," I admitted. "What's the damage? Anything


serious?"

"Well, it was rather a close shave," said Bobby drily. "Manning's


bullet ripped along the side of your skull and knocked you out as
clean as a whistle. A devilish good shot—under the circumstances."

There was a moment's pause.

"Go on, Robert," I said, "you're just getting interesting."

Christine made a faint movement of protest.

"The doctor will be here in a minute. Hadn't we better wait?"

"No, no," I protested. "I must hear what happened."

She glanced across at Bobby.


"Very well, then," she said quietly, "you tell him."

"I don't know if Manning saw you fall," continued Bobby, "but if so
it was the last thing he did see on this earth. We all fired directly he
raised his hand. He got three bullets, one from Christine, one from
Campbell, and one from me. It will be a very interesting point as to
which of us killed him."

"And Craill?" I asked.

"You laid Craill out all right. At the present moment he's in the
Pen Mill Police Station nursing a sick elbow."

For an instant I hesitated. Christine must have guessed my


unspoken question, for when I looked up at her her eyes were wet
with tears.

"We found my uncle lying dead on the deck," she whispered. "Dr.
Ross had always told me that any great shock or excitement——"

Her voice faltered, and, breaking into a pitiful little sob, she buried
her face in her hands.

"My poor darling," I said hoarsely. "I'd have given anything in the
world——"

With a brave effort she raised her head and brushed away the
tears which were running down her cheeks.

"I know," she said, "I know how you feel. I can't help crying, it's
all so sad and terrible, but even if it were possible I don't think I
would wish him to be alive. It nearly broke my heart to see him as
he was. Now at least he is at peace."

She turned to Bobby.


"Don't bother about me," she added. "Just tell him the rest before
the doctor comes."

"There isn't much more to tell," said Bobby quietly. "We towed the
launch to Pen Mill, and Campbell went ashore and rang up the
police. The Head Constable came over at once and brought the
doctor with him. There was the devil of a fuss, as you can imagine.
Fortunately, however, the old boy knew all about Campbell, and after
a lot of jaw we were allowed to bring you back here and put you to
bed. It was nearly midnight by then, and we've been taking turns
sitting up with you ever since."

"What's the time now?" I demanded.

Bobby glanced at his watch.

"Close on twelve."

"And where's Campbell?" I asked.

"He stopped ashore with the police. There's going to be an


inquest on Manning this afternoon, and——"

He was interrupted by a loud ring at the front door bell.

Christine rose quickly.

"It's probably the doctor," she said. "He promised to come over as
soon as he was free."

She motioned Bobby to remain where he was, and, crossing the


room, disappeared into the passage.

"We got the diamonds all right," added Bobby cheerfully.


"Campbell had a squint at them, and he says there are only about a
third missing. He reckons you ought to get at least twenty thousand
out of the Brazilian Government."
"I've had my share," I said. "You and he and Christine can split it
up between you."

"I'll do nothing of the sort," began Bobby indignantly. "If you like
to give Campbell—" He stopped short at the sound of returning
footsteps, and a moment later Christine entered the room.

"A man has called with a message from Mr. Campbell," she said.
"He wants you to go over to the hotel at once."

Bobby got up from the bed.

"Something to do with this infernal inquest I suppose."

He reached for his cap, which was lying on the dressing-table,


and, having patted Christine paternally on the shoulder, walked to
the doorway, where he turned round and surveyed us both.

"So long, my children," he observed. "Settle it for when you like,


but don't forget that I'm to be best man."

*****

For just a second after he had gone we both remained silent.

"I suppose we must let him have his way," I said. "We can't very
well refuse after all he's done for us."

Christine stood looking down at me with a world of love and


tenderness in her eyes.

"I don't know why it is," she said helplessly, "I feel as if I wanted
to laugh and cry at the same time."

I stretched out my hand and drew her down on to the bed beside
me.
"It's only this house, dear heart," I said gently. "As soon as it's all
over we'll go away together and——"

She stopped me with a little gesture.

"But I don't want to go away," she whispered. "I think Greensea


Island is the only place in the world that I was ever really happy in."

I sat up, and, putting my arms around her, pressed my lips to


hers.

"Oh, but your shoulder!" she faltered. "Your poor shoulder! The
doctor said——"

"Hang the doctor," I exclaimed, and with this ungrateful sentiment


I kissed her again.

THE END
*** END OF THE PROJECT GUTENBERG EBOOK GREENSEA ISLAND:
A MYSTERY OF THE ESSEX COAST ***

Updated editions will replace the previous one—the old editions will
be renamed.

Creating the works from print editions not protected by U.S.


copyright law means that no one owns a United States copyright in
these works, so the Foundation (and you!) can copy and distribute it
in the United States without permission and without paying
copyright royalties. Special rules, set forth in the General Terms of
Use part of this license, apply to copying and distributing Project
Gutenberg™ electronic works to protect the PROJECT GUTENBERG™
concept and trademark. Project Gutenberg is a registered trademark,
and may not be used if you charge for an eBook, except by following
the terms of the trademark license, including paying royalties for use
of the Project Gutenberg trademark. If you do not charge anything
for copies of this eBook, complying with the trademark license is
very easy. You may use this eBook for nearly any purpose such as
creation of derivative works, reports, performances and research.
Project Gutenberg eBooks may be modified and printed and given
away—you may do practically ANYTHING in the United States with
eBooks not protected by U.S. copyright law. Redistribution is subject
to the trademark license, especially commercial redistribution.

START: FULL LICENSE


THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK

To protect the Project Gutenberg™ mission of promoting the free


distribution of electronic works, by using or distributing this work (or
any other work associated in any way with the phrase “Project
Gutenberg”), you agree to comply with all the terms of the Full
Project Gutenberg™ License available with this file or online at
www.gutenberg.org/license.

Section 1. General Terms of Use and


Redistributing Project Gutenberg™
electronic works
1.A. By reading or using any part of this Project Gutenberg™
electronic work, you indicate that you have read, understand, agree
to and accept all the terms of this license and intellectual property
(trademark/copyright) agreement. If you do not agree to abide by all
the terms of this agreement, you must cease using and return or
destroy all copies of Project Gutenberg™ electronic works in your
possession. If you paid a fee for obtaining a copy of or access to a
Project Gutenberg™ electronic work and you do not agree to be
bound by the terms of this agreement, you may obtain a refund
from the person or entity to whom you paid the fee as set forth in
paragraph 1.E.8.

1.B. “Project Gutenberg” is a registered trademark. It may only be


used on or associated in any way with an electronic work by people
who agree to be bound by the terms of this agreement. There are a
few things that you can do with most Project Gutenberg™ electronic
works even without complying with the full terms of this agreement.
See paragraph 1.C below. There are a lot of things you can do with
Project Gutenberg™ electronic works if you follow the terms of this
agreement and help preserve free future access to Project
Gutenberg™ electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the
Foundation” or PGLAF), owns a compilation copyright in the
collection of Project Gutenberg™ electronic works. Nearly all the
individual works in the collection are in the public domain in the
United States. If an individual work is unprotected by copyright law
in the United States and you are located in the United States, we do
not claim a right to prevent you from copying, distributing,
performing, displaying or creating derivative works based on the
work as long as all references to Project Gutenberg are removed. Of
course, we hope that you will support the Project Gutenberg™
mission of promoting free access to electronic works by freely
sharing Project Gutenberg™ works in compliance with the terms of
this agreement for keeping the Project Gutenberg™ name associated
with the work. You can easily comply with the terms of this
agreement by keeping this work in the same format with its attached
full Project Gutenberg™ License when you share it without charge
with others.

1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside the
United States, check the laws of your country in addition to the
terms of this agreement before downloading, copying, displaying,
performing, distributing or creating derivative works based on this
work or any other Project Gutenberg™ work. The Foundation makes
no representations concerning the copyright status of any work in
any country other than the United States.

1.E. Unless you have removed all references to Project Gutenberg:

1.E.1. The following sentence, with active links to, or other


immediate access to, the full Project Gutenberg™ License must
appear prominently whenever any copy of a Project Gutenberg™
work (any work on which the phrase “Project Gutenberg” appears,
or with which the phrase “Project Gutenberg” is associated) is
accessed, displayed, performed, viewed, copied or distributed:
This eBook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this eBook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.

1.E.2. If an individual Project Gutenberg™ electronic work is derived


from texts not protected by U.S. copyright law (does not contain a
notice indicating that it is posted with permission of the copyright
holder), the work can be copied and distributed to anyone in the
United States without paying any fees or charges. If you are
redistributing or providing access to a work with the phrase “Project
Gutenberg” associated with or appearing on the work, you must
comply either with the requirements of paragraphs 1.E.1 through
1.E.7 or obtain permission for the use of the work and the Project
Gutenberg™ trademark as set forth in paragraphs 1.E.8 or 1.E.9.

1.E.3. If an individual Project Gutenberg™ electronic work is posted


with the permission of the copyright holder, your use and distribution
must comply with both paragraphs 1.E.1 through 1.E.7 and any
additional terms imposed by the copyright holder. Additional terms
will be linked to the Project Gutenberg™ License for all works posted
with the permission of the copyright holder found at the beginning
of this work.

1.E.4. Do not unlink or detach or remove the full Project


Gutenberg™ License terms from this work, or any files containing a
part of this work or any other work associated with Project
Gutenberg™.

1.E.5. Do not copy, display, perform, distribute or redistribute this


electronic work, or any part of this electronic work, without
prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the Project
Gutenberg™ License.

1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if you
provide access to or distribute copies of a Project Gutenberg™ work
in a format other than “Plain Vanilla ASCII” or other format used in
the official version posted on the official Project Gutenberg™ website
(www.gutenberg.org), you must, at no additional cost, fee or
expense to the user, provide a copy, a means of exporting a copy, or
a means of obtaining a copy upon request, of the work in its original
“Plain Vanilla ASCII” or other form. Any alternate format must
include the full Project Gutenberg™ License as specified in
paragraph 1.E.1.

1.E.7. Do not charge a fee for access to, viewing, displaying,


performing, copying or distributing any Project Gutenberg™ works
unless you comply with paragraph 1.E.8 or 1.E.9.

1.E.8. You may charge a reasonable fee for copies of or providing


access to or distributing Project Gutenberg™ electronic works
provided that:

• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”

• You provide a full refund of any money paid by a user who


notifies you in writing (or by e-mail) within 30 days of receipt
that s/he does not agree to the terms of the full Project
Gutenberg™ License. You must require such a user to return or
destroy all copies of the works possessed in a physical medium
and discontinue all use of and all access to other copies of
Project Gutenberg™ works.

• You provide, in accordance with paragraph 1.F.3, a full refund of


any money paid for a work or a replacement copy, if a defect in
the electronic work is discovered and reported to you within 90
days of receipt of the work.

• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.

1.E.9. If you wish to charge a fee or distribute a Project Gutenberg™


electronic work or group of works on different terms than are set
forth in this agreement, you must obtain permission in writing from
the Project Gutenberg Literary Archive Foundation, the manager of
the Project Gutenberg™ trademark. Contact the Foundation as set
forth in Section 3 below.

1.F.

1.F.1. Project Gutenberg volunteers and employees expend


considerable effort to identify, do copyright research on, transcribe
and proofread works not protected by U.S. copyright law in creating
the Project Gutenberg™ collection. Despite these efforts, Project
Gutenberg™ electronic works, and the medium on which they may
be stored, may contain “Defects,” such as, but not limited to,
incomplete, inaccurate or corrupt data, transcription errors, a
copyright or other intellectual property infringement, a defective or
damaged disk or other medium, a computer virus, or computer
codes that damage or cannot be read by your equipment.

1.F.2. LIMITED WARRANTY, DISCLAIMER OF DAMAGES - Except for


the “Right of Replacement or Refund” described in paragraph 1.F.3,
the Project Gutenberg Literary Archive Foundation, the owner of the
Project Gutenberg™ trademark, and any other party distributing a
Project Gutenberg™ electronic work under this agreement, disclaim
all liability to you for damages, costs and expenses, including legal
fees. YOU AGREE THAT YOU HAVE NO REMEDIES FOR
NEGLIGENCE, STRICT LIABILITY, BREACH OF WARRANTY OR
BREACH OF CONTRACT EXCEPT THOSE PROVIDED IN PARAGRAPH
1.F.3. YOU AGREE THAT THE FOUNDATION, THE TRADEMARK
OWNER, AND ANY DISTRIBUTOR UNDER THIS AGREEMENT WILL
NOT BE LIABLE TO YOU FOR ACTUAL, DIRECT, INDIRECT,
CONSEQUENTIAL, PUNITIVE OR INCIDENTAL DAMAGES EVEN IF
YOU GIVE NOTICE OF THE POSSIBILITY OF SUCH DAMAGE.

1.F.3. LIMITED RIGHT OF REPLACEMENT OR REFUND - If you


discover a defect in this electronic work within 90 days of receiving
it, you can receive a refund of the money (if any) you paid for it by
sending a written explanation to the person you received the work
from. If you received the work on a physical medium, you must
return the medium with your written explanation. The person or
entity that provided you with the defective work may elect to provide
a replacement copy in lieu of a refund. If you received the work
electronically, the person or entity providing it to you may choose to
give you a second opportunity to receive the work electronically in
lieu of a refund. If the second copy is also defective, you may
demand a refund in writing without further opportunities to fix the
problem.

1.F.4. Except for the limited right of replacement or refund set forth
in paragraph 1.F.3, this work is provided to you ‘AS-IS’, WITH NO
OTHER WARRANTIES OF ANY KIND, EXPRESS OR IMPLIED,
INCLUDING BUT NOT LIMITED TO WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR ANY PURPOSE.

1.F.5. Some states do not allow disclaimers of certain implied


warranties or the exclusion or limitation of certain types of damages.
If any disclaimer or limitation set forth in this agreement violates the
law of the state applicable to this agreement, the agreement shall be
interpreted to make the maximum disclaimer or limitation permitted
by the applicable state law. The invalidity or unenforceability of any
provision of this agreement shall not void the remaining provisions.

1.F.6. INDEMNITY - You agree to indemnify and hold the Foundation,


the trademark owner, any agent or employee of the Foundation,
anyone providing copies of Project Gutenberg™ electronic works in
accordance with this agreement, and any volunteers associated with
the production, promotion and distribution of Project Gutenberg™
electronic works, harmless from all liability, costs and expenses,
including legal fees, that arise directly or indirectly from any of the
following which you do or cause to occur: (a) distribution of this or
any Project Gutenberg™ work, (b) alteration, modification, or
additions or deletions to any Project Gutenberg™ work, and (c) any
Defect you cause.

Section 2. Information about the Mission


of Project Gutenberg™
Project Gutenberg™ is synonymous with the free distribution of
electronic works in formats readable by the widest variety of
computers including obsolete, old, middle-aged and new computers.
It exists because of the efforts of hundreds of volunteers and
donations from people in all walks of life.

Volunteers and financial support to provide volunteers with the


assistance they need are critical to reaching Project Gutenberg™’s
goals and ensuring that the Project Gutenberg™ collection will
remain freely available for generations to come. In 2001, the Project
Gutenberg Literary Archive Foundation was created to provide a
secure and permanent future for Project Gutenberg™ and future
generations. To learn more about the Project Gutenberg Literary
Archive Foundation and how your efforts and donations can help,
see Sections 3 and 4 and the Foundation information page at
www.gutenberg.org.

Section 3. Information about the Project


Gutenberg Literary Archive Foundation
The Project Gutenberg Literary Archive Foundation is a non-profit
501(c)(3) educational corporation organized under the laws of the
state of Mississippi and granted tax exempt status by the Internal
Revenue Service. The Foundation’s EIN or federal tax identification
number is 64-6221541. Contributions to the Project Gutenberg
Literary Archive Foundation are tax deductible to the full extent
permitted by U.S. federal laws and your state’s laws.

The Foundation’s business office is located at 809 North 1500 West,


Salt Lake City, UT 84116, (801) 596-1887. Email contact links and up
to date contact information can be found at the Foundation’s website
and official page at www.gutenberg.org/contact

Section 4. Information about Donations to


the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission of
increasing the number of public domain and licensed works that can
be freely distributed in machine-readable form accessible by the
widest array of equipment including outdated equipment. Many
small donations ($1 to $5,000) are particularly important to
maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws regulating


charities and charitable donations in all 50 states of the United
States. Compliance requirements are not uniform and it takes a
considerable effort, much paperwork and many fees to meet and
keep up with these requirements. We do not solicit donations in
locations where we have not received written confirmation of
compliance. To SEND DONATIONS or determine the status of
compliance for any particular state visit www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states where


we have not met the solicitation requirements, we know of no
prohibition against accepting unsolicited donations from donors in
such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot make


any statements concerning tax treatment of donations received from
outside the United States. U.S. laws alone swamp our small staff.

Please check the Project Gutenberg web pages for current donation
methods and addresses. Donations are accepted in a number of
other ways including checks, online payments and credit card
donations. To donate, please visit: www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could be
freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose network of
volunteer support.
Project Gutenberg™ eBooks are often created from several printed
editions, all of which are confirmed as not protected by copyright in
the U.S. unless a copyright notice is included. Thus, we do not
necessarily keep eBooks in compliance with any particular paper
edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg Literary
Archive Foundation, how to help produce our new eBooks, and how
to subscribe to our email newsletter to hear about new eBooks.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebooknice.com

You might also like