0% found this document useful (0 votes)
141 views40 pages

Get C Programming On Raspberry Pi Develop Innovative Hardware Based Projects in C 1st Edition Dogan Ibrahim Free All Chapters

The document promotes the ebook 'C Programming on Raspberry Pi' by Dogan Ibrahim, which focuses on developing hardware-based projects using the C programming language. It includes various projects utilizing popular C libraries like wiringPi and pigpio, with complete program listings and explanations. Additional recommended ebooks related to Raspberry Pi and other topics are also mentioned, available for instant download on ebookmeta.com.

Uploaded by

kitanyoretta
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)
141 views40 pages

Get C Programming On Raspberry Pi Develop Innovative Hardware Based Projects in C 1st Edition Dogan Ibrahim Free All Chapters

The document promotes the ebook 'C Programming on Raspberry Pi' by Dogan Ibrahim, which focuses on developing hardware-based projects using the C programming language. It includes various projects utilizing popular C libraries like wiringPi and pigpio, with complete program listings and explanations. Additional recommended ebooks related to Raspberry Pi and other topics are also mentioned, available for instant download on ebookmeta.com.

Uploaded by

kitanyoretta
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/ 40

Get the full ebook with Bonus Features for a Better Reading Experience on 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 HERE

DOWLOAD NOW

Download more ebook instantly today 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
[Contents]

120. The Boy and his Master. [Story]

See Grimm 68, The Thief and his Master, Bolte u. Polívka 2: 60–69;
and compare Tremearne, 223–224; Mason and Espinosa, New
Mexico, JAFL 24: 423–424.

[Contents]

121. The Language of Beasts. [Story]

See Grimm 17, The White Snake, Bolte u. Polívka 1: 131–134; and
Aarne’s study, Der Tiersprachen verstehende Mann, in FF
Communications No. 15. Compare Koelle, 143–145; Basset 2: 119–
124; Junod, 314–317; Chatelain, 219–223; Smith, 565.

[Contents]

122. The Three Pieces of Advice. [Story]

Compare Steere, 413; Mason & Espinosa, JAFL 24: 408–411:


discussed by Espinosa, JAFL 27: 213–214.
[Contents]

123. The Brothers and the Life-tree. [Story]

See Grimm 107, The Two Travellers; Bolte u. Polívka 2: 468–482


and compare Dayrell, 58–60; Espinosa, JAFL 27: 191–195. [285]

[Contents]

124. The Skillful Brothers. [Story]

See Grimm 129, Four Skillful Brothers, Bolte u. Polívka 2:165–169


and compare Cronise and Ward, 200–205; Renel 1:215–223;
Dennett, 33–34; Parsons, Sea Islands, 75.

[Contents]

125. The Three Sillies. [Story]

See Grimm 34, Clever Elsie, Bolte u. Polívka 1:335–342, and


Clouston, Book of Noodles, 7. Compare Parsons, Andros Island,
128–129; Sea Islands, 94.

[Contents]
126. A Misunderstanding. [Story]

See Grimm 84, Hans Married, Bolte u. Polívka 2:203–204.

[Contents]

127. Big-head, Big-belly and Little-foot. [Story]

The story is very common in Jamaica. See Grimm 18, The Straw, the
Coal and the Bean, Bolte u. Polívka 1:135–137, and compare
Parsons, Andros Island, 147.

[Contents]

128. The Goat in the Lion’s Den. [Story]

[Contents]

129. Donkey, Cat and the Lion’s Head. [Story]

The familiar episode of the Wolf’s head which occurs early in the
Reynard cycle (see Percy Society Publications 12, Introduction,
pages xxxiii–xxxiv) is, in African stories, often combined with that of
the Goat in the Lion’s den (or the Hyena’s). Compare Rattray,
Chinyanje, 149–152; Tremearne, 227–229; FL 22:63–65.

[Contents]

130. Clever Molly May. [Story]

See Grimm 77, Clever Gretel, Bolte u. Polívka 2:129–131; and


Parsons, Sea Islands, 140. From this point in the group of stories
Anansi is introduced in the role of hero.

[Contents]

131. Dancing to Anansi’s Fiddle. [Story]

