Instant Download C Programming on Raspberry Pi Develop innovative hardware based projects in C 1st Edition Dogan Ibrahim PDF All Chapters

Download as pdf or txt
Download as pdf or txt
You are on page 1of 50

Get ebook downloads in full at ebookmeta.

com

C Programming on Raspberry Pi Develop innovative


hardware based projects in C 1st Edition Dogan
Ibrahim

https://ebookmeta.com/product/c-programming-on-raspberry-pi-
develop-innovative-hardware-based-projects-in-c-1st-edition-
dogan-ibrahim/

OR CLICK BUTTON

DOWNLOAD NOW

Explore and download more ebook at https://ebookmeta.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Raspberry Pi for Radio Amateurs 1st Edition Dogan Ibrahim

https://ebookmeta.com/product/raspberry-pi-for-radio-amateurs-1st-
edition-dogan-ibrahim/

ebookmeta.com

Raspberry Pi IoT In C 2nd Edition Harry Fairhead

https://ebookmeta.com/product/raspberry-pi-iot-in-c-2nd-edition-harry-
fairhead/

ebookmeta.com

Raspberry Pi Projects for Kids 1st Edition Daniel Bates

https://ebookmeta.com/product/raspberry-pi-projects-for-kids-1st-
edition-daniel-bates/

ebookmeta.com

Razor Components Succinctly 1st Edition Ed Freitas

https://ebookmeta.com/product/razor-components-succinctly-1st-edition-
ed-freitas/

ebookmeta.com
Designing the Patient Room A New Approach to Healthcare
Interiors 1st Edition Sylvia Leydecker

https://ebookmeta.com/product/designing-the-patient-room-a-new-
approach-to-healthcare-interiors-1st-edition-sylvia-leydecker/

ebookmeta.com

When the Smoke Cleared Attica Prison Poems and Journal 1st
Edition Celes Tisdale

https://ebookmeta.com/product/when-the-smoke-cleared-attica-prison-
poems-and-journal-1st-edition-celes-tisdale/

ebookmeta.com

Making Sense of Media and Politics Five Principles in


Political Communication 2nd Edition Gadi Wolfsfeld

https://ebookmeta.com/product/making-sense-of-media-and-politics-five-
principles-in-political-communication-2nd-edition-gadi-wolfsfeld/

ebookmeta.com

Recovering History Through Fact and Fiction Forgotten


Lives 1st Edition Dallas John Baker

https://ebookmeta.com/product/recovering-history-through-fact-and-
fiction-forgotten-lives-1st-edition-dallas-john-baker/

ebookmeta.com

Practical ESD Protection Design 1st Edition Wang Albert

https://ebookmeta.com/product/practical-esd-protection-design-1st-
edition-wang-albert/

ebookmeta.com
Introduction to Internet of Things in Management Science
and Operations Research Implemented Studies International
Series in Operations Research Management Science 311
https://ebookmeta.com/product/introduction-to-internet-of-things-in-
management-science-and-operations-research-implemented-studies-
international-series-in-operations-research-management-science-311/
ebookmeta.com
books
books books

C Programming on
C Programming

C Programming on Raspberry Pi • Dogan Ibrahim


Raspberry Pi
Develop innovative hardware-based projects in C

The Raspberry Pi has traditionally been programmed using Python.


Although Python is a very powerful language, many programmers may not
on Raspberry Pi
be familiar with using it. The C language is probably the most commonly Develop innovative hardware-based projects in C
used programming languages. All embedded microcontrollers can be
Prof. Dr. Dogan Ibrahim is
programmed using the C language these days. The C language is taught a Fellow of the Institution of
in all technical colleges and universities - almost all engineering students Electrical Engineers. He is the
are familiar with the use of this language in their projects. author of over 60 technical
books, published by publishers
including Wiley, Butterworth, and
This book is about using C with Raspberry Pi to develop various hardware-
Newnes. He is the author of over
based projects. Two of the most popular C libraries, wiringPi and pigpio 250 technical papers, published
are used. Its starts with an introduction to the C language and most in journals, and presented in
students and newcomers will find this chapter invaluable. Many projects seminars and conferences.
are provided in the book, including using Wi-Fi and Bluetooth to establish
communication with smartphones.

The book includes many sensors and hardware-based projects. Both


wiringPi and pigpio libraries are used in all projects. Complete program
listings are given with full explanations. All projects given in the book
have been fully tested and work. The following hardware-based projects
are provided in the book:
> Using sensors > Using Wi-Fi
> Using LCDs > Webservers
> I2C and SPI buses > Communicating with
> Serial communication smartphones
> Multitasking > Using Bluetooth
> External and timer interrupts > Sending data to the cloud

Program listings of all Raspberry Pi projects developed in this book are


available on the Elektor website. Readers can download and use these
programs in their projects. Alternatively, they can customize them to suit
their applications. Elektor International Media BV
www.elektor.com

Dogan Ibrahim

Cover C Programming on Raspberry Pi .indd Alle pagina's 06-04-2021 13:06


C Programming
on Raspberry Pi

Dogan Ibrahim

design > share > sell

an Elektor Publication
● This is an Elektor Publication. Elektor is the media brand of
Elektor International Media B.V.
78 York Street
London W1H 1DP, UK
Phone: (+44) (0)20 7692 8344
© Elektor International Media BV 2021
First published in the United Kingdom 2021

● All rights reserved. No part of this book may be reproduced in any material form, including
photocopying, or storing in any medium by electronic means and whether or not transiently or incidentally
to some other use of this publication, without the written permission of the copyright holder except in
accordance with the provisions of the Copyright, Designs and Patents Act 1988 or under the terms of a
licence issued by the Copyright Licensing Agency Ltd, 90 Tottenham Court Road, London, England W1P 9HE.
Applications for the copyright holder's written permission to reproduce any part of this publication should be
addressed to the publishers. The publishers have used their best efforts in ensuring the correctness of the
information contained in this book. They do not assume, and hereby disclaim, any liability to any party for
any loss or damage caused by errors or omissions in this book, whether such errors or omissions result from
negligence, accident or any other cause.

● British Library Cataloguing in Publication Data


Catalogue record for this book is available from the British Library

● ISBN: 978-3-89576-431-8

● EISBN: 978-3-89576-432-5

● EPUB: 978-3-89576-433-2

Prepress production: DMC ¦ daverid.com


Printed in the Netherlands by Wilco

design > share > sell


Elektor is part of EIM, the world's leading source of essential technical information and electronics products for pro
engineers, electronics designers, and the companies seeking to engage them. Each day, our international team develops
and delivers high-quality content - via a variety of media channels (e.g., magazines, video, digital media, and social media)
in several languages - relating to electronics design and DIY electronics. www.elektor.com
To my wife Nadire, my daughter Alev, and my son Ahmet, for their love and wisdom.
C Programming on Raspberry Pi

● Preface

The Raspberry Pi 4 is the latest credit-card sized computer that can be used in many
applications, such as audiovisual media centers, desktop computers, industrial control,
robotics, and many more domestic and commercial applications. In addition to the many
features found in other versions of Raspberry Pi, The Pi 4 also offers Wi-Fi and Bluetooth,
making it highly desirable in remote and internet-based control and monitoring applications.

