0% found this document useful (0 votes)
2 views

Python Programming Recipes For Iot Applications Jivan S Parab download

Ebook

Uploaded by

tenerufret0s
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)
2 views

Python Programming Recipes For Iot Applications Jivan S Parab download

Ebook

Uploaded by

tenerufret0s
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/ 91

Python Programming Recipes For Iot Applications

Jivan S Parab download

https://ebookbell.com/product/python-programming-recipes-for-iot-
applications-jivan-s-parab-50499156

Explore and download more ebooks at ebookbell.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Applying Math With Python Practical Recipes For Solving Computational


Math Problems Using Python Programming And Its Libraries Sam Morley

https://ebookbell.com/product/applying-math-with-python-practical-
recipes-for-solving-computational-math-problems-using-python-
programming-and-its-libraries-sam-morley-49184402

Applying Math With Python Practical Recipes For Solving Computational


Math Problems Using Python Programming And Its Libraries Sam Morley

https://ebookbell.com/product/applying-math-with-python-practical-
recipes-for-solving-computational-math-problems-using-python-
programming-and-its-libraries-sam-morley-49849188

Micropython Cookbook Over 110 Practical Recipes For Programming


Embedded Systems And Microcontrollers With Python Alsabbagh

https://ebookbell.com/product/micropython-cookbook-over-110-practical-
recipes-for-programming-embedded-systems-and-microcontrollers-with-
python-alsabbagh-22965632

Python Gui Programming Cookbook Use Recipes To Develop Responsive And


Powerful Guis Using Tkinter 2nd Edition 2nd Revised Edition Meier

https://ebookbell.com/product/python-gui-programming-cookbook-use-
recipes-to-develop-responsive-and-powerful-guis-using-tkinter-2nd-
edition-2nd-revised-edition-meier-29873666
Qgis Python Programming Cookbook Over 140 Recipes To Help You Turn
Qgis From A Desktop Gis Tool Into A Powerful Automated Geospatial
Framework Lawhead

https://ebookbell.com/product/qgis-python-programming-cookbook-
over-140-recipes-to-help-you-turn-qgis-from-a-desktop-gis-tool-into-a-
powerful-automated-geospatial-framework-lawhead-20640250

Python Network Programming Techniques 50 Realworld Recipes To Automate


Infrastructure Networks And Overcome Networking Challenges With Python
Marcel Neidinger

https://ebookbell.com/product/python-network-programming-
techniques-50-realworld-recipes-to-automate-infrastructure-networks-
and-overcome-networking-challenges-with-python-marcel-
neidinger-49850024

Python Programming Blueprints Build Nine Projects By Leveraging


Powerful Frameworks Such As Flask Nameko And Django Daniel Furtado
Marcus Pennington

https://ebookbell.com/product/python-programming-blueprints-build-
nine-projects-by-leveraging-powerful-frameworks-such-as-flask-nameko-
and-django-daniel-furtado-marcus-pennington-46502508

Python Programming For Beginners The Most Comprehensive Programming


Guide To Become A Python Expert From Scratch In No Time 1st Reed

https://ebookbell.com/product/python-programming-for-beginners-the-
most-comprehensive-programming-guide-to-become-a-python-expert-from-
scratch-in-no-time-1st-reed-47434972

Python Programming Exercises Gently Explained Al Sweigart

https://ebookbell.com/product/python-programming-exercises-gently-
explained-al-sweigart-49467034
Transactions on Computer Systems and Networks

Jivan S. Parab ·
Madhusudan Ganuji Lanjewar ·
Marlon Darius Sequeira · Gourish Naik ·
Arman Yusuf Shaikh

Python
Programming
Recipes for IoT
Applications
Transactions on Computer Systems
and Networks

Series Editor
Amlan Chakrabarti, Director and Professor, A. K. Choudhury School of
Information Technology, Kolkata, West Bengal, India
Transactions on Computer Systems and Networks is a unique series that aims
to capture advances in evolution of computer hardware and software systems
and progress in computer networks. Computing Systems in present world span
from miniature IoT nodes and embedded computing systems to large-scale
cloud infrastructures, which necessitates developing systems architecture, storage
infrastructure and process management to work at various scales. Present
day networking technologies provide pervasive global coverage on a scale
and enable multitude of transformative technologies. The new landscape of
computing comprises of self-aware autonomous systems, which are built upon a
software-hardware collaborative framework. These systems are designed to execute
critical and non-critical tasks involving a variety of processing resources like
multi-core CPUs, reconfigurable hardware, GPUs and TPUs which are managed
through virtualisation, real-time process management and fault-tolerance. While AI,
Machine Learning and Deep Learning tasks are predominantly increasing in the
application space the computing system research aim towards efficient means of
data processing, memory management, real-time task scheduling, scalable, secured
and energy aware computing. The paradigm of computer networks also extends it
support to this evolving application scenario through various advanced protocols,
architectures and services. This series aims to present leading works on advances
in theory, design, behaviour and applications in computing systems and networks.
The Series accepts research monographs, introductory and advanced textbooks,
professional books, reference works, and select conference proceedings.
Jivan S. Parab · Madhusudan Ganuji Lanjewar ·
Marlon Darius Sequeira · Gourish Naik ·
Arman Yusuf Shaikh

Python Programming
Recipes for IoT Applications
Jivan S. Parab Madhusudan Ganuji Lanjewar
School of Physical and Applied Sciences School of Physical and Applied Sciences
Goa University Goa University
Taleigao, Goa, India Taleigao, Goa, India

Marlon Darius Sequeira Gourish Naik


School of Physical and Applied Sciences School of Physical and Applied Sciences
Goa University Goa University
Taleigao, Goa, India Taleigao, Goa, India

Arman Yusuf Shaikh


School of Physical and Applied Sciences
Goa University
Taleigao, Goa, India

ISSN 2730-7484 ISSN 2730-7492 (electronic)


Transactions on Computer Systems and Networks
ISBN 978-981-19-9465-4 ISBN 978-981-19-9466-1 (eBook)
https://doi.org/10.1007/978-981-19-9466-1

© The Editor(s) (if applicable) and The Author(s), under exclusive license to Springer Nature
Singapore Pte Ltd. 2023
This work is subject to copyright. All rights are solely and exclusively licensed by the Publisher, whether
the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse
of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and
transmission or information storage and retrieval, electronic adaptation, computer software, or by similar
or dissimilar methodology now known or hereafter developed.
The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication
does not imply, even in the absence of a specific statement, that such names are exempt from the relevant
protective laws and regulations and therefore free for general use.
The publisher, the authors, and the editors are safe to assume that the advice and information in this book
are believed to be true and accurate at the date of publication. Neither the publisher nor the authors or
the editors give a warranty, expressed or implied, with respect to the material contained herein or for any
errors or omissions that may have been made. The publisher remains neutral with regard to jurisdictional
claims in published maps and institutional affiliations.

This Springer imprint is published by the registered company Springer Nature Singapore Pte Ltd.
The registered company address is: 152 Beach Road, #21-01/04 Gateway East, Singapore 189721,
Singapore
Foreword

I am extremely happy to write a foreword for the book “Python programming


recipes for IoT applications”. This book aims to provide a comprehensive guide on
how to use Python to develop applications for the Internet of Things (IoT). The IoT
has revolutionized the way we interact with the world around us, and Python is one
of the most popular programming languages used for developing IoT applications.
This book will teach how to use Python to develop solutions that can connect to and
interact with IoT devices.
This book is divided into six chapters, each focusing on a different aspect of
Python programming for IoT applications. The first chapter will introduce you to the
world of IoT and provide an overview of the Python programming language. The
subsequent chapters will delve into various topics, such as data handling, networking,
security, and machine learning. Each chapter will contain several recipes, which are
step-by-step guides that will teach one how to solve specific problems or accomplish
specific tasks. The recipes are designed to be easy to follow, and they provide practical
examples that one can use to build own IoT applications.
This book is designed for anyone who wants to learn how to use Python to develop
IoT applications. Whether you are a beginner or an experienced programmer, this
book will provide you with the knowledge and tools you need to build your own IoT
solutions. If you are interested in developing applications that can connect to and
interact with IoT devices, this book is for you.

v
vi Foreword

In conclusion, I would like to say that Python is an excellent language for devel-
oping IoT applications, and this book will provide one with the knowledge and
tools one need to get started. Whether you are building a simple sensor network or a
complex machine learning application, the recipes in this book will guide you through
the process. So, let’s dive in and start building some awesome IoT applications with
Python.

Taleigao, India Professor Harilal B. Menon


March 2023 Vice Chancellor
Goa University
Preface

We are pleased to present this book titled “Python Programming Recipes for
IoT Applications” to the readers. As we all know, Python is powerful, yet flex-
ible, easy to learn, and can be adapted to work with most of the microcontroller-
based environments. Simplicity serves as a great asset to Python, which allows it
to flourish on every platform. The coding flexibility and dynamic nature of Python
help developers to create intelligent Internet of Things (IoT) devices.
So, we thought this is the right time to bring such a book to the market which
explains the basic glimpses of Python followed by three different embedded platforms
and their configuration setup. Various IoT applications with FoG and cloud-based
computation on these platforms are explained in a very simple and understandable
manner so that the readers can start programming on any of the platforms of their
choice with ease.
The detailed chapter-wise flow is as follows:
Chapter 1 “Python Programming and IoT” discusses the basics of Python language
such as features of Python, Integrated Development Environment (IDE), data types,
and so on. It also discusses comparison of Python with C and C++ language. The
C/C++ programming languages dominates embedded systems programming. On the
other hand, Python has many strengths that make it a great programming language for
embedded systems. This chapter also gives the overview of IoT and its applications.
Chapter 2 provides detailed step-wise configuration setup of Raspberry Pi,
MicroPython Pyboard, and NVIDIA Jetson Nano This chapter also covers the details
of all above boards including block diagram, features available in these boards, and
functions of each block.
Chapter 3 gives the detailed implementation steps of simple IoT applications using
Raspberry Pi such as controlling LED blinking, OLED display interface, camera
interface, and motor control (DC motor, stepper motor, and servo motor).
Chapter 4 gives the detailed implementation steps of MicroPython Pyboard for
IoT applications such as home automation, smart e-waste bin, industrial environment
monitoring, green house monitoring, and aquaculture monitoring.
Chapter 5 focusses on FoG and cloud computing with NVIDIA Jetson Nano
board. It covers the introduction and the model architecture of both the FoG and

vii
viii Preface

cloud computing. Detailed stepwise implementation of patient monitoring with cloud


computing and home security (home surveillance, home safety lock, fire alert system)
with FoG computing.
Chapter 6 covers the implementation of Machine Learning (ML) applications
such as pattern recognition, object classification, and prediction using Jetson Nano.

Taleigao, India Jivan S. Parab


Madhusudan Ganuji Lanjewar
Marlon Darius Sequeira
Gourish Naik
Arman Yusuf Shaikh
Acknowledgement

The book is a result of practical implementation of various IoT applications using


Python programming on Raspberry Pi, MicroPython Pyboard, and NVIDIA Jetson
Board with a hands-on approach. Special thanks to Mrs. Kamiya Khatter, Associate
Editor and publishing team of Springer to bring this book in the market.
Authors are thankful to Prof. Harilal. B. Menon,Vice-Chancellor and
Prof. Vishnu Nadkarni, Registrar, Goa University for encouraging and providing
administrative and financial support. The main motivational force behind this book
is Professor, Dr. Rajanish Kamat (Vice-Chancellor of Dr. Homi baba State University,
Mumbai) who has co-authored several books with authors.
We are thankful to Prof. Kaustubh Priolkar, Dean of School of Physical and
Applied sciences (SPAS), Prof. Ramesh Pai, Vice-Dean (Academic), and Prof.
Rajendra Gad, Vice-Dean (Research) of SPAS.
Authors would like to acknowledge with gratitude, the support and love of family
members. They all kept us going and this book would not have been possible without
them. Our sincere gratitude goes to Mr. Saish S. Nayak Dalal and Mr. Sameer Patil
for helping us in editing the book.
Finally, authors wish to express their gratitude to God, whose presence has given
them strength to finish the book.
We will be failing in our duties, if we do not mention the support, encouragement
received from friends, supporting staff and colleagues.

ix
Contents

1 PYTHON Programming and IoT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1


1.1 Introduction to Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Can Python Replace C/C++? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Overview of Python Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.4 Python for Embedded System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
1.5 Introduction to IoT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
1.6 IoT Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2 Configuring Raspberry Pi, MicroPython Pyboard, and Jetson
Nano for Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.1 Raspberry Pi Board Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.1.1 Configuration of Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . 29
2.2 MicroPython Pyboard Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
2.2.1 Configuration of MicroPython Pyboard . . . . . . . . . . . . . . . . . 34
2.3 Jetson Nano Board Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
2.3.1 Configuration of Jetson Nano Board . . . . . . . . . . . . . . . . . . . . 41
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
3 Simple Applications with Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
3.1 Blinking of LED . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
3.2 OLED Display Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
3.3 Camera Interfacing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
3.4 Motor Control (DC Motor, Stepper Motor, and Servo Motor) . . . . . 69
3.5 Raspberry Pi and Mobile Interface Through Bluetooth . . . . . . . . . . . 83
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
4 MicroPython PyBoard for IoT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
4.1 Home Automation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
4.2 Smart e-waste Bin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
4.3 Industrial Environmental Monitoring . . . . . . . . . . . . . . . . . . . . . . . . . . 105

xi
xii Contents

4.4 Greenhouse Monitoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111


4.5 Aquaculture Monitoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
5 FoG and Cloud Computing with Jetson Nano . . . . . . . . . . . . . . . . . . . . . 123
5.1 Introduction to FoG Computing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
5.2 Architecture Model of FoG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
5.3 Introduction to Cloud Computing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
5.4 Cloud Computing Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
5.5 Role of FoG and Cloud Computing in IoT . . . . . . . . . . . . . . . . . . . . . . 131
5.6 Examples of FoG and Cloud Computing . . . . . . . . . . . . . . . . . . . . . . . 131
5.6.1 Patient Monitoring system with Cloud . . . . . . . . . . . . . . . . . . 131
5.6.2 Home security with FoG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
6 Machine Learning (ML) in IoT with Jetson Nano . . . . . . . . . . . . . . . . . 167
6.1 What is AI? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
6.2 Concepts of Machine Learning (ML) and Deep Learning (DL) . . . . 168
6.3 Pattern Recognition Using ML with Cloud . . . . . . . . . . . . . . . . . . . . . 171
6.4 Object Classification Using ML with FoG . . . . . . . . . . . . . . . . . . . . . . 178
6.5 Prediction of Unknown Glucose Concentration Using ML
at EDGE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
About the Authors