See Grimm 110, The Jew among Thorns, Bolte u. Polívka 2:490–
503; and compare Bundy, JAFL 32:412–413.

[Contents]

132. Anansi Claims the Dinner. [Story]

Compare Nassau, 42–44; Tremearne, FL 21:212; Krug, JAFL


25:106–107.
[Contents]

133. Anansi seeks his Fortune. [Story]

See note to number 106, and Grimm 104, Wise Folks, Bolte u.
Polívka, 2:440–451. One version from Parsons, Andros Island,
[286]93–94, connects this episode with those of the frightened
robbers and the tongue-cutting in number 109.

[Contents]

134. The Pannier Jar. [Story]

See note to number 106. This is episode F‴ in Bolte u. Polívka’s


analysis of Grimm’s Little Peasant. Compare Parsons, Sea Islands,
89; JAFL 32: 372, and note for references.

[Contents]

135. Anansi kills his Grandmother. [Story]

See note to number 106. This is episode G″ in Bolte u. Polívka’s


analysis of Grimm’s “Little Peasant.” Compare Parsons, Andros
Island, 87 and note for references.
[Contents]

136. White-belly and Anansi. [Story]

See note to number 106. The trick corresponds to F′ or G′ in Bolte u.


Polívka’s analysis of The Little Peasant.

[Contents]

137. Monkey hunts Anansi. [Story]

See Boas, JAFL 25: 223–226, where the Devil is the rival sorcerer.

[Contents]

138. Anansi and the Pig. [Story]

See Grimm 72a, Bolte u. Polívka, 2: 100–106; and compare


Parsons, Andros Island, 108 and note; discussion of Spanish forms
by Boas, JAFL 25: 252, note; by Espinosa, JAFL 27: 222–227.

[Contents]

139. The Fifer. [Story]


The story is common in Jamaica. See Jekyll, 98–99. It was told me
as a “speak-acting” story, but as I could get no other of exactly the
same character, I do not know how common it used to be to present
a Nansi story in this way. The Nansi story is now given in the form of
a dramatic monologue or rehearsed simply as a tale.

For the story of “The Fifer,” six actors were required, one to
represent the boy, one the father, and four others the “wild beasts.”
“Anansi,” “Dry-head,” “Tacoomah” and “Tiger” were the “beasts.” Roe
said that “the one who takes the son’s part tells the story.” The
dramatization went on much like a school exercise performed by
grown men, with improvised action and (probably) extemporized
dialogue. It ended in a dance in which all six joined.

Compare Tremearne, 301; Harris, Nights, 370–373; Edwards, 87–


88; Parsons, Andros Island, 137–138. [287]

The story seems to be drawn from such prohibitions against


whistling at night or whistling more than twice when walking at night
or through a haunted forest as are quoted by Sebillot, Le Folk-lore
de France 1: 159, 283. He tells a Breton story of a lad who forgot the
prohibition and found himself mocked and followed by the Devil, who
bore him off just as he had reached home. Compare number 66,
note.

[Contents]

141. Tacoomah makes a Dance. [Story]

Medleys of this character seem to have been a popular form of


entertainment and may still be common, though the examples I have
were given me in every case by old men. They are composed of
scraps of song or whole scenes from well-known Nansi stories,
together with game-songs, imitations of animal sounds, and
“rhyming,” strung together much like our own musical medleys—the
last line of one suggesting the first of the next. In this example, story-
songs from numbers 97 and 86 are followed by a game dialogue;
next by some animal imitations; last, by a specimen of Jamaica
“rhyming.” Other examples of this kind of improvised “rhyming” are:

“Mr. Might, jump up a height, after a kite,


And knock his eye, upon his hog-sty, and cry out ‘hi!
oh, my! why should I die’.”

“There is a boat, and in the boat, is a goat, and has


a long coat, catch him under the throat.”

[Contents]

142. Anansi makes a Dance. [Story]