The Raspberry Pi has traditionally been programmed using Python. Although Python is
a very powerful language, many programmers may not be familiar with using it. The C
language is probably the most commonly used programming languages. All embedded
microcontrollers can be programmed using the C language these days. The C language
is taught in all technical colleges and universities - almost all engineering students are
familiar with the use of this language in their projects.

This book is about using C with Raspberry Pi to develop various hardware-based projects.
Two of the most popular C libraries, wiringPi and pigpio are used.

The book starts with an introduction to the C language and most students and newcomers
will find this chapter invaluable. Many projects are provided in the book, including using
Wi-Fi and Bluetooth to establish communication with smartphones.

The book includes many sensors and hardware-based projects. Both wiringPi and pigpio
libraries are used in all projects. Complete program listings are given with full explanations.
All projects given in the book have been fully tested and work. The following sub-headings
are used in the projects where applicable:

• Project title
• Project description
• Aim of the project
• Block diagram
• Circuit diagram
• Program listing

wiringPi and pigpio program listings of all Raspberry Pi projects developed in the book are
available on the Elektor website. Readers can download and use these programs in their
projects. Alternatively, they can modify the supplied programs to suit their applications.

I hope readers find this book helpful and enjoy reading it.

Prof Dr Dogan Ibrahim


January 2021
London.

●6
Table of Contents

Table of Contents

● Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

Chapter 1 ● Installing the Operating System on Raspberry Pi . . . . . . . . . . . . . . . . . . 12


1.1 ● Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
1.2 ● Raspbian Buster installation steps on Raspberry Pi 4 . . . . . . . . . . . . . . . . . . . . 12
1.3 ● Using networked connection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
1.4 ● Remote access . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
1.5 ● Using Putty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
1.5.1 ● Configuring Putty . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
1.6 ● Remote access of the Desktop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
1.7 ● Static IP address . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
1.8 ● Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

Chapter 2 ● Raspberry Pi Program Development . . . . . . . . . . . . . . . . . . . . . . . . . . . 25


2.1 ● Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.2 ● The nano text editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.3 ● Example project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
2.4 ● Creating and running a Python program on Raspberry Pi . . . . . . . . . . . . . . . . . 27
2.5 ● Creating and running a C program on Raspberry Pi . . . . . . . . . . . . . . . . . . . . . 34
2.6 ● Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35

Chapter 3 ● C Programming for Raspberry Pi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37


3.1 ● Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
3.2 ● The C Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
3.2.1 ● Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
3.2.2 ● Screen output and keyboard input . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
3.2.3 ● Comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
3.2.4 ● Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
3.2.5 ● Auto increment/decrement operators . . . . . . . . . . . . . . . . . . . . . . . . . . 41
3.2.6 ● Logical operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
3.2.7 ● Flow control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
3.2.8 ● Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
3.2.9 ● String variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
3.2.10 ● Arithmetic functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
3.2.11 ● String functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
3.2.12 ● Character macros . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
3.2.13 ● Alternative numeric input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
3.2.14 ● User functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
3.2.15 ● File processing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
3.2.16 ● Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82

●7
C Programming on Raspberry Pi

3.2.17 ● Unions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
3.2.18 ● Pointers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
3.3 ● Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100

Chapter 4 ● Hardware Programming using C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101


4.1 ● Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
4.2 ● The general purpose input-output ports (GPIO) . . . . . . . . . . . . . . . . . . . . . . 101
4.3 ● Interfacing with GPIO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
4.3.1 ● Loads requiring small currents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
4.3.2 ● Loads requiring higher currents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
4.3.3 ● Using relays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
4.4 ● Project 1: Flashing LED - compilers available . . . . . . . . . . . . . . . . . . . . . . . . 105
4.4.1 ● Using the pigpio library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106
● Using the wiringPi library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4.4.2 107
4.4.3 ● Other C libraries/compilers for Raspberry Pi . . . . . . . . . . . . . . . . . . . . . 110
4.5 ● Using the Geany editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
4.6 ● The hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
4.7 ● Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113

Chapter 5 ● Hardware Projects using C . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114


5.1 ● Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
5.2 ● Project 1 – Rotating LEDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
5.3 ● Project 2 – Christmas lights . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
5.4 ● Project 3 – Binary up counter with LEDs . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
5.5 ● Project 4 – Binary up/down counter with LEDs . . . . . . . . . . . . . . . . . . . . . . . 130
5.6 ● Project 5 – LED dice . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
5.7 ● Project 6 – LED colour wand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
5.8 ● Project 7 – Changing the brightness of an LED . . . . . . . . . . . . . . . . . . . . . . . 152
5.9 ● Project 8 – Generating random sounds using a buzzer . . . . . . . . . . . . . . . . . 157
5.10 ● Project 9 – Display temperature and relative humidity . . . . . . . . . . . . . . . . . 160
5.11 ● Project 10 – ON/OFF temperature controller . . . . . . . . . . . . . . . . . . . . . . . . 172
5.12 ● Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179

Chapter 6 ● LCD Projects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180


6.1 ● Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
6.2 ● HD44780 LCD module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
6.3 ● Project 1 – Displaying text . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
6.4 ● Project 2 – Second counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
6.5 ● Project 3 – Creating a custom character . . . . . . . . . . . . . . . . . . . . . . . . . . . 187
6.6 ● Project 4 – Creating multiple custom characters . . . . . . . . . . . . . . . . . . . . . . 190
6.7 ● Project 5 – Displaying current date and time . . . . . . . . . . . . . . . . . . . . . . . . 194
6.8 ● Project 6 – Displaying the temperature and humidity . . . . . . . . . . . . . . . . . . 196
6.9 ● Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200

●8
Table of Contents
Chapter 7 ● I2C Bus Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
7.1 ● Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
7.2 ● The I2C Bus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
7.3 ● Project 1 – Port expander . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
7.4 ● Project 2 – EEPROM memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 210
7.5 ● Project 3 – TMP102 temperature display . . . . . . . . . . . . . . . . . . . . . . . . . . . 216
7.6 ● Project 4 – I2C LCD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
7.7 ● Project 5 – Using the pigpio library with I2C – TMP102 temperature display . . . 237
7.8 ● Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 239

Chapter 8 ● SPI Bus Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240


8.1 ● Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 240
8.2 ● Raspberry Pi SPI pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
8.3 ● Project 1 – Port expander . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
8.4 ● Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252

Chapter 9 ● Using Analogue to Digital Converters (ADCs) . . . . . . . . . . . . . . . . . . . . 253


9.1 ● Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 253
9.2 ● Project 1 – Analogue temperature sensor thermometer . . . . . . . . . . . . . . . . . 253
9.3 ● Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260

Chapter 10 ● Using Digital-to-Analogue Converters (DACs) . . . . . . . . . . . . . . . . . . . 261


10.1 ● Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
10.2 ● The MCP4921 DAC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261
10.3 ● Project 1 - Generating square wave signal with any peak voltage . . . . . . . . . 262
10.4 ● Project 2 - Generating sawtooth wave signal . . . . . . . . . . . . . . . . . . . . . . . 267
10.5 ● Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271

Chapter 11 ● Using Serial Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272


