100% found this document useful (11 votes)
80 views

(Ebook) C Programming on Raspberry Pi: Develop innovative hardware-based projects in C by Dogan Ibrahim ISBN 9783895764325, 3895764329 All Chapters Instant Download

The document promotes various eBooks focused on programming and hardware projects using Raspberry Pi and PIC microcontrollers, authored by Dogan Ibrahim. It highlights the use of the C programming language for developing innovative projects, providing complete program listings and explanations for various applications. The eBooks are available for instant download in multiple formats from ebooknice.com.

Uploaded by

fochtpooni6j
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (11 votes)
80 views

(Ebook) C Programming on Raspberry Pi: Develop innovative hardware-based projects in C by Dogan Ibrahim ISBN 9783895764325, 3895764329 All Chapters Instant Download

The document promotes various eBooks focused on programming and hardware projects using Raspberry Pi and PIC microcontrollers, authored by Dogan Ibrahim. It highlights the use of the C programming language for developing innovative projects, providing complete program listings and explanations for various applications. The eBooks are available for instant download in multiple formats from ebooknice.com.

Uploaded by

fochtpooni6j
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 71

Download the Full Ebook and Access More Features - ebooknice.

com

(Ebook) C Programming on Raspberry Pi: Develop


innovative hardware-based projects in C by Dogan
Ibrahim ISBN 9783895764325, 3895764329

https://ebooknice.com/product/c-programming-on-raspberry-pi-
develop-innovative-hardware-based-projects-in-c-36304238

OR CLICK HERE

DOWLOAD EBOOK

Download more ebook instantly today at https://ebooknice.com


Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...

Start reading on any device today!

(Ebook) Raspberry Pi 5 for Radio Amateurs: program and


Build Raspberry Pi 5 Based Ham Station Utilities with the
RTL-SDR by Dogan Ibrahim, Ahmet Ibrahim ISBN
9783895766121, 3895766127
https://ebooknice.com/product/raspberry-pi-5-for-radio-amateurs-
program-and-build-raspberry-pi-5-based-ham-station-utilities-with-the-
rtl-sdr-57614318
ebooknice.com

(Ebook) Raspberry Pi for Radio Amateurs by Dogan Ibrahim


ISBN 9783895764059, 9783895764042, 3895764043, 3895764051

https://ebooknice.com/product/raspberry-pi-for-radio-amateurs-36304276

ebooknice.com

(Ebook) PIC Microcontroller Projects in C. Basic to


Advanced by Dogan Ibrahim (Auth.) ISBN 9780080999241,
0080999247
https://ebooknice.com/product/pic-microcontroller-projects-in-c-basic-
to-advanced-4674732

ebooknice.com

(Ebook) Raspberry Pi Hardware Projects 1 by Andrew


Robinson ISBN 9781118589038, 1118589033

https://ebooknice.com/product/raspberry-pi-hardware-projects-1-4706072

ebooknice.com
(Ebook) Raspberry Pi Hardware Projects 2 by Andrew
Robinson, Mike Cook ISBN 9781118588901, 9781118723906,
1118588908, 1118723902
https://ebooknice.com/product/raspberry-pi-hardware-
projects-2-50783782

ebooknice.com

(Ebook) Advanced PIC Microcontroller Projects in C: From


USB to ZIGBEE with the PIC 18F Series by Dogan Ibrahim
ISBN 9780750689823, 075068982X
https://ebooknice.com/product/advanced-pic-microcontroller-projects-
in-c-from-usb-to-zigbee-with-the-pic-18f-series-1123344

ebooknice.com

(Ebook) Raspberry Pi Hardware Reference by Warren Gay

https://ebooknice.com/product/raspberry-pi-hardware-reference-54981260

ebooknice.com

(Ebook) Raspberry Pi Hardware Projects, Volume 1 by Andrew


Robinson and Mike Cook ISBN 9781118588949, 9781118723913,
1118588940, 1118723910
https://ebooknice.com/product/raspberry-pi-hardware-projects-
volume-1-55322474

ebooknice.com

(Ebook) Raspberry Pi IoT Projects: Prototyping Experiments


for Makers by John C. Shovic ISBN 9781484269107,
9781484269114, 1484269101, 148426911X
https://ebooknice.com/product/raspberry-pi-iot-projects-prototyping-
experiments-for-makers-23518952

ebooknice.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
Chapter 1 ● Installing the Operating System on Raspberry Pi

country=GB
update_config=1
ctrl_interface=/var/run/wpa_supplicant

network={
scan_ssid=1
ssid="MySSID"
psk="MyPassword"
}

• Copy the file (save) to the boot folder on your SD card with the name: wpa_
supplicant.conf.
• Insert the SD card back into your Raspberry Pi and power-up the device.
• Use Advanced Ip Scanner or one of the methods described earlier to find out the IP
address of your Raspberry Pi.
• Log in to your Raspberry Pi remotely using Putty on your PC (see Section 1.3 and 1.4).
• After logging in, you are advised to change your password for security reasons. You
should also run sudoraspi-config from the command line to enable VNC, I2C, and
SPI as they are useful interface tools that can be used in your future GPIO based work.

1.4 ● Remote access

It is much easier to remotely access the Raspberry Pi over the internet: for example
using a PC rather than connecting a keyboard, mouse, and display to it. Before being able
to remotely access the Raspberry Pi, we have to enable SSH by entering the following
command in a terminal session (if you have followed the steps given earlier, SSH is already
enabled and you can skip the following command):

pi$raspberrypi:~ $ sudo raspi-config

Go to the configuration menu and select Interface Options. Go down to P2 SSH and
enable SSH. Click <Finish> to exit the menu.

You should also enable VNC so the Raspberry Pi Desktop can be accessed graphically over
the internet. This can be done by entering the following command in a terminal session:

pi$raspberrypi:~ $ sudo raspi-config

Go to the configuration menu and select Interface Options. Go down to P3 VNC and
enable VNC. Click <Finish> to exit the menu. At this stage you may want to shut down or
restart your Raspberry Pi by entering one of the following commands in command mode:

pi@raspberrypi:~ $ sudo shutdown now


or
pi@raspberrypi:~ $ sudo reboot

● 17
C Programming on Raspberry Pi

1.5 ● Using Putty

Putty is a communications program used to create a connection between your PC and


Raspberry Pi. This connection uses a secure protocol called SSH (Secure Shell). Putty
doesn’t need to be installed and can be stored in any folder of your choice and run from
there.

Putty can be downloaded from the following web site:

https://www.putty.org/

Simply double click to run it and the Putty startup screen will be displayed. Click SSH and
enter the Raspberry Pi IP address, then click Open (see Figure 1.7). The message shown in
Figure 1.8 will be displayed the first time you access the Raspberry Pi. Click Yes to accept
this security alert.

Figure 1.7 Putty startup screen

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

Figure 1.8 Click Yes to accept

You will be prompted to enter the username and password. Notice the default username
and password are:

username: pi
password: raspberry

You now have a terminal connection with the Raspberry Pi and can type in commands,
including the sudo privileged administrative commands.

To change your password, enter the following command:

passwd

You can use the cursor keys to scroll up and down through the commands you’ve previously
entered in the same session. You can also run programs although not graphical programs.

1.5.1 ● Configuring Putty

By default, the Putty screen background is black with white foreground characters. The
author prefers to have white background with black foreground characters, with the
character size set to 12 points bold. The steps to configure the Putty with these settings
are given below. Notice that in this example these settings are saved with the name RPI4
so that they can be recalled whenever the Putty is restarted:

• Restart Putty.
• Select SSH and enter the Raspberry Pi IP address.
• Click Colours under Window.
• Set the Default Foreground and Default Bold Foreground colours to black (Red:0,

● 19
C Programming on Raspberry Pi

Green:0, Blue:0).
• Set the Default Background and Default Bold Background to white (Red:255,
Green:255, Blue:255).
• Set the Cursor Text and Cursor Colour to black (Red:0, Green:0, Blue:0).
• Select Appearance under Window and click Change in Font settings. Set the font
to Bold 11.
• Select Session and give a name to the session (e.g. RPI4) and click Save.
• Click Open to open the Putty session with the saved configuration.
• Next time you re-start the Putty, select the saved session and click Load followed by
Open to start a session with the saved configuration.