The songs of this medley at first follow the story of Goat’s escape
from the dance, number 40, combined with the parallel story of Rat’s
escape from Puss’s dance. The song is taken from a popular game
in which one player represents the cat, another the rat; all the others
form a line with clasped hands, and Puss tries to catch Rat through
the line, while all sing the song. The bull’s song belongs to number
88 or 89. Anansi’s fifing is possibly taken from 139.
[Contents]

143. Red Yam. [Story]

Old Mary Roden was bed-ridden and lived in a one-roomed hut, the
floor of which was falling in. The little grandchild, when prompted to
“make a figure,” danced quite spontaneously to the rhythm of the
grandmother’s quavering song. The same is true of the next two
numbers. Songs sung to be danced to in this fashion have rather the
monotonous rhythm of a drum-beat than any melody in our sense of
the word. For the story, see number 23. [288]

[Contents]

145. Fowl and Pretty Poll. [Story]

Literally this means, Fowl wants to be married to Parrot in church,


but Parrot has no good clothes. Parrot wants Crow to marry her in
church, but he says he can’t because of his peelhead (or perhaps he
wants to in spite of this peelhead). Compare the witticism vi.

[Contents]

146. The Cumbalo. [Story]

Sarah Findley was an old-time negress who lived in a little hut far out
in the bush. She danced to the song with a queer jumping motion
like boys playing leap-frog and with all the agility of a young girl. The
dance as a wake game is performed upon two parallel bars held by
four men. One informant called it dancing “Calimbe.”

[Contents]

149. Animal Talk. [Story]

Again there are, in this medley which imitates animal sounds,


reminiscences of consecutive Nansi stories—Crab’s words, in
number 54; Ground Dove’s in 50. For the fasting contest, see
number 61.

Tremearne, 28, says that the imitation of animal cries is a favorite


device in African story-telling. Compare Hollis, Nandi, 109–111,
where a great many examples are given of this kind of
entertainment.

[Contents]

Witticisms.

I & II. These old-fashioned slave stories are from old Vassel Edwards
at Retirement, in the Cock-Pit country. They belong to the “nager-
trick” stories quoted by Lewis.
III. The Congo negro is said to be duller-witted than negroes from the
Gold Coast. To call a man a “Congo” is hence a term of ridicule.

IV. This witticism is common. In one version, the man was said to be
“walking in Kingston.” Mrs. Elizabeth Hilton gave me a version she
learned from Henry Roe, school-master at Retirement, which bears
the marks of having been put together by some literary entertainer.

“Massa Peter was a funny sort of a buckra massa. He was “mustafenia”


(white by law). Massa Peter an’ me, we go to school together. We were
readin’ in a ‘pellin’ (book) an’ we were doin’ jumba fraction sum.

“From the day me leave school me never see Marse Peter any more till
one day we buck up. A glad to see him till a couldn’t glad any more. Marse
Peter went a tell me somet’ing, a laugh till me belly nearly pop.

“Marse Peter was the sort of boy used to go out after hours. Him ma tell
him if him (she) been dead before him, she will show him token (frighten
him). [289]But Marse Peter never will believe her. One night, Marse Peter
go out. When him coming back, he catch right at the cross-road where
dem Taylor boy used to sit down a day-time, an’ smell somet’ing funny, but
he never know wha’. He been ’fraid, but afterward he no ’fraid again. An’
see one man come wid litt’e fire. He say, ‘I beg you a light, sah!’ The man
give him a light. The man has some teeth a his mouth, they long like a
Jack-ass a laugh a sun-hot. Marse Peter pass the man. He meet up
another man. He say, ‘Look here, me frien’, I meet a man jus’ roun’ the
turning, have teeth long like a Jack-ass a laugh a sun-hot.’ The man said,
‘Teeth like these do they long?’ Marse Peter run an’ he run an’ never stop
runnin’ till he meet up a mother bed. From that, Marse Peter never go af’er
no girl again. Marse Peter behave a good buckra massa af’er this.”

V. The witticism is used in a good many connections. In one story, a


man finds a boy by the roadside and takes him home. When he asks
the boy to blow the fire, the duppy says, “Me kyant blow de fire, for
me dead long time an’ dirt eat out all me teet’.” The man beats him
and he runs away crying, “Lor! me dead two time.” In another
version, “Rolling Calf” takes possession of a house. While he is
asleep, the owner makes an iron fork red hot and catches him about
the neck.