Jivan S. Parab is an Associate Professor & Programme Director of the School of


Physical and Applied Sciences, Goa University, India. He has completed his Ph.D.
from Goa University in 2011 with the title “Development of novel Embedded DSP
architecture for Non-Invasive Blood Glucose analysis”. He received his M.Sc. and
B.Sc. degrees in Electronics from Goa University, in 2005 and 2003, respectively. He
has co-authored four books and several papers in national and international journals
and conferences. He has been awarded the Visvesvaraya Young Faculty award of
Rs. 38 lakhs by MeiTy, the Government of India. He has completed two industry
consultancies and two major research projects. He also has three Indian patents to his
credit. His research interest is Embedded system design, Signal processing, Machine
Learning, Biomedical Instrumentation, and Agro-Instrumentation.

Madhusudan Ganuji Lanjewar is a Technical Officer at the University Science


Instrumentation Centre (USIC), School of Physical and Applied Sciences, Goa
University, India. He received his M.Sc. Electronics in 2003 and B.Sc. Electronics
degree in 2001 from RTM Nagpur University. His research interests include artificial
neural networks, image processing, and embedded system using the “C” language and
Python. He has published several papers in national and international level journals
and conferences. He has two patents to his credit.

Marlon Darius Sequeira is an Assistant Professor of Electronics at the School of


Physical and Applied Sciences, Goa University, India. He received his B.Sc. and
M.Sc. degrees from Goa University in 2012 and 2014 respectively. He obtained
his Ph.D. from Goa University in 2021. His research interests include biomedical
Instrumentation, machine learning, embedded systems, and FPGA designs. He has
published several papers in national and international journals and conferences. He
has two patents to his credit.

Gourish Naik Former Dean Faculty of Natural Science & Former Head Department
of Electronics obtained his Ph.D. from the Indian Institute of Science, Bangalore
(1987) and served the institute as a research associate in the areas of Optoelectronics

xiii
xiv About the Authors

and Communication until 1993. He was associated with the Goa University for
27 years. He is the founding head of the University Instrumentation Centre and
established fiber optic LAN and wireless communication networks at Goa University.
He was also the coordinator of DEITI (an educational broadcast studio supported by
Indian Space Research). His other commitments are regulating the digitization center
at Goa University to support the various digital repository projects like DIGITAP
(Digital Repository for Fighter Aircrafts Documentation) of the Indian Navy, the
Million Book project of the Ministry of Information Technology and Antarctica
Study Center (NCAOR). He has to his credit around 60 research papers published
in international journals and has presented research works at various national and
international forums. He has delivered several keynote addresses and has been invited
to talks at various institutes and also authored five books on embedded systems and
allied areas published by CRC Press, Springer, Lambert, etc. He was a member of
the Goa State Rural Development Authority and also an advisor for the Directorate
of Education. He was a governing body member of the engineering college of Goa
and also a member of the faculty board of Goa University.

Arman Yusuf Shaikh is currently associated with the industry-leading VLSI


company as an ASIC Design engineer, where he is responsible for taking a design
through RTL-GDS2 flow involving steps like Synthesis, Floor planning, PNR, STA,
Et Cetera. He is a motivated professional holding an M.Sc. in Electronics degree from
Goa University (2021) and a B.Sc. in Electronics from Dnyanprassarak Mandal’s
College and Research Center (2019). As a Research Student at SPAS Electronics, Goa
University, Arman completed a couple of projects that exposed him to the domains of
Biomedical Instrumentation, ML, IOT, Signal Processing, and Embedded systems.
He has published papers in notable journals and conferences. He has two patents to
his credit.
Chapter 1
PYTHON Programming and IoT

Abstract There are number of books that cover Python programming in detail. This
chapter is not exhaustive; instead, it briefly describes Python’s programming basics
that will give a good hold for programmers to write the programs. It answers the
question of whether Python will replace C/C++? This chapter also briefly introduces
IoT and Python for embedded and IoT applications.

Keywords Python · IDE · Operators · Internet of Things · IoT applications ·


Embedded system

1.1 Introduction to Python

Python is a widely used general-purpose interpreted programming language that


allows to work more quickly and integrates the systems more perfectly. It is easy to
learn, supports object-oriented programming with dynamic semantics which enables
a programmer to write intelligible and logical code for small and bigger enti-
ties (Kuhlman 2012). Due to the availability of extensive standard libraries, it is
considered as “batteries included” language.
Why the Name Python?
The first question that arises in a programmers’ mind is that why the name Python is
given to this interesting programming language. Does this have some relation with
the Python Snake? There is one interesting fact behind choosing the name Python.
In the 1980s, Guido Rossum developed Python and wanted to choose a distinctive
name and a little bit funny one too. While reading the interesting script of a British
Broadcasting Corporation (BBC) comedy series, which was quite popular i.e. “Monty
Python’s Flying Circus”. So, he made his mind to name their programming language
as "Python".
History and Different Python Versions
The foundation of Python was laid in the late 1980s but, practical implementation
was commenced in December 1989 by Guido at CWI in the Netherlands. Today

© The Author(s), under exclusive license to Springer Nature Singapore Pte Ltd. 2023 1
J. S. Parab et al., Python Programming Recipes for IoT Applications, Transactions
on Computer Systems and Networks, https://doi.org/10.1007/978-981-19-9466-1_1
2 1 PYTHON Programming and IoT

Python has evolved as such a popular programming language with several releases,
and with every release, some new features are added in it.
Python versions:
• The first Python code was published with labeled version 0.9.0 by Guido Van
Rossum in February 1991.
• Python 1.0 was manumitted in 1994 with features such as lambda, map, filter, and
reduce, followed by Python 1.5 and 1.6 in the years 1997 and 2000 respectively.
• Python 2.0 was released with addon features such as comprehensions, garbage
collection systems. Python 2 also has intermediate version 2.1 till 2.7.
• Similarly, on December 3, 2008, Python 3.0 (also called “Py3K”) was manumitted.
Python 3 was specially developed to rectify the basic flaws of the earlier versions.
From 2008 till date several releases of Python 3 have come, from version 3.1 till
3.11 which was released in February 2023.

1.2 Can Python Replace C/C++?

The answer to the question “can Python replace C/C++?” is NO. C and C++ forms the
basis of every programming. Python is built using C by keeping web programming
in mind. So there is no possibility that Python will replace fundamental languages
like C or C++ at least not in the near future.
Overall Python is better than C/C++ in terms of its simplicity, readability,
writability, and very simple syntax, while C/C++ is tedious and time-consuming,
prone to errors, and not easy to understand . Although C/C++ is better in terms of
performance, speed and has enormous application areas.
Python offers enormous error-checking option than C. Being a very high-level
programming language, it has various data types, arrays, and dictionaries already
built-in that would have cost someone many days to implement effectively in C.
Python gives the flexibility to break up the program into small modules which later
can be leveraged in another Python programs.
For embedded system code development, the programmer prefers C/C++ language
due to faster runtime code. When it comes to runtime speed Python may be less
efficient than C/C++, however, runtime speed is sometimes not that important when
development speed is considered, which is good for Python. Now in recent times,
Python is extensively used for embedded systems explained in Sect. 1.4.

1.3 Overview of Python Programming

Python programming language is easy to learn because of its simple syntax and huge
library packages. Before starting with the basics of Python programming one has to
1.3 Overview of Python Programming 3

understand the process of Python and Integrated Development Environment (IDE)