1.6 ● Remote access of the Desktop

You can control your Raspberry Pi via Putty, and run programs on it from your Windows
PC. This however will not work with graphical programs because Windows doesn’t know
how to represent the display. As a result of this, for example, we cannot run any graphical
programs in the Desktop mode. We can get round this problem using some extra software.
Two popular software used for this purpose are: VNC (Virtual Network Connection), and
Xming. Here, we shall be learning how to use the VNC.

Installing and using VNC

VNC consists of two parts: VNC Server and the VNC Viewer. VNC Server runs on the
Raspberry Pi, and the VNC Viewer runs on the PC. VNC server is already installed on your
Raspberry Pi and is enabled as described in Section 1.3 using raspi-config.

The steps to install and use VNC Viewer on your PC are given below:

• There are many VNC Viewers available, but the recommended one is TightVNC which
can be downloaded from the following web site:

https://www.tightvnc.com/download.php

• Download and install TightVNC for your PC. You will have to choose a password during
the installation.
• Enter the following command:

pi@raspberrypi:~ $ vncserver :1

• Start TightVNC Viewer on your PC and enter the Raspberry Pi IP address (see Figure
1.9) followed by :1. Click Connect to connect to your Raspberry Pi.

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

Figure 1.9 Start TightVNC and enter the IP address

Figure 1.10 shows the Raspberry Pi Desktop displayed on the PC screen.

Figure 1.10 Raspberry Pi Desktop on a PC screen

1.7 ● Static IP address

When we are using the Raspberry Pi with a Wi-Fi router, the IP address is automatically
allocated by the router. It is possible that every time we start the Raspberry Pi, the Wi-Fi
router will give the Pi another IP address. This makes it difficult to log in as we have to find
the new IP address before we log in.

We can give our Raspberry Pi a static IP address so that every time it starts, the same IP

● 21
C Programming on Raspberry Pi

address is allocated from the Wi-Fi router. The IP address is given by the DHCP protocol
running on the Wi-Fi router.

Before setting a static IP address, we have to decide what this address will be, and also
make sure that no other devices on our network use this address. We can check this by
logging in to the Wi-Fi router or by displaying the devices on our network using an app on
a smartphone.

The steps to assign a static IP address are as follows:

• First, check dhcpcd is active by entering the following command:

pi@raspbberrypi:~ $ sudo service dhcpcd status

You should see the text active: (running) displayed as shown in Figure 1.11 (only part of
the display is shown). Enter Ctrl+C to exit from the display.

Figure 1.11 Check DHCP running

• If dhcpcd is not running, enter the following commands to activate it:

pi@raspbberrypi:~ $ sudo service dhcpcd start


pi@raspbberrypi:~ $ sudo systemctl enable dhcpcd

• We now need to find the IP address (Default Gateway) and the Domain Name Server
address of our router. This can easily be obtained either from our Wi-Fi router or PC.
The steps to obtain these addresses from a PC are:
• Go to Control Panel on your Windows 10 PC.
• Click Network and Sharing Centre.
• Click Internet as shown in Figure 1.12.

Figure 1.12 Click Internet

• Click Details. You will see a screen similar to the one shown in Figure 1.13 where you

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

can see the Default Gateway and DNS server addresses. In this example, they are
both: 191.168.1.254.

Figure 1.13 Click Details

• You will have to edit the following file: /etc/dhcpcd.conf using a text editor such as
nano. Although you may not be familiar with nano, follow the instructions given here
(nano is described in a later chapter).

pi@raspbberrypi:~ $ sudo nano /etc/dhcpcd.conf

• Go to the end of the file using the down arrow key and enter the following lines:

interface wlan0
static ip_address=191.168.1.120/24
static routers=191.168.1.254
staticdomain_name_servers=191.168.1.254

interface eth0
static ip_address=191.168.1.120/24
static routers=191.168.1.254
static domain_name_servers=191.168.1.254

In this example, we chose a static IP address of 191.168.1.120 after making sure there are
no other devices on our network with the same IP address. The suffix /24 is an abbreviation
of the subnet mask 255.255.255.0. You have to make sure you only change the last digit of
the IP address. i.e. choose an address in the form 191.168.1.x. wlan0 is for the Wi-Fi link,
and eth0 is for the Ethernet link.

• Now, save the file by entering Ctrl+X, followed by Y.


• Display the file on your screen to make sure the changes you made are correct. Enter
the command:

pi@raspberrypi:~ $ cat /etc/dhcpcd.conf

• Reboot your Raspberry Pi and it should come up with the IP address set as required

● 23
C Programming on Raspberry Pi

1.8 ● Summary

In this chapter, we learned how to install the latest Raspberry Pi operating system on an SD
card, and also how to start using the Raspberry Pi remotely. The instructions provided apply
to all versions of Raspberry Pi. Additionally, setting a static IP address for your Raspberry
Pi is demonstrated.

In the next chapter, we will look at various Raspberry Pi program development tools.

● 24
Chapter 2 ● Raspberry Pi Program Development

Chapter 2 ● Raspberry Pi Program Development

2.1 ● Overview

In the last chapter, we learned how to install Raspbian Buster on a Raspberry Pi SD card. In
this chapter, we will learn how to develop programs using Raspberry Pi 4. We will develop
a very simple example project and learn how to use Python and C. Although Python is not
the topic of this book, it will be used in a simple project so that readers can compare Python
with C programming.

2.2 ● The nano text editor

A text editor is a very useful tool for creating program source files. Raspberry Pi supports
several text editors including vi, nano, etc. In this section, we will introduce nano which is
normally run from the command line.

As an example, suppose we wish to create a text file called myfile.txt and insert the
following lines into the file:

This is a simple text file created using nano


This is the second line of the file
This is the third line of the file

The steps are as follows:

• Start nano

pi@raspberrypi:~ $ nano myfile.txt

• Enter the above text into the file (see Figure 2.1). You should see several control codes
at the bottom of the screen.

Figure 2.1 Text entered into the editor

● 25
C Programming on Raspberry Pi

• Enter Ctrl+X followed by the letter Y to save the file. You should now see the file listed
in your directory if you enter the command:

pi@raspberrypi:~ $ ls myfile.txt
myfile.txt
pi@raspberrypi:~ $

• Let us now edit the file we just created to learn some of the editor commands. Restart
nano as above by specifying the filename.
• Let us search for text starting with the word simple: press Ctrl+W and type simple
and press Enter (see Figure 2.2). You should see the cursor moving to the start of the
word simple. Delete simple and change it to difficult.

Figure 2.2 Search for word simple

• Let us replace the word third with fourth: press Ctrl+\ and type third, and then
fourth when Replace with: is displayed. Press Enter. The message Replace this
instance? will be displayed. Type Y. You should see that the word third is replaced
with fourth.
• Let us delete the second line of text: Move the cursor to the second line and enter
Ctrl+K. You should see all the text on the second line is deleted.
• To recall the line just deleted, enter Ctrl+U.
• To get help on using nano, enter Ctrl+G. An example help screen is shown in Figure
2.3. Enter Ctrl+N to display the next page, and Ctrl+P to display the previous page.
Enter Ctrl+X to close the help screen.

Figure 2.3 Example help screen

• Enter Ctrl+X followed by Y to save and exit the editor.


• The contents of the edited file are shown in Figure 2.4.

● 26
Chapter 2 ● Raspberry Pi Program Development

Figure 2.4 Contents of the edited file

As a summary, some of the more useful nano shortcuts are given below:

Ctrl+W: Search for a word.

Ctrl+V: Move to the next page.

Ctrl+Y: Move to the previous page.

Ctrl+K: Cut the current row of text.

Ctrl+R: Read file.

Ctrl+U: Paste the text you previously cut.

Ctrl+J: Justify.

Ctrl+\: Search and replace text.

Ctrl+C: Display current column and row position.

Ctrl+G: Get detailed help on using nano.

Ctrl+-: Go to a specified line and column position.

Ctrl+O: Save (write out) the file currently open.

Ctrl+X: Exit nano.

2.3 ● Example project

In this chapter, we will develop a simple project using both Python and C which will display
the message Hello From Raspberry Pi 4 on your PC screen. This project aims to show
how a project can be created and then run on Raspberry Pi.