VI. See number 145.

VIII. Compare Cundall, FL 15:91, where the “Rolling Calf,” afraid of


the moon, tumbles over into the stream and sprains his foot. He
says, “A don’t mind the wet, a wet, but the ’prain a ’prain me foot’.”

X. In Tremearne, FL 22:222–223, Lizard and Mouse both court a


woman. Mouse tells her that Lizard is blind, can’t see at night; Cock
tells her that Rat is a thief, can’t be seen in the market.

In Koelle, 174–177, Toad and Rat have a wager to see if one can do
what the other cannot. Toad passes a crowd with a whole skin; Rat is
pursued with sticks and stones.

XI. See number 48.

XII. From Alexander Archibald, near Mandeville.

XIII. From Mrs. Matilda Hall, Harmony Hall. See number 4.

XVI. This and the next two witticisms were written out by some
young lads in Bethlehem, Santa Cruz Mountains.

1 See supplementary note, p. 289. ↑


2 See supplementary note, p. 290. ↑
3 See supplementary note, p. 290. ↑
4 See supplementary note, p. 290. ↑
5 See supplementary note, p. 290. ↑
[Contents]
SUPPLEMENTARY NOTES.

[Contents]

46. Why Tumble-bug Rolls in the Dung. [Story]

In Seidel’s story of the “Miracle of the Sidi” (Geschichten und Lieder


der Afrikaner, 105), the devil dares the Sidi to marry a slave to a
princess. The father of the princess has set to her wooers the
supposedly impossible task of filling a bag with hyacinths out [290]of
hyacinth season. The Sidi fills the bag with stones and bids the slave
empty it out before the king, when the stones are by miracle turned
into hyacinths.

[Contents]

48. Why Dog is always Looking. [Story]

A Jamaica negro proverb runs, “Darg say befo’ him plant yam fe look
like masquita’ foot, him satisfy fe tun beggar.” See Cundall’s
collection (Kingston, 1910), 211.

[Contents]

56. Rat’s Wedding. [Story]


It is not the wooden foot-bridge but any drain beside the road—the
gutter—which Jamaicans call a ‘water table.’

[Contents]

66. Simon Tootoos. [Story]

For the music of these songs see Publications of the Modern


Language Association of America, 39 (1924): 482.

[Contents]

97. Leap, Timber, Leap. [Story]

An old man over eighty who was present at the recital of this story
remembered hearing it when he was a little boy. Hauling lumber was
in old days accompanied by song. The story turns upon a theme
common in American Indian hero cycles, that of a trickster’s claim to
magical powers which he does not possess. [291]

[Contents]
INDEX TO INFORMANTS.

1. Alexander, Emily, aged 15. She came to my room in the evening


after her work was done at the hotel and recited to me more than
twenty stories which she had from her father, who was a native of
Mandeville, and with which she was in the habit of entertaining the
other young people employed at the hotel.

See 108, 109, 110, 111, 130.

2. Archibald, Alexander, aged 62. He was “tea-meeting chairman” in


the district of New Green, near Mandeville. I visited him at his home
one late afternoon. Seated on his own door-step in the midst of a
circle of his neighbors, he recited six stories with much wit and good
humor.

See 32b, 36.

3. Bailey, Vivian, a lad, also of Mandeville.

See 1b.

4. Baker, Maud, aged 21. She called upon me with her stories, which
she had from her father, a native of Dry River, though she herself
had been educated in Kingston.

See 102, 106.

5. Barrett, Eliza, aged 30. She was one of a group of women who
were friends of the colored housekeeper at Harmony Hall.

See 92b (1).


6. Barrett, George, aged 60 or over. He visited me at Harmony Hall
with a group of men from Maroon Town. They would spend a whole
morning or even all day telling stories in this way, first one and then
another taking his turn and each making way for the other with a fine
sense of fair play.

See 57b (2), 76a, 84a.

7. Brown, Arthur, aged 23. He was a friend of the chauffeur for the
hotel at St. Ann’s Bay and took me down to his mother’s house at
Steeretown, where he gathered a group for story-telling, each one
reciting one or two stories in turn.