11.1 ● Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272
11.2 ● Raspberry Pi serial port . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274
11.3 ● Project 1 – Serial communication between Raspberry Pi and Arduino Uno . . . . 275
11.4 ● Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282

Chapter 12 ● Other Useful Functions wiringPi . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283


12.1 ● Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
12.2 ● Project 1 – Using external interrupts – event counter . . . . . . . . . . . . . . . . . 283
12.3 ● Project 2 – Using the tone library – generating 1kHz signal . . . . . . . . . . . . . 287
12.4 ● Project 3 – Using the tone library – sweep frequency tone generation . . . . . . 290
12.5 ● Project 4 – Using the tone library – reading the frequency from the keyboard . 291
12.6 ● Project 5 – Using the tone library – melody maker . . . . . . . . . . . . . . . . . . . 293
12.7 ● Timing library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
12.8 ● Multitasking threads . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
12.9 ● Project 6 – Multi-threading - flashing 3 LEDs at different rates . . . . . . . . . . . 297
12.10 ● Project 7 – Multi-threading – Two-digit 7-segment LED counter . . . . . . . . . . 300
12.11 ● Hardware PWM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308
12.12 ● GPIO utility . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309

●9
C Programming on Raspberry Pi
12.13 ● Support for other chips and add-on boards . . . . . . . . . . . . . . . . . . . . . . . 310
12.14 ● Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 310

Chapter 13 ● Other Useful Functions - pigpio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311


13.1 ● Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 311
13.2 ● Project 1 – Using external interrupts – event counter . . . . . . . . . . . . . . . . . 311
13.3 ● Timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 313
13.4 ● Timer interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314
13.5 ● Project 2 – Using timer interrupts – flashing LED . . . . . . . . . . . . . . . . . . . . 315
13.6 ● Project 3 – Using timer interrupts – 2 digit 7-segment LED counter . . . . . . . . 316
13.7 ● Project 4 – Multi-threading - flashing 3 LEDs at different rates . . . . . . . . . . . 319
13.8 ● Project 5 – Hardware PWM- generate 1kHz PWM wave with hardware . . . . . . 322
13.9 ● File handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
13.10 ● Waves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
13.11 ● picscope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324
13.12 ● pigpiod . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325
13.13 ● Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 325

Chapter 14 ● Communication Over Wi-Fi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326


14.1 ● Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
14.2 ● UDP and TCP/IP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
14.3 ● UDP communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 326
14.4 ● Project 1 – Communicating with an Android smartphone using UDP (Raspberry Pi
is the server) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 327
14.5 ● Project 2 – Sending temperature readings to Android smartphone (Raspberry Pi is
the server) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 331
14.6 ● Project 3 – Communicating with an Android smartphone using UDP (Raspberry Pi
is the client) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 336
14.7 ● Project 4 – Sending time-stamped temperature readings to Android smartphone .
(Raspberry Pi is the server) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 337
14.8 ● Project 5 – Web Server application – controlling two LEDs . . . . . . . . . . . . . . 341
14.9 ● Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 349

Chapter 15 ● Bluetooth Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350


15.1 ● Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350
15.2 ● Project 1 – Bluetooth communication with a smartphone – sending and receiving
text messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 350
15.3 ● Project 2 – Bluetooth communication with a smartphone – controlling two LEDs .
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354

Chapter 16 ● Automatically Running Programs on Startup . . . . . . . . . . . . . . . . . . . 358


16.1 ● Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358
16.2 ● Scheduling a program to run at specified times . . . . . . . . . . . . . . . . . . . . . 358

Chapter 17 ● Sending Data to the Cloud . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366


17.1 ● Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 366
17.2 ● Project – Sending temperature and humidity data to the cloud . . . . . . . . . . . 366

● 10
Table of Contents
● Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374

● 11
C Programming on Raspberry Pi

Chapter 1 ● Installing the Operating System on Raspberry Pi

1.1 ● Overview

In this chapter, we will learn how to install the latest operating system (Raspbian Buster)
on the Raspberry Pi 4. We will also learn the different ways that Python can be used to
develop applications. Notice the installation process given below applies to all Raspberry Pi
models unless otherwise specified.

1.2 ● Raspbian Buster installation steps on Raspberry Pi 4

Raspbian Buster is the latest operating system for the Raspberry Pi. This section provides
the steps necessary for installing this operating system on a new blank SD card, ready to
use with Raspberry Pi 4. You will need a micro SD card with a capacity of at least 8GB (16
GB is preferable) before installing the new operating system.

The steps to install the Raspbian Buster operating system are as follows:

• Download the Buster image to a folder on your PC (e.g. C:\RPIBuster) from the
following link by clicking the Download ZIP under section Raspbian Buster with
desktop and recommended software (see Figure 1.1). At the time of writing this
book, the file was called: 2020-02-13-raspbian-buster-full.img. You may have to
use the Windows 7Zip software to unzip the download due to some features not being
supported by older zip software.

https://www.raspberrypi.org/downloads/raspbian/

Figure 1.1 Raspbian Buster download page

● 12
Chapter 1 ● Installing the Operating System on Raspberry Pi

• Put the blank micro SD card into the card slot of your computer. You may need an
adapter to do this.
• Download Etcher to your PC to flash the disk image. The link is (see Figure 1.2):

https://www.balena.io/etcher/

Figure 1.2 Download Etcher

• Double click to open Etcher and then click Select image. Select the Raspbian Buster
file you downloaded and unzipped.
• Click Select target and select the micro SD card.
• Click Flash (see Figure 1.3). This may take several minutes, wait until it is finished.
The program will then validate and unmount the micro SD card. You can remove your
micro SD card after it is unmounted.

Figure 1.3 Click ‘Flash’ to flash the disk image

● 13
C Programming on Raspberry Pi

Your micro SD card now has been loaded with the Raspberry Pi operating system. The
various options now are as follows:

Using direct connection

If you are making a direct connection to your Raspberry Pi using a monitor and keyboard,
just insert the SD card into the card slot and power-up your Raspberry Pi. After a short
while, you will be prompted to enter the login details. The default values are username: pi,
password: raspberry.

You can now start using your Raspberry Pi either in command mode or in desktop mode. If
you are in command mode, enter the following command to start the GUI mode:

pi@raspberrypi:~ $ startx

If you want to boot in GUI mode by default, the steps are:

• Start the configuration tool:

pi@raspberrypi:~ $ sudo raspi-config

• Move down to Boot Options and press Enter to select (Figure 1.4).

Figure 1.4 Select Boot Options

• Select Desktop / CLI and then select Desktop Autologin to boot automatically into
GUI mode.
• Click OK and accept to reboot the system. The system will be in GUI mode next time
it reboots.
• You can change your selections to boot in command mode if you wish by selecting
Console in Boot Options.

You may now want to connect your Raspberry Pi to the internet either to access it remotely
from a PC or to use the internet. If your Raspberry Pi is equipped with an ethernet port
(e.g. Raspberry Pi 2/3/4), you can directly connect to your Wi-Fi router using an ethernet
cable. You can find the IP address of your connection by entering the command: ifconfig in
command mode.

Alternatively, you may want to connect your Raspberry Pi to Wi-Fi and access it remotely.

● 14
Chapter 1 ● Installing the Operating System on Raspberry Pi