2.4 ● Creating and running a Python program on Raspberry Pi

As described below, there are four methods we can employ to create and run Python
programs on Raspberry Pi:

● 27
C Programming on Raspberry Pi

Method 1 – Interactively from command mode

Using this method, we will log in to our Raspberry Pi remotely using SSH and create and run
our program interactively in command mode. This method is excellent for small programs.
The steps are as follows:

• Log in to your Raspberry Pi 4 using SSH (or through a connected monitor and keyboard).
• On the command prompt, enter python3. You should see the Python command mode
which is identified by the following three characters: >>>.
• Type the program:

print ("Hello From Raspberry Pi 4")

• The text required will be displayed interactively on the screen as shown in Figure 2.5.
Enter Ctrl+Z to exit Python.

Figure 2.5 Running a Python program interactively

Method 2 – Create a Python program in command mode

In this method, we will log in to our Raspberry Pi using SSH as before and then create a
Python file. A Python file is simply a text file with the extension .py. We can use a text
editor, e.g. nano to create our file. In this example, a file called hello.py is created using
nano. Figure 2.6 shows the contents of hello.py. This figure also shows how to run the file
using Python 3. Notice the program is run by entering the command:

pi@raspberrypi:~ $ python3 hello.py

Figure 2.6 Creating and running a Python program

Method 3 – Create a Python program in Desktop GUI mode

Using this method, we will log in to our Raspberry Pi in desktop mode using VNCViewer (if
we do not have a monitor directly connected) and create and run our program in GUI mode.
We will be using Thonny which is used to create, debug, and run Python 3 programs.

● 28
Chapter 2 ● Raspberry Pi Program Development

Thonny is an easy to use tool which is only available for Python 3. The nice thing about
Thonny is that it formats code while it is entered from the terminal. For example, all
statements in the body of a while loop are automatically and correctly indented.

The steps to use Thonny are provided below:

• Click Applications menu, then Programming, and select Thonny Python IDE as
shown in Figure 2.7

Figure 2.7 Select Thonny Python IDE

• The Thonny startup screen will be displayed as shown in Figure 2.8. The screen has two
parts: The program is written in the upper part. The lower part is the shell where the
results of the program are displayed. We can also run Python 3 commands interactively
in the lower part of the screen. In the upper part, we have the usual menu items found
in most GUI type displays. Menu option File is used to create a new file, open an
existing file, close, save, or print a file. Menu option Edit is used to undo, cut, paste,
select, find, replace, and so on. Option View is used to enable us to view files, heap,
notes, stack, variables, and so on. Menu option Run is used to run or debug a program.
Menu option Device is used to soft reboot, upload a current script as main script, and
so on. Menu option Tools is used to manage packages, manage plug-ins, configure
Thonny, and so on. Finally, the Help menu option is used to get help on using Thonny.

● 29
C Programming on Raspberry Pi

Figure 2.8 Thonny startup screen

• Type your program in the upper part as shown in Figure 2.9.

Figure 2.9 Type your program

• Click File and save your program by giving it a name. You do not have to specify the
file extension as this is automatically added by Thonny.
• Click Run and you should see the program output on the lower part of the screen as
shown in Figure 2.10.

Figure 2.10 Output of the program

● 30
Chapter 2 ● Raspberry Pi Program Development

Thonny provides the option to debug a program, where we can single-step through a
program and display the variables as the program is stepped through. As an example, let
us debug the program given in Figure 2.9. The steps are:

• Click Run and then Debug current script (nicer).


• You should see the current program line highlighted in yellow.
• We now have the options of: Step over, Step into, and Step out.
• Clicking Step over will step through the program lines as we see them on the screen.
Click this and you should see the output of the program displayed on the lower part of
the screen.
• While in Debug mode, you can also Resume (the orange and white icon) the program
so it continues normally, or Stop and Restart (the red and white icon) the program
from the beginning.

Method 4 – Using the Mu editor

In this method, we will use Mu to create and run our Python example program. Mu is a very
easy to use Python editor and Integrated Development Environment (IDE) for beginners.

Mu is installed by default with the Raspbian Buster operating system and can be started by
clicking the Applications Menu, followed by Programming and then Mu (see Figure 2.11).

Figure 2.11 Starting Mu

If not available, Mu can be installed using the following steps:

• Click Applications Menu ->Preferences ->Recommended Software (Figure


2.12).

● 31
C Programming on Raspberry Pi

Figure 2.12 Select Recommended Software

• Enter Mu in the search box and click on Mu. Click Apply to install the software (Figure
2.13).

Figure 2.13 Install Mu

● 32
Chapter 2 ● Raspberry Pi Program Development

Mu can also be installed from the command line using the command:

pi@raspberrypi:~ $ sudo apt-get install mu-editor

Figure 2.14 shows the startup screen of Mu where the statement to display the message
Hello Form Raspberry Pi 4 is entered.

Figure 2.14 Enter the statement

The menu options are listed on the top of the screen. Click Run to execute the program. The
result will be displayed on the bottom part of the screen as shown in Figure 2.15.

Figure 2.15 Running the program

Interested readers can learn how to use other menu options but this is outside the scope
of this book.

● 33
C Programming on Raspberry Pi

Which Method?

The choice of method depends upon the size and complexity of the program we wish to
develop. Small programs can be interactively run without creating a program file. Larger
programs can be created as Python files by using either nano in command mode. Thonny
and Mu can be used to create programs in Desktop GUI mode. Python beginners should
find Mu easy to use.

2.5 ● Creating and running a C program on Raspberry Pi

Programming Raspberry Pi in C is the main topic of this book. We will use nano to create
our C source programs. The programs should have the file extensions .c. Figure 2.16 shows
the program listing our simple project (Program: msg.c).

#include <stdio.h>

int main(void)
{
printf("Hello From Raspberry Pi 4\n");
}
Figure 2.16 Program: msg.c

The header file stdio.h is included at the beginning of the program. The message is printed
using the printf statement. A new-line is printed at the end of the text using the \n keyword.
The program is compiled by entering the following command. Here, gcc is the C compiler,
-o option specifies that the next word (i.e. hello) is the output filename:

pi@raspberrypi:~ $ gcc –o hello msg.c

The program is run by entering the command:

pi@rasberrypi:~$ ./hello
Hello From Raspberry Pi 4
pi@raspberrypi:~ $

Notice ./ specifies the file is in our current directory, which is by default /home/pi.
Alternatively you could enter the following command to run the program:

pi@raspberrypi:~ $ /home/pi/hello
Hello From Raspberry Pi 4
pi@raspberrypi:~ $

Some useful options of the gcc compiler are:

• If the output option –o is not specified, the compiler creates the executable file

● 34
Chapter 2 ● Raspberry Pi Program Development

called a.out in the default directory. For example:

pi@raspberrypi:~ $ gcc msg.c

• Option –Wall enables all compiler warnings. For example:

pi@raspberrypi:~ $ gcc –Wall –o hello msg.c

• Option –S generates an assembly code listing of the program. In the following example,
the assembly listing is stored in file msg.s:

pi@raspberrypi:~ $ gcc –S msg.c>msg.s

• Option –save-temps creates executable file (a.out), assembly file, compile file, and
list file:

pi@raspberrypi:~ $ gcc –save-temps msg.c


pi@raspberrypi:~ $ ls msg.*
msg.cmsg.imsg.omsg.s
pi@raspberrypi:~ $

• Option –l links with the specified library. In the following example, the code is linked
with a library called wiringPi:

pi@raspberrypi:~ $ gcc –o hello msg.c –lwiringPi

• Option –v displays all the steps gcc takes while compiling the program:

pi@raspberrypi:~ $ gcc –v msg.c

• Option @ can be used to read the compiler options from a file. For example, assume
MyOptions contains the lines:

-Wall –o MyOutputFile

Then, program msg.c can be compiled with the above options as:

pi@raspberrypi:~ $ gcc msg.c @MyOptions

2.6 ● Summary

In this chapter, we learned how to develop Python 3 and C programs using several
methods. The choice of method for Python depends entirely on the user. In this book, we
are interested in developing programs using C. Therefore, the remainder of this book is
about the C language and its use with Raspberry Pi.