See 127a.

8. Brown, Margaret, aged 55, mother of Arthur.

See 47a.

9. Brown, Philip, aged 19, a jolly contingent of Caledonia, near


Mandeville.

See 75, 76b.

10. Brown, T., another contingent, a Claremont lad who had picked
up a quantity of stories but recited them in a slovenly way, without wit
or point.

See 117.

11. Christie, Samuel, over 60. He was one of the group at


Steeretown, near St. Ann’s Bay, and a good story-teller.

See 5b, 12a, 14. [292]


12. Collins, Benjamin, a crippled lad of George’s Valley, near
Mandeville.

See 11a.

13. Daley, Edward, part East Indian. He was in the prison-gang


whose overseer I was interviewing.

See 132.

14. Dodd, Emiline, under 30. She visited the house at Lacovia where
I was staying.

See 86b.

15. Doran, Grace, very old. She was from Whitehall, near Harmony
Hall. She interpolated her stories with songs in the old style, but
talked so rapidly I was unable to follow except in snatches.

See 27a.

16. Edwards, Vassel, over 80. His father and mother had been
slaves in the same district, one at Retirement, where he himself had
lived all his life and was now deacon in the Scotch Presbyterian
church.

See 134 and the first two witticisms.

17. Falconer, Simeon, aged 47. He was an intelligent and


resourceful man, a church member but nevertheless a frequenter of
wakes, where he learned his stories. He dictated his stories to me at
his home, without audience, and on various visits. His little sitting-
room held a mahogany table set against the wall, at each end two
mahogany chairs, in which we sat, and a curiously carved chair
which a friend had brought him from Africa.
See 10a, 16, 17a, 50, 62, 64.

18. Findley, Sarah, “over 50.” She was mother to one of the house-
girls at Bethlehem, in the Santa Cruz Mountains, an old-time woman
and quite illiterate.

See 146.

19. Forbes, William, over 75. He came from Dry River and was one
of my best story-tellers. He had been song-leader and “Tea-meeting
chairman” for his district and was much respected for his intelligence
and sense of order. He came at several different times and sang or
told stories with equal ease and with a freshness and delight which
was contagious, never failing to bring a small gift from his garden
and never arguing over the pay. He had a very long-shaped head
and beaming eyes.

See 2a, 3, 7, 8, 11b, 24, 25b, 46, 70, 85b, 86a, 101, 140, 141,
142.

20. Ford, May, a young girl. She was of the better class, daughter of
the lodging-house keeper at Newmarket, in Westmoreland.

See 44.

21. Foster, Alexander, aged 40, one of the Maroon story-tellers.

See 88.

22. Gentle, Julia, over 70. She came to me twice at Bethlehem in the
Santa Cruz mountains and recited the stories with great rapidity as if
she knew them by heart in a fixed form, among them some English
ballads of second rate interest.

See 18, 60b, 61, 69b, 77, 112.


23. Hall, Matilda, aged 50, one of the women who came to me at
Harmony Hall, and a good singer and story-teller.

See 57c, 71a, 85b, 148. [293]

24. Harris, William, a young man. He came from a shop at Maggotty


and was scarcely able to speak from bashfulness.

See 73b.

25. Hendricks, Moses, over 60. He was a white man, but lived with
his negro family like one of the race; an excellent story-teller,
dictating some fifteen stories to me at three different visits to his
house.

See 13b, 15, 25a, 26, 29, 35, 48, 69a, 99, 138.

26. Hilton, Elizabeth, aged 41. She was care-taker at Harmony-Hall


and a fine intelligent type. In the evening when her work was done,
she recited to me some thirteen stories learned from her mother who
was brought up at Harmony Hall, and from an old school-master at
Retirement.

See 37a, 40b (1), 84b, 104, 105.

27. Hilton, Norman, aged 13, son to Elizabeth.

See 5.

28. Hilton, James Anderson, aged 33, one of the Maroon men.

See 149.

29. Iron, Adolphus, about 50. A reputed humorist from Golden Grove
near Claremont, but disappointing in frock coat at the lodging house.

You might also like