installation to get acquainted with the respective IDE’s environment.
1.3.1 Python Installation
Python official website (https://www.Python.org/) provides the most updated and
current source code, binaries, documentation, news, etc. Python can be downloaded
from the above website link. The Python can also be installed with the Anaconda .
In order to install Python on a windows machine one has to follow the below steps.
Installation steps on Windows machine
Step 1: Visit a web page https://www.Python.org/downloads/, as shown in Fig. 1.1.
Click on the ’Download’ button to download the latest Python version. If someone
wants the older versions of Python, the same is available for download on the same
link.
Step 2: The Python version 3.9.7 is now downloaded and saved in the Download
directory. Search file name Python 3.9.7-amd64 → double click on it → click on
’Run’ and follow the pop up instructions till it shows the finished installation.

Fig. 1.1 Python downloading web portal


4 1 PYTHON Programming and IoT

Anaconda Installation
Anaconda is an incredible collection of Python packages, tools, resources, and IDEs.
This package comprises several tools which are helpful for the data scientist to
exploit Python’s unbelievable strength. Anaconda is a free and open-source individual
edition available for developers. The installation steps are given below:
Step 1: Visit the web page https://www.anaconda.com/products/individual-dto and
download the individual edition of the Anaconda. Click on ’Download’ button as
shown in Fig. 1.2a.
Step 2: Search.exe file (Anaconda3-2021.05-Windows-x86_64) in Download direc-
tory. Double click on it → click on ’Run’ → click on ’Next’ (Fig. 1.2b) to continue
→ click on ’Agree’ (Fig. 1.2c) → select ’Just me’ and then ’Next’ (Fig. 1.2d)
→ choose the location for installation (Fig. 1.2e) and click on ’Next’ → click on
’Register Anaconda3 as my default Python’ (Fig. 1.2f) → click on ’Install’ button.
Step 3:After completion of installation process (Fig. 1.2g) click on ’Next’ → click
on ’Next’ button to finish the process as shown in Fig. 1.2h and then ’Finish’ button
(Fig. 1.2i).

Fig. 1.2 Anaconda installation


1.3 Overview of Python Programming 5

Fig. 1.2 (continued)

Python IDEs and Code Editors


A tool for writing and editing code is called a code editor. Usually, code editors
are lightweight and easy to learn. However, if the program is large, then IDEs are
helpful to understand the program in a much better way compared to text editors.
IDEs come up with various features such as, build automation, testing, debugging, and
code compilation. There are various Python IDEs available such as IDLE, Thonny,
PyCharm, Atom, etc. Most of the time, the Thonny, PyCharm, and Jupyter notebook
6 1 PYTHON Programming and IoT

IDEs are used for developing the codes for various applications. In this book, authors
have used Thonny and PyCharm IDEs for developing various applications. The
installation process of these two IDEs is depicted as follows.
Thonny IDE Installation
Thonny is an easy and simple IDE to use and it comes with a built-in Python 3.7.
The downloading and installation process of Thonny IDE is given below:
Step 1: Visit https://thonny.org/ and choose OS as Windows, Mac, or Linux depending
on your requirement. Here the installation steps of Thonny for Windows are shown
below.
Step 2: Download the Thonny for Windows → search Thonny-3.3.13 (or latest
version) file in the Download folder → double click on it → accept terms and
conditions and then click on ’Next’ → select the location (destination) → click on
’Next’ → select create desktop icon → select start menu folder and click on ’Next’
→ click on ’Install’ → installation process will start and after installation click on
’Finish’. The full installation flow is depicted in Fig. 1.3a–e.
PyCharm IDE installation
The step-by-step process of how to download and install PyCharm IDE on Windows
is as follows:
Step 1: Visit the website https://www.jetbrains.com/pycharm/download/ to download
PyCharm → click the ’DOWNLOAD’ link under the community section as shown
in Fig. 1.4a.
Step 2: Run the.exe file (pycharm-community-2021.2.2 or latest version) to install
PyCharm → the setup wizard will start and then click ’Next’ as shown in Fig. 1.4b.
Step 3: Installation path can be changed if required or click on ’Next’ to continue
(Fig. 1.4c).
Step 4: Create Desktop shortcut and then click on ’Next’ (Fig. 1.4d).
Step 5: Choose the start menu folder (Fig. 1.4e) → keep JetBrains selected → click
on ’Install’ → wait until the installation process is finished.
Step 6: After finishing the installation, a message screen will display as shown in
Fig. 1.4f → click on ’Finish’.
1.3.2 Glimpses of Python Programming
Python is a fantastic language for beginners and helps to develop various applications.
Following are some of the important characteristics which make this language very
powerful:
• Python supports Object-Oriented Programming (OOP) as well as it is structured
programming.
• It supports scripting language.
1.3 Overview of Python Programming 7

Fig. 1.3 Thonny installation process

• It accepts dynamic data types and does dynamic type checking.


• It can be efficiently encapsulated using C, C++, COM, ActiveX, CORBA, and
Java.

Syntax of the Python Programming Language


This section outlines the general syntactical elements of the Python language, but
not in an exhaustive way. The rules on how to use identifiers, reserved keywords,
8 1 PYTHON Programming and IoT

Fig. 1.4 PyCharm installation steps


1.3 Overview of Python Programming 9

Table 1.1 Keywords in python


And Assert Break Class Continue Def Del Elif Else Except
Exec Finally For From Global If Import In Is Lambda
Not Or Pass Print Raise Return Try While With Yield

lines and indentations, quotations, different data types, operators, functions, etc. are
outlined. After navigating through the following section, the reader will be able to
write their first Python code for any desired applications.
Identifiers
An identifier refers to the name used to represent a variable, function, module, or class
in Python. It must always begin with an uppercase letter (A–Z) or lowercase letter
(a–z) or an underscore, and then can continue with a letter, underscore, and digits
(0–9). We cannot use special characters such as @, $, and % in building an identifier.
It must be noted that Python is a case-sensitive language and care must be taken to
construct the identifier accordingly. For example, var and VAR are considered two
separate identifiers in Python.
Reserved Words
Reserved words cannot be used as identifiers or variables or constants. The Python
keywords are always constructed using lowercase letters. Table 1.1 gives the
keywords which are used in the Python language.
Indentation in Python
Unlike other languages, a block of code under functions and flow control in Python
is not specified using braces or brackets. Instead, Python relies on line indentations,
which are rigidly applied in the language.
One can use a variable number of spaces to specify indentations, but this number
must be consistent in the entire block. An example showing proper indentation is
shown below:
a=10
b= 10
if (a==b):
print("Yes")
else:
print("No")

Multi-line Statements
Usually a statement is terminated by a new line in Python. However Python permits
to continue line by using a line continuation character(\):
history=10
geography=9
maths=2
10 1 PYTHON Programming and IoT

science=3
Marks = history + geography +maths + science
print(Marks)

However, statement which are contained in {}, [], or () do not require the line
continuation character.
Employees= [‘John’, ’kevin’, ’Wenzel’, ’Albert’, ’Peter’]

In Python, one can use the semicolon ( ; ) character to type multiple statements
on the same line provided neither of the statement starts a new code block.
print("hello"); a = 50; a = a + 34

Quotation
A string in Python is specified using quotes. Single, double, or triple quotes are used
to specify literals provided the same type of quotes are used to terminate the string.
However, triple double quotes allow spanning a string across multiple lines.
name = ’Haston’
message= "Hello World of Python programming"
long_message = """We are going to land on the island tomorrow after
the sunset"""

Comments
In Python, a comment is indicated to the interpreter by a hash sign (# ) and this
character must not be contained in a string literal. The characters placed after the #
till the end of the line makes up the comment. The Python interpreter will ignore all
the characters after # character.
# This line is a comment, below code prints hello Python on the screen
print(“hello world”) # command to print

The Python interpreter ignores the triple single quoted string, as such can be used
as a multiline comments.
’ ’ ’Comment can span multiple Lines ’ ’ ’

1.3.3 Data Types in Python


Different data types are featured in Python namely numerical and alphanumeric The
standard data types allowed in Python are boolean, numeric, strings, lists, tuples,
dictionaries, and sets etc. (Beazley and Jones 2013; Pilgrim and Willison 2009).
Figure 1.5 shows the various data types in Python.
Boolean
The boolean type is a built-in data type in Python which is used to store only two
values, namely, ’True’ and ’False’. The main use of the boolean type is to represent
1.3 Overview of Python Programming 11

Fig. 1.5 Data types in Python

the ’True’ value of an expression. The code below prints the type of the variable z
which is <class ‘bool’>:
z = True
print(type(z))

Numeric
Numeric data types are one of the most extensively used data types in Python. It is
further subdivided into integers, float, and complex types. Integers can be positive,
negative, and whole numbers including zero which do not have a fractional part and
have unlimited precision. Integers can be specified with binary, octal, and hexadec-
imal values. The numbers 78, -58, and 0 are examples of valid integers in Python. It
must be noted that leading zeros are not allowed in non-zero numbers.
Floating-point data type are positive and negative real numbers that have a frac-
tional part. The fractional part is specified after the decimal point. One can use a
decimal point representation or scientific representation to specify a floating-point
number. For example, 1000.47 is decimal point representation and 1.00047E3 is in
scientific representation. The scientific representation is particularly useful to show
numbers having many digits.
The third type of number which Python supports is the Complex number. It has a
real part and
√ the imaginary part. The imaginary part of the number is multiplied by j
(j refer to −1). For example, for the complex number 3 + 2j, the 3 is the real part
and the 2j is the imaginary part. Care must be taken to use j or J as the imaginary
component, the use of any other character results in a syntax error. The code below
shows the use of integer, float, and complex numbers:
# The numerical types in Python
# Use of integer data type in Python
int1 = 15
int2 = 2500
int3 = -25
# We can use binary, octal, and hexadecimal values to
represent integer variables
12 1 PYTHON Programming and IoT

int4 = 0b11011011 # binary


int5 = 0o12 # octal
int6 = 0x12 # hexadecimal
# Use of float variable in Python
float1=10.5
# Scientific notation is used to shorten the float
# representation
float2 =1e4
float3 =3.664547e2
# Use of complex data type in Python
comp= 10 + 4j

Python Dictionary
Dictionary in Python is similar to a hash table. They operate similar to hashes or
associative arrays which are part of the Perl programming language. Dictionary is a
pair of key and value. Any valid type in Python can be specified as a key, however
numbers and strings are preferred over others. Whereas any arbitrary Python object
can be a value for the key.
It must be noted that curly braces ({ }) are used to indicate a dictionary whereas
square braces ([]) are used to assign and access.
dictionary={}
dictionary[’one’]="Test one"
dictionary [2] ="test two"
smalldictionary ={’name’:’tony’,’srno’:789,’section’:’research’}
print(dictionary[’one’]) # Displays value of key ‘one’
print(dictionary [2]) # Displays value of key 2
print(smalldictionary) # Displays entire dictionary
print(smalldictionary.keys()) # Displays the keys
print(smalldictionary.values())# Displays the values

Sequence Type
Sequence type in Python refers to an ordered set. Strings, tuples, and lists are the
popular sequence data types used in Python.
Python Strings
A string is a set of characters that are specified within quotation marks. We can use
single or double quotes as a pair to contain a string. Python allows to access a subset
of string using the slice operator [] or [:]. This needs to be done using the index which
begins at 0. The ’+’ operator is used to concatenate two strings, and the ’*’ operator
is used to repeat the string as shown in below example:
string =’Hello Python !’
print(string) # Displays whole string
print(string[0]) # Displays first character in string
print(string[1:8]) # Displays 1st to 7th index characters
print(string[3:]) # starting from 3rd index is Displayed
1.3 Overview of Python Programming 13

After executing above code the output is shown below: Hello Python ! H ello Py lo
Python ! The index can begin with 0 and end with (length -1). The use of concatenate
is shown below:
print(string *3) # Displays string 3 times
print(string +" World") # concatenated string is Displayed

Python Lists
Python has powerful compound data types, one of them is the List data type. The
items within the list are specified by a comma separator. All the items are contained
within square brackets. A Python list allows entering different data types within the
list in contrast to arrays in other programming languages.
list =[’albert’, 145, 3.14, ’raman’, 36]
smalllist =[654, ’bose’]
print(list) # Shows the list
print(list[0]) # Shows only the the 1st element of the list
print(list[0:4]) # Shows elements starting from 1st till 4th
print(list[2:]) # Shows elements starting from 3rd till end
print(smalllist*4) # Shows the list 4 times
print(list + smalllist) # Prints the concatenated list

Python Tuples
Yet another powerful data type in Python is a tuple. This again stores a sequence of
data and is similar to a list in its operation. In a tuple, commas are used to separate
the items contained within it. However, as compared to a list, the items within a tuple
are enclosed within parentheses.
Here we summarize the main differences between a list and a tuple. Square
brackets ([]) are used to enclose items in a list whereas parentheses (( )) are used to
enclose items in a tuple. In the case of a list, we can change the elements and size,
but in a tuple, we cannot change the elements and size. The tuple is a read-only list.
tuple =(’albert’,145,3.14,’raman’,36)
smalltuple =(654,’bose’)
print(tuple) # prints the tuple
print(tuple[0]) # Displays only the the1st element of the tuple
print(tuple[0:4]) # elements are Displayed from 1st till 4th
print(tuple[2:]) # Displays elements from 3rd till end
print(smalltuple*4) # Displays the smalltuple 4 times
print(tuple + smalltuple) # Displays the concatenated tuple and
smalltuple

Set
Python programming language enables us to use the concept of set. A set is defined
as a collection of items that are not in order. The items must be enclosed in curly
braces ({}) and commas are used to separate the items. The interpreter automatically
14 1 PYTHON Programming and IoT

removes duplicate items. The basic operations such as set intersection, union, differ-
ence, and symmetric difference are allowed in Python. Indexing is not allowed for a
set as the items are not ordered.
a = {4,5,5,6,6,6} # a set with repeated values,
b = {4,7,8} # set b
c = a.union(b) # set c is union of a and b print (c)
d = a.intersection(b) # set d is intersection of a and b print (d)
e = a.difference(b) # set e is difference of a from b print(e)
f = a.symmetric_difference(b) # set f is symmetric difference
print(f)

Variable Assignment in Python


As the variable is instantiated, the Python interpreter allots memory locations exclu-
sively reserved to that variable. The memory locations allocated to the variable will
depend on the data type and dictate what type can be stored in it. Decimals, integers,
and characters can be stored in the variables.
The declaration in Python is not explicit and is handled automatically when a
value is assigned to the variable. The variable assignment is done as shown in the
below examples using the assignment operator (=). The value on the right of the
operator is assigned to the variable on the left of the operator.
speed = 1000 # An assignment of integer
pi = 3.14 # an assignment of floating-point number
name = "Albert" # string assignment
print(speed)
print(pi)
print(name)

The above lines of code explain how to assign values to variables. The value 1000,
3.14, and “Albert” are assigned to the variables speed, pi, and name, respectively and
then printed.
We can also handle multiple assignments in the Python language. In the statement
below, the variables j, k, and l are initialized to a value 15.
j=k=l=15

To perform multiple object assignments to multiple variables the below statement


can be used:
x,y,z= 21,22, “Albert”

An integer object having values 21 and 22 are assigned to x and y, respectively,


and at the same time variable z is initialized with string object “Albert”.
1.3.4 Python—Basic Operators
Operators are essential constructs of any programming language which are used to
manipulate the value of operands. In the expression: 7 * 3, 7 and 3 are the operands
1.3 Overview of Python Programming 15

and ’*’ is the operator. In Python, operators are classified into various types which
are intended for specific purposes. The different categories of the operators are listed
below:
• Arithmetic.
• Comparison (Relational).
• Assignment.
• Logical.
• Bitwise.
• Membership.
• Identity.

Arithmetic Operators
The arithmetic operators are used to perform various arithmetic operations on the
operands. Table 1.2 explains all the arithmetic operators assuming that the variables
x and y are the operands on whom the operators are applied upon.
Comparison Operators
Operators which compare the operands on each of its sides and find the relation
between them are comparison operators. Another name for comparison operators is
relational operators. Table 1.3 gives the different comparison operators.
Assignment Operators
These operators are used to assign a value to the variable on the left of the command.
Different assignment operators are given in Table 1.4.
Bitwise Operators
Bitwise operators perform bit-by-bit operations. If we assume that x = 126 and y =
31. Then their binary representation will be 0111 1110 and 0001 1111, respectively.
The bitwise operators in Python take the two operands and perform the desired
operation on every corresponding bit of two operands. For bitwise AND, it takes
the two operands and performs a bitwise AND operation. For bitwise OR, it takes

Table 1.2 Python arithmetic operators


Operator Code Description
+ (Addition) x + y Addition is performed on operands x and y
− (Subtraction) x–y Subtracts right operand y from the left operand x
* (Multiplication) x*y Multiply left operand x with the right operand y
/ (Division) x/y Left operand x is divided by the right operand y
% (Modulus) x%y Left operand x is divided by right operand y and assigns its remainder
** (Exponent) x**y Finds the left operand x raised to the power of right operand y
// (Floor division) x//y Does the Floor Division of the operand on the left x with the operand
on the right which is y
16 1 PYTHON Programming and IoT

Table 1.3 Python comparison operators


Operator Python command Description
== (x = = y) The result of the operation will be True if the operands x and y
are equal
!= (x != y) The result of the operation will be True if the operands x and y
are not equal
<> (x <> y) The result of the operation will be True if the operands x and y
are not equal
> (x > y) The result of the operation will be True if the operand x is greater
than operand y
< (x < y) The result is True if the operand x is less than operand y
>= (x >= y) The result is True if the operand x is greater than or equal to
operand y
<= (x <= y) The result is True if the operand x is less than or equal to operand
y

the two operands and performs a bitwise OR. Similarly, for bitwise XOR, it takes
the two operands and performs a bitwise XOR. In a bitwise complement, it takes
the operand and performs a bitwise compliment. In addition, there are bitwise shift
left and shift right operators. In the left shift, the bits of the operand on the left are
shifted left by the value of the right operand. Similarly, in the right shift, the bits of
the operand on the left are shifted right by the value of the right operand. Table 1.5
gives the different bitwise operators.

Table 1.4 Python assignment operators:


Operator Python command Description
= x=y The value of the right-side operand is assigned to the left-side
operand
+= x+=y The value of right-side operand is added to the operand on the
left side and then assigned to the left-side operand
-= x-=y The value on the right side of the operator is subtracted from the
value on the left side and then assigned to the left-side operand
*= x*=y The value on the right side of the operator is multiplied with the
value on the left side and assigned to the left-side operand
/= x=/y The value on the left side of the operator is divided with the value
on the right side and the result is assigned to the left operand
%= x%=y The modulus of the two operands on either side is taken and the
result is assigned to the left operand
** = x** = y After performing the power operation on the two operands the
value is assigned to the left operand
// = x// = y After performing the floor division operation on the two
operands the value is assigned to the left operand
1.3 Overview of Python Programming 17

Table 1.5 Python bitwise


Operator Command Result
operators
& (bitwise AND) x&y 0001 1110
| (bitwise OR) x|y 0111 1111
^ (bitwise XOR) x^y 0110 0001
~ (bitwise compliment) ~x 1000 0001
<< (bitwise Left Shift) x << 2 1111 1000
>> (bitwise Right Shift) x >> 2 0001 1111

Logical Operators
There are three logical operators, namely, NOT, AND, and OR which are supported
by Python. These are used to make a logical decision.
In logical AND, if both the operands are true or non-zero, then only the result will
be True. In logical OR, if either of the operands are True or non-zero then the output
is True. In logical NOT, the output is the reversal of the logical state of the original
operand. Table 1.6 gives the logical operators in Python.
Membership Operators
A membership operator is used in Python to check if the element is a member of a
sequence, such as tuples, lists, or strings. The ’in’ operator is used for this purpose
and will evaluate to True if it finds a variable in the mentioned sequence and False
another time. The ’not in’ evaluates to true if it does not find a variable in the specified
sequence and false otherwise. In the code below, ’A’ is a member of the string and
hence the print statement outputs True. In the second statement as ’s’ is not a member
of the string and hence the print statement outputs True.
a = ’Albert’
print(’A’ in a ) # Results in True
print(’s’ not in a) # Results in True

Identity Operators
Identity operators are used for checking the memory locations of two objects. The
’is’ operator results to True if the variables on either side of the operator point to
the same object or False another time. The ’is not’ evaluates to False if the variables
on either side of the operator point to the same object and True another time. In the
code below the first print statement outputs a False and the second print statement
outputs a True as in both cases the values are identical (Guzdial and Ericson 2015).
a = 10

Table 1.6 Python logical


Operator Command Result
operators:
a = 15, b = 0
and (Logical AND) (a and b) False
or (Logical OR) (a or b) True
not (Logical NOT) not(a and b) True
18 1 PYTHON Programming and IoT

b = 10
x = ’Albert’
y = ’Albert’
print(a is not b) #Results in False
print(x is y) #Results in True

Python Operators Precedence


Table 1.7 gives the precedence of the various operators provided in Python. If the
operator is placed higher in the precedence table, it will be executed before the
operators at the bottom when they appear in an expression. The operators appearing
in the same level/row will have the same precedence. Operators having the same
precedence have associativity from left to right (except for exponential operator
which has right to left).

Table 1.7 Operator


Operator and description
precedence
**
Exponentiation (raise to the power)
~, +, −
Complement, unary plus, and minus (method names for the last
two are + @ and -@)
*, /, %, //
Multiply, divide, modulo, and floor division
+,-
Addition and subtraction
>> , <<
Right and left bitwise shift
&
Bitwise “AND”
^, |
Bitwise exclusive ’OR’ and regular ’OR’
<= , <,> , > =
Comparison operators
<>,==,!=
Equality operators
= ,% = , / = , // = ,- = , + = , * = ,** =
Assignment operators
is, is not
Identity operators
in, not in
Membership operators
not , or, and
Logical operators
1.3 Overview of Python Programming 19

1.3.5 Python—Decision-Making
In programming, decision-making is done by anticipating a condition to occur in
the execution process and then specifying a list of commands to be executed, if that
condition occurs.
Various decision structures are employed which evaluate expressions that produce
a TRUE or FALSE result. A set of actions have to be performed if the outcome is
TRUE and a different set of actions have to be performed if the outcome is FALSE.
Figure 1.6 shows the general control flow in most programming languages when
a decision has to be made by the program.
Python has various decision-making statements such as if…statements, if…else
statements and if…elif… else statements.
An ’if’ statement is made up of a boolean expression followed by single or multiple
statements. An ’if…else’ statement has an additional ’else’ statement executed when
the boolean expression results in a FALSE value. In an ’if…elif…else’ statement
the ’elif’ is short for ’else if’. It allows us to check for multiple expressions. If all
the conditions are FALSE, the body of else is executed. The below Python program
illustrates the use of the above decision-making structure:

Fig. 1.6 Decision flow in programming languages


20 1 PYTHON Programming and IoT

# if statement in Python
a = 50
if(a==50):
print("the value is 50")

# if.....else statement in Python


if(a==50):
print("the value is 50")
else:
print("the value is not 50")

# if....elif....else statement in Python


a=10
if(a==50):
print("the value is 50")
elif( a> 50):
print("the value is greater 50")
else:
print("the value is less than 50")

Loops
In a programming laguage, statements are executed in a sequential manner. A
programmer may be faced with a situation where he needs to execute a block of code
multiple times. Python provides several control structures which allow the above
situation. A loop in Python is a control structure used to run a block of statements
multiple times.
The loop control structures in Python are listed below:
• while loop
• for loop
• nested loop
The ’while’ loop repeats a block of statements when a condition evaluates to a
TRUE value. The condition is tested before the execution of the block of statements.
The ’for’ loop is a concise way of writing a ’while’ loop, as such it is said to
abbreviate the code section which is used to update the loop variables. The nested
loop structure uses multiple loops inside any other ’while’or ’for’ loop.
Loop Control Statements
A loop control statement changes the normal loop execution. It must be noted that
when execution has left a scope, all automatic objects that were created in that scope
are destroyed.
The control statements which are provided are
• break statements
• continue statement
• pass statement
The ’break’ is used to terminate the loop and the program control is transferred to
the first statement after the loop. The ’continue’ is used to skip the rest of the body of
1.3 Overview of Python Programming 21

the loop and to immediately re-evaluate the condition before reiterating. The ’pass’
in Python results in no operation . It may be used by the user to avoid error when
empty code is syntactically not allowed in cases such as loops, function definitions,
etc.
1.3.6 Functions
A function is defined as a reusable block of related and organized code that can be used
to perform a task. A function is principally used to provide modularity. A function
called multiple times as such promotes the reusability of code. Python language has
a repository of a large number of built-in functions such as print(),input() etc. In
addition, Python also allows users to define a function to perform a user-defined
task, such functions are called as user-defined functions.
Function Definition in Python
The following set of rules needs to be followed to define a function:
• The keyword ’def’ followed by the function name and parentheses ’()’ is used to
define a function block.
• Input arguments are placed within parentheses.
• An optional first statement in a function is the documentation string of the function
or docstring.
• Indentation must be followed in a function and the indentation begins after the
“:”.
• A function has a ’return [expression]’ statement. Its main task is to exit a function
or passing back an expression to the caller. We can use return statements without
arguments. Below is the example of a function definition:

Syntax

#Example
def multiply(a):
"function to multiply"
ans = a * a
return [ans]

val = multiply(50)
print(" the value of multiplication",val)

1.3.7 Modules
A module is used to arrange code in order to make it more readable. Grouping similar
code into modules makes it easier to comprehend and distribute the code. A module
is a Python object containing randomly named characteristics that may be bound and
referenced. A module contains function definition, classes, and variables. One can
include runnable code in a module.
22 1 PYTHON Programming and IoT

When a module is created in Python whose name is test.py, the corresponding


code is written to the file named test.py. The file test.py contains the following for
the definition of a function to find a square of a number.
def square(val):
print("The squre is :",val*val)
return

The import Statement


Now the above test.py is used as the source file for the module. By executing an
import statement in some other Python source file one can import the above source
code(test.py). The syntax for import is as follows:
import module_name

When the interpreter comes across an import statement, it imports the module if
it is on the search path. A search path is a directory list that the interpreter looks
over before importing a module. To import the module test.py, use the following
commands:
#!/usr/bin/Python
import test
test.square(15)

1.3.8 Files I/O

Printing to the Screen


The print statement is used to display output on the screen. A comma is used to pass
more expressions to the output. The print function converts the expression to a string
and then writes to the standard output. Whatever is in the double quotes inside a print
statement will appear as it is on the output. An example of a print statement is given
below:
print("Hello to the Python World")

Reading Keyboard Input


A built-in function can be used to read a line of text from standard input. The
input([prompt]) function is used to read one line from standard input. The string
inside the brackets is displayed as it is on the output, as a prompt message to the user.
This function returns the input as a string after the removal of the newline at the end
of the input. Whatever is input through the keyboard is displayed on the screen.
input_data = input("Please enter a input")
print(" The input by the user is :", input_data)
1.5 Introduction to IoT 23

1.4 Python for Embedded System

According to IEEE Spectrum, presently Python is positioned No. 1 among the


programming languages. Python has carried on its skyward ambit since 2016 and
jumped to No. 1 in the overall rating in the year 2017. This is a very interesting
programming language, but it still requires to make an impact in the embedded
field. There are Zerynth and MicroPython platforms, which are on rise for embedded
system development. As we are aware, the embedded code is still written in C.
C programming experts justify this stating that “C has faster runtime and is more
compact”.
… BUT…
if one replaces C with “assembly” in the above declaration, this is exactly what the
programmers said about 20 years ago!

Can Python be Used for Embedded Systems? Over the years, the C/C++
programming languages have dominated the embedded systems programming.
On the other side, Python has many strengths that make it a great language for
embedded programming.

Python isn’t only the most popular language, it’s also the fastest growing language
for embedded computing. May be that sounds silly, but the reality is that Python has
started eating into C/C++’s space.
Python can be used in embedded, small, or minimal hardware devices, depending
on how limiting the devices actually are.
The question arises: Can Python be used to program microcontrollers?
MicroPython is an efficient and optimized implementation of the Python 3
programming language that allows the programming of microcontrollers. MicroPy-
thon is a small subset of the Python standard library and is optimized to run on
microcontrollers and in constrained environments.
We will also talk about PyBoard, a microcontroller board specifically designed to
be programmed using MicroPython.

1.5 Introduction to IoT

The term IoT, i.e. “Internet of Things” (IoT) was initially coined by Kevin Ashton
in 1999, which later became widely accepted throughout the world. IoT is a mesh
of physical objects or people called “things” that are encapsulated with software,
hardware, network connectivity, and sensors, which admits these objects to gather
and barter the data. IoT makes everything “smart” and “easy” by improving aspects
24 1 PYTHON Programming and IoT

facet of individuals’ life with the potential of data collection, Artificial Intelligence
algorithm, and connectivity. There are basically four basic components of an IoT
system, namely, sensors, connectivity, data processing, and user interface as shown
in Fig. 1.7.
Sensors: Sensors/devices are important parts of IoT system which help to gather live
data from the surrounding. This data is complex and varied in nature. Sometimes a
device may have other types of sensors which perform some kind of intelligent task
apart from sensing.
Connectivity: Connectivity is another component of IoT. All the data gathered from
the sensors is sent to a cloud. These sensor data will be sent to the cloud by using
several communication protocols such as Bluetooth, wireless, NFC, RFID, radio
protocols, and Wi-Fi-Direct.
Data Processing: Once the data is gathered and uploaded on to the cloud, the various
available data processing software performs required processing algorithm.
User Interface: After performing the processing on data, the processed data must be
made available to the end user in some way. The end user gets these data on his smart
device. Sometimes user from distant place can control the various devices through
IoT.

Fig. 1.7 Basic components of IoT


1.6 IoT Applications 25

1.6 IoT Applications

IoT helps to create opportunities to connect and interact with physical world by using
sensors and Internet. IoT system allows devices to be controlled remotely over the
Internet. The interconnection of these various devices helps in automizing the entire
system. This results in enhanced accuracy, system efficiency, and economic benefit
with minimal human intervention.
IoT devices find extensive set of applications into consumer, commercial, indus-
trial, and infrastructure spaces (Vongsingthong and Smanchat 2014; Jump up to 2015,
Perera et al. 2015). Below are the list of few applications of IoT.
Energy Applications: IoT find its extensive use in energy sector. The energy saving
is very important, so one has to utilize it very effectively. Individuals and organiza-
tions are finding out various ways to minimize and control the energy consumption.
With advancement in IoT technologies it makes it possible to monitor the energy
consumption at the device level, individuals house level, electric grid level, and also
at distribution level. It also helps to monitor the system performance.
Smart Homes/Smart City: This is one of the most frequently used practical appli-
cations of IoT. Smart homes system ensures both convenience and home security.
Under smart city, it allows Internet access to people. IoT helps to manage traffic,
waste management, water distribution, electricity management, etc. This will help
to give some kind of convenience to the city management administration.
Healthcare Application: In today’s world health monitoring is very important. In
present state, people need to monitor their own health at regular intervals. Smart
devices on patients continuously updates the data on cloud and notifies this to the
hospital/doctor in case of emergency. So, if a patient is coming to the hospital in
case of emergency, by the time he or she reaches the hospital his health report is
diagnosed by doctors and the hospital can quickly take the treatment decision which
is very much crucial.
Education: IoT plays an important role in education. IoT in education system means
better connectivity for learning which helps to fulfill the gaps in the education sector.
Today, many schools and colleges have IoT embedded into their day-to-day learning.
It improves the overall quality of education.
Air and Water Pollution: IoT also plays an important role in monitoring the environ-
mental pollution. There are various sensors available which help to detect pollution
in the air and water. By employing IoT system, one can automize and reduce the
human intervention in monitoring.
Agriculture: Agriculture is the main stay of our economy. Smart agriculture is very
important these days as farmers will have ready information about various agricul-
tural parameters. IoT device installed at remote places measures various parameters
such as soil moisture, chemical application, dam levels, and provides this information
to the farmer in real time.
26 1 PYTHON Programming and IoT

Transportation: In transportation sector, IoT has changed the entire facet of the
same. Now, the market has seen introduction of automated cars with embedded
sensors, which can sense the traffic and switch off automatically. IoT also helps
to identify the location of free parking slot. Some cars are embedded with sensors
which can monitor the current health status of the vehicle, so that one doesn’t face
any issues while traveling.
Marketing your product: IoT has ventured into the marketing industry, using IoT,
companies can now analyze and respond to customer preferences by providing the
desired content and solutions. IoT helps enhance the business strategies in the real
time.
Conclusion:
Python programming and IoT chapter gives the brief introduction to Python and
history of various Python versions. As we all know, compared to other programming
languages, C/C++ is preferred by programmers for embedded applications. But in
recent past Python is extensively used for embedded application and it is eating the
C/C++ space. Developers shouldn’t be surprised when they see Python cropping up
and beginning to play a vital role in embedded system development. An overview
of the Python programming with detailed installation steps of various Python IDEs
such as Thonny, Pycharm, and Anaconda is also provided. There’s a lot of noise
at the moment about the IoT and its impact on everything. The coding flexibility
and dynamic nature of Python helps developers in creating intelligent IoT devices.
Introduction to IoT, its working, and few examples are covered nicely in this chapter.

References

Beazley D, Jones BK (2013) Python cookbook: recipes for mastering python, vol 3. O’Reilly Media,
Inc.
Guzdial MJ, Ericson B (2015) Introduction to computing and programming in Python. Pearson
Jump up to: The enterprise internet of things market. Business Insider. 25 February 2015. Accessed
26 June 2015
Kuhlman D (2012) A python book: beginning python, advanced python, and python exercises.
Section 1.1. Archived from the original (PDF) on 23 June 2012
Perera C, Liu CH, Jayawardena S (2015) The emerging internet of things marketplace from an
industrial perspective: a survey. IEEE Trans Emerg Top Comput 3(4):585–598. arXiv:1502.
00134. Bibcode:2015arXiv150200134P. https://doi.org/10.1109/TETC.2015.2390034. ISSNS
2168-6750. S2CID 7329149
Pilgrim M, Willison S (2009) Dive into Python 3, vol 2. Springer
Vongsingthong S, Smanchat S (2014) Internet of things: a review of applications & technologies
(PDF). Suranaree J Sci Technol
Chapter 2
Configuring Raspberry Pi,
MicroPython Pyboard, and Jetson Nano
for Python

Abstract In today’s world one need not spend much time in configuring and getting
acquainted with any embedded platform. The main focus should be towards quick
launch of any designed application to market. Keeping these points in mind authours
have provided the detailed steps involved in configuration and programming the
platform. Here, authours have focused on three different embedded Platforms such
as Raspberry pi Board for basic interface application, MicroPython Py board for IoT
applications and NVIDIA Jetson Nano board for Machine learning and deep learning
Applications using Python programming with FoG/cloud Computing.

Keywords Raspberry pi · MicroPython Py · Jetson Nano · Firmware · Network


interface card · Single board computer

2.1 Raspberry Pi Board Features

Raspberry Pi is a small single-board computer (SBC). By connecting peripherals


like keyboard, mouse, display to the Raspberry Pi, it will act as a mini personal
computer. Raspberry Pi is popularly used for image/video processing, IoT, and also
robotics applications. Raspberry Pi will have speed limitations as compared to a
general-purpose desktop but can still provide comparable capabilities with much
lower power consumption and cost. Debian-based NOOBS Operating Systems (OS)
and Raspbian OS are the official operating systems for Raspberry Pi. In addition,
there are other OSs such as Archlinux, Ubuntu, Windows 10, RISC OS, IoT Core,
etc. which are adapted for the Raspberry Pi platform. Currently, the Raspbian OS is
optimized for use on the Raspberry Pi. Task such as Python programming, browsing,
word processing, games, can be efficiently handled on the Raspbian OS. The microSD
card with an 8 GB minimum storage is recommended for the smooth functioning of
the OS. Here we have used Raspberry Pi 3 B+ boards as shown in Fig. 2.1.
General-Purpose Input Output (GPIO) is provided on the Raspberry Pi which can
be used for a myriad of applications such as control of motors, sensors, etc. The
computing unit of the Raspberry Pi is the ARM-based Broadcom Processor SoC
which has an on-chip GPU(Graphics Processing Unit). The clock speed offered for

© The Author(s), under exclusive license to Springer Nature Singapore Pte Ltd. 2023 27
J. S. Parab et al., Python Programming Recipes for IoT Applications, Transactions
on Computer Systems and Networks, https://doi.org/10.1007/978-981-19-9466-1_2
28 2 Configuring Raspberry Pi, MicroPython Pyboard, and Jetson Nano …

Fig. 2.1 Raspberry Pi 3B+ board

the processor range from 0.7 to 1.2 GHz based on the various models of the Raspberry
Pi. SDRAM is provided with capacities ranging from 256 MB to 1 GB. Popular serial
interfaces such as the SPI, I2C, I2S, and UART are provided on the Raspberry Pi.
The different versions of the Raspberry Pi are Raspberry Pi Zero, Raspberry Pi 1
A, Raspberry Pi 1 A+, Raspberry Pi 1 B, Raspberry Pi 1 B+, Raspberry Pi 2 B,
Raspberry Pi 3 B, Raspberry Pi 3 B+, and Raspberry Pi 4.
Out of the above versions of Raspberry Pi, more prominently used Raspberry Pi
models and their features are given in Table 2.1.
Raspberry Pi 3 B+ Hardware
The hardware on the Raspberry Pi 3 B+ is highlighted in Fig. 2.2. Important hardware
features are explained here. “Raspberry Pi 3 ModelB+”. https://static.raspberrypi.
org/files/product-briefs/Raspberry-Pi-Model-Bplus-Product-Brief.pdf

Table 2.1 Features of different versions of Raspberry Pi


Features Raspberry Pi Raspberry Pi 2 Raspberry Pi 3 Raspberry Pi zero
model B model B model B+
SOC Broadcom Broadcom 2836 Broadcom Broadcom 2835
2835 2837B0
CPU ARM-11 A7 Quad-Cortex A53 ARM-11
Quad-Cortex
Operating 0.7 0.9 1.4 1
frequency (GHz)
RAM (SDRAM) 512 MB 1 GB 1 GB 512 MB
GPU speed 0.25 GHz 0.25 GHz 0.4 GHz 0.25 GHz
(Videocore IV)
Storage (microSD) Supported Supported Supported Supported
Ethernet Supported Supported Supported Not supported
Wireless Not supported Not supported Bluetooth and Not supported
Wi-Fi
2.1 Raspberry Pi Board Features 29

Fig. 2.2 Raspberry Pi 3 model B+ hardware

• CSI Camera Interface: CSI (Camera Serial Interface) connector is used to


connect a Pi camera to the Broadcom Processor.
• HDMI (High-Definition Multimedia Interface): This interface is used to
transmit video and digital audio in an uncompressed form to a display monitor
which supports HDMI.
• Composite Audio and Video Output: The port is used to send audio along with
the video to the audio/video systems.
• Power LED: The red-colored LED gives the power indication. This LED begins
to blink when the supply voltage falls below 4.63 V.
• DSI (Display Serial Interface): DSI interface uses a 15-pin ribbon cable to
connect to an LCD. This is a fast high-resolution display interface that sends
video data directly to the display from the GPU.
• Activity LED: This green-colored LED indicates microSD card activity.

2.1.1 Configuration of Raspberry Pi

Flashing OS image on Raspberry Pi


Raspberry Pi OS is open-source based on Debian 10. Debian is a popular open-
source Linux distribution. Two methods are generally used to install the Raspberry
Pi OS on a blank microSD card. Before starting, make sure you have the following
prerequisites:
• Raspberry Pi board.
• Micro-SDHC card (with SD adapter) of size at least 8–32 GB.
• Micro-HDMI to HDMI cable.
• 5 V DC via USB-C connector.
• Keyboard, mouse, monitor.
30 2 Configuring Raspberry Pi, MicroPython Pyboard, and Jetson Nano …

Flashing OS image using Raspberry Pi Imager (Method 1)


Step 1: Download and install Raspberry Pi Imager from the official Raspberry Pi
website (https://www.raspberrypi.org/software/) as shown in Fig. 2.3a.
Step 2: Click on download for windows and install it.
Step 3: Open Raspberry Pi imager.
Step 4: Choose OS as shown in Fig. 2.3b.

Fig. 2.3 a Raspberry website, b Raspberry imager, c Raspberry OS selection, d choose storage for
OS installation, e microSD card or storage selection, and f OS installation
2.1 Raspberry Pi Board Features 31

Fig. 2.4 a Raspberry Pi Desktop website and b Raspberry Pi Desktop OS download

Step 5: Select ’Raspberry Pi OS’ as shown in Fig. 2.3c.


Step 6: Insert microSD card and it will get detect automatically as shown in Fig. 2.3d
and e.
Step 7: Click on ’Write’ as shown in Fig. 2.3f.
Flashing OS image using balenaEtcher (Method 2)
Step 1: Download Raspberry Pi Desktop OS from https://www.raspberrypi.org/
software/ by clicking on the Download Raspberry Pi Desktop button as shown in
Fig. 2.4a.
Step 2: Click on the ’Download’ button as shown in Fig. 2.4b https://www.raspbe
rrypi.org/software/raspberry-pi-desktop/).
Step 3: Download balenaEtcher from https://www.balena.io/etcher/ and install it.
Etcher enables the user to create bootable USB flash drives.
Step 4: There are three versions of Raspberry Pi OS, namely, Raspberry Pi OS (32
bit) Lite, Raspberry Pi OS (32 bit), and Raspberry Pi OS Full (32 bit) are available.
Step 5: While using balenaEtcher, select the option ’Flash from file’ and browse to
the location where the image is downloaded.
Step 6: The microSD card needs to be formatted. Choose the ’select target’ option
and select the target as your microSD.
32 2 Configuring Raspberry Pi, MicroPython Pyboard, and Jetson Nano …

Fig. 2.5 BalenaEtcher for flashing Raspberry Pi

Step 7: The final step is to hit the ’Flash’ button and then the balenaEtcher will start
the flashing process as shown in Fig. 2.5.
Booting Raspberry Pi for the First Time
Step 1: Insert your microSD card into Raspberry Pi.
Step 2: Connect power, keyboard, mouse, and monitor to Raspberry Pi.
Step 3: After booting you get “Welcome to the Raspberry Pi” dialog on the display,
as shown in Fig. 2.6.
Step 4: Quick setup of Raspberry Pi:
(i) On the next screen you will be asked to choose your Country (Fig. 2.7a),
Language, and Timezone.
(ii) Set account password as shown in Fig. 2.7b.
(iii) Followed by this, select a Wireless Network and its network password.
(iv) Set up the desktop screen by clicking ’Next’ as shown in Fig. 2.7c.
(v) Finally it shows setup complete as shown in Fig. 2.7d.
Now the Raspberry Pi is ready to use.
2.2 MicroPython Pyboard Features 33

Fig. 2.6 Screen after the first boot

2.2 MicroPython Pyboard Features

The MicroPython Pyboard is a small form factor development board designed to run
MicroPython to realize various IoT projects. MicroPython is versatile and provides
an interactive prompt, locks, generators, list understanding, exception handling, etc.
Below is the specification of Pyboard V1.1: “Quick reference for the Pyboard”.
https://docs.micropython.org/en/latest/Pyboard/quickref.html
Pyboard V1.1 Specifications:
• STM32F405RG microcontroller (clock frequency 168 MHz Cortex-M4 core)
• 1024 KB flash ROM, 192 KB RAM
• Power from microUSB connector
• MMA7660 3-axis accelerometer
• MicroSD card slot
• 5 GPIO on the bottom, 24 GPIO on the left and right, Real-Time Clock (RTC)
• Three 12-bit analog-to-digital converters (ADC)
• Two 12-bit digital-to-analog (DAC) converters
• One user and one reset switch, four LEDs
• Wide input voltage range from 3.6 V to 16 V, 3.3 V low dropout voltage regulator
• Upgrade firmware through DFU bootloader in ROM
34 2 Configuring Raspberry Pi, MicroPython Pyboard, and Jetson Nano …

Fig. 2.7 a Set country, language, and timezone; b set a new password; c set up screen for desktop;
and d setup complete

2.2.1 Configuration of MicroPython Pyboard

Loading the MicroPython firmware on Pyboard v1.1


The Pyboard comes with a strong microcontroller of ARM Cortex-M4, as shown in
Fig. 2.8. The coding can be started without any installation because the MicroPython
interpreter is pre-loaded with the Pyboard. The pin details are given in Fig. 2.9.
The basic steps to start the Pyboard are as follows:
• Connect the Pyboard to a laptop or computer and list it as a USB storage device.
• Navigate to the Pyboard drive (likely called “PYBFLASH”).
• Edit ’main.py’ with MicroPython code and save the file.
• Select the drive from the OS.
• To start executing code or application press the Reset button (RST).
2.2 MicroPython Pyboard Features 35

Fig. 2.8 Front and back of Pyboard v1.1

Fig. 2.9 Pyboard pin details


36 2 Configuring Raspberry Pi, MicroPython Pyboard, and Jetson Nano …

Fig. 2.10 a Connect P1 (DFU) and 3V3 pins and b connection of P1 (DFU) and 3V3 pins using
jumper

Update Firmware
To update the Pyboard’s interpreter the following steps need to be followed:
Step 1: Disconnect the power supply from the Pyboard.
Step 2: Short P1 (DFU) pin to power (3V3) pins using jumper or wire as shown in
Fig. 2.10 a and b.
Step 3: Connect the Pyboard to the computer through the USB port.
Step 4: Download the firmware file from MicroPython website as shown in Fig. 2.11
(https://micropython.org/download/pybv1/). Carefully select the firmware based on
the version of Pyboard used (PYBv1.0 or PYBv1.1). Several firmware versions are
created with distinct functionalities for each Pyboard version.
Step 5: Download the latest stable firmware file for Pyboard having extension ’.dfu’.
The ’dfu-util’ will be used to flash the Pyboard with the new firmware. The installation
process is different for OS like Windows, Linux, etc.
The installation process for Windows OS:
Windows makes it difficult to install non-signed drivers, so use a special program to
install such drivers.
Step 1: Download and install the Zadig utility from https://zadig.akeo.ie/. Open the
utility as shown in Fig. 2.12. Make sure that Pyboard is plugged in and it is in DFU
mode (with P1 and 3.3V shorted).
Step 2: In the Zadig utility, select Options → ‘List All Devices’. From the drop-
down menu, select ’STM32 BOOTLOADER’. Zadig utility recommends replacing
Random documents with unrelated
content Scribd suggests to you:
CHAPTER VI

“I
HAVE something serious to say to you, my daughter.”
The speaker was Israel Hart. The place, his study, a
commodious apartment overlooking the front drive, of which
the most striking features were a great library table and a solid iron
safe. The time was a mid-autumn Sunday afternoon. A cheerful fire
showed up the warmth of a Turkey carpet, and cast flickering gleams
upon the varnished surfaces of the three oil pictures on the walls.
The money-lender was sitting at the table, with some
correspondence in front of him, when he greeted Minna, who had
come in obedience to a summons, with this announcement. He was
a man of over sixty, stout and loose-featured, with grizzling hair and
beard. His race was clearly written on his countenance, which bore,
too, that stamp of his calling which can best be suggested negatively
as an absence of spirituality. The absorbing pursuit of money
hardens the eyes and leaves the lower part of the face
undetermined. One meets a thousand such, morning and evening, in
suburban trains. Yet the face of Israel Hart was not without marks of
integrity and even of a certain benevolence.
Minna crossed the room slowly to the fireplace and rested one
small shoe on the fender.
“Yes, papa?”
“I have here a formal letter from my good friend, Simeon
Goldberg, which I wish you to read.”
“About marrying me?”
“Yes. It deals exclusively with the subject.”
“What is the use of my reading the letter?” she said, without
shifting her attitude, and ignoring the letter which her father had
wheeled round in his chair in order to offer her. “I can guess what’s
in it. Oh, dear! Why does he worry?”
“I desire you to read it, Minna,” said her father. She moved, took it
from him, read it nonchalantly, with a contemptuous smile, and
threw it, with a woman’s charming awkwardness in throwing, upon
the table.
“I might be shares in a new company he was asking you for. Do I
look like a scrip or a bond? I won’t have him, of course, but when
you write to him, tell him that that’s not the way to win a woman
with blood in her veins.”
“You’re a foolish girl, Minna. If you have any kind of regard for my
wishes you will give this matter further consideration. Where will
you, Minna Hart, find a better match?”
“Oh, in a penny box!” she cried, flippantly.
“At least it would have some latent fire at the end of it!”
“You will regret it,” said her father.
“It will be something to do, then. Tell him I’ll try. It may soothe his
vanity.”
“Come here, my daughter,” said the old man.
She moved obediently to his side and put her hand in his that was
held open.
“You and I have managed to drift quite apart, but I am your father
and must think for you. What are you going to do, when I am gone,
if you don’t get some good man to take care of you?”
She looked at him rather pityingly. It was such a futile question.
Her undeveloped sympathies saw only its ludicrous, not its pathetic
side.
“Oh, I shall marry some day,” she said, lightly. “You need have no
fear of that.”
“Ay. But whom?”
She shrugged her shoulders and tapped her toe on the carpet with
a shade of irritation. It was ridiculous to stand there like a tableau
vivant, holding her father’s hand.
“Think of Simeon Goldberg, a good friend, a man not so careless
in observance of the Law as we—but still of the Reformed faith—and
worth”—his voice grew unconsciously reverential—“five hundred
thousand pounds, if he’s worth a penny.”
The girl’s eyes flashed for a second, then grew again
contemptuous.
“It’s an absolute impossibility. You must let this drop, papa. We
don’t live in the Middle Ages when you could put me on bread and
water and lock me up until I consented; or in patriarchal times,
when you could curse me for disobeying you—so why discuss the
matter further? I shall marry in my own good time. I am not the sort
that old maids are made of.”
He released her hand and turned towards the table. “Very well,”
he said, taking up a pen, “I will not force you. But remember that
your choice among our people is limited.”
“I might choose outside them,” she said, pausing in her lazy walk
towards the door.
Israel Hart started round in the chair and bent his brows upon her.
She tried saucily to meet his eyes, but hers sank abashed.
“My daughter,” he said, sternly. “Let me never hear you say such a
thing again, even in jest. Remember you are a Jewess.”
She stood for a moment or two twitching her fingers, longing to
retort. But she did not dare. It was only when she found herself
outside his door that she gave vent to the passionate outburst:
“Would to God the accursed race had perished with the other ten
tribes!”
She went upstairs to her bedroom with anger and foreboding at
her heart, and put on hat and jacket, casting mere mechanical
glances at the mirror, for the sake of adjustment. Six months before,
her dressing to meet Hugh had been a matter of sweet and import
and coquetry. She looked, however, very pretty in her dark-blue
costume, with dainty ruffle at her throat when she met him three-
quarters of an hour later in Kensington Gardens. He was walking
moodily up and down the broad walk, near their appointed meeting
place; but when he caught sight of her he quickened his step.
“I am sorry I’m late,” she said, with some petulance; “but when
you will make me take these long journeys——”
“It is not my fault, dear,” he said, casually. “I told you I was
lunching at Lancaster Gate and was going to put in a call near by
before dinner. It was my only hour.”
“Oh, well, never mind. I’m here now. It was papa who kept me.
I’ve been discussing matrimony with him.”
“In the abstract, or——”
“Both. It began with the all too concrete Goldberg. Refusing him,
I’m to marry an abstract Jew or the curse of Abraham will fall upon
me.”
“Be more precise, if you don’t mind,” he said seriously.
She gave him a detailed account of the conversation,
picturesquely satiric. Hugh listened sombrely, holding his stick with
both hands behind his back, as they strolled slowly down among the
fallen leaves.
“So he’ll never consent,” she concluded. “I suppose we’ll have to
wait until—well—the ordinary way of nature. He’s an old man.”
“We mustn’t think of that, my child,” said Hugh, with some
gentleness.
“I don’t see why not. It will solve all our difficulties.”
“What a mixture of flint and flesh you are, Minna,” he said,
regarding her curiously.
“I never pretend to love where I don’t,” she replied. “And when
people thwart me I begin to dislike.”
They walked on a little in silence, turned and retraced their steps.
The dusk began to gather round them and the autumn mist to hang
upon the thinning branches. Minna shivered a little and took his arm.
“Why don’t you say something kind to me, Hugh dear?” she said,
plaintively.
He stooped and kissed her, and they went on their way less far
apart than before. Presently she asked him where he was going to
dine.
“At the Merriams.”
“I wish to goodness you wouldn’t!” she exclaimed, petulantly.
“My dear girl, because I am secretly married to you, I am not
going to give up my dearest and oldest friends.”
“I hate them. You know I do.”
“It’s a pity, my dear, but it can’t be helped. And haven’t we
discussed this rather too often lately?”
“You do very little to please me,” she said.
“I would do anything in reason.”
“If you loved me, you would not think of reason.”
“Look here, Minna,” said Hugh, losing patience, “what do you
want? Of course I love you. But as things are, I must lead my own
life. If you were always with me, there would be modifications—
naturally. I am getting as tired of this half and half state as you are.
I was going soon to approach your father on the subject. But what
you have told me this afternoon has somewhat disturbed my plans.
We must wait a little longer. But in the meantime——”
“I don’t mind waiting at all,” she interrupted. “It isn’t that.”
“Well, what is it, dear, that I can do for you?”
“I see so little of you—and you don’t seem to care. If you go on
like this, I feel I shall grow to dislike you—and you are my husband
—and oh, darling, I want you so sometimes!”
All the seductive richness in her voice toned the last appeal.
Hugh’s conscience pricked him. He had of late felt himself drifting far
from her and had made no efforts to reapproach. Now, however, the
pathetic and languorous appeal caused him to bend his head very
tenderly.
“Tell me what to do, sweetheart.”
“Ah! you know,” she murmured.
“The window?”
She pressed his arm tightly. “I shall go to sleep so happy.”
So he promised and the girl’s face brightened. Soon afterwards
they parted. Minna drove homewards in a cab, kissing her hand to
him as it moved off, and Hugh walked along towards Lancaster Gate,
deep in troubled thought. It was an ill-starred marriage, already he
regretted his folly and his weakness. If they had shared the same
home, living a common life, he felt that he could have maintained a
constantly tender attitude towards her, by means of a passive
acceptance of his lot. But in the present circumstances, the nature of
things demanded of him active demonstration. The necessary
intriguing was repugnant to him. To visit his wife like a thief in the
night was an act from which he shrank as from something mean and
degrading. A passionate love would have swept away pettier
feelings. It is only such a love that laughs at locksmiths; a waning
passion be-bestows on them irritable curses. The prospect of
entering The Lindens, late at night, by a window which Minna
secretly unlatched, and creeping thief-wise up the stairs to her
apartments, had lost its edge of romance. He had promised,
however, and it became a disagreeable duty.
It damped his spirits for the evening. Even Irene could not cheer
him. Conversation degenerated into futile bar gossip between Gerard
and himself, which they protracted sleepily till a late hour. When at
last he found himself with Minna, who had taken infinite pains to
make her beauty as attractive as possible, she reopened, with
feminine inconsistency, the chapter of the Merriams and sent him
away, after a little, angry and disheartened.
His unqualified refusal to allow his regard for her to affect his
relations with his friends gradually magnified itself, through the girl’s
jealousy, into a great wrong. Once at the turn of a road she met him
with them face to face. The after-glow of laughter was in Irene’s
eyes. Minna acknowledged their salute with sullen stiffness, and
when Hugh fell back a pace and turned to her with outstretched
hand, she dismissed him angrily. Her face wore the hardened
expression he had seen on it once before. Then he had attributed it
to strength. But now it seemed to reveal only sulky ill-breeding. A
phrase defining her flashed through his mind. She looked common.
“What a peculiarly disagreeable young woman,” said Gerard, as he
rejoined his friends.
Hugh winced. Although not ill pleased to see that Gerard had no
suspicions of the relations between himself and Minna, the
outspoken judgment on his wife was anything but gratifying.
He struggled, however, to atone by gentleness for his grievous
fault in marrying her. But it was a futile task to try to convince a
jealous, untrained girl, who reasoned from her appetites and argued
from her passions. At last he gave it up with a helpless gesture of
impatience.
“It seems beyond your nature to comprehend the bond between
the Merriams and myself,” he said, one day.
She laughed scornfully. “It would appeal to the meanest
understanding. ‘A man and his wife and the Tertium Quid.’”
It was the first time she had made such an insinuation. A second
passed before he could quite realise the scope of her words. Then
the anger blazed in his eyes and the girl shrank back frightened.
“If you ever say such a silly and wicked thing again,” he said, “I
will not speak to you again as long as I live.”
He left her there and then, in the middle of the road, and returned
homewards with angry strides. The first available post brought him a
repentant letter. A semblance of harmony was re-established.
Thenceforward Minna kept silence concerning Irene, but she none
the less harboured a bitter resentment against her husband. The
habit of brooding over grievances grew into a disastrous occupation.
They rarely spent a non-recriminative hour. The issue of dispute, no
longer Irene, became in turns his work, his social engagements his
neglect, his aloofness, even his Gentile birth and inherited instincts.
And so the dreary months wore on. At last certain horrible fears
that had been vaguely haunting the girl’s ignorance developed into
certainties. The prospect of maternity was inexpressibly repugnant
to her idle, sensuous nature. The thought became a nightmare. So
bitterly did she resent Hugh’s attitude towards her, that she shrank
from telling him. At last she made up her mind, wrote to him asking
for an interview at his chambers. He replied that he would be
engaged in court at the time she mentioned, and regretted that he
could not see her until the next day. Quite an affectionate and
courteous letter from a busy and unsuspecting man. But it sent her
into an unreasoning passion of anger. She tore the letter into tiny
fragments, ordered her boxes to be packed and went off forthwith to
Brighton.
It was only a fortnight afterwards that Hugh received a letter from
Anna Cassaba telling of an accident, illness and a premature end of
troubles. In consternation he took the first train down. Minna
refused to see him. Old Anna was in great distress. Hugh’s
handsome face and proud bearing had won her heart. To act the
stern janitress taxed all her love for her darling. She sought to
alleviate his disappointment, suggested that women often had
strange, unaccountable fancies and aversions. Better to leave the
poor child alone for the present. When she recovered she would be
her own gay self again—forget the irrational dislike she had
conceived for him, love him with all her old love and there would yet
be a bonny babe of theirs for old Anna to dandle on her knees
before she died.
The man’s pity and tenderness were wonderfully quickened. If she
had willed, he would have folded her in his arms and made her sick
bed sweet. He scribbled a hasty line.
“Darling—I am grieved to the heart. Your husband loves you, dear,
with a fresher love. Let me tell you so—and tell you to get well,
when all things will be different and dear again.”
The old woman took the note to Minna. He crept up to the
bedroom door, listened, heard the faint rustle of the paper in her
hands, and then came her voice, irritable and peevish:
“Tell him to go away and let me be.”
So Hugh returned to London heavy-hearted, with a gnawing sense
of having ruined the girl’s life. The weeks went past. Early in the
New Year Minna returned to her father’s house, looking ill and worn.
Israel noticed the change, grew solicitous as to her well-being. Why
had she not told him she had been poorly at Brighton? He would
have given her all the care and nursing that money could provide.
His kind words caused her a faint stirring of emotion—an
adumbration of a tenderness that might have been; and as the
loneliness and aimlessness of her life grew more oppressive, an
instinct of self-preservation drew her nearer to his side. The horror
of her illness still clung to her. It was a kind of Maccabre dance over
her dead passion. Yet she was conscious of wrong done to Hugh,
and received him kindly when he came to see her one afternoon
shortly after her return. He was anxious to make reparation.
“We are bound together for the rest of our lives, dear,” he said.
“Perhaps it was a mistake to begin with—and certainly the secrecy
has been a terrible blunder. Let us brave it all out now and be done
with it, and start life afresh.”
“Do you think we can ever be happy again together?”
“My dear little girl, I have wronged you—but I will try to make
amends. I have a certain position in society—even if you don’t love
me, your life will be brighter than it is now.”
She leaned back in one of her indolent attitudes. “Perhaps. Not
now. I am afraid of my father. He might curse me—and that would
be annoying.” Hugh paused, somewhat baffled at this new idea.
“They will be merely words of anger,” he replied. “It will not be long
lived.”
But she shook her head. It was better to wait. Perhaps she might
gradually influence him—and then all would be smooth sailing. Hugh
saw an element of reason in her proposal, and for a time returned to
his briefs. For his own sake, he was not loth to postpone the
announcement. The debt to Israel weighed heavily upon his
conscience. But as long as his marriage remained a secret, and as
long as his uncle lived, he could spare himself the galling reproach of
trickery. Meanwhile his practice was showing signs of improvement.
A brilliant cast might land him at a bound into affluence, and then he
could raise the money, cry quits with the urbane and gentle
mannered Shylock on the score of his ducats, and brave his
reproaches on the score of his daughter. Thus doth hope spring
eternal in the human breast.
But unforeseen action on the part of old Anna Cassaba suddenly
hastened events. She let her house in Brighton for an indefinite
period, and announced her return to Smyrna. A lawsuit had arisen
over some property which Minna’s Syrian mother had bequeathed to
the old nurse, and which formed the chief source of her comfortable
income. Anna was summoned to look after her interests. The
nostalgia of her native East, which she had not visited for over
twenty years, grew strong upon her. She could not tell how long she
might be absent from England.
Minna contemplated her departure with sinking heart. Anna was
the saving spar to which she clung. Sheltering her, temporarily, in
her own dressing-room at The Lindens, Minna wept in her arms and
implored a speedy return. The old nurse cried, too, and spoke of
death, as old folks will, and comforted her in such wise that at last
the girl grew desperate in her anticipated desolation. The result was
a sudden determination that Hugh should speak.
“I have come to the end of my tether,” she said to him. “Anything
would be better than this. I’ll get papa to ask you to dinner. He likes
you, and has been enquiring why you come so seldom now.”
In the course of a day or two he received and accepted an
invitation for the following Monday. He felt happier. The die was cast.
If Hart called him a scamp for thus tricking him out of five thousand
pounds, he would bear it as an atoning humiliation for Minna’s sake.
He prepared to go through the ordeal with an air of disdain. But in
his category of scorn he himself was included.
CHAPTER VII

“H
E saved Gerard’s life? What nonsense! If he had, I should
have heard about it.”
Irene spoke warmly. The person she addressed was
Harroway, an elderly solicitor, an intimate friend of Hugh and the
Merriams. His wife Selina, who had brought him to pay an afternoon
call on Irene, watched with amused serenity the discomfiture on his
broad and benevolent face.
“It isn’t nonsense,” he protested. “I’m not in the habit of talking
nonsense, I assure you. Am I, Selina?”
“A wife’s testimony isn’t evidence,” replied Mrs. Harroway.
“But what do you mean?” asked Irene, growing serious.
“Literally what I said. Have you never heard?”
“No.”
“It was in Switzerland, years ago. Chevasse, who was on the trip
with them, told me. The two were roped together, suddenly fell and
dangled over a precipice, Colman lowest. The guide on top couldn’t
hold them up. The rope was slipping. So Colman whipped out his
knife and cut himself off.”
“And then?”
“Oh, then the guide hauled Gerard up safe and sound.”
“But Hugh?”
“When they looked over to identify the spot where his pulp was
lying, they saw him half way down, miraculously caught on a jag of
rock. You might try the game twenty million times without it
succeeding. I’ve had the place pointed out to me. And there he
remained some hours clinging on between heaven and earth.”
Irene closed her eyes with a shiver.
“Don’t,” she said. “You make me sick.”
“Funny that Gerard never told you of it, for a clearer case of
saving life at the obvious sacrifice of one’s own, I have never heard
of.”
Irene’s hand trembled a little as she poured out the tea. Mrs.
Harroway, unobserved, shook her head reproachfully at her
husband, who, interpreting her action rightly, plunged into irrelevant
observations. But at that moment Gerard entered the room. Irene
turned to him at once impulsively.
“Oh, Gerard, Mr. Harroway has been telling me a horrible story of
Hugh saving your life in Switzerland. Is it true?”
A shade of annoyance passed over his face.
“Yes,” he replied. “I remember his doing something of the kind.”
“Oh, do let us talk of something cheerful,” said Mrs. Harroway;
and she led the conversation to ordinary topics until the end of the
visit.
When the Harroways had gone, Irene sat on the arm of Gerard’s
chair.
“Why did you never tell me?”
He grew red, fidgeted awhile with his hands. At last, looking up,
and seeing her luminous eyes fixed upon him, he said, gravely:
“There are certain things that a man keeps in his own heart.”
The solemnity of the saying somewhat awed her. “And Hugh never
spoke either.”
“Of course not,” said Gerard.
“What an unpayable debt we owe him.”
“We’ll pay it all right when the time comes.”
“What little things women are when compared with men,” said
Irene. “We could never have kept a fact like that locked up in our
souls.”
Gerard accepted the tribute with his usual reserve. As his wife
knew, he was not a man to waste words over sentiment. She uttered
what she felt were his thoughts.
“I didn’t understand your not telling me. But now I do. Those
things, when unspoken of, knit two men more firmly together.”
She was silent for a moment; then changing her tone and
grasping Gerard’s arm:
“We won’t speak of it again, either,” she said. “It is horrible to
think of. And what should I have done without you?”
The servant entering to remove the tea things was a signal for
Irene to dress for dinner. She left the room, and then Gerard rose,
and, walking to the window, took out his pocket handkerchief and
wiped the perspiration from his forehead.
The result of her knowledge of this fact in the lives of Hugh and
Gerard was an added tenderness of gratitude in her feelings towards
the former. During the past few months he had been slipping
somewhat apart from her. He had lost his old buoyancy of manner,
and it was easy for her feminine intuition to perceive that the
change had some radical cause. Now she blamed herself for not
having taken the initiative, and offered him more openly the aid of
her friendship. The chance of doing so occurred on the following
Sunday, when, in response to an urgent little note, Hugh came to
lunch. Gerard was absent. Business had summoned him to
Edinburgh, where he was likely to remain some time. The two sat
down to table alone together, and, while the servant was in the
room, talked of divers matters: the waif who had been admitted into
St. Katherine’s school, the Institution which was flourishing, and
extending its sphere of benevolence. At last she touched upon
literary matters.
“When are we to see a new volume?”
He lifted his shoulders slightly, and fingered the stem of his old
German wine glass.
“When I have regained my lost youth,” he said, ironically. “One
must have enthusiasm even for that kind of rubbish. Don’t look so
concerned,” he added, with a laugh; “I’m not hypochondriac yet. My
view of life is only growing a little more materialistic, that is all. I
share Peter Bell’s conception of the primrose.”
He quoted the lines jestingly, and, the meal being over, drew out
his cigarette case and began to smoke.
“You are talking for the sake of talking,” said Irene. “I wish you
wouldn’t. Hugh,” she continued, with a certain shy softness that had
its charm, “don’t be vexed with me. Tell me what is changing you.
You know that I owe to you the existence of all that is dearest to me
in the world, and I long so to pay you back a little in the help that
friendship can give.”
“You can’t do it now, Renie,” he said, abruptly. “Afterwards you
may. That is, if you and Gerard don’t think me a pitiful scamp. You
won’t have long to wait.”
The sudden realisation that this was perhaps the last of the
brotherly meals he should have with her, dismayed him. In a few
days he would be either the acknowledged betrothed or the
acknowledged husband of another woman—her bitterest enemy. The
old dear order had changed. Hitherto he had held a unique and
delicate position in her thoughts, that of the loyal friend and
honourable lover. Henceforward he would be another woman’s
husband, which would make an immeasurable difference. He looked
round the familiar walls of the cosy dining-room, and then with
unconscious wistfulness upon her face in profile. To him there was
none more beautiful in all the world. The broad forehead; the
delicate, sensitive nose; the strong, pointed chin; the mobile, faintly
coloured lips; the eyes capable of great passion, yet showing
habitually a grave and luminous kindness; the noble up sweep of her
hair from the temple contours, giving an impression of queenliness;
the soft, fair gold of her hair itself, crowning her head too lightly to
be a crown and too individually to be a halo; the head poised with
tender dignity upon a broad, full throat—all the conflicting features
combined harmoniously together to form in a lover’s eyes a face
telling of a great and tender womanhood. And the picture of that
other rose before him, beautiful, too, in its sensuous duskiness, yet
stamped forever with his own condemnation of commonness. His
glance grew troubled as it met Irene’s.
“There is nothing in the wide world that we would not do for you,
Hugh,” she said.
“Doing is one thing,” he replied. “Letting things go on is another,
I’m afraid you’ll come to look upon me as a blackguard, and that
must make some difference.”
“Nothing will make any difference in our love for you. So long as
Gerard and I sit opposite here, there will be your place always
between us. Besides, the idea of your being a blackguard is simply
silly!”
He laughed in spite of his depression. Her tone was emphatic.
“I believe you’d champion me through a grand jury list of
iniquities. I wish you could have split yourself into two in the years
past, Renie. You would have kept me out of mischief.”
It was Irene’s turn to look troubled.
“Do you know, Hugh,” she said in a low voice, “that lately I have
feared I may have spoiled your life.”
“Ah, my dear child,” he cried, regaining in a flash all his old
vehemence, “it is not the missing of the angel’s touch that spoils a
man’s life. He is singularly fortunate to come within the beat of her
wings.”
“Thank you,” she said, blushing very prettily. “That is like your old,
extravagant self.”
For a long time afterwards the colour remained in her face.
Thousands of women have been called angels, and have thought
little of it. But not one has felt otherwise than tremulously abashed
when the similitude has come from a man’s worshipping sincerity.
But that was the end of the conversation. Irene had said her say,
and no more was to be gained by dwelling on the topic.
When he had gone, she settled down to her correspondence. But
for a long while she sat biting the end of her quill pen.
“I wonder who she can be,” she said, musingly. Of course it was a
woman. She passed in review all their common acquaintance; then
shook her head with a smile. This disturbing element in Hugh’s life
lay outside the circle. The image of Minna Hart never presented itself
before her thoughts. For Irene had large ideas, and pictured the
woman as one of commanding intelligence and brilliant personality.
How else to account for the folly of so vigorous a manhood as
Hugh’s? A noble man, a noble choice. Foolish—but sublimely so. She
knew little of the ways of men, judged them according to her own
ideals. For her life had been spent singularly apart from men. Her
mother, a delicate woman, unable to bear the Indian climate, had
brought her up in quiet seclusion. She had been a choice spirit, a
weaver of dreams, one whose presence is felt like the moonlight
through Gothic tracery, a writer of flower-like fairy tales for children,
an ethereal being whom it was Irene’s impassioned mission to
shelter from the rough winds. Her father, once a soldier with a V. C.
in the Mutiny, afterwards a commissioner of a great Indian province,
had appeared to her in brief spells of leave, invested with a halo of
glory. On her mother’s death, she had gone out heartbroken to join
him, but only to learn, on arrival at Bombay, that she was fatherless.
And then, for the first time, men, Gerard and Hugh, had come into
her life—and she saw them as gods walking. The years had
mellowed into a strong, homogeneous character her inherited
qualities—the mother’s delicate womanliness, the father’s daring and
power of leadership—and busy contact with the world had
developed the acuteness of her judgment; but the ideals of the girl
survived, unprofaned by vulgar touch. The two men to whom she
had given her love and friendship still remained as gods, above the
baser passions and meaner follies of mankind.
Suddenly a face flashed before her, as that, possibly, of the
mysterious woman who was involved in Hugh’s life. She had never
seen it in the flesh; only a photograph of it some years ago, in
Hugh’s rooms, when she was lunching there with Gerard. She had
taken a book from the shelves and the portrait had fallen out. It
represented a woman, tall, resplendent, haughty, cruelly beautiful.
The eyes, even in the photograph, glittered coldly and dangerously.
Irene had uttered a little cry of surprise and admiration. Hugh had
taken it from her hands.
“A great beauty,” she had remarked.
“Yes. La Belle Dame sans merci.”
“Her eyes are cruel.”
“They are ophidian. I don’t like you to look at them,” he had
replied, throwing the photograph into a drawer. And then he had
said, with a smile: “They belong to ‘old unhappy far-off things, and
battles long ago.’”
Did they? That was the question she now put to herself, and vainly
tried to answer. It is permitted even to the most confiding of women
to entertain occasional doubts as to the ingenuousness of bachelor
friends.
At last she drew a sheet of note-paper from the stationery case in
front of her and inscribed the date. But she paused, and gazed
absently at the wall, her mind full of Hugh’s dilemma. She felt an
unaccountable dislike for the woman with the ophidian eyes.
Presently she broke into a little laugh.
“I do believe I am jealous! I must tell Gerard.”
CHAPTER VIII

A
n anxious face met Hugh as he was shown into the drawing-
room. Minna had grown into a woman since her illness, and
had hardened considerably during the process. Instead of the
lazy uplifting of silky lashes, veiling swimming eyes, with which she
had been wont to greet him, she met him with a glance as keen as
his own. The racial spirit of bargain revealed itself in her expression.
Once more he was struck by the latent power of strength and
hardness. She wore a dark red dinner dress and heavy gold
bracelets, and a diamond star shone in the dark clusters of her hair.
“I am glad you have come early,” she said, receiving his kiss
mechanically. “I wanted to have a word with you before papa comes
down.”
They walked slowly to the fireplace and stood turned towards
each other, leaning against the mantelpiece.
“Well?” he said.
“When are you going to tell papa?”
“After dinner—‘over the walnuts and the wine.’”
“Don’t. Wait until you have said good-bye to me.”
“How shall I let you know the result? You will be anxious.”
“Do you mind coming to me afterwards—the old way?”
“Not at all. But I shall have to wait outside until the house is
quiet.”
“There will be a nice fire upstairs to warm you.”
“And my wife’s heart?”
“That depends,” she replied, with a curious smile. “Shall you be
perishing for it?”
“We must try to win back to each other again, Minna,” he said,
stretching out his hand so as to touch lightly her cheek. “It will not
be hard, for circumstances will be more favourable than they have
been. I am afraid I haven’t played a very noble part, my dear—and
when a man is conscious of that, he vents his spleen upon others.
That’s not very noble either, but it’s miserable human nature. Do you
understand?”
“I am glad you see that you have treated me badly,” she said. “At
any rate it’s a hopeful beginning.”
The thought of her failure to grasp his meaning was dancing
irritatingly in his mind as he stepped forward to greet Israel Hart,
who at that moment entered the room.
“Very pleased to see you, Mr. Colman. Sorry I’m late. Kept in the
city. Cold, isn’t it?”
He rubbed his soft palms together and held them out to the blaze
of the fire.
“How’s business? Been letting loose lots of lucky gaol-birds lately?”
“Oh, we always believe firmly in our clients’ innocence,” retorted
Hugh with a laugh.
“That’s more than I do in mine,” said the moneylender.
The young man returned a light answer, but curled his moustache,
and drew himself up with unconscious haughtiness. The touch of
vulgarity jarred upon him. When one has to humble one’s pride
before a man, one is apt to become supersensitive of such things.
Unfortunately for Hugh, Israel evinced a more genial and familiar
mood than usual, and, during the elaborate meal that followed,
allowed himself privileges of allusion that a finer taste would have
restrained. Aware of the senselessness of feeling chafed at what, on
other occasions, he would have let pass almost unnoticed, Hugh
conversed with a great outward show of good-humour. But once or
twice he caught Minna’s eyes fixed on him in a malicious smile,
which irritated him still further. The courses seemed infinite. His host
referred to each, now praising the merits of his cook, now estimating
its money value. As he grew more genial, the more did he throw off
the cloak of breeding that at times he well assumed, and display the
inevitable, impregnating colour of his mind. To the man of artistic
temperament money had no intrinsic value. It merely represented
power over the beauty and charm of life. To the Jew financier, the
making of it was an absorbing pursuit. Its possession was an end in
itself. He had his being in an atmosphere of money; could scarcely
conceive different environment—just as the average gamekeeper
cannot realise a life in which rabbits and partridges play no part. As
the bookmaker talks inevitable turf, so Israel talked inevitable
money.
“Has my daughter ever shown you those bracelets, Mr. Colman?
They’re almost historical. Been in a great nobleman’s family for
centuries. Take one off and show it to Mr. Colman. The present
countess came to grief horse-racing—applied to me for money.
Those were part of the security. The same lady tried to do me with
some paste diamonds, but I was down too sharp. Solid things, aren’t
they?”
“I come in for a lot of the plunder, don’t I, papa?” said Minna,
gaily.
Hugh winced. Hitherto she had always expressed the profoundest
distaste for her father’s profession. Was this speech genuine, was it
pure malice, or was its intention that of keeping a stern parent in
good-humour? To save the situation he handed it back to Minna with
a little courtly bow.
“It has never adorned a fairer arm,” he said.
Minna’s quicker ear caught an ironical note, and she bit her lip.
But Israel was delighted.
“I like to hear a young man pay a pretty compliment,” he said,
rolling back in his chair. “The art is dying out.”
When Minna rose, Hugh held the door open for her. On passing
him she whispered:
“You are making a wonderful impression; keep it up.”
He bowed, closed the door upon her and came round to the fire,
hating the part so bluntly defined by his wife. To have to cajole this
somewhat vulgar old Jew of shady profession, his actual father-in-
law! It was trailing his pride in the mud. But he had been doing so
ever since the disastrous day of his marriage. A little extra soiling, he
reflected cynically, would make but faintly appreciable difference.
The grave butler entered with coffee and cigars. Hugh declined
the latter.
“Better have one,” said Israel, carefully selecting. “Don’t get this
sort of thing every day. I give seven pound ten a hundred for them.”
“I am a cigarette smoker,” said Hugh, “but still——”
He accepted a cigar courteously. For he knew that a man is apt to
be ruffled when you refuse an eighteen-penny havana, and he had
good reasons for not wishing to ruffle his host. Presently they went
upstairs. Minna moved to the piano. Usually she played with taste
and correctness. To-night she strummed abominably.
“We are not quite in the mood for Chopin,” said Hugh, who was
turning over her leaves. She stopped dead.
“No. This is more suitable to one’s irritation,” and she plunged into
Stephen Heller’s Tarantella. The old man, dozing in his chair, did not
notice the change.
“Don’t give it away at once,” she said in a low voice, as she
played. “Begin with a formal demand in marriage and see how he
takes it.”
“I shall do whatever seems to me judicious,” he answered, curtly.
“Remember I am an interested party,” she retorted. “There is such
a thing as money to be considered, however much you may despise
it.”
“You may trust to my not forgetting,” he replied.
The evening was over at last. He bade Minna good-bye.
“I should like to say a few words to you, Mr. Hart, before I go,” he
remarked on his way downstairs. His host, cordiality itself, showed
him into his study, poked the fire and lighted a cigar.
“Business?”
“Yes.”
“About the loan. I was wanting to discuss it. Best now, when we’re
comfortable. Wait a moment—allow me. What is the chance of your
being left a small legacy?”
“None whatever, I fear,” replied Hugh.
“It is devilish hard lines on me, Colman, you know. When I
advanced you that money, I thought your inheritance was as safe as
a mortgage. You are aware it is not my usual way of doing business.
This is not an actual reversion; it’s only a convenient term. But I
liked you, and somehow it’s pleasant now and then to do a friend a
good turn.”
“I am deeply aware of all that,” said Hugh.
“And, as I mentioned, I considered the security safe.”
“So did I. You can scarcely blame me.”
“I believe you,” said the old man, cordially. “You meant to play
square, I know. Otherwise you wouldn’t be here, would you? But, all
the same, if your uncle were to die to-morrow, I should be done out
of £5,000. I don’t pretend to say that £5,000 would break me.
Thank God I can run to six figures with something bigger than a ‘1’
in front any day, when all is called in. But money is money. Now, as
a gentleman, would you feel morally justified in abiding by your legal
rights?”
“No,” said Hugh, “I wouldn’t. But circumstances——”
“I know,” interrupted the money-lender, with upraised hand. “They
aren’t quite yet what they ought to be. But you are going to be a
successful man. They will alter. Now I have a friendly proposal to
make to you.”
“And I am coming with one to you, Mr. Hart,” said Hugh, with a
smile. “And I think you had better hear mine first. You consider me
an honest man?”
“I do.”
“And you don’t disapprove of me personally?”
“On the contrary, I’m very pleased and proud to call you a friend
of mine. You wouldn’t have had my money otherwise.”
“Then, Mr. Hart, you make easier what I have to say. It concerns
your daughter, Miss Hart.”
“What? Minna—my daughter?” said the old man, with a sharp
change of tone.
“I have the honour to ask you for her hand in marriage.”
“You!”
An indescribable change came over the old man’s face. Instantly it
lost the sleek and coarse materialism of the money-getter, the half-
sensual content of the easy-going man who has well dined, the
patronising geniality of the prosperous host. A fire glowed in his
eyes. His Jewish features seemed to grow more prominent. The grey
beard framed a strange, patriarchal dignity. The Jew, proud and
unconquered through centuries of oppression, overwhelming all
other accidents of life in the eternal arrogance of race, was
regarding, with angry and incredulous scorn, the Gentile, the hybrid
child of yesterday.
“You!” he repeated, almost insultingly.
The young man’s quick blood flamed in his cheeks. He started to
his feet.
“Yes, I. Why shouldn’t I?” he cried in a loud voice.
At that moment the door opened, and the butler entered, bearing
a tray with spirit-case and glasses. Hugh turned quickly, and bent
towards the fire with a spill, to light a cigarette. The butler set his
trayload on the great library table, secured the windows of the room
and drew the curtains, which had remained looped back.
“You need not sit up, Samuels,” said Israel. “I will let Mr. Colman
out and lock up.”
With discreet thanks the butler withdrew. Hugh threw his cigarette
into the grate, put his hands into his pockets and faced his host once
more.
“I consider my proposal is quite justifiable, Mr. Hart.”
“Are you aware what you are asking?”
“Yes. I am a poor man. She is rich. I owe you money. But still——”
“Money? What has money to do with it?” interrupted the Jew,
grandly. “If you had the rent-roll of the Grosvenors it would make no
difference.”
“If it’s a question of religion—I always thought your views were
latitudinarian.”
“I suppose Minna knows of this?” said Israel, apparently
disregarding the remark.
“Certainly.”
“Mr. Colman, I have no wish to wound your feelings. But I would
sooner have my daughter dead at my feet than see her married to a
Christian.”
“Then it is useless to ask for your consent?”
“Quite useless.”
“In that case I fear we shall have to do without it. I am
exceedingly sorry to cause you pain—but the marriage will take
place.”
Israel rose from his chair and poured some whiskey into the
glasses, and made a courteous motion with his hand towards the
siphon of soda-water.
“We stand on opposite sides of a great gulf. I am a Jew. You are a
Gentile. We need not discuss the question. I can’t restrain my
daughter from carrying out her wishes. But I can solemnly curse her
after the manner of my people, and cut her adrift from me for ever. I
shall warn her. The wrath of the Almighty will be on her head. She
will also be disinherited.”
“That will ease my mind of a great burden,” said Hugh.
“To show you that it is no animosity towards you personally that
influences me,” continued Israel, with great dignity, inconceivable of
the man of an hour before, “I will let you see a copy of my will made
some time ago when the thought of you as a suitor never crossed
my mind.”
He drew a bunch of keys from his pocket and opened the great
safe. From a locked compartment he drew forth a document, and,
folding it so that only the particular paragraph should be visible, he
showed it to Hugh. Nothing could be more explicit. In the event of
Minna marrying a Gentile all the estate would pass from her and be
devoted to specified Jewish charities.
“I hope Minna will be able to persuade you to a more favourable
view of the case,” said Hugh.
“My daughter can do many things, but not that. She despises her
people, I know. But she shall marry among them or be cut off from
our congregation for ever.”
“There seems nothing more to be said, Mr. Hart,” said Hugh.
“You quite realise that when my daughter leaves this house, the
clothes that cover her will be her sole possession?”
“I have told you—I am immensely relieved. As to our business
relations——”
“They can be discussed on a future occasion.”
Proud as he was of his birth and breeding, Hugh could not but be
abashed before this pride of race that transformed the vulgar usurer
into a gentleman of fine feeling. Israel’s words and attitude had not
conveyed the slightest reproach on the score of fortune-hunting. He
had cast neither his poverty nor his debt in his teeth. A great feeling
of respect for the old man rose in his heart.
“Believe me,” he said after a turn across the room; “if fate would
allow it, I would give up the idea for your sake.”
“We all make our destiny,” replied the old man, bitterly. “I have
made mine.”
A few moments later Hugh took his leave. Israel accompanied him
to the front door, shook hands with him, and, turning out the light in
the hall, went back to his study. Then he remembered that he had
forgotten to secure the door.
“I will do it afterwards,” he said to himself.
He picked up the will, glanced through it and replaced it in the
safe. For half an hour he sat in deep thought; then rose, went
upstairs and returned, bringing with him a small padlocked ledger.
He sat down in his writing-chair by the table, but remained in deep
thought, tapping the unopened book with his fingers.
“My own daughter—Sara’s child—married, to a Christian.”
Long he sat in an awful loneliness, his eyes dull and weary,
looking at the spectres of the past. At length he took from a drawer
at his side a double sheet of blue foolscap, and dipped a pen very
slowly in the ink.
“I, Israel Hart, will and bequeath——”
“No,” he said. “Not now—I must think it out again. Ask God for
guidance.”
He rose, put the paper in the fire, and sank into the great
armchair close by. And there he sat, thinking, thinking. At last his
eyelids closed and he slept.

Hugh went out into a night of utter blackness and icy sleet. Great
splashes of half-melted snow fell against his face and oozed down in
liquid. He made his way along the drive and out of the front gate.
Dimly through the darkness the sound reached him of the
Sunnington clock striking the half hour. Halfpast eleven. He would
wait till twelve before keeping his appointment with Minna. A mile up
the Heath Road and a mile back would fill up the time. He walked on
through the darkness, splashing through the mud and drawing his
head down into the collar of his ulster so as to keep the frozen rain
from his neck. Not a soul was visible. On his return he saw a bull’s-
eye lantern flash within the grounds of a house. It was a policeman
examining the fastenings. Hugh hurried on, turned down the lane
that led from the Heath Road to the wood and waste lands behind
The Lindens. At last he came to the brick wall enclosing the
property. A key in his possession opened a small side door leading
into a garden which Minna’s caprice had made so exclusively her
own, that entrance to it was not practicable from any portion of the
grounds. On the right were green-houses, closing off egress from
the back-while, following the line of the side of the house, a thick
box hedge ran to meet the front wall, and thus separated the little
pleasance from the front lawn, through which curved the carriage
drive.
The house was in total darkness, scarcely discernible against the
pitch-black sky. Hugh crossed the turf, walking warily so as to avoid
the shrubs with which it was thickly planted, ever and anon thrusting
his hand through the icy, dripping foliage.
“Thank Heaven this is the last time,” he muttered to himself.
He came to the house, to whose walls stretched the carpet of turf.
A low verandah, reached by a flight of steps, and communicating
with the interior by means of French windows, now closely barred,
extended not quite the breadth of the building. Masking its end rose
a tall clipped yew. Behind this he crept, and a low window, whose
sash he lifted, thanks to Minna’s previous unbarring, admitted him
into the house. It was a tiny chamber, used by Minna as a dark-room
during an intermittent photographic fever.
Outside this was a heavily carpeted staircase, up which Hugh stole
noiselessly.
The handle turned smoothly beneath his grasp, and he found
himself at last in his wife’s presence. The large room was lit only by
the leaping flames of the fire, that threw quick flashes on the richly
curtained bed and the luxurious appointments of a wealthy woman’s
bedchamber. In a long chair before the fire, the tips of fur-lined
slippers thrust on bare feet, resting on the fender, lay Minna. She
wore a rich dressing-gown, with lace at throat and wrists. Her dark
hair clustered about her shoulders. A delicate odour of toilette-
washes and powder hung on the warmth of the room. Hugh stopped
for a moment on the threshold, with a little catch at his breath. The
subtle charm of the woman’s shrine stole gratefully over him. After
all, it was sweet to have the right of such intimacy. He took off his
dripping ulster and laid it aside before coming forward. Then he
stooped and kissed her.
“Oh! how wet you are!” she cried, with a little grimace, rubbing
her cheek with her handkerchief. “Do come and dry yourself. You will
find your slippers in the secret drawer, as usual.”
She handed him a key which she took from her dressing-gown
pocket, and while he was changing his wet boots:
“Well?” she said. “What news?”
“Bad. Your father will not consent, because I am a Christian. We
shall have to elope.”
“Then you haven’t told him all?”
“No. I thought it wiser. There seemed no necessity. It will be
better for us to get married again—publicly.”
He drew up an armchair by her side, close to the fire, and, leaning
forward, warmed himself appreciatively.
“It’s an infernal night. You don’t know how sweet and cosy it is
here.”
“It was kind of you to come,” she said, with cold politeness.
Her tone chilled the reviving glow of his imagination, which
already was beginning to picture gentle possibilities of their married
life. He remained silent for some time. When he spoke again, it was
in less genial accents.
“I am afraid, Minna, that in marrying me you have unwittingly
made a tremendous sacrifice.”
“Not more than most women, I suppose.”
“Unfortunately, yes.”
With much tact and delicacy he put her in possession of all the
details of his recent interview. She said not a word until he had
finished, but clenched her fingers on the arms of her chair and
looked rigidly into the fire.
“I had an awful horror of this,” she said, in a toneless voice.
“It will make an enormous difference to you. God knows I realise
it. But, after all, we shall not starve.”
She darted a quick, sidelong glance at him, then, with a shudder,
put her hands before her face.
“I knew it would be woe and misery,” she said, “whilst we were
walking away from that horrible registrar’s office. Oh, God! I wish it
had never been!”
“It need not be misery. It shan’t be misery, if I can help it.”
“You? You have robbed me of my birthright!”
“Perhaps your taunt is just, Minna,” he replied, a scornful
generosity forgetting that with her had lain considerable initiative in
the matter of the marriage.
“But it scarcely can mend our happiness.”
“Happiness!” she echoed, contemptuously. “A poky little house,
and rechauffés dinners, and a cheap gown once a year. The
gingerbread would have been pretty enough ten months ago. Now
the gilt is off.”
With great patience, knowing that on him, the man, the stronger,
the more rational, the less in love of the two, rested the
responsibility of the disaster, he strove to reassure her, to paint their
coming life together in the most cheerful colours. Grand style of
living he could not offer her. But comfort, a certain social position,
clever and bright society—all that was within his reach. He had done
her a wrong in marrying her, would repair it by devoting the rest of
his life to her happiness. He pleaded to a hardened heart. She either
listened stonily or broke into petulant recriminations. The talk grew
spasmodic, interrupted by long gaps of silence. Imperceptibly the
night wore on. Once he noticed that she had fallen info a weary
doze. He watched for a long time her face, lit up by the flickering
flames. How hard and common and sullen it had grown! He read in
it the history of the last few months—of her previous life—of her
soul. A revulsion of feeling turned his heart against her and against
himself. The man with ambitions and wide interests in the world of
action revolted against the slavery to such a woman.
There was little use in staying longer. He rose to go. His
movement startled her, and she opened her eyes.
“Don’t go yet. I am not asleep. I have been thinking.”
He sat down again, watched her as she looked into the fire with
eyes that in the fantastic light seemed haggard, and waited for her
to speak.
“I cannot forfeit my money,” she said. “It would kill me. Even if I
loved you I couldn’t do it. And you have made me hate you. Our
living together as you propose would be a ghastly mockery. I could
not share the same room with you any more,” she continued,
hurriedly, “not for millions!”
“I should not desire it,” he replied, coldly.
“Then why should we not keep our secret—as we have kept it—
and part now, for ever and ever?”
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookbell.com

You might also like