● 35
C Programming on Raspberry Pi

In the next chapter, we will make an introduction to C. Readers who are familiar with C can
skip most sections.

● 36
Chapter 3 ● C Programming for Raspberry Pi

Chapter 3 ● C Programming for Raspberry Pi

3.1 ● Overview

In this chapter we will be look at the basic principles of programming using C. There are
hundreds of books, tutorials and application notes on programming using C and therefore
this chapter is not intended to teach C programming in detail.

3.2 ● The C Language

3.2.1 ● Variables

C language supports the following variable types:

char single character or 8-bit variable (-255 to + 256)


unsigned char 8-bit unsigned number (0 to +255)
int 32-bit signed integer (-2147483648 to +2147483647)
long 32-bit signed integer (-2147483648 to +2147483647)
unsigned int 32-bit unsigned integer (0 to +4294967295)
unsigned long 32-bit unsigned integer (0 to +4294967295)
short 16-bit signed integer (-32768 to +32767)
unsigned short 16-bit unsigned (0 to +65535)
float floating point number (±3.402823x1038)
double double precision number (±10308)

3.2.2 ● Screen output and keyboard input

As we have seen earlier, printf is used to display data and text on the screen. Data can be
inputted from the keyboard using the scanf statement. An example is given below.

Example 3.1

Write a program to read the base and height of a triangle and then calculate and display
its area.

Solution 3.1

The required program listing (Program: TriangleArea.c) is shown in Figure 3.1.

/*-----------------------------------------------------------
AREA OF A TRIANGLE
==================

This program calculates the area of a triangle, given its


base and height

● 37
C Programming on Raspberry Pi

Author: Dogan Ibrahim


File : TriangleArea.c
Date : December 2020
------------------------------------------------------------*/
#include <stdio.h>

int main(void)
{
float Base, Height, Area;
printf("\nArea of a Triangle\n\n");
printf("Enter base: ");
scanf("%f", &Base);
printf("Enter Height: ");
scanf("%f", &Height);
Area = Base * Height / 2.0;
printf("Area = %f\n", Area);
return 0;
}
Figure 3.1 Program: TriangleArea.c

At the beginning of the program, variables Base, Height and Area are declared as floating-
point variables. The program then displays the heading Area of a Triangle. New lines are
printed before and after displaying this heading. The text Enter base: is displayed and the
user is requested to enter the base of the triangle which is stored in variable Base. Notice
that scanf requires the memory address of the variable to store the data. Then height is
requested from the user. The area of the triangle is calculated and displayed on screen.
Figure 3.2 shows an example run of the program.

Figure 3.2 Example run of the program

We can change the number of decimal places using the %f statement. The general format
of this statement is:

%n.df where n is the total length of the number to be displayed and d is the
number

● 38
Chapter 3 ● C Programming for Raspberry Pi

of digits after the decimal point.

For example, to display area with one digit after the decimal point, we can use the statement:

printf("Area = %4.1f\n", Area);

Which will display the result in Figure 3.2 as 62.4.

Some other example output formats are (assuming the number to be displayed is 62.0):

%4.2 62.40
%5.2 62.40
%6.3 62.400

To read or display other variables we can use:

%c character
%d integer number
%s string
%u unsigned decimal integer
%lu unsigned decimal long integer
%o octal number
%x, %X hexadecimal number
%e exponential number

Example 3.2

In this example, we will again calculate the area of a triangle but its base and height will
be entered on the same line.

Solution 3.2

The required program listing (Program: TriangleArea2.c) is shown in Figure 3.3.

/*-----------------------------------------------------------
AREA OF A TRIANGLE
==================

This program calculates the area of a triangle, given its


base and height. The base and height are entered on the same line

Author: Dogan Ibrahim


File : TriangleArea2.c
Date : December 2020
------------------------------------------------------------*/
#include <stdio.h>

● 39
C Programming on Raspberry Pi

int main(void)
{
float Base, Height, Area;
printf("\nArea of a Triangle\n\n");
printf("Enter base and height: ");
scanf("%f %f", &Base, &Height);
Area = Base * Height / 2.0;
printf("Area = %6.3f\n", Area);
return 0;
}
Figure 3.3 Program: TriangleArea2.c

This program is very similar to the one provided in Example 1, but scanf is used to read
both the base and height of the triangle with a space separating the two entries. Figure 3.4
shows an example run of the program.

Figure 3.4 Example run of the program

3.2.3 ● Comparison

The following comparison operators can be used in our programs:

> greater than


< less than
== equal to
!= not equal to
>= greater than or equal to
<= less than or equal to

3.2.4 ● Operators

x + y addition
x – y subtraction
x * y multiplication
x / y division
x % y remainder of x/y
x & y bitwise AND
x | y bitwise OR

● 40
Chapter 3 ● C Programming for Raspberry Pi

x ^ y bitwise exclusive OR
~x complement
!x logical NOT
x << y bit shift left
x >> y bit shift right

3.2.5 ● Auto increment/decrement operators

x++ increment x by 1 (after)


x-- decrement x by 1 (after)
++x increment x by 1 (before)
--x decrement x by 1 (before)
x += y increment x by y (same as x = x + y)
x -= y decrement x by y (same as x = x – y)
x *= y multiply x by y (same as x = x * y)
x /= y divide x by y (same as x = x / y)
x&= y bitwise AND x with y (same as x = x & y)
x |= y bitwise OR x with y (same as x = x | y)
x ^= y bitwise Exclusive OR x with y (same as x = x ^ y)

3.2.6 ● Logical operators

&& Logical AND (used in conditional tests)


|| Logical OR (used in conditional tests)
! Logical NOT

3.2.7 ● Flow control

Flow control statements constitute very important statements in all programming languages.
These statements enable programmers to form conditional program executions, selections,
and iterations (loops).

Conditional statements

if…else

The if…else block of statements are the main conditional statements. The general format
of an if…else block is:

if(condition is true)
{
execute these statements
…………………………
…………………………
}
else

● 41
C Programming on Raspberry Pi

{
execute these statements
………………………….
………………………….
}

If there is only one statement inside an if block, there is no need to use a curly bracket:

if(condition is true)
execute a single statement;

or, if(condition is true) execute a single statement;

Example 3.3

Write a program to read two numbers from the keyboard and calculate their average. If
the average is greater than 10, display Average is greater than 10. If on the other hand
the average is less than 10, display Average is less than 10. If on the other hand, the
average is equal to 10, display Average is 10.

Solution 3.3

Figure 3.5 shows the program listing (Program: Average.c). The program reads two
floating-point numbers into variables no1 and no2. The average is calculated and stored in
variable average. A message is then displayed depending on whether the average is equal
to 10, greater than 10, or less than 10. Figure 3.6 shows an example run of the program.

/*-----------------------------------------------------------
AVERAGE OF 2 NUMBERS
====================

This program calculates the average of two numbers read from


the keyboard and compares it with 10

Author: Dogan Ibrahim


File : Average.c
Date : December 2020
------------------------------------------------------------*/
#include <stdio.h>

int main(void)
{
float no1, no2, average;
printf("\nAverage of two numbers\n\n");
printf("Enter two numbers: ");

● 42
Chapter 3 ● C Programming for Raspberry Pi

scanf("%f %f", &no1, &no2);


average = (no1 + no2) / 2.0;

if(average > 10)


printf("Average is greater than 10\n");
else if(average < 10)
printf("Average is less than 10\n");
else
printf("Average is 10\n");

return 0;
}
Figure 3.5 Program: Average.c

Figure 3.6 Example run of the program

switch

The switch statement is another conditional statement that is used to test a variable
against several conditions, and do different things for each condition. The general format of
the switch statement is as follows:

switch (variable)
{
condition 1: do some statements
condition 2: do some statements
condition 3: do some statements
default: do some statements
}

Notice that default is optional and if none of the conditions are satisfied, the statements
under default are executed.

Example 3.4

Write a calculator program to perform the operations of addition, subtraction, multiplication,


and division. The user should enter the first number, the required operation, followed by
the second number. The result should be displayed on the screen.

● 43
C Programming on Raspberry Pi

Solution 3.4