You will need to enable SSH. The steps are as follows:

• Start the configuration tool:

pi@raspberrypi:~ $ sudo raspi-config

• Move down to Interface Options and select SSH and enable it.
• If you are in GUI mode, click the Wi-Fi icon at the top right hand of the screen and
enable Wi-Fi. Note the IP address allocated automatically to your Raspberry Pi.
• You can now remotely access your Raspberry Pi using terminal emulation software,
such as Putty (see Section 1.4 and 1.5).

1.3 ● Using networked connection

If you do not have a suitable monitor and keyboard to directly connect to your Raspberry Pi,
you will have to use a networked connection and remotely access your Raspberry Pi using a
PC. There are two options: connection using an Ethernet cable, and connection over
Wi-Fi.

Connection using an Ethernet cable: The steps are as follows:

• Install Notepad++ on your PC from the following web site:

https://notepad-plus-plus.org/downloads/v7.8.5/

• Insert the SD card back to your PC and start Notepad++.


• Click Edit -> EOL Conversion -> UNIX/OSX Format.
• Create a new empty file with the Notepad++ and save it to the boot folder of the SD
card with the name ssh(without any extension), where this file will enable SSH to be
used to remotely access your Raspberry Pi. In Windows, this is the only folder you will
see which contains items including loader.bin, start.elf, kernel.img, etc.
• Insert the SD card back into your Raspberry Pi.
• Connect your Raspberry Pi to one of the ports of your Wi-Fi router through an Ethernet
cable and power it up.
• Find out the IP address allocated to your Raspberry Pi by accessing your Wi-Fi router.
Alternatively, install Advanced IP Scanner on your PC, which is available at the
following link:

https://www.advanced-ip-scanner.com

• Run the software and look for your Raspberry Pi. You do not have to install the software
to run it. Click Run portable version, and then Scan. As shown in Figure 1.5, the IP
address of the author’s Raspberry Pi was 191.168.1.202.

Figure 1.5 IP address of the Raspberry Pi

● 15
C Programming on Raspberry Pi

• You can now use Putty to log in to your Raspberry Pi (see Section 1.4 and 1.5)

Alternatively, you can find the IP address of your Raspberry Pi by opening the command
prompt on your PC with administrator privilege (by right-clicking to accepting to run as an
administrator) and then inputting the command: ping raspberrypi.home as shown in
Figure 1.6.

Figure 1.6 Using ping to find the Raspberry Pi IP address

It is also possible to find the IP address of your Raspberry Pi using your smartphone. Many
apps can be used to find out who is currently using your Wi-Fi router. e.g. Who’s On My
Wi-Fi – Network Scanner by Magdalm.

Connection using Wi-Fi: This is the preferred method to access your Raspberry Pi and is
the one used by the author. Here, as described in Chapter 1, the Raspberry Pi can be placed
anywhere you like within the range of the Wi-Fi router and is easily accessed from your PC
using Putty (see Section 1.4 and 1.5).

The steps are:

• Install Notepad++ on your PC from the following web site:

https://notepad-plus-plus.org/downloads/v7.8.5/

• Insert the SD card back to your PC and start Notepad++.


• Click Edit -> EOL Conversion -> UNIX/OSX Format
• Create a new empty file with Notepad++ and save it to the boot folder of the SD card
with the name ssh(without any extension), where this file will enable SSH to be used
to remotely access your Raspberry Pi. In Windows, this is the only folder you will see
which contains items like loader.bin, start.elf, kernel.img, etc.
• Enter the following statements into a blank file (replace the MySSID and MyPassword
with the details of your own Wi-Fi router):

● 16
Another Random Scribd Document
with Unrelated Content
The Project Gutenberg eBook of There is a tide
This ebook is for the use of anyone anywhere in the United
States and most other parts of the world at no cost and with
almost no restrictions whatsoever. You may copy it, give it away
or re-use it under the terms of the Project Gutenberg License
included with this ebook or online at www.gutenberg.org. If you
are not located in the United States, you will have to check the
laws of the country where you are located before using this
eBook.

Title: There is a tide

Author: J. C. Snaith

Release date: March 24, 2024 [eBook #73250]

Language: English

Original publication: New York: D. Appleton and Company, 1924

Credits: D A Alexander, David E. Brown, and the Online


Distributed Proofreading Team at
https://www.pgdp.net (This file was produced from
images generously made available by The Internet
Archive)

*** START OF THE PROJECT GUTENBERG EBOOK THERE IS A TIDE


***
THERE IS A TIDE
By J. C. SNAITH

THERE IS A TIDE
ARAMINTA
THE VAN ROON
THE COUNCIL OF SEVEN
THE ADVENTUROUS LADY
THE UNDEFEATED
THE SAILOR
THE TIME SPIRIT
THE COMING
ANNE FEVERSHAM

D. APPLETON AND COMPANY


Publishers New York
THERE IS A TIDE
BY

J. C. SNAITH
AUTHOR OF “THE VAN ROON,” “THE SAILOR,”
“THE UNDEFEATED,” ETC.

D. APPLETON AND COMPANY


NEW YORK :: :: MCMXXIV
COPYRIGHT, 1924, BY
D. APPLETON AND COMPANY

PRINTED IN THE UNITED STATES OF AMERICA


THERE IS A TIDE
THERE IS A TIDE