Figure 3.7 shows the required program (Program: calculator.c). The function scanf is
used to read the two numbers and the required operation on the same line. A switch
statement is used to perform the required calculation. Notice the conditions are specified
using the case statement followed by the condition. If for example, the user entered +,
the two numbers added together and the sum is stored in variable result, which is then
displayed. The break statements make sure that the switch block terminates after the
contents of a condition are executed.

/*-----------------------------------------------------------
SIMPLE CALCULATOR
=================

This is a simple calculator program which can perform + - * /

Author: Dogan Ibrahim


File : calculator.c
Date : December 2020
------------------------------------------------------------*/
#include <stdio.h>

int main(void)
{
float no1, no2, result;
char oper;

printf("Enter first number, operation, and second number: ");


scanf("%f%c%f", &no1,&oper, &no2);

switch(oper)
{
case ‘+’:
result = no1 + no2;
break;
case ‘-’:
result = no1 - no2;
break;
case ‘*’:
result = no1 * no2;
break;
case ‘/’:
result = no1 / no2;
break;
}

● 44
Chapter 3 ● C Programming for Raspberry Pi

printf("\nResult = %6.2f\n", result);


return 0;
}
Figure 3.7 Program: calculator.c

Figure 3.8 shows an example run of the program.

Figure 3.8 Example run of the program

while

This flow control statement is usually used in loops (repetition). The statements inside the
curly brackets are executed as long as the condition is true. Notice if the condition does not
become true inside the curly brackets, the loop is executed forever. Also, if the condition is
false on entry to the loop, the statements inside the loop are never executed. The general
format of this statement is as follows:

while(condition is true)
{
execute these statements
}

Example 3.5

It is required to write a program to calculate the total resistance of several resistors


connected in series. Write a program to accept the number of resistors and enter the value
of each resistor. Total resistance should be displayed on the screen.

Solution 3.5

The total resistance of resistors connected in series is calculated by adding up the values of all
the resistors. Figure 3.9 shows the required program listing (Program: SerialResistors.c).
At the beginning of the program, the user is asked to enter the number of resistors
connected in series and this is stored in variable no. A while loop is then formed and inside
this loop, the user is asked to enter the value of each resistor. The total resistance is stored
in the variable Total which is displayed on the screen.

● 45
C Programming on Raspberry Pi

/*-----------------------------------------------------------
SERIALLY CONNECTED RESISTORS
=============================

Total resistance of serially connected resistors

Author: Dogan Ibrahim


File : SerialResistors.c
Date : December 2020
------------------------------------------------------------*/
#include <stdio.h>

int main(void)
{
int no, k, R, Total;

printf("\nSerially Connected Resistors");


printf("\n============================\n");

printf("How many resistors are there? ");


scanf("%d", &no);

k = 1;
Total = 0;

while(k <= no)


{
printf("Enter resistance (Ohms) of Resistor %d: ", k);
scanf("%d", &R);
Total = Total + R;
k++;
}

printf("\nTotal resistance = %d Ohms\n", Total);


return 0;
}
Figure 3.9 Program: SerialResistors.c

● 46
Another Random Scribd Document
with Unrelated Content
A BRIEF

A C C O U NT
OF THE

Occasion, Process, and Issue,


Of a Late

T R I A L
AT THE

Assize held at Gloucester, March 3, 1743


BETWEEN

Some of the People called Methodists,


Plaintiffs,
AND

Certain Persons of the Town of Minchin-


Hampton, in the said County, Defendants.
IN A

L E T T E R to a F R I E N D.
And when the town-clerk had appeased the people, he said, Ye men of
Ephesus, what man is there that knoweth not how that the city of the Ephesians is
a worshipper of the great goddess Diana, and of the image which fell down from
Jupiter. Seeing then that these things cannot be spoken against, ye ought to be
quiet, and to do nothing rashly. For ye have brought hither these men, which are
neither robbers of churches, nor yet blasphemers of your goddess. Wherefore if
Demetrius, and the craftsmen which are with him, have a matter against any man,
the law is open, and there are deputies; let them implead one another. But if ye
enquire any thing concerning other matters, it shall be determined in a lawful
assembly. For we are in danger to be called in question for this day’s uproar, there
being no cause whereby we may give an account of this concourse.

Acts xix. 35‒40.

A BRIEF

A C C O U N T, &c.
London, March 12, 1744.

My dear friend,

O N Thursday evening I came hither from the Gloucester assizes,