I
SO this was England.
A slight, pretty girl, in a corner seat of the boat express, was looking
out of the window. To her everything was new and odd and a face
curiously expressive was quick to register its emotions.
All was on a scale so much less than the land from which she had
come. The neatly parcelled acres somehow reminded her of Noah’s
ark. Farmsteads trim and tiny; amusing hedgerows; the cattle and
horses in the fields; the comic little villages, each with its moss-
grown church tower peering through the damp mist, were so
expected and yet so unnatural to the eye of a stranger that it was
rather like a scene in a play.
The girl was in the compartment alone. By her side was a “grip,”
cheap looking, battered, with an air of travel; in the rack, above her
head, was its fellow with a mackintosh and an umbrella. Like their
owner, these articles had a subtle air of the second rate. Yet the girl
herself, had she known how to wear her clothes, which were not bad
of their kind, had certain points that seemed to promise a way out.
For one thing, she was alive. Grey eyes, shrewd, keen and clear,
looking out from under the brim of a hat that had a touch of
smartness, seemed to absorb every detail of this film reeled off at
the rate of sixty miles an hour. It was like the movies, but less
exciting. Not that the traveller craved excitement. This trip to an
unknown land was far from being a pleasure jaunt.
So intent were the grey eyes in absorbing a scene which was a good
deal below expectation, that they were not content with the window
against which her elbow pressed. Now and then they roved to the
left across the narrow corridor, for a glimpse of the more distant
view. Broadly speaking, this, too, was a washout. The mist, clammy
and all-pervading, might have a lot to do with the general effect, but
England, so far, was nothing to write home about.
Disappointment already loomed in a receptive mind, when a man
appeared in the corridor. He gazed through the glass at the
compartment’s sole occupant; then he came in and closed the door
carefully. With a quiet air he took a corner seat immediately facing
the girl. She had a feeling that she had seen him before; but where
or in what circumstances she could not say. Indeed, so vague was
her memory that she soon decided it was a mere reaction to the
man’s striking personality.
He was not a man to forget. Big, handsome, muscular, clean and
trim, he had all the snap of the smart New Yorker. Evidently he went
to good tailors and he paid for dressing.
He raised his ten-dollar Stetson with an air of class. “Miss Durrance!”
The girl gave a start and coloured hotly.
“Don’t remember me, eh, Miss Durrance?”
It was clear that she didn’t. But he remembered her, and the calm
enforcement of his knowledge in a tone near the familiar flecked the
girl’s cheek with a picturesque confusion.
“Can’t say I do.”
At the awkward answer his eyes twinkled into a slow, bright smile.
“Myself, I never forget a face or a name.”
The voice sounded oddly familiar, but she could not recall it. Not able
to place this man, the effort to do so teased her forehead into a
frown.
“My job, you see, to remember folks.”
She half resented the cool laugh. “Not sure I want to remember
everybody.”
“I’ll say not. Pikers good and plenty don’t want to remember me.”
His tone was jocular, but there was something in it beyond mere
banter.
Mame Durrance realised suddenly that she had taken a strong dislike
to the man opposite. He realised it, too. The breadth of his smile
became aggressive. As her eyes met it they received a challenge
which they were too proud to accept. She withdrew them quickly
and looked ostentatiously away through the carriage window.
Even the English scene, as much as was visible, could not divert her
mind from a gentle snigger that stole upon her ear. Whoever this
man was she hoped he would go. But he showed not a sign. Settling
into the opposite corner, he sprawled his long legs, brushing her
knees as he did so, and finally crossed them. And then, past master
of the art of making himself offensive, he began to hum softly, but in
a way to keep in the middle of her consciousness.
“Miss Durrance.” The voice was mild but half a sneer was in it.
Somehow “it got her goat” to have his conversation thrust upon her
after she had taken pains to let him know that she had no use for it.
Anger made her eyes sparkle. “You quit,” she said. “Beat it.”
Rude, certainly, but she meant it to be. But in that art, too, he had
nothing to learn. “Now, then, Miss Durrance, come off it.” His laugh
was hateful.
One outstanding detail of the compartment there was, which the
sharp-eyed traveller had already noted. A metal disc fixed below the
luggage rack was within reach. It was adorned by the words, “To
communicate with the Attendant, pull the handle.”
On the spur of the moment she half turned and raised her hand. But
the voice of the man opposite grew instantly so full of menace that
she felt a little frightened.
“Can that, Miss Durrance, or I’ll have to make it hot for you.”
II
THE force of the threat made the girl withdraw her hand. She met
the laugh which followed with a look of defiance, but she had not art
nor cleverness enough to conceal the fact that she was rattled. Her
cheeks grew scarlet. Some very white and even teeth bit savagely
into her lower lip.
The man, watching narrowly, was obviously pleased with the effect.
“Got me now, hey, Miss Durrance?”
“I don’t know who you are,” was the answer of Miss Durrance. A
brave and steady answer it was. “And I don’t want to know anyway.”
The look in the girl’s eyes, the note in her voice, appeared sharply to
recall the man opposite to a sense of his position. After all, it would
not do to carry the thing too far. It was as if he suddenly
remembered that in an especial degree he was a guardian of the
public interest. When he spoke again his voice had consideration,
even a certain kindness.
“I’m one of Tillotson’s men.”
Already her startled mind had flown to that conclusion. But neither
the man’s change of tone nor her own insight softened the steely
hostility of her eyes. She lifted a fighting chin to rake him with a
glance of grey fire. “I’m a very respectable girl.” The note was
deeper than she had touched yet. “I don’t know you an’ I don’t want
to know you. Cops are no class anyway.”
Detective Addelsee, an eminent member of a highly specialised
calling, was a long way from being a fool. He was growing a bit
annoyed with himself for his lack of diplomacy. In spite of the girl’s
insolence there was something about her that he respected. And,
what was just as important, he respected human nature.
He decided to remove the bad impression he had made. “Got in
wrong in New York, hey? Over here, ain’t you, to try and change the
luck?” His voice was honey now. Its only reward was grim silence.
“Know folks this side?”
The girl looked at Detective Addelsee as if he were dirt. She curled
her lip and shook a scornful head.
“Then you better watch your step. London crawls with slick ducks.
All sorts, all nations. Up to every game. A bad place, London.”
“If it’s worsen New York, it must be,” conceded Miss Durrance.
“Capital of a free country. Every kind of cag-handed dago lies around
loose in London. No place for a lone girl. What’s the stuff you goin’
to pull?”
“That’s my affair.”
Detective Addelsee smiled. He had caught a tartar. But he secretly
liked the way she gave it him back. Sand always appealed to him.
“Well, I wish you the best, Miss Durrance.” The voice was official, yet
kindness came uppermost. “We’ve nothing against you in New York;
but we might have had. You got in with a crooked push. Sorry to
have to run you in, but findin’ you on the premises and callin’
yourself the old Haunt’s secretary—she done two goes of time
already—how was we to know you were on the level?”
Detective Addelsee meant well, but this display of tact hardly met
the case. The grey eyes looked straight through him. He laughed.
Serve him right for being clumsy. A regular little hell cat, but he
admired her. Most girls of her kind would have been scared to death;
he half suspected Miss Durrance was; but she would have died
sooner than let him know it.
He liked the cut of her so much that he felt he must try to improve
the acquaintance or at least to soften a bad impression. It was a
shame to rag her, because to the expert eye she had a look of being
up against it. But her pride, her grit, lured him on.
“What you goin’ into, Miss Durrance, in this bum island? The
movies?”
“No, I ain’t, Fatty Arbuckle.”
The answer was pat as your hat. Detective Addelsee chuckled.
“Make good on the fillum, a girl of your looks and style.”
She eyed him with cool scorn from under the brim of her hat.
“What’s a cheap guy like you know about looks and style?”
Her drawl could only have come from one place on earth, yet each
little word had a kick in it quick and vicious, as if from the hind leg of
a mule. Detective Addelsee felt this live child of the Middle West had
had old Ned for a sire.
He decided now that only one course would be safe. That course
was silence. But he had not been so amused in years. The trained
professional memory at once recalled the circumstance of their
previous meeting. During a raid on the apartment of an old harpy in
the neighbourhood of Madison Avenue, who mingled crystal-gazing
and fortune-telling with other illegal practices, this girl had been
found seated at a typewriter. Investigation proved, however, that she
had only held her job a fortnight, and that in the first place her
association with such a dangerous person was due to an
advertisement she had incautiously answered. Mame Durrance had
no difficulty in satisfying the police that she was in total ignorance of
the character and history of the notorious Cassandra, alias Zeno,
alias Madame Bretsky. All the same the law took pains to impress on
the unlucky stenographer that her escape had been narrow. In
future she must be more discreet. Innocence as great as hers was
apt to incur heavy penalties in such a city as New York.
This episode, as Detective Addelsee was shrewd enough to suspect,
had shaken Miss Durrance to her foundations. She was undoubtedly
a very respectable girl, the daughter of a simple Iowa farmer, and
she had come East to try her luck. Having made a bad break at the
start of her career she had decided to seek fortune elsewhere. As
William R. Addelsee sat gazing at that fighting profile out of the
corner of his left eye, all that he knew about the girl passed in
review order through a well-regulated mind. His had been the job of
running her in; and of setting her free with a caution. He had caught
sight of her again as she left the second-class deck of the Sidonia;
he had seen her board the London train. She had the sort of
personality not easy to forget. He was interested in this girl for her
own sake; but the effort to get into conversation was having no
success. The plain truth was, that as far as Miss Durrance was
concerned William R. Addelsee was in the discard.
Man of the world, he was amused by her attitude. And he admired
her grit. Moreover, he wished her well. That, however, was not easy
to convey.
He tried the dulcet and disarming. “You see, Miss Durrance, there’s a
bunch of jewel thieves I’m lookin’ for. Scotland Yard has rounded up
several. I expect we’ll soon fix the hull circus.”
Miss Durrance, with glacial eye, continued to gaze upon the English
scene. “The frozen mit” with a vengeance. Jewel thieves, Scotland
Yard, even the brightest of Tillotson’s Agency, haloed with romance
for a normal girl, were cutting no ice for the moment. Her pride had
been wounded and Detective Addelsee had now to foot the bill.
“You can quit.” A fierce eye pinned him like an arrow. “Cops don’t
interest me nothing.”
Silence again. The position was a little humiliating for a man of the
world. But this charming spitfire intrigued him. Such a you-be-
damnedness quite took the fancy of William R. And the simple
independence touched his sense of chivalry.
“If I can help you any I’ll be glad,” he said, humble as pie, yet
adroitly raising a hand to hide the laugh in his eyes.
Said Miss Spitfire: “You can beat it. That’ll help me considerable.”
The entrance at this moment of a very small and very polite boy in a
strangely bright and extremely tight suit of livery was most
opportune. Miss Durrance, who had a fixed determination to see,
mark and learn as much as she could in the shortest time possible,
was taken at once by this new kind of “bell-hop.”
“Corfee, miss?”
The fair traveller ordered coffee.
Under cover of this diversion William R. suddenly rose. It was the
best chance he was likely to get of extricating himself with any sort
of dignity from a position which every second grew worse. Nothing
doing with this girl, and it was hardly fair to bait her.
As Detective Addelsee, on the heels of the departing boy, moved
towards the corridor, he was guilty of one more false step. For he
looked back and said: “Good-bye, Miss Durrance, an’ good luck. Be
careful this time to get in on the level. But I’ll say London is a tough
burg. If any time I can help you any, my name’s Addelsee.” He had
the temerity to open a gold cigar case and produce his card.
“Scotland Yard, Whitehall, ’ll get me pro tem.” As concrete evidence
of good will, Detective Addelsee had the further temerity to write his
address upon the card and then with a bland smile to hand it to Miss
Durrance.
It was asking for trouble. William R. Addelsee duly received a full
ration. Miss Durrance tore the card across. Then she coolly lowered
the window and flung out the pieces. “Beat it.” Her face was
crimson, her eye ruthless. “And thank you for nix. Cops are no class
at all, cops aren’t.”
With a little sigh that was offset by a humorous eye, Detective
Addelsee raised the ten-dollar Stetson and followed the bell-boy
along the corridor.
III
“SAY, Jackie Coogan, there’s no sugar.”
The polite boy in the button suit gazed at Miss Durrance with mild
surprise. New stars constantly swam into his ken. Few had better
opportunities than he of testing the simple truth that all sorts of
people are needed to make a world. It was this, no doubt, which
gave depth to his character. Nothing could have exceeded the grace
of his regret for the sugar’s omission and of his promise to bring
some.
“That kid’s fierce,” was the mental comment of the traveller to the
English scene as this by-product gently closed the door upon her.
She had a very keen and lively sense of things and the air and
manner of the button suit’s wearer gave it a jolt.
Mame Durrance had certain preconceived ideas about the land she
had come to and the odd folks who peopled it, derived in the main
from exquisitely humorous writers, usually with Irish names, in her
favourite magazines. The British, if not given to mirth themselves,
were yet the cause of mirth in others. An obvious back number, the
land of George Washington’s forebears was a mass of weary
pomposities; it took itself so seriously that it couldn’t raise a smile to
save its soul. Up till now she had not had much opportunity of
judging it, but the funny little toy of a train in which she was puffing
along to London, the tame scenery—what she could see of it—
through which it passed, the little cubbyhole in which she sat alone,
and the comic child with oiled hair and the manner of a senator who
ministered to her wants, all seemed to fit neatly into the theory.
Buttons came back with two small pieces of sugar on a large tray.
“Say, son, does it hurt you any to look that way?”
“Beg your pardon, moddam?”
“All right, Mr. Asquith. On’y my ignorance. You can beat it.”
“Thank you, moddam.” Gently and gravely, without a ghost of a
smile, the polite child went.
It was well for Mame Durrance that she had these resources within
herself. For at the moment she was not on good terms with life. The
railway company’s café au lait, for which it had the nerve to charge a
quarter, allowing for the rate of exchange, was not very stimulating
either. And Detective Addelsee had shaken her considerably. It surely
looked as if the bad luck which had dogged her ever since she left
Cowbarn, Iowa, six months ago was going to cling.
It was just six months ago that Mame Durrance had heard the call of
ambition in rather strange circumstances. At that time she was a
stenographer, earning a few dollars a week, in the office of the
Cowbarn Independent. But her Aunt Lou, a sister of her long dead
mother, having left her a legacy of two thousand dollars, she at once
turned her face east.
These providential dollars must be invested in seeing life. And as
native wit had carried her already from a farm kitchen to a
stenographer’s chair, she saw no reason why, with money in her
purse, that priceless quality should not take her much further.
Anyhow it should not be for lack of trying.
She would see life. And in moments of optimism, of which at the
start she had many, she went on to describe what she saw. The
seeing, alas, proved easier than the writing; or rather the seeing and
the writing were easier than to persuade editors “to fall” for her
copy. Too many were at the game in the bright city of New York;
wisenheimers of both sexes, who instead of coming via Poppa’s pig-
farm had been through College.
There was the rub. At Cowbarn the folks didn’t set much store by
College. But New York was different.
She was a shrewd girl and it did not take long for her to realise that
she was some way behind the game. Human nature was always
human nature, when you came down to cases, but there was no
denying that she lacked experience. Back of everything was faith in
herself, but so wide was the gulf between Cowbarn, Iowa, and the
banks of the Hudson that no amount of faith could bridge it.
New York had laughed at her, scorned her, humiliated her deeply and
cruelly in more ways than one. She had been advised by newspaper
men and also by police officers, professing a disinterested care for
rustic ignorance playing a lone hand, to go back to dad and the pigs.
These experts were confident that Miss Mame Durrance would get
no good of New York.
However, they didn’t know quite so much about Mame Durrance as
she knew about herself. She might be down but she was not out.
New York had no use for her, but there were other places on the
map. For instance, there was London. No, not London, Ontario. As
far as the big stuff was concerned, that burg was in the Cowbarn
class. London, England, was the spot. She heard that London,
England, offered scope for ambition. A few years in Europe might
even stop the gaps in her education. It would be like putting herself
through College. Hers was a forward-looking mind. And as with set
lips and ten fingers on a purse, which in spite of Aunt Lou’s legacy,
was not so heavy as her heart, she put off in the Sidonia, she
determinedly envisaged the future return of Mame Durrance to the
land of her fathers with at least three trunks of real Paris frocks and
an English accent. New York would laugh then at the little mucker on
the other side of its mouth.
Conflicting opinions had been expressed to Miss Durrance about
London. But in her small circle only one was able to speak from first-
hand knowledge. Paula Wyse Ling had been there. The others spoke
from hearsay, and in one or two cases with a little help from the
imagination. But Paula Ling had lived in London a year. This rising
columnist, who in the view of Mame was “the goods,” had taken
pains to impress the traveller with the stark truth that in the Strand
ten cents went no further than they did on Broadway.
Miss Ling had provided the adventurous Mame with the address of a
cheap but respectable boarding house in Bloomsbury, where she had
stayed herself, where, all things considered, she had received value
for her money, and could conscientiously recommend. This
enterprising girl had also given the traveller a letter of introduction
to the editor of High Life, a weekly journal with an address in Fleet
Street, whose ostensible business was to record the doings and
sayings of Society with a large S.
As the train sped on the practical Mame began to arrange certain
things in her mind. First she opened the small bag which was
attached to her wrist, to make sure that the sinews of war were
really there; and then, in spite of having made all sorts of
calculations already, she did one more sum in her head to find out
just how far Aunt Lou’s legacy would carry her. Then she searched
for the address of Miss Ling’s boarding house and found it written on
an envelope: Beau Sejour, 56 Carvell Street, Bloomsbury, London, W.
C. Sole Proprietress Miss Aimee Valance. Terms en pension.
Somehow the information in its fulness and dignity was quite
reassuring. Next the pilgrim reverently fingered the sealed envelope
which bore the address: Walter Waterson, Esq., c/o High Life, 9 Tun
Court, Fleet Street, London, E. C. That was reassuring too. Finally
she took in her fingers her own private card and they thrilled as she
did so.
Her own private card, which had been engraved just before she had
sailed in the Sidonia, had a cosmopolitan air. The world was going to
be impressed by it.
Miss Amethyst Du Rance
New York City, U. S. A.
European Correspondent
Cowbarn Independent
The good old Independent looked quite class tucked away in the
left-hand corner. But it would have raised a sure smile in New York.
That city of four-flushers had taken a lot of pains to impress upon
her that Cowbarn, Iowa, was at best a one-horse burg. Perhaps
London might not be quite so good at geography. And it might not
be quite so set up with itself, although as far as Miss Durrance could
learn that was a subject upon which opinion varied.
However, there it was. European Correspondent, Cowbarn
Independent. At the sight of the magic words the thoughts of Mame
Durrance went rather wistfully back to the hard and dull and
uncomfortable place in which she had been born and reared. After
all it was home. And even if she was ready to die rather than go
back to live there for keeps, it was nothing to be ashamed of, for
there was no place like it.
The card looked so well in the hand of Mame that she decided to
mail one as soon as she reached London, to Elmer P. Dobree, the
young and aspiring editor of the Cowbarn Independent. Good old
Elmer P.! It would simply tickle him to pieces. But it would show him
the stuff she was made of. He had tried to dissuade her from
quitting the safe anchorage of her stool in the Independent office,
and when unable to do so, like the sport he was, had told her to
send along a weekly letter of New York news, and if able to print it
he would pay the top rate of four dollars a thousand words. The
Cowbarn Independent was an influential journal, but it had never
paid President Harding more than four dollars a thousand words.
Mame took the editor at his word. Sometimes her stuff was printed.
Sometimes it wasn’t. But Elmer P.’s kindly interest in her had
continued. She had been encouraged to let him know that she was
going to Europe and that it would help her considerably if she could
depend on his keeping a corner for her London Impressions which
she would mail every Friday. Elmer P., before all things the man of
affairs and the cautious editor, would not be drawn into a rash
promise, but he would do his best. To this end he gave a bit of
advice. Let her see to it that the doggone Britishers didn’t take the
pep out of her style.
So far Miss Durrance had not realised that she had a style. Anyhow
she had never aspired to one. She set down what she saw and
heard and read in words that came just naturally. And she had a
kind of hunch that the slick-a-lick New Yorkers always found
something funny in the way those words came.
The Northwestern express steamed at last into Euston and Mame
found herself up against the raw reality of London. From Crewe on
the fog had been getting more and more businesslike. By the time
the metropolis was reached a very fair imitation of a “London
particular” was on the platform to receive her. It was almost the
famous “pea-soup” variety, but not quite, which was just as well for
Miss Durrance. All traffic would have been at a standstill had she
been greeted by that luxury and the troubles of a stranger in a land
of strangers increased a hundred-fold. Even as it was, for one used
to clear skies the fog was pretty thick, yet the seasoned Cockney
would have described it as not a bad day for the time of year.
A Cockney of that genus, in the person of a luggage porter, opened
the carriage door. He took charge of Miss Durrance’s gear; also he
took charge of Miss Durrance. Slow he was, very slow, to her way of
thinking. As yet the alert traveller had not got the tempo of this
nation of mossbacks; but the porter, if not exactly an Ariel, was sure
as a rock. An earthquake or a landslide would not have hurried him
and Mame had the wisdom not to try.
He got her trunk out of the van and put it on a taxi. She gave the
address, 56 Carvell Street, Bloomsbury, in a tone of crisp
importance; the taximan, who vied with the porter in deference,
touched his cap and off they trundled into the fog. For London it was
really nothing to speak of, but the acrid vapour caused the eyes of
Mame to sting and her throat to tickle; and the combination of raw
air, grimy buildings, and an endless mud-churning sea of vehicles,
slow-moving and enormous in their bulk and mass, somehow filled
her with an odd depression.
In spite of all checks to progress it was not long before they reached
Carvell Street. The taxi stopped at 56. Mame sprang out and boldly
attacked six bleak stone steps, at the top of which was a door in
sore need of paint. Her ring was answered by a comic sort of hired
girl, with cap and apron complete. When Mame asked if she might
see Miss Valance she was very politely invited to come in.
As Mame went in she made a mental note that her first impression
must record the civility of these Londoners. Somehow it had a
quality riper and mellower than any brand she had met with on her
native continent. Whether it came from the heart or was merely a
part of the day’s work of a people addicted to “frills” or just a candid
admission of the superiority of the race to which Mame herself
belonged, must be left to the future to determine; but so far the
critic was pleased with the universal Cockney politeness and she
hoped it would pan out as good as it seemed.
The observer had not time to do justice to the small gas-heated
anteroom into which she was shown before she was joined by the
lady of the house. Miss Valance was a replica of all the Cockney
landladies that ever were. Thin, angular, severe, a false front and an
invincible red tip to a freely powdered nose masked immense
reserves of grim respectability. In the view of Miss Durrance she was
“a regular he-one.” All the same the pilgrim declined to be impressed
by Miss Valance. It was part of her creed to be impressed by nothing
that wore skirts. But had an exception been allowed to this article of
faith Miss Valance would sure have put one over on her.
A disappointment was in store. Beau Sejour was full. Miss Valance
was awfully sorry but she had no vacancy. This was a blow. Mame’s
experience, brief though it was, had been chequered; and she had
duly impressed upon herself that if she adventured as far as London,
England, she must keep her eyes skinned, for like every
cosmopolitan city it was a natural home of the crook. Therefore she
informed Miss Valance that she was a very respectable girl and
wasn’t going to take a chance on any old boarding house.
From the peak of her own respectability the châtelaine of Beau
Sejour applauded Mame’s wisdom. She was helpful besides. Round
the corner in Montacute Square was an establishment she could
recommend. It was called Fotheringay House and was kept by a lady
of the name of Toogood and Miss Valance had heard her well spoken
of. She might have a room to let. Anyhow there would be no harm in
trying Mrs. Toogood.
Mame felt let down. It was clear from the manner of Miss Valance
that she was not very hopeful that the worthy Mrs. Toogood would
be able to take her in. However, Mame warmly thanked Miss Valance
for her helpfulness; and then buttoning up her coat she made a
resolute dive through a passage dark and narrow towards the foggy
street.
In the very act of doing so, a pang keen as the blade of a knife
drove through Mame. Her luggage! All she had in the world had
been left outside in the taxi. The villainous looking guy who had
fawned on her with a wolf’s smile as he had taken her trunk, her
grip, her mackintosh, her umbrella and herself aboard his machine,
had only to trundle away into the fog and she would be left high and
dry with the clothes she stood up in. So sharp was the thought that
Mame nearly groaned aloud. A fool trick to take a chance of that
kind in a foreign city.
Coming over in the Sidonia she had read in the New York Herald of a
girl who had just arrived in Paris having done what she had just
done; and the girl had never seen her luggage again. And here was
Mame Durrance, fed to the teeth with wise resolutions, walking into
a trap with open eyes!
However, the taxi stood by the kerb just as she had left it, with her
box strapped on to the front. Twopences were being registered by
the meter at an alarming rate while the driver was placidly dozing.
But the relief of Miss Durrance was considerable as she jumped in,
after ordering Jehu, who was much less of a bandit than he looked,
to trek round the corner into Montacute Square as far as Fotheringay
House.
La pension Toogood was curiously like Beau Sejour, except that it
had five stone steps instead of six and that one of its area railings
was missing. For the rest it was able to muster a similar air of tired
respectability. Painted over the fanlight of the front door, in letters
that once had been white, was the historical name Fotheringay
House, yet even this did not cause the mansion to look inspiring. But
Mame, obsessed by the knowledge that she was literally burning
money, did not pause to study details.
As she sprang out of the taxi and ran up the steps of Fotheringay
House she hoped that this time she would meet better luck.
A hired girl, the twin in every detail of the slave of Beau Sejour,
opened the door. Miss Durrance was in a hurry, but she could not
help being amused and interested. It was her attitude to life to be
amused and interested; but then who would not have been with
such an apron and such a cap, with such prim politeness, with such
a way of speaking? Evidently the Britishers had standardised the
hired girl. She might have been a flivver or a motor cycle.
The theory applied with equal force to the London landlady. Mrs.
Toogood was Miss Valance over again. But if anything, she was
raised to a slightly higher power. The same dignity, the same
wariness, the same ironclad gentility; but she was a widow with two
children, whereas Miss Valance was a spinster with none. Her
attributes, therefore, were fuller and firmer, a little more clearly
defined. Mame did not make the comparison, but it was the
difference between the Barbizon school and Picasso or Augustus
John.
With the taxi outside ticking off twopences with quiet fury Mame felt
she was getting down to the real meaning of her favourite maxim,
Time is Money. She cut out, therefore, all preliminaries. Without
troubling to remark that it was a nice day, as for London it was no
doubt, she began in a tone of strict business, spot cash only. “Say,
ma’am, can you let me a hall bedroom?”
From the chill mountain height of her disdain the landlady gave
Mame a once-over. No matter what the case with her visitor she was
in no hurry. The châtelaine of Fotheringay House had never heard of
a hall bedroom. Her icy gaze travelled from Mame’s rather crushed
hat via her seal plush coat to her tarnished rubbers with a quietly
stiffening reserve. Clearly a foreigner. Picturesque creatures no
doubt. The late Mr. Toogood was partial to them, but he, though of
pure English blood, was of a romantic mind and an Italian
warehouseman. His widow preferred to order her life on the sound
old plan of giving a wide berth to aliens.
Christian people never knew quite where they were with aliens.
Some of them paid, some of them didn’t. Mrs. Toogood’s experience
had been mainly among the latter. And in her view, this sharp-eyed
slip of a girl who asked for something outlandish in an accent you
could cut with a knife, had the look and air of the didn’t.
It might have been racial prejudice, but that was the landlady’s
feeling.
“From the Isle of Man, I presume,” said Mrs. Toogood loftily.
Although she was the widow of an Italian warehouseman she was
not in the least imaginative. The Isle of Man was her Ultima Thule,
the farthest eagle flight of which her mind was capable.
Mame knew as much about the Isle of Man as the landlady knew
about a hall bedroom. But she smiled broadly.
“I’m from New York.” Her voice went up a little as she made that
damaging admission. For the admission was damaging.
“That would be America, would it not?” The growing gloom of the
landlady began to verge upon melancholia.
Mame allowed that it would be.
The landlady sniffed. Mame knew by that sniff that the home of her
fathers was in the discard.
Mrs. Toogood, if not a travelled woman, or a widely read or highly
informed, was yet an educated one. She had been educated by the
movies. That form of hyperculture which aims to instruct as well as
to amuse and delights to draw together the nations of the earth had
put this good lady wise on the subject of America.
Every Saturday afternoon it was the custom of a modern and
progressive mother to take her twin sons, ætat nine years and two
months, Horatio Nelson Toogood and Victor Emanuel Toogood by
name—the Italian warehouseman had insisted on the Victor
Emanuel in honour of his calling—to the Britannia Picture Palace in
the Euston Road. In that centre of light they had learned that
America was not quite what she gave herself out to be. God’s Own
Country was a truly wicked place. The crook, the vamp, the dope-
fiend, the cattle-rustler, the bootlegger, the forger, the slick duck, the
run amok quick shooter, the holder-up of mails was as thick on the
floor of those United States as the white and yellow crocus in a
Thames meadow in the middle of February. And as London is to the
virtuous island of Britain, so is New York to the infamous land of the
free.
The English are a moral race. They honestly believe their morals are
purer than any upon the wide earth. That is why the Pictures are not
only educational, but popular. They exhibit Cousin Yank in the buff.
And even if the sight embarrasses the pious cheek of Euston Road,
N. W., it is pleasant sometimes to spare a blush for one’s rich
relations.
In the dour eye that regarded Mame was sorrow. The girl looked
harmless even if her speech was odd. But appearances are not
things to bank on; at least in Mrs. Toogood’s experience.
“Any old box’ll do for me, so long as it’s clean and ain’t beyond my
wad.”
“I have a small room on the top floor.” The landlady was guarded. It
was next the servants and very difficult to let; the p.g.’s of
Fotheringay House were persons of clearly defined social status.

You might also like