where I have been engaged in a trial between some of those
who are called Methodists, and some violent rioters. Perhaps this
news may a little startle you, and put you upon enquiry (as it hath
done some others) “How we came to go to law with our adversaries,
when it is our avowed principle to suffer patiently for the truth’s
sake?” I will tell you, my dear friend: though perhaps there is nothing
in the world more abused than the law, and there are very few that
go to law out of a proper principle; yet we hold, that there is a proper
use of it, and the law is good, when used lawfully. Whether or know
we have used it lawfully in the present case, I shall leave my friend
to judge, after I have told him the motives that induced us to engage
in it.――The Methodists, you know, are every where accounted
enthusiasts, in the worst sense of the word; but though they are
accounted such, yet they would not be enthusiasts in reality. Now we
look upon it to be one species of enthusiasm, to expect to attain an
end, without making use of proper means. We also think, that
believers should be very careful not to be fond of suffering
persecution, when they may avoid it, by making application to the
higher powers. We are likewise of opinion, that good christians will
be good subjects, and consequently it is their duty, as much as in
them lies, to put a stop to every thing, in a rightful way, that may
prove destructive to the king or the government under which they
live. Christian ministers, in particular, we think, ought to consider the
weakness of people’s grace, and, in pity to precious souls, do what
they can to remove every thing out of the way, that may discourage
or prevent poor people’s hearing the everlasting gospel. These
considerations, my dear friend, for some time past, have led me to
examine whether the Methodists in general (and I myself in
particular) have acted the part of good subjects, and judicious
christian ministers, in so long neglecting to make an application to
the superior courts, and putting in execution the wholesome laws of
the land, in order to prevent those many dreadful outrages which
have been committed against us. I need not descend to particulars.
Our Weekly History is full of them; and before that came out, several
of our brethren, both in England and Wales, have received much
damage from time to time, and been frequently in great hazard of
their lives. Wiltshire has been very remarkable for mobbing and
abusing the Methodists; and, for about ten months last past, it has
also prevailed very much in Gloucestershire, especially at Hampton,
where our friend Mr. Adams has a dwelling-house, and has been
much blessed to many people. This displeased the grand enemy of
souls, who stirred up many of the baser sort, privately encouraged
by some of a higher rank, to come from time to time, in great
numbers, with a low-bell and horn, to beset the house, and beat and
abuse the people. About the beginning of July last, their opposition
seemed to rise to the highest. For several days they assembled in
great bodies, broke the windows, and mobbed the people to such a
degree, that many expected to be murdered, and hid themselves in
holes and corners, to avoid the rage of their adversaries. Once,
when I was there, they continued from four in the afternoon till
midnight, rioting, giving loud huzzas, casting dirt upon the hearers,
and making proclamations, “That no Anabaptists, Presbyterians, &c.
should preach there, upon pain of being first put into a skin-pit, and
afterwards into a brook.” At another time they pulled one or two
women down the stairs by the hair of their heads. And on the 10th of
July they came, to the number of near a hundred, in their usual way,
with a low-bell and horn, about five in the afternoon, forced into Mr.
Adams’s house, and demanded him down the stairs whereon he was
preaching, took him out of his house, and threw him into a skin-pit
full of noisome things and stagnated water. One of our friends,
named Williams, asking them, “If they were not ashamed to serve an
innocent man so?” they put him into the same pit twice, and
afterwards beat him, and dragged him along the kennel. Mr. Adams
quietly returned home, and betook himself to prayer, and exhorted
the people to rejoice in suffering for the sake of the gospel. In about
half an hour, they came to the house again, dragged him down the
stairs, and led him away a mile and a half to a place called Bourn-
brook, and then threw him in. A stander-by, fearing he might be
drowned, jumped in and pulled him out; whereupon another of the
rioters immediately pushed him into the pool a second time, and cut
his leg against a stone, so that he went lame for near a fortnight.
Both the constable and justices were applied to, but refused to act;
and seemed rather to countenance the mobbing, hoping thereby
Methodism (as they called it) would be put a stop to, at least at
Hampton. For a season they gained their end. There was no
preaching for some time, the people fearing to assemble on account
of the violence of the mob. Upon my return to town, I advised with
my friends what to do. We knew we wanted to exercise no revenge
against the rioters, and yet we thought it wrong that the gospel
should be stopped by such persons, when the government under
which we lived countenanced no such thing; and also, that it was
absurd to thank God for wholesome laws, if they were not to be
made use of. We knew very well, that an Apostle had told us, that
magistrates were ordained for the punishment of evil doers; and that
they bear not the sword in vain. We were also fearful, that if any of
our brethren should be murdered by future riotings (as in all
probability they might), we should be accessary to their death, if we
neglected to tie up the rioters hands, which was all we desired to do.
Besides, we could not look upon this as allowed persecution, since it
was not countenanced by the laws of the land, and we might have
redress from these rioters and inferior magistrates, by appealing to
Cæsar, whose real friends and loyal subjects we judged ourselves
not to be, if we suffered his laws to be publicly trampled under foot
by such notorious rioting; and which, though begun against the
Methodists, might terminate in open rebellion against King George.
For these and such like reasons, we thought it our duty to move for
an information in the King’s-Bench against five of the ring-leaders,
and fixed upon the riot which they made on Sunday, July 10, when
they put Mr. Adams and Williams into the skin-pit and brook. But
before this was done, I wrote a letter to one whom they called
Captain, desiring him to inform his associates, “That if they would
acknowledge their fault, pay for curing a boy’s arm, which was
broken the night I was there, and mend the windows of Mr. Adams’s
house, we would readily pass all by; but if they persisted in their
resolutions to riot, we thought it our duty to prevent their doing, and
others receiving, further damage, by moving for an information
against them in the King’s-Bench.” I also sent a copy of this letter to
a minister of the town, and to a justice of the peace, with a letter to
each from myself: but all in vain. The rioters sent me a most insolent
answer, wrote me word, “They were in high spirits, and were
resolved there should be no more preaching in Hampton.” Finding
them irreclaimable, we moved the next term for a rule of court in the
King’s-Bench to lodge an information against five of the ring-leaders,
for the outrage committed, violence offered, and damage done to Mr.
Adams and Williams, on Sunday, July 10. The rioters were apprized
of it, appeared by their council, and prayed the rule might be
enlarged till the next term. It was granted. In the mean while they
continued mobbing, broke into Mr. Adams’s house one Saturday
night at eleven o’clock, when there was no preaching, made those
that were in bed get up, and searched the oven, cellar, and every
corner of the house, to see whether they could find any Methodists.
Some time after, they threw another young man into a mud-pit three
times successively, and abused the people in a dreadful manner.
The next term came on. We proved our accusations by twenty-six
affidavits; and the defendants making no reply, the rule was made
absolute, and an information filed against them. To this they pleaded
not guilty; and, according to the method in the crown-office, the
cause was referred to the assize held at Gloucester, March
3d.――Thither I went, and on Tuesday morning last the trial came
on. It was given out by some, “That the Methodists were to lose the
cause, whether right or wrong.” And I believe the Defendants
depended much on a supposition, that the gentlemen and jury would
be prejudiced against us. We were easy, knowing that our Saviour
had the hearts of all in his hands. Being aware of the great
consequences of gaining or losing this trial, both in respect to us and
the nation, we kept a day of fasting and prayer through all the
societies both in England and Wales. Our Scotch friends also joined
with us; and chearfully committed our cause into his hands by whom
kings reign and princes decree justice. We had about thirty
witnesses to prove the riot and facts laid down in the information.
Our council opened the cause (as I heard, being not present when
the trial begun) with much solidity and sound reasoning: they
shewed, “That rioters were not to be reformers; and that his Majesty
had no where put the reins of government into the hands of
mobbers, or made them judge or jury.” One of them in particular, with
great gravity reminded the gentlemen on the jury of the advice of
Gamaliel, a doctor of the law, recorded Acts v. 38, 39. “Refrain from
these men, and let them alone; for if this council, or this work, be of
men, it will come to nought: but if it be of God, ye cannot overthrow
it, lest haply ye be found even to fight against God.” Our witnesses
were then called. I came into court when the second witness was
examining. Mr. Adams and four more (three of which were not called
Methodists) so clearly proved both the riot and the facts laid to the
charge of the Defendants, that the Judge was of opinion there
needed no other evidence. The council for the Defendants then rose,
and exerted a good deal of oratory, and I think said all that could well
be said, to make the best of a bad matter. One urged, “That we were
enthusiasts, and our principles and practices had such a tendency to
infect and hurt the people, that it was right, in his opinion, for any
private person to stand up and put a stop to us; and whoever did so,
was a friend to his country.” He strove to influence the jury, by telling
them, “That if a verdict was given against the Defendants, it would
cost them two hundred pounds: that the Defendants rioting was not
premeditated; but, that coming to hear Mr. Adams, and being
offended at his doctrine, a sudden quarrel arose, and thereby the
unhappy men were led into the present fray, which he could have
wished had not happened; but however it did not amount to a riot,
but only an assault.” Their other council then informed the jury, “That
they would undertake to prove that the Methodists began the tumult
first.” He was pleased also to mention me by name, and acquainted
the court, “That Mr. Whitefield had been travelling from common to
common, making the people cry, and then picking their pockets,
under pretence of collecting money for the colony of Georgia; and
knowing that Gloucestershire was a populous country, he at last
came there. That he had now several curates, of which Mr. Adams
was one, who in his preaching had found fault with the proceedings
of the clergy, and said if the people went to hear them, they would be
damned. He added, that there had lately been such mobbing in
Staffordshire, that a regiment of soldiers was sent down to suppress
them; insinuating that the Methodists were the authors. That we had
now another cause of a like nature depending in Wiltshire; and that
we were not of that mild pacific spirit, as we would pretend to
be.”――This, and much more to the same purpose, though foreign
to the matter in hand, pleased many of the auditors, who expressed
their satisfaction in hearing the Methodists in general, and me in
particular, thus lashed, by frequent laughing. The eyes of all were
upon me. Our Saviour kept me quite easy. I thought of that verse of
Horace,

――Hic murus aheneus esto,

Nil conscire sibi, nullâ pallescere culpâ.

Tertullus’s accusing Paul came also to my mind, and I looked upon


myself as highly honoured in having such things spoken against me
♦ falsely for Christ’s great name’s sake. To prove what the
Defendants council had insinuated, they called up a young man, who
was brother to one of the Defendants, and one of the mob. He swore
point blank, “That Mr. Adams said, if people went to church, they
would be damned; and if they would come to him, he would carry
them to Jesus Christ. He swore also, that the pool in which Mr.
Adams was thrown, was no deeper than half way up his legs. He
said first, that there were about ten of them that came to the house
of Mr. Adams; and then he swore that there were about threescore.
He said, there was a low-bell, and that one of the Defendants did ask
Mr. Adams to come down off the stairs, but that none of them went
up to him; upon which Mr. Adams willingly obeyed, went with them
briskly along the street, and, as he would have represented it, put
himself into the skin-pit and pool, and so came out again.” He said
also some other things; but through his whole evidence appeared so
flagrantly false, that one of the counsellors said, “It was enough to
make his hair stand an end.” The Judge himself wished, “He had had
so much religion as to fear an oath.” So he went down in disgrace.
Their second evidence was an aged woman, mother to one of the
defendants. She swore, “That her son did go up the stairs to Mr.
Adams, and that Mr. Adams tore her son’s coat, and would have
broken his neck down stairs.” But she talked so fast, and her
evidence was so palpably false, that she was sent away in as much
disgrace as the other. Their third and last evidence was father to one
who was in the mob, though not one of the defendants. The chief he
had to say was, “That when Mr. Adams was coming from the pool,
one met him, and said, “Brother, how do you do?” Upon which he
answered, “That he had received no damage, but had been in the
pool, and came out again.” So that all their evidences, however
contrary one to another, yet corroborated ours, and proved the riot
out of their own mouths. The book was then given to a justice of the
peace, who had formerly taken up Mr. Cennick, for preaching near
Stroud, and had lately given many signal proofs that he was no
friend to the Methodists. But he intending to speak only about their
characters, and the council and Judge looking upon that as quite
impertinent to the matter in hand, he was not admitted as an
evidence.――Upon this, his Lordship, with great candour and
impartiality, summed up the evidence, and told the jury, “That he
thought they should bring all the Defendants in guilty; for our
evidences had sufficiently proved the whole of the information, and
also that the riot was premeditated.” He said, “That, in his opinion,
the chief of the Defendants evidence was incredible; and that,
supposing the Methodists were heterodox, (as perhaps they might
be) it belonged to the ecclesiastical government to call them to an
account; that they were subjects, and rioters were not to be their
reformers.”――He also reminded them of the dreadful ill
consequences of rioting at any time, much more at such a critical
time as this; that rioting was the fore-runner of, and might end in,
rebellion; that it was felony, without benefit of clergy, to pull down a
meeting-house; and, for all as he knew, it was high-treason to pull
down even a bawdy-house. That this information came from the
King’s-Bench; that his Majesty’s justices there thought they had
sufficient reason to grant it; that the matters contained in it had been
evidently proved before them, and consequently they should bring all
the Defendants in guilty.”

♦ “falsly” replaced with “falsely”

Upon this the jury were desired to consider of their verdict. There
seemed to be some little demur amongst them. His Lordship
perceiving it, informed them, “They had nothing to do with the
damages, (that was to be referred to the King’s-Bench) they were
only to consider whether the Defendants were guilty or not.”
Whereupon, in a few minutes, they gave a verdict for the
prosecutors, and brought in all the Defendants, “guilty of the whole
information lodged against them.” I then retired to my lodgings,
kneeled down, and gave thanks, with some friends, to our all-
conquering Emmanuel. Afterwards I went to the inn, prayed, and
returned thanks with the witnesses, exhorted them to behave with
meekness and humility to their adversaries, and after they had taken
proper refreshment sent them home rejoicing. In the evening I
preached on those words of the Psalmist, “By this I know, that thou
favourest me, since thou hast not suffered mine enemy to triumph
over me.” God was pleased to enlarge my heart much. I was very
happy with my friends afterwards, and the next morning set out for
London, where we have had a blessed thanksgiving season, and
from whence I take the first opportunity of sending you as many
particulars of the occasion, progress, and issue of our trial, as I can
well recollect. What report his Lordship will be pleased to make of
the case, and how the Defendants will be dealt with, cannot be
known till next term; when I know I shall apprize you of it, as also of
our behaviour towards them.――In the mean while let me entreat
you to give thanks to the blessed Jesus in our behalf, and to pray
that his word may have free course, may run and be glorified, and a
stop be put to all such rebellious proceedings. I remain, Sir,

Your very affectionate friend, and humble servant,

George Whitefield.

⁂ For more particulars of this affair, see Volume II. Letters 526,
527, 529, 545, 549, and 550.
A

L E T T ER
TO THE

Revᵈ. Thomas Church, M.A.


Vicar of Battersea, and Prebendary of St. Paul’s;

IN

A N S W ER
TO HIS

Serious and Expostulatory Letter


TO THE

Revᵈ. George Whitefield,


On Occasion of his late Letter to the Bishop of
London, and other Bishops.

L E T T E R, &c.
London, May 22, 1744.

Reverend Sir,

I HAVE read your expostulatory letter, and thank you for prefixing
your name. Had the author of the observations been so
ingenuous, he would have saved you and me some trouble; but as
he hath not, and the pamphlet was published in such a way, I cannot
think myself justly chargeable with ill-manners or censoriousness, for
treating him and their Lordships concerned, in the manner I have
done. Our Saviour dealt always very plainly with the rulers of the
Jewish Church; and when one was offended, and said, “Master, thus
saying, thou reproachest us also,” he was so far from recanting, that
he said, “And woe unto you also ye lawyers.” In the same spirit, the
proto-martyr Stephen addressed himself to the Jewish Sanhedrim,
and said unto them, “Ye stiff-necked and uncircumcised in hearts
and ears, ye do always resist the Holy Ghost; as your fathers did, so
do ye.” And however shocking, Rev. Sir, it may appear to you, (page
43d of your letter) for us to urge our Lord’s example and his blessed
apostles, yet I think it quite consistent for a minister, who has
received an apostolical commission at his ordination, “Receive thou
the Holy Ghost now committed unto thee by the imposition of our
hands, &c.” to make use of the example of our Lord and his
apostles, in vindication of his conduct; because Christ left us an
example, that we might follow his steps; and we are called to be
followers of the apostles, as they were of Jesus Christ. I know not
how to give flattering titles, and therefore must stand to it, that they
are false witnesses, however dignified or distinguished, and lay to
my charge a thing that I know not, who tax me with being an open
defier of government, for preaching in the fields. Neither do I think I
have wronged the author of the observations at all, by insinuating,
“That the design and scope of this pamphlet was to represent the
proceedings of the Methodists as dangerous to the church and state,
in order to procure an act of parliament against them, or oblige them
to secure themselves by turning dissenters.” That this was his drift,
(at least that he intended to move the government against the
Methodists in general, and me in particular) I think appears quite
plain from a little two-penny paper lately published, (I suppose by the
same anonymous author) wherein he declares, “That though Mr.
Whitefield has pleaded in behalf of the Methodists, that they are an
harmless and loyal people, yet 1st. He cannot possibly be supposed
to know all the persons, or even one tenth part of those present at
his meetings of 30, 50, or 80000.—2d. When he appoints or holds a
meeting, all people are at liberty to come, and to carry on such
purposes as they think proper.—3d. Such a free and safe resort for
great multitudes to one place, subject to no controul or examination,
is doubtless a great opportunity put into the hands of seditious
persons to raise disturbances.” He adds, “How consistently with the
act of toleration, or with what safety to the public, these field-
preachings may be continued, let the world judge.” If this be not
intended to move the government against me, surely there was
never a motion made against any man living; but with what little
shew of true reasoning I need not mention. Let the world judge.

Here lies the point, Rev. Sir: the generality of the clergy are
offended in their hearts, that his majesty is so mild towards his
harmless and loyal people the Methodists. They have denied the
Methodist preachers the use of their churches, and think, if field-
preaching was put a stop to, Methodism, as they term it, would be
less extensive. But were they to gain their point, and the preachers
to be bound, yet perhaps after all they would find themselves
mistaken, for the word of God would not be bound. And I remember
a saying of the then Lord Chancellor to that holy martyr Bradford,
“Thou hast done more hurt (as he called it) by thy letters and
exhortations since thou hast been in prison, than thou ever didst
before.” However this be, field-preaching is at present the clergy’s
eye-sore. Hence they raise a clamour that it is unlawful. We deny it.
We say the act of toleration urged against us is nothing to the
purpose, for we are true members of the established church; and
that if we were not (quod magno mercenter Atridæ) yet the trial of
Mede and Pen is an adjudged case. But still, if you or any other
person please to move for an information against me, for preaching
in a field, or a street, though I purpose to go abroad shortly, yet I
shall think it my duty to stay some time, to make a legal defence. But
if not, henceforward whatever questions may be put to me in print,
about the lawfulness of field-preaching, they will lie unanswered.

Not that I think it is barely field-preaching that gives the generality


of the clergy such offence. No, it is the doctrine that I preach there,
that is the grand cause of their contending with me. You are pleased,
Rev. Sir, to say (Page 39th) “That I have revived the old Calvinistical
disputes concerning predestination, &c.” (I suppose you mean
justification by faith alone, the imputed righteousness of Jesus
Christ, man’s utter inability to turn to God, or to do good works,
&c.) “Which you say had happily slept for so many years.” But if this
be my shame, I glory in it. For what is this but reviving the essential
articles of the Church of England, which undoubtedly are
Calvinistical, and which, by your own confession, have happily slept
for so many years? This is too true. But however you may count this
a happiness, yet in my opinion it is one of the greatest judgments
that has befallen our nation. And if it had not been for the remnant of
free-grace, dissenting ministers, (stiled by the author of the
observations, dissenting teachers) and the little flock of the
Methodist preachers, that the Lord Jesus has raised up and
preserved amongst us, many of the essential doctrines of the articles
of the Church of England might have, as you term it, happily slept
many years more.

These, Rev. Sir, are the real sentiments of my heart. I think they
are founded on truth and soberness. And if so, blame me not, as you
do (page 21st) for comparing the Church of England, as it now
subsists, to a leaky ship. For is it not too evident that she is not only
leaky, but really sinking, when several of the Right Reverend the
Bishops, and a prebendary of St. Paul’s, can openly plead for works
being a condition of our justification in the sight of God? This was
the particular charge my Lord of London gave his clergy in his last
pastoral letter, “So to explain the doctrine of justification by faith
alone, as not to exclude good works from being a condition of our
justification.” Was the great apostle of the Gentiles now living, what
anathema’s would he pronounce against such Judaizing doctrine?
Was Luther on earth, how would he thunder against such a charge?
For he calls justification by faith alone, articulus stantis aut cadentis
ecclesiæ. This is the great fundamental point in which we differ from
the church of Rome. This is the grand point of contention between
the generality of the established clergy, and the Methodist preachers:
we plead for free justification in the sight of God, by faith alone, in
the imputed righteousness of Jesus Christ, without any regard to
works past, present, or to come. You (Bellarmine like) are for making
your works, conditions (page 17th); “And joining your honest, though
imperfect endeavours to serve and please your Maker, with a hearty
trust and confidence in his everlasting mercies,” (page 42.) You say,
(page 58th) we are very far from building wholly on our morality;” we
say, our morality is not to be built on at all, but that “Christ is the
end of the law for righteousness to every one that believeth.” This,
you think, is one of my errors. But if it be an error, it is a scriptural
error; and so plainly taught in the eleventh article of our church, that
he that runs may read: and however you may blame me for
insinuating, “That some of the clergy may adhere to his majesty only
for his preferments, and consequently not appear altogether so
hearty in a time of danger;” yet I cannot think it an instance of hard-
judging at all. For if persons can deliberately subscribe to the
doctrines of justification by faith alone, and other articles that are
purely Calvinistical, yet so explain them away as plainly to prove
they scarce believe a word of them, I should not wonder if they
turned Jacobites, or went over to the pretender, whenever they saw
it suited their worldly interest so to do.

That I am not alone in my opinion, give me leave, Rev. Sir, to


transcribe a passage I lately met with in the latter end of a book,
entitled, The Honeycomb of Free Justification, written by one Mr.
Eaton, A.M. of Trinity College in Cambridge, printed at London in the
year 1642.

“Free justification was first enjoined to be diligently taught, for the


reformation of the church, by King Henry VIII. but was by King
Edward VI. and Queen Elizabeth, principally established by
parliament, and singled out from all the rest of the established
articles of religion; and reduced into sermons and homilies to be
(after the people’s sight of their lost estate, and woeful misery by sin)
principally taught, and chiefly known and understood of all the
subjects and commons of the land, for these four causes.

1st. “Because it is the only immediate cause and means of our


peace with God. For being justified by faith we have peace with
God, Romans v. 1. and our assurance of free salvation by Jesus
Christ, and is therefore called the justification of life, Romans v. 18.
‘For whom God justifieth, them he also glorifieth,’ Romans viii. 30.

2d. “Because it is the ordinance of God (quite contrary to the


judgment of popish carnal reason) that powerfully causeth people to
leave their sins, and live a true sanctified and godly life. Titus ii. 11 to
15. Romans 5th and 6th chapter.

3d. “Because it is the chief cause and means to discover and


suppress the Romish antichrist, popery, &c. and all other
superstitions, sects, errors and schisms out of the land; and to
establish unity, peace and concord in matters of religion, and of
assurance of free salvation, and makes every man to keep in a
lawful vocation, and to do it profitably in love. Galatians v. 13.

4th. “To direct ministers ὀρθοποδεῖν to go with a right foot to the


truth of the gospel, Galatians ii. 14. in sound preaching, and pure
declaring of the word of God, by true faith of free justification,
because (saith the established doctrine of our church) sincere
preachers ever were, and ever shall be but a few; and their
preaching of God’s word most sincere in the beginning, by process
of time waxeth less and less pure, and after is corrupt, and last of all
quite laid down, and left off; because free justification is a doctrine
hardly learned in a church, and soon lost again, Galatians i. 6. and
yet is the true strength, happiness and safety of the whole land,
Isaiah lxii. 1‒6.”

Hereupon, the 5th part of the sermon against disobedience and


rebellion, established by Queen Elizabeth, teacheth the commons,
that such bishops or ecclesiastical persons, as by pride and
ambitious rule, do by terms of error, schism, or heresy, hinder this
main light of God’s word from the people, are the chiefest traytors in
the land: and the 6th and last part largely teacheth, that such
subjects and commons to whom through ignorance of God’s word,
this light of righteousness, and this sun of understanding doth not
shine, although they may brag, as did sometimes the Jewish clergy
and people, that they cannot lack knowledge, yet are such by their
blind dead faith, traytors to God, traytors to their king, traytors to
their own souls and bodies, and traytors to the whole land and
country.”

Thus writes that good man Mr. Eaton. I leave you, Rev. Sir, to
make what use of it you please. You see we have human as well as
divine authority on our side. And yet we are looked upon as
erroneous, and are accordingly denied the churches: and what for?
even for preaching up the doctrine of justification by faith alone; for
which the glorious martyrs of the Church of England burnt in
Smithfield. If this be not like Nero’s setting Rome on fire, and then
charging it upon the christians, I know not what is.

This is really, Rev. Sir, the truth of the case. However, we are
willing to frequent the church, and receive the holy sacrament, if the
clergy please to give us leave. This I think we may do, without being
guilty of the inconsistency you charge us with (page 29th), because
in the 26th article of our church we are taught, “Although in the
visible church the evil be ever mingled with the good, and sometime
the evil have chief authority in the ministration of the word and
sacraments: yet, forasmuch as they do not the same in their own
name, but in Christ’s, and do minister by his commission and
authority, we may use their ministry, both in hearing the word of God,
and in receiving of the sacraments: neither is the effect of Christ’s
ordinance taken away by their wickedness, nor the grace of God’s
gifts diminished from such, as by faith, and rightly do receive the
sacraments ministered unto them, which be effectual, because of
Christ’s institution and promise, although they be ministered by evil
men.” This I think a sufficient vindication, for the methodists keeping
in the church. But if some cannot go thus far, nor bear to hear the
doctrine of justification by faith alone continually preached against,
the preachers must thank themselves if any entirely desert the
church, and run to meeting-houses or elsewhere, to get food for their
souls. For I am persuaded, if the doctrine of justification by faith
alone be banished from our pulpits, people may attend to their lives
end, and yet never have the whole counsel of God (as you think
they may, page 50.) declared unto them.

I could enlarge upon this point, and also answer the charge of
enthusiasm which you bring against me in several parts of your
letter. But I willingly omit it, because I shall have occasion to write
more explicitly on these points in my second answer to the
Observations: I have some reasons for deferring it at present. But I
assure you, Rev. Sir, you must not expect me to treat that
anonymous author with less justice than in my last. For however
worthy perhaps he may be in your sight, I think I shall prove him to
be no better than an unskilful slandering sophister; and if a
clergyman, an unorthodox blind guide.

As for the irregularities I have been guilty of, in curtailing the


liturgy, or not using the common-prayer in the fields, &c. I think it
needless to make any apology, till I am called thereto in a judicial
way by my ecclesiastical superiors. They have laws and courts. In
and by those, ecclesiastics are to be judged; and I am ready to make
a proper defence, as I mentioned in my answer to the first part of the
observations, whenever it shall be required at my hands. Only I
would beg leave to observe, that by calling extempore prayer,
extempore effusions, you cast a slur upon the whole body of
dissenters, and on many of the reformed churches abroad. And as
the free grace dissenters have helped to keep up the Calvinistical
disputes, which you say have happily slept in the established church
for so many years; was it not for his Majesty’s great kindness, and
the lenity of his government, they would meet with no better
treatment than the poor Methodists do now.

Indeed you say (page 41st) “We do not oppose or deny the true
scripture doctrine concerning these points, (viz. Free justification, the
new birth, and the in-dwelling of the spirit) but only your account and
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

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

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebooknice.com

You might also like