0% found this document useful (0 votes)
56 views83 pages

Arduino V Machine Learning Steven Barrett PDF Download

The document discusses 'Arduino V: Machine Learning' by Steven Barrett, which is part of a series focused on Arduino applications, specifically in AI and machine learning. It outlines the book's structure, which includes tutorials on AI concepts suitable for microcontroller implementation, and emphasizes the accessibility of Arduino hardware for various audiences. The book aims to introduce readers to AI and ML applications on microcontrollers, detailing techniques such as K Nearest Neighbors and Artificial Neural Networks.

Uploaded by

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

Arduino V Machine Learning Steven Barrett PDF Download

The document discusses 'Arduino V: Machine Learning' by Steven Barrett, which is part of a series focused on Arduino applications, specifically in AI and machine learning. It outlines the book's structure, which includes tutorials on AI concepts suitable for microcontroller implementation, and emphasizes the accessibility of Arduino hardware for various audiences. The book aims to introduce readers to AI and ML applications on microcontrollers, detailing techniques such as K Nearest Neighbors and Artificial Neural Networks.

Uploaded by

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

Arduino V Machine Learning Steven Barrett

download

https://ebookbell.com/product/arduino-v-machine-learning-steven-
barrett-47440834

Explore and download more ebooks at ebookbell.com


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

Tinyml Machine Learning With Tensorflow On Arduino And Ultralow Power


Microcontrollers Daniel Situnayake

https://ebookbell.com/product/tinyml-machine-learning-with-tensorflow-
on-arduino-and-ultralow-power-microcontrollers-daniel-
situnayake-10679310

Iot Machine Learning Applications In Telecom Energy And Agriculture


With Raspberry Pi And Arduino Using Python 1st Edition Puneet Mathur

https://ebookbell.com/product/iot-machine-learning-applications-in-
telecom-energy-and-agriculture-with-raspberry-pi-and-arduino-using-
python-1st-edition-puneet-mathur-50195440

Arduino I Getting Started Steven F Barrett

https://ebookbell.com/product/arduino-i-getting-started-steven-f-
barrett-46867338

Arduino Iv Diy Robots 3d Printing Instrumentation And Control Tyler


Kerr

https://ebookbell.com/product/arduino-iv-diy-robots-3d-printing-
instrumentation-and-control-tyler-kerr-47229038
Arduino A Beginners Guide To Arduino Programming 1st Edition George
Gibson

https://ebookbell.com/product/arduino-a-beginners-guide-to-arduino-
programming-1st-edition-george-gibson-48621802

Arduino For Dummies 1st Edition John Nussey

https://ebookbell.com/product/arduino-for-dummies-1st-edition-john-
nussey-48672310

Arduino Sketches Tools And Techniques For Programming Wizardry 1st


Edition James A Langbridge

https://ebookbell.com/product/arduino-sketches-tools-and-techniques-
for-programming-wizardry-1st-edition-james-a-langbridge-48672312

Arduino In Easy Steps Stuart Yarnold

https://ebookbell.com/product/arduino-in-easy-steps-stuart-
yarnold-50317872

Arduino Project Handbook Mark Geddes

https://ebookbell.com/product/arduino-project-handbook-mark-
geddes-50317882
Synthesis Lectures on
Digital Circuits & Systems

Steven F. Barrett

Arduino V:
Machine Learning
Synthesis Lectures on Digital Circuits &
Systems

Series Editor
Mitchell A. Thornton, Southern Methodist University, Dallas, USA
This series includes titles of interest to students, professionals, and researchers in the
area of design and analysis of digital circuits and systems. Each Lecture is self-contained
and focuses on the background information required to understand the subject matter and
practical case studies that illustrate applications. The format of a Lecture is structured
such that each will be devoted to a specific topic in digital circuits and systems rather
than a larger overview of several topics such as that found in a comprehensive handbook.
The Lectures cover both well-established areas as well as newly developed or emerging
material in digital circuits and systems design and analysis.
Steven F. Barrett

Arduino V: Machine
Learning
Steven F. Barrett
Department of Electrical and Computer
Engineering
University of Wyoming
Laramie, WY, USA

ISSN 1932-3166 ISSN 1932-3174 (electronic)


Synthesis Lectures on Digital Circuits & Systems
ISBN 978-3-031-21876-7 ISBN 978-3-031-21877-4 (eBook)
https://doi.org/10.1007/978-3-031-21877-4

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

This Springer imprint is published by the registered company Springer Nature Switzerland AG
The registered company address is: Gewerbestrasse 11, 6330 Cham, Switzerland
Preface

This book is about the Arduino microcontroller and the Arduino concept. The visionary
Arduino team of Massimo Banzi, David Cuartielles, Tom Igoe, Gianluca Martino, and
David Mellis launched a new innovation in microcontroller hardware in 2005, the concept
of open-source hardware. Their approach was to openly share details of microcontroller-
based hardware design platforms to stimulate the sharing of ideas and promote innovation.
This concept has been popular in the software world for many years. In June 2019, Joel
Claypool and I met to plan the fourth edition of “Arduino Microcontroller Processing
for Everyone!” Our goal has been to provide an accessible book on the rapidly evolv-
ing world of Arduino for a wide variety of audiences including students of the fine arts,
middle and senior high school students, engineering design students, and practicing sci-
entists and engineers. To make the book even more accessible to better serve our readers,
we decided to change our approach and provide a series of smaller volumes. Each vol-
ume is written to a specific topic and audience. This book, “Arduino V: AI and Machine
Learning”, explores Arduino applications in the fascinating and rapidly evolving world
of small, local microcontroller-based AI and ML applications. The first three chapters
explore the Arduino IDE, the Arduino Nano 33 BLE Sense, and sensor and periph-
eral interface techniques. In the remaining three chapters, we take a tutorial approach to
Artificial Intelligence (AI) and Machine Learning (ML) concepts appropriate for imple-
mentation on a microcontroller including: K Nearest Neighbors (KNN), Decision Trees,
Fuzzy Logic, Perceptrons, and Artificial Neural Nets (ANN).

Approach of the Book

This book is part of a multi-volume introduction to the Arduino line of processors. The
book series also serves as the “fourth edition” of “Arduino Microcontroller Processing
for Everyone!” When discussing plans for a fourth edition, Joel Claypool and I (sfb)
decided to break the large volume up into a series of smaller volumes to better serve
the needs and interests of our readers. I have tried to strike a balance between each
volume being independent of one another while holding to a minimum of information
v
vi Preface

contained in other volumes. For completeness and independence, this volume contains
tutorial information on getting started, microcontroller interface information, and motor
control partially contained in some of the other volumes and related works completed
for Morgan and Claypool and Springer Nature. I have identified via chapter footnotes
the source of this information contained elsewhere in the series. The book series thus far
includes:

• “Arduino I: Getting Started”


• “Arduino II: Systems”
• “Arduino III: Internet of Things”
• “Arduino IV: DIY Robots—3D Printing, Instrumentation, Control”
• “Arduino V: AI and Machine Learning”

In this book, “Arduino V: AI and Machine Learning”, we concentrate on Artificial Intel-


ligence (AI) and Machine Learning (ML) applications for microcontroller-based systems.
In a recent release, the Arduino Team stated “Arduino is on a mission to make machine
learning simple enough for everyone to use [1]”. Those acquainted with AI and ML con-
cepts might counter these concepts are most appropriate for more powerful computing
platforms. However, recent developments have allowed certain AI and ML applications
to be executed on microcontrollers once they have been trained. There are applications
that lend themselves to remote, battery-operated microcontroller-based AI and ML appli-
cations [3]. In this book, we limit our discussions to AI and ML techniques specifically
for microcontrollers. The intent is to introduce the concepts and allow you to practice on
low cost, accessible Arduino hardware and software. Hopefully, you will find this book a
starting point, an introductory, to this fascinating field. We provide a number of references
for further exploration.
Figure 1 illustrates the relationship between Artificial Intelligence, Machine Learning,
and Deep Learning. The goal of Artificial Intelligence is for computing machinery to
imitate and mimic intelligent human behavior. Some trace the origins of AI back to 1300
BCE [6]. We limit our historical review to AI developments within the 20th century and
forward. Within the realm of AI, we explore Fuzzy Logic.
Machine Learning is under the umbrella of Artificial Intelligence. Its goal is to develop
algorithms to control a process or categorize objects. The developed algorithm undergoes
a learning step where input data is used to confirm or develop desired controller out-
puts. During the learning process the algorithm adjusts certain weights to improve the
performance of the algorithm. Within the realm of ML we explore K Nearest Neighbor
(KNN) algorithms, decision trees, perceptrons, and Artificial Neural Networks (ANN).
Deep Learning involves the development of algorithms using multi-layer Artificial Neural
Networks (ANN).
Preface vii

Machine Learning Artificial Intelligence


- K Nearest Neighbors (KNN) - Imitate intelligent human behavior
Deep Learning
- Decision Trees - Fuzzy Logic
- Multi-layer Neural Nets
- Perceptrons - Applications in vision, robotics
- Artificial Neural Nets (ANN)

Fig. 1 Artificial Intelligence and Machine Learning [5].

As in other books in the series, for completeness, we provide prerequisite information


in Chap. 1. The chapter provides a Quickstart guide to getting started with the Arduino
Integrated Development Environment (IDE).
Chapter 2 introduces the Arduino Nano 33 BLE Sense microcontroller development
board. This is a 3.3 VDC microcontroller.1 The Nano hosts the NINA B306 module which
includes a powerful 64 MHz, 32-bit Arm Cortex-M4F Nordic Semiconductor nRF52840
processor with 256 KB of static RAM (SRAM) and 1 MB of flash memory. The module
also contains Bluetooth and Zigbee communications, serial communication subsystems
(UART, I2C, SPI), direct memory access features, analog-to-digital converters (ADC),
and a 128-bit Advanced Encryption Standard (AES) co-processor [2, 4].
Onboard the Nano 33 development board is an extensive series of peripherals
including a nine axis inertial measurement unit; sensors for barometric pressure, tem-
perature, humidity, proximity, light, and gesture detection; a digital microphone; and a
cryptographic co-processor [2].
Chapter 3 introduces the extremely important concept of the operating envelope for a
microcontroller. The voltage and current electrical parameters for the Arduino microcon-
trollers are presented and applied to properly interface input and output devices to the 3.3
VDC Arduino Nano 33 BLE Sense microcontroller development board. We provide the
bare essentials of interfacing to the Nano 33 for the applications discussed in the book.
In Chap. 4, following a brief historical review, we explore the Machine Learning con-
cepts of K Nearest Neighbors (KNN) and Decision Tree classification techniques. Within

1 We emphasize throughout the book that this is a 3.3 VDC processor. Processor inputs and outputs
must not exceed 3.3 VDC!
viii Preface

the realm of AI, we explore Fuzzy Logic in Chap. 5. In Chap. 6, we explore the percep-
tron and Artificial Neural Networks (ANNs). Deep Learning involves the development
of algorithms using multi-layer Artificial Neural Networks (ANN). We conclude Chap. 6
with a brief introduction to advanced AI and ML deep learning tools and applications.

Laramie, WY, USA Steven F. Barrett


January 2023

References

1. Arduino Team, Get started with machine learning on Arduino, blog.arduino.cc, October 15, 2019.
2. Arduino Nano 33 BLE Sense, ABX00031, January 5, 2022, www.arduino.cc
3. G. Lawton, Machine Learning on Microcontrollers Enables AI, targettech.com, November 17,
2021.
4. nRF52840 Advanced multi--protocol System--on--Chip, nRF52840 Product Brief Version 1.0,
Nordic Semiconductor.
5. J.P. Mueller and L. Massaron, Artificial Intelligence for Dummies, John Wiley and Sons, Inc,
2018.
6. C. Pickover, Artificial Intelligence an Illustrated History, Sterling, New York, 2019.
Acknowledgments

A number of people have made this book possible. I would like to thank Massimo Banzi
of the Arduino design team for his support and encouragement in writing the first edition
of this book: “Arduino Microcontroller: Processing for Everyone!”
I would also like to acknowledge Joel Claypool for his publishing expertise and support
to a number of writing projects. His vision and expertise in the publishing world has made
this book possible. Joel “retired” in September 2022 after 40 plus years of service to the
U.S. Navy and the publishing world. On behalf of the multitude of writers you have
provided a chance to become published authors, we thank you! The next adventurous
chapter in Joel’s life begins with an upcoming hurricane relief effort service trip. I dedicate
this book to you my friend.
I would also like to thank Dharaneeswaran Sundaramurthy of Total Service Books
Production for his expertise in converting the final draft into a finished product.
Finally, as most importantly, I would like to thank my wife and best friend of many
(almost 50) years, Cindy.

Laramie, WY, USA Steven F. Barrett


January 2023

ix
Contents

1 Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 The Big Picture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3 Arduino Quickstart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3.1 Quick Start Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.3.2 Arduino Development Environment Overview . . . . . . . . . . . . . . . . 6
1.3.3 Sketchbook Concept . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.3.4 Arduino Software, Libraries, and Language References . . . . . . . . 7
1.3.5 Writing an Arduino Sketch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.4 Application: LED Strip . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
1.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
1.6 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2 Arduino Nano 33 BLE Sense . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.2 Arduino Nano 33 BLE Sense SoC Board . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.3 Arduino Nano 33 BLE Sense Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.4 NINA B306 Module Subsystems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.4.1 B306 Module Memory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.5 NINA B306 Module Peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.5.1 Pulse Width Modulation (PWM) Channels . . . . . . . . . . . . . . . . . . . 22
2.5.2 Serial Communications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.5.3 Bluetooth Low Energy (BLE) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
2.6 Nano 33 BLE Sense Peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
2.6.1 Nine Axis IMU (LSM9DS1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
2.6.2 Barometer and Temperature Sensor (LPS22HB) . . . . . . . . . . . . . . 46
2.6.3 Relative Humidity and Temperature Sensor (HTS221) . . . . . . . . . 47
2.6.4 Digital Proximity, Ambient Light, RGB, and Gesture
Sensor (APDS–9960) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

xi
xii Contents

2.6.5 Digital Microphone (MP34DT05) . . . . . . . . . . . . . . . . . . . . . . . . . . . 55


2.7 Application: Bluetooth BLE Greenhouse Monitor . . . . . . . . . . . . . . . . . . . 57
2.8 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
2.9 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
3 Arduino Nano 33 BLE Sense Power and Interfacing . . . . . . . . . . . . . . . . . . . . . 67
3.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
3.2 Arduino Power Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
3.3 Voltage Regulators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
3.3.1 Powering the Nano 33 From Batteries . . . . . . . . . . . . . . . . . . . . . . . 68
3.4 Interfacing Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
3.5 Input Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
3.5.1 Switches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
3.6 Output Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
3.6.1 Light Emitting Diodes (LEDs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
3.6.2 Serial Liquid Crystal Display (LCD) . . . . . . . . . . . . . . . . . . . . . . . . 73
3.7 Motor Control Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
3.7.1 DC Motor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
3.8 Application: Dagu Magician Robot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
3.8.1 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
3.8.2 Circuit Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
3.8.3 Dagu Magician Robot Control Algorithm . . . . . . . . . . . . . . . . . . . . 83
3.8.4 Testing the Control Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
3.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
3.10 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
4 Artificial Intelligence and Machine Learning . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
4.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
4.2 A Brief History of AI and ML Developments . . . . . . . . . . . . . . . . . . . . . . . 97
4.3 K Nearest Neighbors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
4.4 Decision Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
4.5 Application: KNN Classifier . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
4.6 Application: Decision Trees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
4.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
4.8 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
5 Fuzzy Logic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
5.1 Overview Concepts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
5.2 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
5.2.1 Establish Fuzzy Control System Goal, Inputs, and Outputs . . . . . 126
Contents xiii

5.2.2 Fuzzify Crisp Sensor Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126


5.2.3 Apply Rules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
5.2.4 Aggregate Active Rules and Defuzzify Output . . . . . . . . . . . . . . . . 129
5.3 Arduino eFLL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
5.3.1 Example: Simple . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
5.3.2 Example: Advanced . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
5.4 Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
5.5 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
5.6 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
6 Neural Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
6.1 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
6.2 Biological Neuron . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
6.3 Perceptron . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
6.3.1 Training the Perceptron Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
6.3.2 Single Perceptron Run Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160
6.3.3 Sorting Tomatoes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
6.4 Multiple Perceptron Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 167
6.4.1 Three Perceptron Run Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
6.5 Perceptron Challenges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
6.6 Artificial Neural Network (ANN) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
6.6.1 Single Neuron Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 177
6.6.2 Single Neuron Run Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
6.6.3 Artificial Neural Networks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
6.6.4 ANN Convergence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
6.7 Deep Neural Networks–Introduction to Software Tools . . . . . . . . . . . . . . . 198
6.8 Application: ANN Robot Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
6.9 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
6.10 Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 203
About the Author

Steven F. Barrett, Ph.D., P.E., received the BS Electronic Engineering Technology from
the University of Nebraska at Omaha in 1979, the M.E.E.E. from the University of Idaho
at Moscow in 1986, and the Ph.D. from The University of Texas at Austin in 1993. He
was formally an active duty faculty member at the United States Air Force Academy,
Colorado and is now the Vice Provost of Undergraduate Education at the University of
Wyoming and Professor of Electrical and Computer Engineering. He is a member of IEEE
(Life Senior) and Tau Beta Pi (chief faculty advisor). His research interests include digital
and analog image processing, computer-assisted laser surgery, and embedded controller
systems. He is a registered Professional Engineer in Wyoming and Colorado. He co-wrote
with Dr. Daniel Pack several textbooks on microcontrollers and embedded systems. In
2004, Barrett was named “Wyoming Professor of the Year” by the Carnegie Foundation
for the Advancement of Teaching and in 2008 was the recipient of the National Society of
Professional Engineers (NSPE) Professional Engineers in Higher Education, Engineering
Education Excellence Award.

xv
Getting Started
1

Objectives: After reading this chapter, the reader should be able to do the following:

• Successfully download and execute a simple program using the Arduino Development
Environment; and
• Describe the key features of the Arduino Development Environment.

1.1 Overview

Welcome to the world of Arduino!1 The Arduino concept of open source hardware was
developed by the visionary Arduino team of Massimo Banzi, David Cuartilles, Tom Igoe,
Gianluca Martino, and David Mellis in Ivrea, Italy. The team’s goal was to develop a line of
easy–to–use microcontroller hardware and software such that processing power would be
readily available to everyone.
In this chapter we provide a brief review of the Arduino Development Environment
and Arduino sketch writing. We use a top–down design approach. We begin with the “big
picture” of the chapter. We then discuss the Arduino Development Environment and how it
may be used to quickly develop a program (sketch) for the Arduino Nano 33 BLE Sense.

1.2 The Big Picture

Most microcontrollers are programmed with some variant of the C programming language.
The C programming language provides a nice balance between the programmer’s control
of the microcontroller hardware and time efficiency in program (sketch) writing. As an

1 This chapter is included for completeness with permission from “Arduino I: Getting Started.”.

© The Author(s), under exclusive license to Springer Nature Switzerland AG 2023 1


S. F. Barrett, Arduino V: Machine Learning, Synthesis Lectures on Digital Circuits
& Systems, https://doi.org/10.1007/978-3-031-21877-4_1
2 1 Getting Started

Arduino Development Environment

computer

Arduino Development
Environment
Micro-B USB

Arduino Nano 33 BLE Sense

Arduino UNO R3 Rev 3

Fig. 1.1 Programming the Arduino processor board. Arduino illustrations used with permission of
the Arduino Team (CC BY–NC–SA) (www.arduino.cc)

alternative, the Arduino Development Environment (ADE) provides a user–friendly interface


to quickly develop a program, transform the program to machine code, and then load the
machine code into the Arduino processor in several simple steps as shown in Fig. 1.1.
The first version of the Arduino Development Environment was released in August 2005.
It was developed at the Interaction Design Institute in Ivrea, Italy to allow students the
ability to quickly put processing power to use in a wide variety of projects. Since that time,
updated versions incorporating new features, have been released on a regular basis
(www.arduino.cc).
1.3 Arduino Quickstart 3

At its most fundamental level, the Arduino Development Environment is a user–friendly


interface to allow one to quickly write, load, and execute code on a microcontroller. A bare-
bones program need only consist of a setup() and loop() function. The Arduino Development
Environment adds the other required pieces such as header files and the main program con-
struct. The ADE is written in Java and has its origins in the Processor programming language
and the Wiring Project (www.arduino.cc).
The ADE is hosted on a laptop or personal computer (PC). Once the Arduino program,
referred to as a sketch, is written; it is verified and uploaded to the Arduino evaluation board.

1.3 Arduino Quickstart

To get started using an Arduino–based platform, you will need the following hardware and
software:

• Arduino Nano 33 BLE Sense SoC platform,


• the appropriate interface cable from the host PC or laptop to the Arduino platform (type
A to type Micro–B), and
• the Arduino Integrated Development Environment (IDE) software.

1.3.1 Quick Start Guide

The Arduino Development Environment may be downloaded from the Arduino website’s
at www.arduino.cc. Versions are available for Windows, Mac OS X, and Linux. Provided
below is a quick start step–by–step approach to blink an onboard LED.

• Download the Arduino Development Environment from www.arduino.cc.


• Connect the Arduino processing board to the host computer via the Micro–B USB cable.
• Start the Arduino Development Environment.
• Under the Tools tab select the type of board Board you are using and the Port that it is
connected to. If the board is not listed, use “Tools” − > “Manage Libraries” to access
the Library Manager. From the Library Manage find and install the library to support the
board. For the Arduino Nano 33 BLE Sense board the library “Arduino Mbed OS Nano
Boards” is installed.
• Type the following program.
4 1 Getting Started

//*****************************************************************

#define LED_PIN 13

void setup()
{
pinMode(LED_PIN, OUTPUT); //set digital pin to output
}

void loop()
{
digitalWrite(LED_PIN, HIGH);
delay(500); //delay specified in ms
digitalWrite(LED_PIN, LOW);
delay(500);
}

//*****************************************************************

• Upload and execute the program by asserting the “Upload” (right arrow) button.
• The onboard LED should blink at one second intervals.

The Arduino Nano 33 BLE Sense is equipped with a Red, Green, and Blue (RGB) LEDs.
The following sketch demonstrates how to control each RGB and the Power LED. Note:
The R, G, B LEDs are asserted active low.

//*********************************************************************
//RGB_test
//
//Adapted from Controlling_RGB_and_Power_LED by the Arduino Team
// arduino.cc
//Demonstrates control of the RGB and Power LEDs on the NANO 33 BLE boards
//Note: The R, G, B LEDs are asserted active low.
//**********************************************************************

#define RED 22 //provide pin locations of LEDs


#define GREEN 23
#define BLUE 24
#define LED_PWR 25

void setup()
{
pinMode(RED, OUTPUT); //initialize digital pins as output
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
pinMode(LED_PWR, OUTPUT);
}

void loop()
{
digitalWrite(RED, HIGH); //turn LEDs off
1.3 Arduino Quickstart 5

digitalWrite(GREEN, HIGH);
digitalWrite(BLUE, HIGH);
digitalWrite(LED_PWR, LOW);
delay(1000); //delay 1s
digitalWrite(RED, LOW); //turn RGB LEDs on in sequence
delay(1000);
digitalWrite(RED, HIGH);
delay(1000);
digitalWrite(GREEN, LOW);
delay(1000);
digitalWrite(GREEN, HIGH);
delay(1000);
digitalWrite(BLUE, LOW);
delay(1000);
digitalWrite(BLUE, HIGH);
delay(1000);
digitalWrite(LED_PWR, HIGH);
delay(1000);
}

//**********************************************************************

This sketch employs a function to set the R, G, and B LEDs.

//**********************************************************************
//RGB_test2
//
//Adapted from Controlling_RGB_and_Power_LED by the Arduino Team
// arduino.cc
//Demnstrates control of the RGB and Power LEDs on the NANO 33 BLE boards
//Note: The R, G, B LEDs are asserted active low.
//
//This sketch uses a function call to set the LED colors.
//**********************************************************************

#define RED 22 //provide pin locations of LEDs


#define GREEN 23
#define BLUE 24
#define LED_PWR 25

void setup()
{
pinMode(RED, OUTPUT); //intitialize digital pins as output
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
pinMode(LED_PWR, OUTPUT);
}

void loop()
{
RGB_set(LOW, HIGH,HIGH); //red
RGB_set(HIGH,LOW, HIGH); //green
RGB_set(HIGH,HIGH, LOW); //blue
6 1 Getting Started

RGB_set(LOW, LOW, HIGH); //yellow


RGB_set(HIGH,LOW, LOW); //cyan
RGB_set(LOW, HIGH,LOW); //magenta
RGB_set(LOW, LOW, LOW); //white

//**********************************************************************

void RGB_set(bool R, bool G, bool B)


{
digitalWrite(RED, HIGH); //turn LEDs off
digitalWrite(GREEN, HIGH);
digitalWrite(BLUE, HIGH);
digitalWrite(LED_PWR, LOW);
delay(1000); //delay 1s

digitalWrite(RED, R); //set LEDs


digitalWrite(GREEN,G);
digitalWrite(BLUE, B);
digitalWrite(LED_PWR, HIGH);
delay(1000); //delay 1s

digitalWrite(RED, HIGH); //turn LEDs off


digitalWrite(GREEN, HIGH);
digitalWrite(BLUE, HIGH);
digitalWrite(LED_PWR, LOW);
delay(1000); //delay 1s
}

//**********************************************************************

With the Arduino Development Environment downloaded and exercised, let’s take a
closer look at its features.

1.3.2 Arduino Development Environment Overview

The Arduino Development Environment is illustrated in Fig. 1.2. The ADE contains a text
editor, a message area for displaying status, a text console, a tool bar of common functions,
and an extensive menuing system. The ADE also provides a user–friendly interface to the
Arduino processor board which allows for a quick upload of code. This is possible because
the Arduino processing boards are equipped with a bootloader program.
1.3 Arduino Quickstart 7

1.3.3 Sketchbook Concept

In keeping with a hardware and software platform for students of the arts, the Arduino
environment employs the concept of a sketchbook. An artist maintains their works in progress
in a sketchbook. Similarly, programs are maintained within a sketchbook in the Arduino
environment. Furthermore, we refer to individual programs as sketches. An individual sketch
within the sketchbook may be accessed via the Sketchbook entry under the file tab.

1.3.4 Arduino Software, Libraries, and Language References

The Arduino Development Environment has a number of built–in features. Some of the
features may be directly accessed via the Arduino Development Environment drop down
toolbar illustrated in Fig. 1.2. Provided in Fig. 1.3 is a handy reference to show the available
features. The toolbar provides a wide variety of features to compose, compile, load and
execute a sketch.

1.3.5 Writing an Arduino Sketch

The basic format of the Arduino sketch consists of a “setup” and a “loop” function. The
setup function is executed once at the beginning of the program. It is used to configure pins,
declare variables and constants, etc. The loop function will execute sequentially step–by-

Upload

Verify

List of
sketches

Board
Manager

Library
Manager

Debug

Search

Fig. 1.2 Arduino development environment (www.arduino.cc)


8 1 Getting Started

Menu

File Edit Sketch Tools Help


- New - Undo - Verify/Compile - Auto Format - Getting Started
- Open - Redo - Upload - Archive Sketch - Environment
- Sketchbook - Cut - Configure and Upload - Troubleshooting
- Manage Libraries
- Copy - Reference
- Examples - Copy for Forum
- Upload Using - Serial Monitor
- Close - Paste Programmer - Serial Plotter - Find in Reference
- Save - Select All - Export Compiled - Board: xxx - Frequently Asked
- Save As - Go to line... Binary - Get Board Info Questions
- Preferences - Comment/ - Optimize for - WiFi101/WiFi NINA - Visit Arduino.cc
- Advanced Uncomment Debugging Firmware Updater - Privacy Policy
- Quit - Increase Indent - Show Sketch Folder - Upload SSL Root - Check for Arduino
- Decrease Indent - Include Library Certificates IDE Updates
- Auto Format - Add File - About Arduino IDE
- Burn Bootloader
- Replace in Files
- Increase Font Size
- Decrease Font Size
- Find
- Find Next
- Find Previous
- Use Selection for Find

Fig. 1.3 Arduino development environment menu (www.arduino.cc)

–step. When the end of the loop function is reached it will automatically return to the first
step of the loop function and execute again. This goes on continuously until the program is
stopped.

//****************************************************************

void setup()
{
//place setup code here
}

void loop()
{
//main code steps are provided here
:
:

//*****************************************************************
1.3 Arduino Quickstart 9

Example: Let’s revisit the sketch provided earlier in the chapter.

//*****************************************************************

#define LED_PIN 13 //name pin 13 LED_PIN

void setup()
{
pinMode(LED_PIN, OUTPUT); //set pin to output
}

void loop()
{
digitalWrite(LED_PIN, HIGH); //write pin to logic high
delay(500); //delay specified in ms
digitalWrite(LED_PIN, LOW); //write to logic low
delay(500); //delay specified in ms
}

//*****************************************************************

In the first line the #define statement links the designator “LED_PIN” to pin 13 on the
Arduino processor board. In the setup function, LED_PIN is designated as an output pin.
Recall the setup function is only executed once. The program then enters the loop function
that is executed sequentially step–by–step and continuously repeated. In this example, the
LED_PIN is first set to logic high to illuminate the LED onboard the Arduino processing
board. A 500 ms delay then occurs. The LED_PIN is then set low. A 500 ms delay then
occurs. The sequence then repeats.
Even the most complicated sketches follow the basic format of the setup function followed
by the loop function. To aid in the development of more complicated sketches, the Arduino
Development Environment has many built–in features that may be divided into the areas of
structure, variables and functions. The structure and variable features follow rules similar
to the C programming language. The built–in functions consists of a set of pre–defined
activities useful to the programmer. These built–in functions are summarized in Fig. 1.4.
There are many program examples available to allow the user to quickly construct a
sketch. These programs are summarized in Fig. 1.5. Complete documentation for these
programs is available at the Arduino homepage (www.arduino.cc). This documentation
is easily accessible via the Help tab on the Arduino Development Environment toolbar.
This documentation will not be repeated here. With the Arduino open source concept, users
throughout the world are constantly adding new built–in features. As new features are added,
they are released in future Arduino Development Environment versions. As an Arduino user,
you too may add to this collection of useful tools. Throughout the remainder of the book
we use both the Arduino Development Environment to program the Arduino Nano 33 BLE
Sense. In the next chapter we get acquainted with the features of the Nano 33.
10 1 Getting Started

Arduino Functions

Digital I/O Advanced I/O


pinMode( ) tone( )
digitalWrite( ) notone( )
digitalRead( ) shiftOut( )
shiftIn( )
pulseIn( )

Fig. 1.4 Arduino development environment functions (www.arduino.cc)

Arduino Environment
Built-in Programs

Communication
Digital Input/Output Analog Input/Output Control Structures Sensors - ASCII Table
- Blink (under Basics) - Analog InOut Serial - Array - ADX3xx accelerometer - Dimmer
- Blink without delay - Analog Input - For loop interation - Knock detector - Graph
- Button - Analog Write Mega - If statement - Memsic2125 two-axis - MIDI
- Debounce - Calibration conditional accelerometer - MultiSerial
- Digital Input Pullup - Fading - Switch case - Ping ultrasonic range - Physical pixel
- State Change - Smoothing - Switch case 2 finder - Read ASCII String
Detection - While statement - Serial call response
- tone Keyboard conditional - Serial call response
ASCII
- tone Melody
- Serial Event
- tone Multiple - Serial Passthrough
- tone Pitch Follower - Virtual color mixer

Multiple Libraries
- Strings
- USB
- LCD
- Robot Control
- Robot Motor
- SD card
- Servo
- Stepper
:

Fig. 1.5 Arduino development environment built–in features (www.arduino.cc)


1.4 Application: LED Strip 11

1.4 Application: LED Strip

Example: LED strips may be used for motivational (fun) optical displays, games, or for
instrumentation–based applications. In this example we control an LPD8806–based LED
strip using the Arduino Nano 33 BLE sense. We use a three meter, 96 RGB LED strip
available from Adafruit (#306) for approximately $30 USD per meter (www.adafruit.com).
The red, blue, and green component of each RGB LED is independently set using an
eight–bit code. The most significant bit (MSB) is logic one followed by seven bits to set the
LED intensity (0 to 127). The component values are sequentially shifted out of the Arduino
33 BLE Sense using the Serial Peripheral Interface (SPI) features as shown in Fig. 1.6a. We
discuss the SPI subsystem in the next chapter.
The first component value shifted out corresponds to the LED nearest the microcontroller.
Each shifted component value is latched to the corresponding R, G, and B component of the

Fig. 1.6 Nano 33 BLE Sense controlling an LED strip. LED strip illustration used with permission of
Adafruit (www.adafruit.com). Nano 33 BLE Sense illustration used with permission of the Arduino
Team (CC BY–NC–SA) (www.arduino.cc)
12 1 Getting Started

LED. As a new component value is received, the previous value is latched and held constant.
An extra byte is required to latch the final parameter value. A zero byte (00)16 is used to
complete the data sequence and reset back to the first LED (www.adafruit.com).
Only four connections are required between the Nano 33 and the LED strip as shown
in Fig. 1.6. The connections are color coded: red–power, black–ground, yellow–data, and
green–clock. It is important to note the LED strip requires a supply of 3.3 VDC and a current
rating of 2 amps per meter of LED strip.
In this example each RGB component is sent separately to the strip. The example illus-
trates how each variable in the program controls a specific aspect of the LED strip. Here are
some important implementation notes:
• SPI must be configured for most significant bit (MSB) first.
• LED brightness is seven bits. Most significant bit (MSB) must be set to logic one.
• Each LED requires a separate R–G–B intensity component. The order of data is G–R–B.
• After sending data for all LEDs. A byte of (0x00) must be sent to return the strip to the
first LED.
• Data stream for each LED is: 1–G6–G5–G4–G3–G2–G1–G0–1–R6–R5–R4–R3–R2–
R1–R0–1–B6–B5–B4–B3–B2–B1–B0

//***********************************************************************
//RGB_led_strip_tutorial: illustrates different variables within
//RGB LED strip
//
//LED strip LDP8806 - available from \url{www.adafruit.com} (#306)
//
//Connections:
// - External 3.3 VDC supply, 2A per LED meter - red
// - Ground - black - include common ground with Nano BLE Sense
// - Serial Data In - Arduino pin 29 (MOSI pin)- yellow
// - CLK Arduino pin 1 (SCK pin)- green
//
//Variables:
// - LED_brightness - set intensity from 0 to 127
// - segment_delay - delay between LED RGB segments
// - strip_delay - delay between LED strip update
//
//Notes:
// - SPI must be configured for Most Significant Bit (MSB) first
// - LED brightness is seven bits. Most Significant Bit (MSB)
// must be set to logic one
// - Each LED requires a separate R-G-B intensity component. The order
// of data is G-R-B.
// - After sending data for all strip LEDs. A byte of (0x00) must
// be sent to return strip to first LED.
// - Data stream for each LED is:
//1-G6-G5-G4-G3-G2-G1-G0-1-R6-R5-R4-R3-R2-R1-R0-1-B6-B5-B4-B3-B2-B1-B0
//
//This example code is in the public domain.
//********************************************************************
1.4 Application: LED Strip 13

#include <SPI.h>

#define LED_strip_latch 0x00

const byte strip_length = 96; //number of RGB LEDs in strip


const byte segment_delay = 10; //delay in milliseconds
const byte strip_delay = 10; //delay in milliseconds
unsigned char LED_brightness; //0 to 127
unsigned char position; //LED position in strip

void setup()
{
SPI.begin(); //SPI support functions
}

void loop()
{
SPI.beginTransaction(SPISettings(200000, MSBFIRST, SPI_MODE3));
SPI.transfer(LED_strip_latch); //reset to first segment
clear_strip(); //all strip LEDs to black
delay(50);

//increment the green intensity of the strip LEDs


for(LED_brightness = 0; LED_brightness <= 60;
LED_brightness = LED_brightness + 10)
{
for(position = 0; position<strip_length; position = position+1)
{
SPI.transfer(0x80 | LED_brightness); //Green - MSB 1
SPI.transfer(0x80 | 0x00); //Red - none
SPI.transfer(0x80 | 0x00); //Blue - none
delay(segment_delay);
}
SPI.transfer(LED_strip_latch); //reset to first segment
delay(strip_delay);
}

clear_strip(); //all strip LEDs to black


delay(50);

//increment the red intensity of the strip LEDs


for(LED_brightness = 0; LED_brightness <= 60;
LED_brightness = LED_brightness + 10)
{
for(position = 0; position<strip_length; position = position+1)
{
SPI.transfer(0x80 | 0x00); //Green - none
SPI.transfer(0x80 | LED_brightness); //Red - MSB1
SPI.transfer(0x80 | 0x00); //Blue - none
delay(segment_delay);
}
SPI.transfer(LED_strip_latch); //reset to first segment
14 1 Getting Started

delay(strip_delay);
}

clear_strip(); //all strip LEDs to black


delay(50);

//increment the blue intensity of the strip LEDs


for(LED_brightness = 0; LED_brightness <= 60;
LED_brightness = LED_brightness + 10)
{
for(position = 0; position<strip_length; position = position+1)
{
SPI.transfer(0x80 | 0x00); //Green - none
SPI.transfer(0x80 | 0x00); //Red - none
SPI.transfer(0x80 | LED_brightness); //Blue - MSB1
delay(segment_delay);
}
SPI.transfer(LED_strip_latch); //reset to first segment
delay(strip_delay);
}

clear_strip(); //all strip LEDs to black


SPI.endTransaction();
delay(50);
}

//****************************************************************

void clear_strip(void)
{
//clear strip
for(position = 0; position<strip_length; position = position+1)
{
SPI.transfer(0x80 | 0x00); //Green - none
SPI.transfer(0x80 | 0x00); //Red - none
SPI.transfer(0x80 | 0x00); //Blue - none
}
SPI.transfer(LED_strip_latch); //Latch with zero
delay(200); //clear delay
}

//******************************************************

1.5 Summary

The goal of this chapter is to provide an introduction and tutorial on the Arduino IDE. We
used a top–down design approach. We began with the “big picture” of the chapter followed
by an overview of the Arduino Development Environment.
References 15

1.6 Problems

1. Describe the steps in writing a sketch and executing it on an Arduino processing board.
2. What is the serial monitor feature used for in the Arduino Development Environment?
3. Describe what variables are required and returned and the basic function of the following
built–in Arduino functions: Blink, Analog Input.
4. What is meant by the term open source?
5. The RGB LEDs onboard the Nano 33 BLE are active low. What does this mean?
6. Be creative! Modify the sketch controlling the strip LEDs to generate a different pattern.
Have fun!

References

1. Arduino homepage, www.arduino.cc


2. Arduino Nano 33 BLE Sense, ABX00031, January 5, 2022. www.arduino.cc
Arduino Nano 33 BLE Sense
2

Objectives: After reading this chapter, the reader should be able to do the following:

• Name and describe the different subsystem peripherals onboard the Nordic Semiconduc-
tor nRF52840 processor;
• Name and describe the different features aboard the Arduino Nano 33 BLE Sense board;
• In your own words describe the background theory of operation for subsystems onboard
the nRF52840 processor and Arduino Nano 33 BLE Sense board; and
• Use the Arduino IDE to program and execute sketches for subsystems onboard the
nRF52840 processor and Arduino Nano 33 BLE Sense board.

2.1 Overview

In this chapter we explore the Arduino Nano 33 BLE Sense SoC board and its nRF52840
processor. We begin with an overview of the Arduino Nano 33 BLE Sense SoC board
features. We then examine the powerful and well–equipped nRF52840 processor and its
associated peripheral subsystems. We then investigate the multiple peripherals onboard the
Nano 33 BLE Sense SoC board. For all peripherals we provide a brief theory of operation,
feature overview, and examples. We conclude the chapter with an extended example featuring
a Bluetooth BLE application–a greenhouse monitoring system.1

1 Portions of the theory provided in the chapter was adapted with permission from “Arduino I: Getting
Started, S. Barrett, Morgan & Claypool Publishers, 2020.

© The Author(s), under exclusive license to Springer Nature Switzerland AG 2023 17


S. F. Barrett, Arduino V: Machine Learning, Synthesis Lectures on Digital Circuits
& Systems, https://doi.org/10.1007/978-3-031-21877-4_2
18 2 Arduino Nano 33 BLE Sense

2.2 Arduino Nano 33 BLE Sense SoC Board

The Arduino Nano 33 BLE Sense SoC board is illustrated in Fig. 2.1. The Nano 33 is a 3.3
VDC processor. Working clockwise from the left, the board is equipped with a Micro–B
USB connector to allow programming the processor from a host personal computer (PC) or
laptop.
The board is equipped with a series of LEDs including the Power LED (L2), the Red,
Green, Blue (RGB) LEDs (DL3), and the Built–In LED (L1). As we experienced in Chap. 1,
these LEDs are accessible via designated pins.
The Arduino Nano 33 BLE Sense SoC board is equipped with a rich complement of
sensors including the (ABX00031):

• Nine axis inertial measurement unit (IMU) (LSM9DS1),


• Barometer and temperature sensor (LPS22HB),
• Relative humidity sensor (HTS221),
• Digital proximity, ambient light, RGB, and gesture sensor (APDS–9960),
• Digital microphone (MP34DT05),

Humidity sensor (HTS221) IMU sensor (LSM9DS1TR)

power LED Red, Green, Blue LEDs

to host PC NINA-B306
via Micro-B module
USB cable BLE 5.0
module

LED Mems microphone (MP34DT06JTR)


push button
Ambient module (APDS-9660)
Step down converter (MP2322GQH)
Crypto chip (ATECC608A)

Fig. 2.1 Arduino Nano 33 BLE Sense SoC board layout. (Figure adapted and used with permission
of Arduino Team (CC BY–NC–SA)(www.arduino.cc).)
2.3 Arduino Nano 33 BLE Sense Features 19

• Crypto Chip (ATEC608A), and the


• DC–DC converter (MPM3610).

Onboard the Nano 33 board is the NINA B306 Module. It contains the Nordic Semi-
conductor nRF52840 processor. This is a 32–bit processor, operating at 64 MHz, with an
ARM Cortex–M4F architecture equipped with a floating point unit (FPU). The processor
is equipped with 1 MB of flash memory and 256 kB of Random Access Memory (RAM)
(nRF52840).
The Nano 33 BLE provides a tremendous amount of computing power in a very small
footprint. The processing power coupled with its peripherals and sensor package provides a
microcontroller ideally suited for AI and ML applications.
The B306 module is also equipped with a large complement of resident peripherals
including (ABX00031):

• Serial communication subsystems including Universal Serial Bus (USB), Universal


Asynchronous Receiver Transmitter (UART), Serial Peripheral Interface (SPI), Quad
SPI (QSPI), Two Wire Interface (TWI).
• A 12–bit resolution, 200 ksps (kilo samples per second) analog–to–digital converter
(ADC),
• A 128 bit Advanced Encryption Standard (AES) co–processor,
• Bluetooth and Zigbee radio,
• Near Field Communication (NFC) features,
• Direct Memory Access (DMA) capability,
• An ARM CC310 Crytocell cryptographic accelerator, and
• Pulse Width Modulation (PWM) channels.

Access to these subsystems are via the Arduino Nano 33 BLE Sense SoC board pins as
shown in Fig. 2.2.

2.3 Arduino Nano 33 BLE Sense Features

With the brief overview of the Arduino Nano 33 BLE Sense board complete, we take an
in–depth look at selected features and subsystems. As described in the previous section, we
partition features related to the NINA B306 Module from the Arduino Nano 33 BLE Sense
as shown in Fig. 2.3. We begin with an exploration of NINA B306 Module subsystems
followed by Arduino Nano 33 BLE Sense subsystems. For each subsystem we provide
related technical information and examples where appropriate.
20 2 Arduino Nano 33 BLE Sense

1. D13, digital, SPI SCK, GPIO 30. D12/MISO, D, SPI MISO, GPIO
2. +3V3, power out to ext devices 29. D11/MOSI, D, SPI MOSI, GPIO
3. AREF, A, analog reference, GPIO 28. D10/PWM, D, GPIO, PWM
4. A0/DAC0, ADC in/DACout, GPIO 27. D9/PWM, D, GPIO, PWM
5. A1, A, ADC in, GPIO 26. D8, D, GPIO
6. A2, A, ADC in, GPIO 25. D7, D, GPIO
7. A3, A, ADC in, GPIO 24. D6/PWM, D, GPIO, PWM
8. A4/SDA, A, ADC in, I2C SDA 23. D5/PWM, D, GPIO, PWM
9. A5/SCL, A, ADC in , I2C SCL 22. D4, D, GPIO
10. A6, A, ADC in, GPIO 21. D3/PWM, D, GPIO, PWM
11. A7, A, ADC in, GPIO 20. D2, D, GPIO
12. VUSB, power in/out, NC 19. GND, power ground
13. RST, D, active low reset 18. RST, D, active low reset
14. GND, power ground 17. RX, D, USART RX, GPIO
15. VIN, power in 16. TX, D, USART TX, GPIO

A: analog
D: digital
G: GPIO: general purpose I/O
PWM: pulse width modulation
NC: no connection

Fig. 2.2 Arduino Nano 33 BLE Sense SoC board pin out. (Figure adapted and used with permission
of Arduino Team (CC BY–NC–SA)(www.arduino.cc).)

NINA B306 Module


Nordic nRF52840 processor
- 32-bit, 48 MHz, FPU
- 1 MB Flash
- 256 kB RAM
Arduino Nano 33 BLE Sense SoC board Serial communication subsystems including:
Nine axis inertial measurement unit (IMU)(LSM9DS1) - Universal Serial Bus (USB)
Barometer and temperature sensor (LPS22HB) - Universal Asynchronous RX TX (UART)
Relative humidity sensor (HTS221) - Serial Peripheral Interface (SPI)
Digital proximity, ambient light, RGB, - Quad SPI (QSPI)
and gesture sensor (APDS-9960) - Two Wire Interface (TWI)
Digital microphone (MP34DT05) 12-bit resolution, 200 ksps ADC
Crypto Chip (ATEC608A) 128 bit Advanced Encryption Standard
DC-DC converter (MPM3610) (AES) co-processor
Bluetooth and Zigbee radio
Near Field Communication (NFC)
Direct Memory Access (DMA)
ARM CC310 Crytocell
Pulse Width Modulation (PWM)

Fig. 2.3 Arduino Nano 33 BLE Sense subsystems (nRF52840)

2.4 NINA B306 Module Subsystems

In this section we explore the peripherals contained within the NINA B306 Module. The
B306 is equipped with the Nordic Semiconductor nRF52840 processor. This is a 32–bit
processor, operating at 64 MHz, with an ARM Cortex–M4F architecture equipped with a
floating point unit (FPU). In addition, it is equipped with specialized instructions to aid in
efficient AI and ML program execution including (nRF52840):
2.4 NINA B306 Module Subsystems 21

• Digital Signal Processing (DSP) instruction set,


• Direct Memory Access (DMA) for efficient CPU and peripheral access to memory,
• Hardware based arithmetic divider to accelerate this operation, and
• Multiple and accumulate (MAC) instructions requiring a single clock cycle for execution.

The 32–bit processor architecture allows a wide range of integer and floating point
(real number) processing capability. The processor is equipped with a floating point unit
to enhance processing. The processor’s 48 MHz clock speed provides enhanced capability
over other Arduino products. For example, the very capable Arduino UNO R3 processor
hosting the Microchip ATmega328 operates at 16 MHz.

2.4.1 B306 Module Memory

The B306 is equipped with two main memory sections: flash electrically erasable pro-
grammable read only memory (EEPROM) and static random access memory (SRAM). The
processor is equipped with 1 MB (megabyte) of flash memory and 256 KB (kilobyte) of
Random Access Memory (RAM) (nRF52840). We discuss each memory component in turn.

2.4.1.1 B306 Programmable Flash EEPROM


Bulk programmable flash EEPROM is used to store programs. It can be erased and pro-
grammed as a single unit. Also, should a program require a large table of constants, it may
be included as a global variable within a program and programmed into flash EEPROM
with the rest of the program. Flash EEPROM is nonvolatile meaning memory contents are
retained even when microcontroller power is lost. The B306 is equipped with 1 MB bytes
of onboard reprogrammable flash memory.

2.4.1.2 B306 Static Random Access Memory (SRAM)


Static RAM memory is volatile. That is, if the microcontroller loses power, the contents of
SRAM memory are lost. It can be written to and read from during program execution. The
B306 is equipped with 256 KB of SRAM. A small portion of the SRAM is set aside for the
general–purpose registers used by the processor and also for the input/output and peripheral
subsystems aboard the microcontroller. During program execution, RAM is used to store
program instructions, global variables, support dynamic memory allocation of variables,
and to provide a location for the stack. The large SRAM component is especially useful in
certain AI and ML applications.
22 2 Arduino Nano 33 BLE Sense

2.5 NINA B306 Module Peripherals

In this section, we provide a brief overview of the internal peripherals of the B306 module. It
should be emphasized that these features are the internal systems contained within the con-
fines of the microcontroller chip. These built–in peripherals allow complex and sophisticated
tasks to be accomplished by the microcontroller.

2.5.1 Pulse Width Modulation (PWM) Channels

The Nano 33 BLE Sense is equipped with five pulse width modulation (PWM) channels.
PWM output can be provided on digital pins 1–13 and analog pins A0–A7. We limit use to
pins 21, 23, 24, 27, and 28 as shown in the pinout diagram at Fig. 2.2. The Nano 33 BLE
sense baseline frequency of the PWM signal is set at 500 Hz.
A pulse width modulated or PWM signal is characterized by a fixed frequency and a
varying duty cycle. Duty cycle is the percentage of time a repetitive signal is logic high
during the signal period. It may be formally expressed as:

dut y cycle[%] = (on time/ period) × (100%)


To generate a PWM signal within the Arduino IDE, the AnalogWrite() function is used.
The function is called with the desired PWM output pin (pin) and the desired PWM duty
cycle value. The duty cycle value is specified in the range of 0% (0) to 100% (255).

analogWrite(pin, value)

Example: In this example the intensity of an LED, connected to Nano 33 BLE Sense pin 21
(digital D3), is slowly increased and then decreased using PWM techniques. Note the use
of a 220 Ohm resistor in series with the LED. We discuss interface techniques in Chap. 3.

//******************************************************
//pwm_LED_test: the intensity of an LED, connected to
//Nano 33 BLE Sense pin 21, is slowly increased and then
//decreased using PWM techniques.
//
//Notes:
//- Provide a 220 Ohm resistor in series with the LED
// to common ground with the Nano 33.
//- Nano 33 BLE Sense pin 21 is specified as digital D3
// in the Arduino IDE sketch.
//*******************************************************

int ext_red_LED_pin = 3; //LED on D3 (physical pin 21)


2.5 NINA B306 Module Peripherals 23

void setup()
{
pinMode(ext_red_LED_pin, OUTPUT); //sets the pin as output
}

void loop()
{
int LED_int = 0;
//increase intensity
for(LED_int=0; LED_int<=255; LED_int=LED_int+5)
{ //0% (0) to 100% (255)
analogWrite(ext_red_LED_pin, LED_int);
delay(100); //delay 100 ms
}

LED_int = 255;
//decrease intensity
for(LED_int=255; LED_int>=0; LED_int=LED_int-5)
{ //100% (255) to 0% (0)
analogWrite(ext_red_LED_pin, LED_int);
delay(100); //delay 100 ms
}
delay(100); //delay 100 ms
}

//******************************************************

PWM signals are used in a wide variety of applications including controlling the position
of a servo motor and controlling the speed of a DC motor. We explore these applications in
the next chapter.

2.5.2 Serial Communications

The Arduino Nano 33 BLE Sense is equipped with a variety of different serial communication
subsystems including the Universal Synchronous and Asynchronous Serial Receiver and
Transmitter (USART), the serial peripheral interface (SPI), and the Two–wire Serial Interface
(TWI). What these systems have in common is the serial transmission of data. In a serial
communications transmission, serial data is sent a single bit at a time from transmitter to
receiver. The serial communication subsystems are typically used to add and communicate
with additional peripheral devices.

2.5.2.1 USART
The serial USART may be used for full duplex (two way) communication between a receiver
and transmitter. This is accomplished by equipping the Nano 33 with independent hardware
24 2 Arduino Nano 33 BLE Sense

for the transmitter and receiver. The USART is typically used for asynchronous communi-
cation. That is, there is not a common clock between the transmitter and receiver to keep
them synchronized with one another. To maintain synchronization between the transmitter
and receiver, framing start and stop bits are used at the beginning and end of each data byte
in a transmission sequence.
The Nano 33 USART is quite flexible. It has the capability to be set to different data
transmission rates known as the Baud (bits per second) rate. The USART may also be set
for several data bit widths and different BAUD rates. Furthermore, it is equipped with a
hardware generated parity bit (even or odd) and parity check hardware at the receiver. A
single parity bit allows for the detection of a single bit error within a byte of data.
Example: In this example we equip the Nano 33 with a liquid crystal display (LCD). An
LCD is an output device to display text information as shown in Fig. 2.5. LCDs come in a
wide variety of configurations including multi–character, multi–line format. A 16 x 2 LCD
format is common. That is, it has the capability of displaying two lines of 16 characters
each.
Characters are sent to the LCD via the American Standard Code for Information Inter-
change (ASCII) format a single character or control command at a time. ASCII is a stan-
dardized, seven bit method of encoding alphanumeric data. It has been in use for many
decades, so some of the characters and actions listed in the ASCII table are not in common
use today. However, ASCII is still the most common method of encoding alphanumeric data.
The ASCII code is shown in Fig. 2.4. We illustrate the use of the table with an example. The
capital letter “G” is encoded in ASCII as 0x47. The “0x” symbol indicates the hexadecimal
number representation.
Unicode is the international counterpart of ASCII. It provides a standardized 16–bit
encoding format for the written languages of the world. ASCII is a subset of Unicode. The
interested reader is referred to the Unicode home page website at: www.unicode.org for
additional information on this standardized encoding format.
LCDs are configured for either a serial or parallel interface to the host microcontroller. For
a parallel configured LCD, an eight bit data path and two control lines are required between
the microcontroller. Many parallel configured LCDs may also be configured for a four bit data
path thus saving several precious microcontroller pins. A small microcontroller mounted to
the back panel of the LCD translates the ASCII data characters and control signals to properly
display the characters. Several manufacturers provide 3.3 VDC compatible displays.
To conserve precious, limited microcontroller input/output pins a serial configured LCD
may be used. A serial LCD reduces the number of required microcontroller pins for interface,
from ten down to one. Display data and control information is sent to the LCD via an
asynchronous USART serial communication link (8 bit, 1 stop bit, no parity, 9600 Baud).
In this example a Sparkfun LCD–16397, 3.3 VDC, serial, 16 by 2 character LCD display
is connected to the Nano 33 BLE Sense. Communication between the Nano 33 and the LCD
is accomplished by a single 9600 bits per second (BAUD) connection using the onboard
USART.
2.5 NINA B306 Module Peripherals 25

Most significant digit


0x0_ 0x1_ 0x2_ 0x3_ 0x4_ 0x5_ 0x6_ 0x7_

0x_0 NUL DLE SP 0 @ P ` p


0x_1 SOH DC1 ! 1 A Q a q
0x_2 STX DC2 “ 2 B R b r
0x_3 ETX DC3 # 3 C S c s
0x_4 EOT DC4 $ 4 D T d t
Least significant digit

0x_5 ENQ NAK % 5 E U e u


0x_6 ACK SYN & 6 F V f v
0x_7 BEL ETB ‘ 7 G W g w
0x_8 BS CAN ( 8 H X h x
0x_9 HT EM ) 9 I Y i y
0x_A LF SUB * : J Z j z
0x_B VT ESC + ; K [ k {
0x_C FF FS ‘ < L \ l |
0x_D CR GS - = M ] m }
0x_E SO RS . > N ^ n ~
0x_F SI US / ? O _ o DEL

Fig. 2.4 ASCII Code. The ASCII code is used to encode alphanumeric characters. The “0x” indicates
hexadecimal notation in the C programming language

Fig. 2.5 LCD display with


TX

serial interface
RT
, U 33
SA
16 o
n n

ro C
pi Na

d
G VD
un
to

3
3.

RX RAW -

Sparkfun LCD-16397

Line Character Position (n)


1 0-15
2 64-79
Note: character position is specifed
as 0X80 + n

Command Code Command


0x01 Clear Display
0x14 Cursor one space right
0x10 Cursor one space left
0x80 + n Cursor to position
Note: precede command with 0xFE (25410)
26 2 Arduino Nano 33 BLE Sense

In the Application section of Chap. 3, we configure a small robot to navigate


autonomously through a maze. The robot will display maze wall status on an LCD. In this
sample sketch we use simulated maze wall data to display on the LCD. Note the USART is
designated “Serial1” in the sketch.

//***********************************************************************
//LCD_example
//
//Sparkfun LCD-16397, 3.3 VDC, 16x2 character display
//- Nano 33 BLE Sense, USART TX pin 16 is connected to LCD USART RX pin
//- Provide 3.3 VDC power to the LCD
//***********************************************************************

int left_IR_sensor_value = 0; //variable for left IR sensor


int center_IR_sensor_value = 0; //variable for center IR sensor
int right_IR_sensor_value = 0; //variable for right IR sensor

void setup()
{
Serial1.begin(9600); //Baud rate: 9600 Baud
delay(500); //Delay for display
}

void loop()
{
//read analog output from IR sensors – simulated maze wall data
left_IR_sensor_value = left_IR_sensor_value + 1;
center_IR_sensor_value = center_IR_sensor_value + 2;
right_IR_sensor_value = right_IR_sensor_value + 3;

//Clear LCD
//Cursor to line one, character one
Serial1.write(254); //Command prefix
Serial1.write(128); //Command

//clear display
Serial1.write(" ");
Serial1.write(" ");

//Cursor to line one, character one


Serial1.write(254); //Command prefix
Serial1.write(128); //Command
Serial1.write("Left Ctr Right");
delay(50);

Serial1.write(254); //Command to LCD


delay(5);
Serial1.write(192); //Cursor line 2, position 1
delay(5);
Serial1.print(left_IR_sensor_value);
delay(5);
Serial1.write(254); //Command to LCD
2.5 NINA B306 Module Peripherals 27

delay(5);
Serial1.write(198); //Cursor line 2, position 8
delay(5);
Serial1.print(center_IR_sensor_value);
delay(5);
Serial1.write(254); //Command to LCD
delay(5);
Serial1.write(203); //Cursor line 2, position 13
delay(5);
Serial1.print(right_IR_sensor_value);
delay(5);
delay(500);
}

//*******************************************************************

2.5.2.2 Serial Peripheral Interface (SPI)


The Nano 33 BLE Sense Serial Peripheral Interface or SPI provides for two–way serial
communication between a transmitter and a receiver. In the SPI system, the transmitter and
receiver share a common clock source. This requires an additional clock line between the
transmitter and receiver but allows for higher data transmission rates as compared to the
USART.
The SPI system allows for fast and efficient data exchange between microcontrollers or
peripheral devices. There are many SPI compatible external systems available to extend the
features of the microcontroller. For example, a liquid crystal display or a digital–to–analog
converter could be added to the microcontroller using the SPI system.
SPI Operation The SPI may be viewed as a synchronous 16–bit shift register with an 8–bit
half residing in the transmitter and the other 8–bit half residing in the receiver as shown
in Fig. 2.6. The transmitter is designated the master since it is providing the synchronizing
clock source between the transmitter and the receiver. The receiver is designated as the slave.
A slave is chosen for reception by taking its Slave Select (SS) line low. When the SS line is
taken low, the slave’s shifting capability is enabled.
SPI transmission is initiated by loading a data byte into the master configured SPI data
register. At that time, the SPI clock generator provides clock pulses to the master and also to
the slave via the SCK pin. A single bit is shifted out of the master designated shift register
on the Master Out Slave In (MOSI) microcontroller pin on every SCK pulse.
The data is received at the MOSI pin of the slave designated device. At the same time, a
single bit is shifted out of the Master In Slave Out (MISO) pin of the slave device and into
the MISO pin of the master device.
After eight master SCK clock pulses, a byte of data has been exchanged between the
master and slave designated SPI devices.
The SPI associated pins on the Arduino Nano 33 BLE Sense include:
28 2 Arduino Nano 33 BLE Sense

Master Device Slave Device

MISO MISO
SPI Data Register (SDR) SPI Data Register (SDR)
MSB LSB MSB LSB

MOSI MOSI

SCK SCK shift


system enable
clock SPI Clock Generator SCK SCK

SPI Status Register (SPSR)

SPI Control Register (SPCR) SS SS

Fig. 2.6 SPI overview

• Pin 29, SPI MOSI also referred to as Computer Out Peripheral In (COPI),
• Pin 30, SPI MISO also referred to as Computer In Peripheral Out (CIPO),
• Pin 1, SPI SCK

To configure the Arduino Nano 33 BLE Sense for SPI operation, the following Arduino
IDE commands are used:

• SPI.begin() is called from within setup()


• SPI.beginTransaction(SPISettings(SPIspeed, SPIbitdirection, SPImode));
• SPI.transfer(data)
• SPI.endTransaction();

In Chap. 1 we used the SPI system to send RGB data to individual LEDs within an SPI
compatible LED strip.
Example: In this example we configure the Sparkfun LCD–16397. The required connec-
tions, shown in Fig. 2.7, between the Nano 33 and the LCD include:

• Nano 33 SCK pin 1 to SCK on LCD


• Nano 33 SPI MOSI pin 29 to SDI (Serial Data In) on LCD
• Ground LCD chip select (\CS)

Provided below is an Arduino sketch to communicate with LCD–16397 using the SPI
system. Several items of interest regarding the sketch:
2.5 NINA B306 Module Peripherals 29

Fig. 2.7 LCD display with the

SI
29 o K

O
pi Na I SC
to SP 3

un I M
serial peripheral interface

, 33
1, o

ro C
SP
n n

d
G VD
pi Na

n n

un
d
to

3
ro

3.
G
SCK SDI /CS RAW -

Sparkfun LCD-16397

Line Character Position (n)


1 0-15
2 64-79
Note: character position is specifed
as 0X80 + n

Command Code Command


0x01 Clear Display
0x14 Cursor one space right
0x10 Cursor one space left
0x80 + n Cursor to position
Note: precede command with 0xFE (25410)

• SparkFun documentation for the LCD provide the following LCD SPI settings: speed-
–100000, MSBFIRST, SPI_MODE0.
• Note the use of function transmit_int_via_SPI to send a three digit integer value to the
LCD. The function isolates each digit and sends its ASCII equivalent to the LCD.

//***********************************************************************
//LCD_SPI_example
//
//The robot is equipped with a Sparkfun LCD-16397
// - Nano 33 SCK pin 1 to SCK on LCD
// - Nano 33 SPI MOSI pin 29 to SDI (Serial Data In) on LCD
// - Ground LCD chip select (\CS)
//- Provide 3.3 VDC power to the LCD
//***********************************************************************

#include <SPI.h>

int left_IR_sensor_value = 0; //variable for left IR sensor


int center_IR_sensor_value = 0; //variable for center IR sensor
int right_IR_sensor_value = 0; //variable for right IR sensor

void setup()
{
30 2 Arduino Nano 33 BLE Sense

SPI.begin();
delay(500); //Delay for display
}

void loop()
{
SPI.beginTransaction(SPISettings(100000, MSBFIRST, SPI_MODE0));

//read analog output from IR sensors


left_IR_sensor_value = left_IR_sensor_value + 1;
center_IR_sensor_value = center_IR_sensor_value + 2;
right_IR_sensor_value = right_IR_sensor_value + 3;

//Clear LCD
//Cursor to line one, character one
SPI.transfer(254); //Command prefix
SPI.transfer(128); //Command

//clear display
spiSendString(" ");
spiSendString(" ");

//Cursor to line one, character one


SPI.transfer(254); //Command prefix
SPI.transfer(128); //Command
spiSendString("Left Ctr Right");
delay(50);

SPI.transfer(254); //Command to LCD


delay(5);
SPI.transfer(192); //Cursor line 2, position 1
delay(5);
transmit_int_via_SPI(left_IR_sensor_value);
delay(5);
SPI.transfer(254); //Command to LCD
delay(5);
SPI.transfer(198); //Cursor line 2, position 8
delay(5);
transmit_int_via_SPI(center_IR_sensor_value);
delay(5);
SPI.transfer(254); //Command to LCD
delay(5);
SPI.transfer(203); //Cursor line 2, position 13
delay(5);
transmit_int_via_SPI(right_IR_sensor_value);

SPI.endTransaction();
delay(500);
}

//*******************************************************************

void spiSendString(char* data)


{
for(byte x = 0; data[x] != ’\0’; x++) //send chars to end of string
{
2.5 NINA B306 Module Peripherals 31

SPI.transfer(data[x]);
}
}

//*******************************************************************

void transmit_int_via_SPI(unsigned int num_to_convert)


{
unsigned int hundreds_place, tens_place, ones_place;
char hundreds_place_char, tens_place_char, ones_place_char;

hundreds_place = (unsigned int)(num_to_convert/100);


hundreds_place_char = (char)(hundreds_place + 48);
SPI.transfer(hundreds_place_char);
delay(5);

tens_place = (unsigned int)((num_to_convert-(hundreds_place * 100))/10);


tens_place_char = (char)(tens_place + 48);
SPI.transfer(tens_place_char);
delay(5);

ones_place=(unsigned int)(num_to_convert-(hundreds_place*100)-(tens_place*10));
ones_place_char = (char)(ones_place + 48);
SPI.transfer(ones_place_char);
delay(5);
}

//***********************************************************************

2.5.2.3 Inter–Integrated Circuit (I2C)


The I2C subsystem allows the system designer to network related devices (microcontrollers,
transducers, displays, memory storage, etc.) together into a system using a two–wire inter-
connecting scheme. The I2C allows a maximum of 128 devices to be interconnected. Each
device has its own unique address and may both transmit and receive over the two–wire bus
at frequencies up to 400 kHz. This allows the device to freely exchange information with
other devices in the network within a small area. Devices within the small area network are
connected by two wires to share data (SDA) and a common clock (SCL).

//***********************************************************************
//LCD_I2C_example
//
//The robot is equipped with a Sparkfun LCD-16397
// - Nano 33 I2C SDA pin 8 to LCD DA pin
// - Nano 33 I2C CLK pin 9 to LCD CL
// - Ground LCD chip select (\CS)
//- Provide 3.3 VDC power to the LCD
//- LCD default I2C address: 0x72
//***********************************************************************

#include <Wire.h>

#define LCD_I2C_addr 0x72 //default address of LCD


32 2 Arduino Nano 33 BLE Sense

int cycles = 0;

int left_IR_sensor_value = 0; //variable for left IR sensor


int center_IR_sensor_value = 0; //variable for center IR sensor
int right_IR_sensor_value = 0; //variable for right IR sensor

void setup()
{
Wire.begin(); //Join I2C bus - master mode
Wire.beginTransmission(LCD_I2C_addr);
Wire.write(’|’); //LCD setting mode
Wire.write(’-’); //clear display command
Wire.endTransmission();
}

void loop()
{
//read analog output from IR sensors
left_IR_sensor_value = left_IR_sensor_value + 1;
center_IR_sensor_value = center_IR_sensor_value + 2;
right_IR_sensor_value = right_IR_sensor_value + 3;

I2CSendValue(left_IR_sensor_value, center_IR_sensor_value, right_IR_sensor_value);


delay(500); //delay
}

//************************************************************************

void I2CSendValue(int value1, int value2, int value3)


{
Wire.beginTransmission(LCD_I2C_addr); //transmit to LCD
Wire.write(’|’); //LCD setting mode
Wire.write(’-’); //clear display command

Wire.print("Left Ctr Right");


Wire.print(value1);
Wire.print(" ");

Wire.print(value2);
Wire.print(" ");

Wire.print(value3);
Wire.print(" ");

Wire.endTransmission(); //Stop I2C transmission


}
//*********************************************************************

2.5.2.4 Analog to Digital Converter–ADC


The goal of the ADC process is to accurately represent analog signals as digital signals.
Toward this end, three signal processing procedures, sampling, quantization, and encoding
must be combined together.
2.5 NINA B306 Module Peripherals 33

Before the ADC process takes place, we first need to convert a physical signal into an
electrical signal with the help of a transducer. A transducer is an electrical and/or mechanical
system that converts physical signals into electrical signals or electrical signals to physical
signals.
Depending on the purpose, we categorize a transducer as an input transducer or an output
transducer. If the conversion is from physical to electrical, we call it an input transducer.
For example, a temperature sensor is considered an input transducer. The output transducer
converts electrical signals to physical signals. For example, an LCD or a motor would be
considered an output transducer.
It is important to carefully design the interface between transducers and the microcon-
troller to insure proper operation. A poorly designed interface could result in improper
embedded system operation or failure. Specific input and output transducer interface tech-
niques are discussed in Chap. 3.
The Arduino Nano 33 BLE Sense is equipped with an eight–channel, 12–bit resolution,
200 kilo samples per second (ksps) analog to digital converter (ADC) subsystem. The ADC
converts an analog signal from the outside world into a binary representation suitable for
use by the microcontroller. The 12–bit resolution means that an analog voltage between
0 and 3.3V will be encoded into one of 4096 binary representations between (000)16 and
(F F F)16 . This provides the Nano 33 with a voltage resolution of approximately 0.81 mV.
An analog channel is read using the “analogRead” function. This function uses a default
value of 10–bit ADC resolution. The resolution of the ADC process can be adjusted using
the “analogReadResolution(num_bits)” function. The desired level of resolution is specified
using the “num_bits” variable.
The Nano 33 has eight analog to digital conversion channels:

• Channel A0, pin 4


• Channel A1, pin 5
• Channel A2, pin 6
• Channel A3, pin 7
• Channel A4, pin 8 (also I2C pin SDA)
• Channel A5, pin 9 (also I2C pin SCL)
• Channel A6, pin 10
• Channel A7, pin 11

Example: In this example we measure the voltage from a variable power supply. Note the line
in code to convert the ADC reading from 0 to 1023 to an analog voltage: A0_voltage =
(analog_reading_A0 * 3.3)/1024. The circuit configuration is shown in Fig. 2.8.
34 2 Arduino Nano 33 BLE Sense

//***********************************************************************
//LCD_USART_ADC_example
//
//The robot is equipped with a Sparkfun LCD-16397
//- Nano 33 BLE Sense, USART TX pin 16 is connected to LCD USART RX pin
//- Provide 3.3 VDC power to the LCD
//- Nano 33 BLE Sense Analog A0 at pin 4
//***********************************************************************

int analog_reading_A0;
float A0_voltage;

void setup()
{
Serial1.begin(9600); //Baud rate: 9600 Baud
delay(500); //Delay for display
}

void loop()
{
analog_reading_A0 = analogRead(A0); //read A0
//convert to voltage
A0_voltage = (analog_reading_A0 * 3.3)/1024;
//Clear LCD
//Cursor to line one, character one
Serial1.write(254); //Command prefix
Serial1.write(128); //Command

//clear display
Serial1.write(" ");
Serial1.write(" ");

//Cursor to line one, character one


Serial1.write(254); //Command prefix
Serial1.write(128); //Command
Serial1.write("Voltage: ");
delay(50);

Serial1.write(254); //Command to LCD


delay(5);
Serial1.write(192); //Cursor line 2, position 1
delay(5);
Serial1.print(analog_reading_A0);
Serial1.write(" ");
Serial1.print(A0_voltage);
Serial1.write("V");

delay(500);
}

//*******************************************************************
2.5 NINA B306 Module Peripherals 35

TX
RT
, U 33
SA
16 o
n n

ro C
pi Na

d
G VD
un
to

3
3.
RX RAW -

to Nano 33
A0 pin 4
Sparkfun LCD-16397
variable
+ Line Character Position (n)
power
-
supply 1 0-15
2 64-79
Note: character position is specifed
as 0X80 + n
Note: Do not exceed 3.3 VDC on the Command Code Command
variable power supply. 0x01 Clear Display
0x14 Cursor one space right
0x10 Cursor one space left
0x80 + n Cursor to position
Note: precede command with 0xFE (25410)

Fig. 2.8 ADC test with LCD display

2.5.3 Bluetooth Low Energy (BLE)

The Arduino Nano 33 BLE Sense is equipped with Bluetooth features. The Classic form of
Bluetooth was designed to provide a wireless replacement for the common RS–232 serial
connection standard. The Arduino Nano 33 BLE sense is also equipped with Bluetooth Low
Energy (BLE) features. It is important to note that Bluetooth Classic and BLE features are
not compatible with one another. We explore Bluetooth Classic in “Arduino III: Internet of
Things.”2 We concentrate on BLE features here.
Bluetooth BLE provides for low transmit power (10 mW), short (maximum 100 m) range
RF connections to replace wires. It uses the crowded Industrial, Scientific, and Medical (ISM)
frequency band from 2.40 to approximately 2.50 GHz. The BLE band is divided into 40
different, 2 MHz channels as shown in Fig. 2.9. BT BLE employs an interesting frequency
hopping technique to communicate. Data for transmission is divided into packets at data
rates from 125 to 2 Mb/s. The device transmits a packet of data at the first carrier frequency.
It then hops to a different carrier frequency for the next packet and so on until the entire
message is transmitted as shown in Fig. 2.9b). Formally the BT BLE modulation technique
is called Direct Sequence Spread Spectrum (DSSS) (www.bluetooth.com).
BLE uses the Generic Attribute (GATT) Profile to establish two different primary roles
for a BLE connection:

2 “Arduino III: Internet of Things,” S.F. Barrett, Morgan and Claypool Publishers, 2021.
36 2 Arduino Nano 33 BLE Sense

g g
u u
a a
r r
d d

f [GHz]
40

41

42

43

44

45

46

47

48
2.

2.

2.

2.

2.

2.

2.

2.

2.
a) Industrial, Scientific, Medical (ISM) frequency band.

1 3 2
g g
u u
a a
r r
d d

f [GHz]
40

41

42

43

44

45

46

47

48
2.

2.

2.

2.

2.

2.

2.

2.

2.
b) Frequency Hopping Spread Spectrum (FHSS) [R and S].

Fig. 2.9 Bluetooth BLE communication concepts

• The peripheral or server role provides bulletin board features where data is posted for
reading.
• The central or client role can read and interact with the posted data.

In Fig. 2.10 we use an Arduino Nano 33 BLE Sense in a peripheral server role to col-
lect important greenhouse information such as external temperature, internal temperature,
humidity, and soil moisture content. The greenhouse related data is collected and organized
into a BLE service. The service related data is provided as BLE configured characteristics.
To allow ease of access to the information from an external central client device, the BLE
service and characteristics are each assigned a universally unique identifier (UUID) (www.
bluetooth.com). If we were to expand the features of the project with additional services,
we could group them into a profile.
There are a number of 16 bit pre–assigned UUIDs. The UUIDs represent different manu-
facturers and technology companies employing Bluetooth–based technologies. Also, UUIDs
have been pre–assigned to common Bluetooth features and common pre–assigned data types
(e.g. temperature, pressure, etc.) (www.bluetooth.com):

• Bluetooth members: 0xFxxx


• GATT characteristic and object type: 0x2xxx
• GATT declarations: 0x28xx and 0x29xx
• GATT service: 0x18xx
• GATT unit: 0x27xx
• protocol identifier: 0x00xx
2.5 NINA B306 Module Peripherals 37

Central Client
Nano 33 BLE Sense cell phone
information
polling and control
Peripheral Server Greenhouse Data Center nRF Connect
Greenhouse Service for Mobile
- characteristic external temperature Applications
- characteristic internal temperature
- characteristic humidity
- characteristic soil moisture
:

Fig. 2.10 Bluetooth BLE equipped greenhouse

• SDO GATT service: 0XFFFx


• service classes and profiles: 0x10xx and 0x11xx

For BLE services and characteristics without a 16 bit pre–assigned UUID, a unique 128
bit UUID code is used. A Bluetooth unique UUID may be obtained using a number of online
UUID generators.
In the greenhouse example, a cell phone is configured as a BLE central or client. Through
the BLE wireless radio interconnect, the cell phone can read and interact with the greenhouse
data and features.
Random documents with unrelated
content Scribd suggests to you:
bilious attacks. Those are the only circumstances upon which I formed that
opinion.
Cross-examined by Mr. James: I knew Mr. Cook for ten years; he hunted
regularly for the last two years in Nottinghamshire. He kept sometimes two
and sometimes three horses. I have known him to hunt three days a week
when he was well. I knew Mr. George Pell. There is a cricket club at
Welford. I do not know whether Cook was a member of the club. I have
seen him there. I saw Cook for the last time at Lutterworth, about the
middle of October last. I last knew him to have a bilious sick headache
about a year and a half ago [laughter].
Lord Chief Justice Campbell: I most strongly implore that there will be
no expression of any sensation evinced at the answers given by any of the
witnesses.
By Mr. James: I saw Cook at my own house when he complained of
suffering. He did not hunt on that day. He came to my house to meet the
hounds, but did not go. He was dressed in his hunting dress. I could not
swear I did not see him next within a week afterwards in the hunting-field.
By Lord Campbell: I never saw Cook sick on any other occasion, except
about seven years previous at Market Harborough, at the cricket match,
after dinner.
George Myatt, saddler, examined by Mr. Gray: I was at Shrewsbury
races on the day when Polestar won. I was at the Raven Hotel on the
evening of that day, Wednesday. I saw Cook and Palmer there about twelve
o’clock on the night of that day. I was waiting in the room at the hotel when
they came in. I considered Cook was the worse for liquor. They proposed
having a glass of brandy and water each before they went to bed. Each of us
had a glass of brandy and water. When Cook commenced to drink it he
made a remark that he fancied it was not good. He drank part of it off, and
said he thought there was something in it. He then gave it to some one near
him to taste. Cook proposed to have some more, and Palmer said he would
not have any more except Cook drank his up. They had no more brandy and
water, and Palmer and I went to bed. I slept in the same room with Palmer.
The brandy was brought in a decanter, and the brandy which I had was
poured out of the decanter, I don’t know by whom. I did not leave the room
during the time when Palmer and Cook came in to me until we went to bed.
I did not see anything put into the brandy and water, and I do not think
anything could have been put in without my seeing it. Palmer and I went
into the bedroom and left Cook in the sitting-room. I slept in the same
bedroom as Palmer. When I went to bed I locked the door, and Palmer did
not go out of the room during the night. When Palmer got up in the
morning, he asked me to go and call Cook. I did so. I went to Cook’s bed-
room door, rapped at it, and he told me to come in. I went in, and he told me
how ill he had been during the night, and that he had been obliged to send
for a doctor. He asked me what it was that was put into the brandy and
water, and I told him I did not know that anything had been put into it. He
asked me to send for the doctor, meaning Palmer. I did so. I next saw Cook
when he came in to his breakfast. Palmer was in the room. Palmer and I
breakfasted first, and Cook came in directly after we had finished, and had
breakfast in the same room. On the evening of that day Cook, Palmer, and
myself, left for Rugeley, having previously dined together at the Raven. We
started for Rugeley about six o’clock in the evening. We travelled by the
express train from Shrewsbury; Palmer paid for the three railway tickets.
On the way Palmer was sick, and both Cook and he said they could not
account for the circumstance of their being sick. Palmer vomited on the
road between Stafford and Rugeley. We left the train at Stafford, at the
junction. We then got into a fly to proceed to Rugeley, there being no train
for that place. It was on the way to Rugeley that Palmer was ill and
vomited. Palmer said he could not account for it unless it was that Cook had
some brass vessel which he had drank out of, or that the water was bad.
There had been a great many people ill during the Shrewsbury races. I
heard several people speak of their having been ill who could not account
for it. The distance by road from Stafford to Rugeley is about nine miles.
Cross-examined by Mr. James: I have known Palmer all my life. He
deals with me for saddlery. I have not been in the habit of going to the races
with him, but I have gone now and then. I was at Shrewsbury races with
him. I never was at Doncaster with him. I was there once with a gentleman
named Robinson. I was at Wolverhampton races in August last. I went with
Palmer. I did not sleep in the same room with him at Wolverhampton. I did
not stop at the same hotel with him. I stopped with my brother-in-law in
Wolverhampton. I believe I was there a couple of days. I did not dine or
breakfast with Palmer. I was at Lichfield races with Palmer in September.
Lichfield course is within ten miles of Rugeley. I did not sleep at Lichfield.
I did not either go to Lichfield or come home with Palmer. I believe I have
never slept in a double-bedded room with Palmer anywhere but at
Shrewsbury. I never did. I never was at Worcester in my life. I paid my own
expenses to Shrewsbury. Palmer paid the expenses of my living at the hotel
at Shrewsbury, and the fare back. He has never paid my expenses at any
other races. If he has paid any expenses for me, I have deducted them from
his bill. I dare say I went to some races with him the year before; I think
two or three, but I can’t call to mind how many. I had an interview with
Palmer in Stafford Gaol. I was with him a couple of hours. I should think
that that was a month or five weeks ago. I cannot say when it was that I saw
him. I cannot say whether it was before or after Stafford Assizes. Mr. Smith
said he was going, and I thought I should like to see Palmer. I have stood
half a sovereign or a sovereign with him occasionally. I know what “putting
on” a horse means. I did not bet at Shrewsbury. I did not back Cook’s mare,
Polestar. I have stood a sovereign with Palmer on a horse. The first time
when I saw Cook at the Raven on the Wednesday evening was as near
twelve o’clock as possible. I had not been dining with Palmer. I had dined
at home, at Rugeley. I arrived at Shrewsbury about eight o’clock. I went to
the Raven. I knew the room which Palmer generally had, and I went up to
see if he was there. That was between eight and nine o’clock. I went there
direct from the railway station. I saw Cook at the door outside. He asked me
what brought me there. I told him I was come to see how they were getting
on. I found that Palmer had gone out, and I then went into the town. I was
away about an hour, and then returned to the Raven. I went into Palmer’s
sitting-room. Palmer was not there. I waited in the sitting-room till he came.
There was a man named Shelley there. He was a betting man. I waited
about a couple of hours before Palmer came in. I think he came in about
twelve o’clock, but I can’t say exactly. He came in with Cook. I saw that
Cook was the worse for liquor. He was not very drunk, but I could see that
he was the worse for liquor. The brandy and water was brought in directly.
The brandy was in a decanter. I believe the water was on the table, but
cannot say. I should say the brandy and the tumbler were brought up
together. I don’t remember Mrs. Brooks coming. I don’t remember Palmer
being called out of the room. I remember a gentleman coming in. I know
now that he was Mr. Fisher. Before Fisher came in, Palmer had not left the
room. That I will swear. Palmer never left the room until he went to bed. I
swear that positively. I was close to him the whole time. When Fisher came
in, Cook asked Palmer to have some more brandy and water. Palmer said he
would not have any more unless Cook drank his. It was evident to any one
that Cook was the worse for liquor. Cook said, “I’ll drink mine,” and he
drank it at a draught. Directly after he drank it he said, “There’s something
in it.” He did not say, “It burns my throat dreadfully.” He said the brandy
was not good. I will swear he did not say, “it burns my throat dreadfully,” or
anything of that kind. He gave it to some one to taste. I believe it was
Fisher, but will not swear. I can’t say whether it was Palmer or Cook who
gave it to Fisher to taste. I believe there were only four persons in the room
at the time. I can’t say whether any other person came into the room before
we went to bed. Cook had emptied the glass as nearly as possible; there was
a little left in it. I can’t swear whether Palmer touched the glass or not. I
believe he did taste. I believe Palmer said he could not taste anything that
was the matter with the brandy and water, and he gave it to Fisher. I don’t
recollect Fisher saying, “It’s no good giving me the glass—it is empty.” I
can’t swear whether he said so or not. I should think we remained in the
room twenty minutes after that. Cook did not leave the room before we
went to bed. Palmer and I went straight up to bed. We left Cook in the
sitting-room. I did not hear that night that Cook had been vomiting and was
ill. I took one glass of brandy and water. We had one glass each. The water
was cold. On the following day I dined with Palmer at the Raven. Mr. Cook
served me with what I had to eat. During the first two days of the inquest I
was at home at Rugeley. I did not go to the inquest.
Re-examined by Mr. Grove: I was not subpœned for the Crown; I was
examined, but not summoned. The deputy-governor was not present all the
time I was with Palmer at Stafford. He went out once, but another officer
came in. Palmer did not say a word about this case. There was an officer
present the whole time.
The Attorney-General: I wish to ask the witness whether he did not
tell Mr. Gardner, when he was asked about the brandy and water, that he
knew nothing about it?
The Lord Chief Justice: There is no objection to that question.
Witness: I never spoke to him about brandy and water at all.
The Attorney-General: Did you meet him at Hednesford, where
Saunders lives?—Yes.
The Attorney-General: Did you not tell him there that you could
recollect nothing about brandy and water?—No.
The Attorney-General: Had you no conversation at all?—I had with
Mr. Stevens.
The Attorney-General: Did you not say, in Mr. Gardner’s presence,
that you could recollect nothing about the brandy and water?—I did not.
The Attorney-General: Were you not examined by Mr. Crisp and Mr.
Sweeting before the inquest was held, and did you not tell them that you
knew nothing about the brandy and water?—No, I did not.
The Attorney-General: You swear you did not tell them anything
about it?—Yes.
John Sargent, examined by Mr. Sergeant Shee: I am not in any
business or profession. I am in the habit of attending almost all public races
in the kingdom. I knew the late Mr. Cook intimately, and also the prisoner
Palmer. I received a letter from Cook during the Shrewsbury races. I was
subpœned on the part of the Crown. I have not had any notice to produce
that letter. I have not got it. I have searched for it, but I had sent it to
Saunders the trainer. I have made application to Saunders for it. The
application was by letter. I received a letter in answer. I have seen Saunders
since. I have done everything I could to get Cook’s letter. I have not a copy
of it, but I know what its contents were.
The Court decided that the contents of the letter could not be received at
that moment, as Saunders perhaps might attend before the conclusion of the
day.
Examination continued: I was not at Shrewsbury, and only know what
Cook stated in his letter. Shortly before Cook’s death I had an opportunity
of noticing the state of his throat. I was with him at Liverpool the week
previous to the Shrewsbury meeting. We slept in adjoining rooms. In the
morning he called my attention to the state of his throat. The back part of
the throat was a complete ulcer, and the throat was very much inflamed. His
tongue was swollen. I said I was surprised, on seeing the state of his mouth,
that he could eat anything. He said he had been in that state for weeks and
months, and now he did not take notice of it. That was all that passed
respecting the sore throat on that occasion. He had shown his throat to me
previously—at almost every meeting we attended. On the platform at
Liverpool, after the races, he took a gingerbread cayenne nut by mistake. I
saw him take it. He did not know it was a cayenne nut. He told me
afterwards that it had nearly killed him. He did not state more particularly
then the effect which it had produced on him. I know that Cook was very
poor at the Liverpool meeting. That was the week before the Shrewsbury
races. He owed me £25, and gave me £10 on account, and said he had not
sufficient to pay his expenses at Liverpool, but that I should have the
balance of £25 at the Shrewsbury meeting. Cook and Palmer were in the
habit of “putting on” horses for each other. They did so at the Liverpool
meeting. I put money on at Liverpool for Palmer, and Palmer told me that
Cook stood it along with him. I heard Cook, a short time before his death,
apply to Palmer to supply him with “black wash.” I don’t know whether it
is a mercurial lotion. I never saw Cook’s throat dressed by anybody.
Cross-examined by Mr. James: The black wash was not to be drunk [a
laugh]. The application was made to Palmer at the Warwick Spring meeting
in 1855. Cook was at Newmarket. I lived in the same house with him there.
He was at nearly all the race meetings last year. His appetite was very good,
and that surprised me. The cayenne nut is made up for a trick and mixed
with other gingerbread nuts. Cook got one of those. I have tasted them.
Some of them are stronger than others.
Jeremiah Smith, by Mr. Serjeant Shee: I am an attorney at Rugeley. I
am acquainted with the prisoner, and was acquainted with Cook. I saw
Cook at the Talbot Arms on Friday, the 16th of November. He was in his
bedroom. I saw him about ten o’clock. I was present at his breakfast. A
small tray was put on the bed. He took tea for breakfast, and had a
wineglass of brandy in it. I dined with him at Palmer’s house. I am not quite
positive that I had seen him between breakfast and dinner. We had a rump-
steak for dinner. We had some champagne at dinner. We drank port-wine
after dinner. He had three bottles altogether, and Cook took his share. Cook,
myself, and Palmer dined together. We left the house about six in the
evening. Cook and I left the house together. We went to my house, and
afterwards to the Albion Hotel, which is next door. We had a glass of cold
brandy-and-water. Cook left me there. He said he felt cold, and warmed
himself at the fire. He said he had borrowed a book, and would go home
and read it in bed. That was between seven and eight o’clock, but I can’t
say exactly. In the afternoon, after dinner, we were talking about racing. I
asked Cook for money—for £50. He gave me £5. When he was taking the
note out of his pocket-case, I said “Mr. Cook, you can pay me all.” He said,
“No; there is only £41 10s. due to you.” He said that he had given Palmer
money, and would pay me the remainder when he returned from Tattersall’s
on the Monday. On the night following (Saturday night) he was not well,
and I slept in his room. It was late when I went; I should think about eleven
or twelve o’clock. I had been at a concert during the early part of the night
on which Cook was unwell. He had got some toast-and-water, and was
washing his mouth. He was sick. There was a night chair in the room before
the fire. I saw him sitting there. He tried to vomit, but whether he did so or
not I cannot say, for I did not get out of bed. I went to sleep about two
o’clock. I slept until Palmer and Bamford came into the room in the
morning. I lay still in bed, and heard a conversation between the doctor and
Cook. Bamford said, “Well, Mr. Cook, how are you this morning?” Cook
said, “I am rather better this morning. I slept from about two or three
o’clock, after the house had become quiet.” Bamford said, “I’ll send you
some medicine.” I don’t recollect any further conversation. I know Mrs.
Palmer, prisoner’s mother. She sent a message to me on Monday, and I went
to her and saw her. In consequence of what had passed, I went to look for
the prisoner to see if he had arrived. That was about nine o’clock. I saw
Palmer at ten minutes past ten. He came from the direction of Stafford, in a
car. He said to me, “Have you seen Cook to-day?” I said, “No; I have been
to Lichfield on business;” on which Palmer said he had better go and see
how he was before he went to his mother’s. Palmer and I went up to Cook’s
room together. Cook said, “You are late, doctor, to-night. I did not expect
you to look in. I have taken the medicine which you gave me.” We did not
stay more than two or three minutes, and I think Cook asked me why I did
not call earlier. I said I had been detained on business. Cook said Bamford
had sent him some pills, which he had taken; and he intimated that he
would not have taken them if Palmer had come earlier. Cook told Palmer,
that he had been up talking with Saunders, and Palmer said, “You ought not
to have done so.” Palmer and I left the room together, and we went straight
to his mother’s.
The distance of Mr. Palmer’s house from the Talbot Arms is about four
or five hundred yards. We were there about half an hour. We both left
together and went to Palmer’s house. I entered with him. I asked him to let
me have a glass of grog, but did not get it. I then went home. After dining
with Palmer on Friday, I invited Cook and Palmer to dine with me on the
next day, Saturday. Cook sent me a message, stating that he was not well
and could not leave his room. I ordered a boiled leg of mutton for dinner,
and sent part of the broth from the Albion by the charwoman—I think her
name was Rowley. Previous to Cook’s death I borrowed £200 for Cook, and
negotiated a loan with Pratt for him for £500. The £200 transaction was in
May. I borrowed £100 of Mrs. Palmer, and £100 of William Palmer, making
together the £200 to which I have referred. I knew that Palmer and Cook
were jointly interested in one horse, and that they were in the habit of
betting for each other. When Cook’s horse was going to run, Palmer “put
on” for him; and when Palmer’s ran, Cook “put on” for him. I have seen
Thirlby, Palmer’s assistant, dress Cook’s throat with caustic. I think this was
before the races at Shrewsbury. I have some signatures of Cook’s which I
know to be in his handwriting. The two notes with instructions to negotiate
the loan of £500, I saw Cook sign. [The notes were put in.] One of them is
signed “J. P. Cook,” the other “J. Parsons Cook.” I knew from Cook that he
was served with a writ. I do not remember that I received any instruction to
appear for him.
The letters put in were read by Mr. Straight, the Clerk of the Arraigns.
The first was without date, and signed “J. Parsons Cook,” Monday. The
following is a copy of the letter:—
“My dear Sir,—I have been in a devil of a fix about the bill, but have at last settled it at
the cost of an extra two guineas, for the —— discounter had issued a writ against me. I am
very much disgusted at it.”

The letter was sent to me, but its envelope was destroyed. The next letter
bore the date 25th June, 1855; it was also without address, but witness
stated that it had been sent to him, and he had destroyed the envelope. The
following is a copy of the letter:—
“Dear Jerry,—I should like to have the bill renewed for two months. Can it be done?
Let me know by return. I have scratched Polestar for the Nottinghamshire and
Wolverhampton Stakes. I shall be down on Friday or Saturday. Fred. tells me Arabis will
win the Northumberland Stakes.”

The memorandum put in and read was signed J. P. Cook, and the
following is a copy:—
“Polestar three years, Sirius two years; by way of mortgage to secure £200 advanced
upon a bill of exchange for £200, dated 29th August, 1855, payable about three months
after date.”

Cross-examined by the Attorney-General: I am the person who took


Mr. Myatt to Stafford Gaol. I have known Palmer long and intimately, and
have been employed a good deal as attorney for him and his family. I
cannot recollect that he applied to me in December, 1854, to attest a
proposal for insurance on the life of Walter Palmer for £13,000 in the
Solicitors’ and General Assurance Office. I will not swear that I was not
applied to on the subject. I do not recollect that an application was made to
me to attest a proposal for £13,000 in the Prince of Wales on Walter
Palmer’s life, in January, 1855. I know that Walter Palmer had been a
bankrupt, but not that he was an uncertificated bankrupt. His bankruptcy
took place at least six years ago. He had been in no business since that
period to the time of his death. I knew that Walter had an allowance from
his mother, and he had also money at various times from his brother
William. In the years 1854 and 1855, I lived at Rugeley, sometimes at
Palmer’s house, and sometimes at his mother’s. There was no improper
intimacy between myself and Palmer’s mother. I slept at her house
frequently, perhaps two or three times a week, having my own place of
abode at Rugeley.
How long did this habit continue of sleeping two or three times a week
at Mrs. Palmer’s house?—Several years.
Had you your own lodgings and chambers at Rugeley?—Yes.
Your own bedroom?—Yes.
How far were your lodgings from Mrs. Palmer’s house?—Nearly a
quarter of a mile.
Will you be so good as to explain why, having your own place of abode,
and your own bed-room so near to Mrs. Palmer’s, you were still in the habit
of sleeping two or three times a week for several years at the house of Mrs.
Palmer?—Yes; sometimes there were members of Mrs. Palmer’s family
present.
Who were they?—There was Mr. Joseph Palmer, who resides at
Liverpool; Mr. Walter Palmer, too; and sometimes William Palmer.
When you went to see the members of Palmer’s family, was it too late
when you separated to return to your own lodgings?—We used to stop very
late drinking gin and water, smoking, and sometimes afterwards playing at
cards.
Then you did not go to your own lodgings?—No.
And this continued several years two or three times a week?—Yes.
Did you ever stay at Mrs. Palmer’s house all night when there were no
members of the family visiting?—Yes, frequently.
How often?—As many as two or three times a week.
When there were none of Mrs. Palmer’s sons there?—Yes.
And when the mother was?—Yes.
How often did that happen?—I cannot say. Sometimes two or three
times a week.
When there was no one else in the house but the lady?—There were the
mother, daughter, and servants.
You might have gone to your own home, then, for there was no one to
drink brandy-and-water with, or to smoke with?—I might have done so, but
I did not.
Do you mean, then, to swear solemnly that no improper intimacy
subsisted between you and Palmer’s mother?—I do [sensation].
Now I will turn to another subject. Do you remember being applied to by
Palmer to attest a proposal for an insurance of £10,000 on the life of Walter
Palmer in the Universal Life Office?—I do not remember; if you have any
document which will show it I shall be able to recollect, perhaps.
Now, do you remember getting a five pound note for attesting the
signature of Walter Palmer’s assignment of his policy to his brother?—I do
not.
Is that your signature [handing a document to witness]?—It is very
similar to it.
Is it not yours?—I do not know [sensation].
Upon your oath, sir, is not that your signature?—Witness hesitating—
Examine the document, and then tell me, on your oath, whether that is
not your signature [witness examined the document].
Now you have perused it, tell me, is not that your signature?—Witness
(hesitating): I have some doubts whether this is my handwriting [sensation].
Have you read the whole of the document?—I have not.
Then do so. [Witness again perused the whole of the paper.] Now, was
that document prepared in your office?—It was not.
Have you ever seen it before?—It is very much like my handwriting.
That is not what I asked you. Upon your oath, have you ever seen that
document before?—Witness (with hesitation): It is very much like my
handwriting [sensation].
I will have an answer to my question. Upon your oath, sir, is not that
your handwriting?—I think it is not in my handwriting. I think it is a very
clever imitation of it [sensation].
Will you swear it is not your handwriting?—I will swear it is not my
handwriting [renewed sensation].
The Attorney-General: Will your lordship please to take a note of that
answer?
Mr. Baron Alderson: Did you ever make such an attestation as that in
your hand?—I do not remember.
The Attorney-General: Now is that the signature of Walter Palmer
(handing a paper to witness)?—I believe it to be.
Is that the signature of Pratt?—I do not know.
Did you not receive that paper from Pratt?—I believe I did not. I think
William Palmer gave it me.
Well, did he give it you?—I don’t recollect.
I repeat my question. Did William Palmer give you that document?—
Most likely he did.
Did he, I ask again?—It was not signed at the time.
But did he give it you? I will have an answer.—I have no doubt he did.
Well, then, if that document bears the signature of Walter Palmer, and
was given to you by William Palmer, cannot you tell whether it bears your
own signature or not?—Mr. Attorney—
Don’t “Mr. Attorney” me—answer my question. Upon your oath, is not
that your handwriting?—I believe it not to be.
Will you swear it is not?—I believe it not to be. [Great sensation.]
Now, did you apply to the Midland Counties Insurance Office to be
appointed agent to the company at Rugeley?—I did.
When was it?—I should like to fetch my documents and papers; I should
then be able to answer you accurately.
Oh, never mind the papers. Was it in October, 1855?—I think it was.
Did you send up a proposal for an insurance of £10,000 on the life of
Bates?—I did.
Did William Palmer ask you to make that proposal?—Bates and Palmer
came together to my office, with a prospectus, and asked me if I knew
whether there was an agent for the Midland Counties Office in Rugeley. I
told him I never heard of one. He asked me afterwards if I would write to
get the appointment, because Bates wanted to raise some money.
Did you send to the Midland Counties Office to get the appointment of
agent, in order that you might be enabled to effect this insurance on Bates’s
life?—I did.
Did you make the application in order to get the insurance effected?—I
did.
Upon the life of Bates for £10,000?—I did. [Sensation.] Bates was at
that time superintending William Palmer’s stud and stables. I do not know
at what salary. I afterwards went to the widow of Walter Palmer to get her
to give up her claim on the policy of her husband. She was then at
Liverpool. William Palmer gave me a letter for Pratt to take to her to sign.
Mrs. Palmer said she would like to see her solicitor about it. I brought the
document back with me because she did not sign it. I had no instructions to
leave it.
Did she give any reason for not signing it?
Mr. Sergeant Shee objected to the question.
Lord Campbell decided that it could not be put.
The Attorney-General: Do you know whether Walter Palmer received
anything on executing the assignment of his policy to William Palmer?—I
believe he ultimately had something.
Did he not get a bill for £200?—I believe he did, and he also got a house
furnished for him.
Was that bill paid?—I do not remember.
Is that document in your handwriting? [document handed in]—It is.
Now, having seen that document with your signature, I ask you whether
you were applied to to effect an insurance on the life of Walter Palmer?—I
do not recollect.
Not recollect! when your signature is staring you in the face?—No, I do
not.
You are an attorney, and accustomed to business transactions?—I am.
Now I ask you again, were you applied to on the subject?—I may have
been; it is from my memory I am speaking, and I wish, therefore, to speak
as accurately as possible [laughter].
I don’t ask you as to your memory in the abstract, but your memory now
that is refreshed by that document. Is that your signature?—Witness
(hesitating) I have no doubt it may be.
Look at that document and see whether you were not applied to to effect
the insurance I have named?—That is my signature.
I ask you, have you any doubt that in the month of January, 1855, you
were called upon to attest another proposal for £13,000 on the life of Walter
Palmer?—Witness (with hesitation): I may have signed that paper in blank.
Did you sign this proposal in blank?—I might have done.
But did you, I ask again?—I cannot swear I did or did not. I have some
doubt whether I did not sign several of these proposals in blank [sensation].
Upon your oath, do you not know that William Palmer applied to you to
effect an insurance for £13,000 on the life of his brother?—I do not
remember.
Why this is a very large sum, surely you must remember such a
transaction as this?—I may have been applied to on the subject.
Were you applied to to attest another proposal for an insurance with the
Universal Life Office?—I cannot say that I was.
Will you swear that when Walter Palmer executed the deed of
assignment of his policy to William Palmer, that you were not present?
Now, be careful, for you will certainly hear of this on some future day if
you are not careful.—I cannot say that I was.
Upon your oath, did you not attest the deed of assignment of Walter to
his brother of his interest in a policy of insurance for £13,000?—I cannot
say. I believe the signature “Jeremiah Smith” is very much like my
handwriting.
I repeat the question?—I cannot say.
Why, did you not receive a cheque for £5 for attesting it?—I think I did
receive a cheque for £5.
Did you not see William Palmer write this upon the counterfoil of his
cheque-book [cheque-book handed to witness]?—Witness, with hesitation:
I cannot positively swear that I did.
Did you not, sir, see him write it?—That is William Palmer’s
handwriting [referring to the cheque-book].
Did you not know that you got a five pound cheque for attesting that
signature?—I may have got a cheque for £5, but I may not have got it for
attesting the signature of the document.
You say you got £200 for Cook—£100 from Mrs. Palmer and £100 from
William Palmer?—Yes, and he gave £10 for the recommendation.
To whom?—To William Palmer.
Do you not know that the £200 bill was given for the purpose of
enabling William Palmer to make up a sum of £500?—I believe it was not,
for Cook received absolutely from me £200.
Did he not have the money from you in order to take up to London to
pay Pratt?—No, he took it with him, I think, to Shrewsbury, to the races.
Who was the bill drawn in favour of?—I think William Palmer.
What became of the bill?—I do not know.
Witness: I was not present at the inquest on Cook. I can’t say who saw
me when I went to the Talbot Arms and went into Cook’s room. One of the
servants gave me a candle—either Bond, Mills, or Lavinia Barnes.
Re-examined by Mr. Serjeant Shee: I have known Mrs. Palmer twenty
years. I knew her before her husband’s death. I should say she is sixty years
of age. William Palmer is not her eldest son. Joseph is the eldest. He resides
at Liverpool. He is forty-five or forty-six years of age. I think George is the
next son. He lives at Rugeley. He was frequently at his mother’s house.
There is another son, a clergyman of the Church of England. He resided
with his mother until within the last two years, except when he was at
college. There is a daughter. She lives with her mother. There are three
servants. Mrs. Palmer’s family does not visit much in the neighbourhood of
Rugeley. Her house is a large one. I slept in a room nearest the Old Church.
Mr. Serjeant Shee: Is there any pretence for saying you have ever been
charged with any improper intimacy with Mrs. Palmer?—Witness: I hope
not.
Mr. Serjeant Shee: Is there any pretence for saying so?—Witness: There
ought not to be.
Mr. Serjeant Shee: Is there any truth in the statement or suggestion that
you have had any improper intimacy with Mrs. Palmer?—Witness: They
might have said so, but there is no reason.
Mr. Serjeant Shee: Is there any truth in the statement?—Witness: I
should say not.
Mr. Serjeant Shee: When did it come to your knowledge that there was a
proposal for Walter’s life?—Witness: I never heard of it until the inquest.
The Court then adjourned for about twenty minutes, when the
proceedings were resumed.
W. Joseph Saunders was then called up on his subpœna, but did not
appear.
The Attorney-General said he should be extremely sorry to commence
his reply if there was any chance of witness making his appearance.
Mr. Serjeant Shee said he should now ask for the production of a letter
written by Cook to Palmer on Jan. 4, 1855.
The letter, of which the following is a copy, was then put in and read:—
“Lutterworth, Jan. 4, 1855.
“My dear Sir,—I sent up to London on Tuesday to back St. Hubert for £50, and my
commission has returned 10s. 1d. I have, therefore, booked 250 to 25 against him, to gain
money. There is a small balance of £18 due to you, which I forgot to give you the other
day. Tell Will to debit me with it on account of your share of training Pyrrhine. I will also
write to him to do so, as there will be a balance due from him to me.
Yours faithfully,
“J. Parsons Cook.”
“W. Palmer, Esq.”

Mr. Serjeant Shee submitted that he was entitled to reply on a part of


evidence. The course taken by the Attorney-General on getting at the
contents of the cheque, the contents of an assignment of the policy on
Walter Palmer’s life, and the contents of the proposals to various offices for
the insurance, he submitted entitled him to a reply on those points.
The Lord Chief Justice: We are of opinion that you have no right to
reply.
Mr. Baron Alderson: That is quite clear.
The Attorney-General said he had been taken somewhat by surprise
yesterday by the evidence of Dr. Richardson, with respect to angina
pectoris. Dr. Richardson adverted to several books and authorities. He had
now those books in his possession, and was desirous of putting some
questions arising out of that part of the evidence.
The Court decided against the application.
The case for the defence here concluded.

THE ATTORNEY-GENERAL’S REPLY.


The Attorney-General, at ten minutes before three, commenced his reply,
speaking occasionally in so low a tone that the conclusion of many of his
sentences was inaudible. He said: May it please your lordships and
gentlemen of the jury, the case for the prosecution and the case for the
defence are now before you, and it now becomes my duty to address to you
such observations upon the whole of the evidence as suggest themselves to
my mind. I feel that I have a moral, solemn, and important duty to perform.
I wish I could have answered the appeal made to me the other day by my
learned friend (Serjeant Shee), and say that I am satisfied with the case
which he submitted to you for the defence. But, standing here as the
instrument of public justice, I feel that I should be wanting in the duty that I
have to perform if I did not ask at your hands for a verdict of guilty against
the prisoner. I approach the consideration of the case in, I hope, what I may
term a spirit of fairness and moderation. My business is to convince you, if
I can, by facts and legitimate arguments, of the prisoner’s guilt; and if I
cannot establish it to your satisfaction, no man will rejoice more than I shall
in a verdict of acquittal. Gentlemen, in the mass of evidence which has been
brought before you, two main questions present themselves prominently for
your consideration. Did the deceased man, into whose death we are now
inquiring, die a natural death, or was he taken off by the foul means of
poison? And if the latter proposition be sanctioned by the evidence, then
comes the important—if possible, the still more important—question,
whether the prisoner at the bar was the author of the death? I will proceed
with the consideration of the subject in the order which I have mentioned.
Did John Parsons Cook die by poison? I assert and contend the affirmative
of that proposition. The case which is submitted to you on behalf of the
Crown is this—that, having been first practised upon by antimony, Cook
was at last killed by strychnine. The first question to be considered is—
what was the immediate and proximate cause of his death. The witnesses
for the prosecution have told you, one and all, that, in their judgment, he
died of tetanus, which signifies a convulsive spasmodic action of the
muscles of the body. Can there be any doubt that their opinion is correct?
Of course it does not follow that, because he died of tetanus, it must be the
tetanus of strychnia. That is a matter for after consideration. But, inasmuch
as strychnine produces death by tetanus, we must see, in the first place,
whether it admits of doubt that he did die of tetanus. I have listened with
great attention to every form in which that disease has been brought under
your consideration—whether by the positive evidence of witnesses, or
whether by reference to the works of scientific writers; and I assert
deliberately that no case, either in the human subject or in the animal, has
been brought under your notice in which the symptoms of tetanus have
been so marked as in this case.
From the moment the paroxysms came on of which the unhappy man
died, the symptoms were of the most marked and of the most striking
character. Every muscle, says the witness, the medical man who was
present at the time—every muscle of his body was convulsed—he
expressed the most intense dread of suffocation—he entreats them to lift
him up lest he should be suffocated—and every muscle of his body, from
the crown of his head to the soles of his feet, was so stricken—the
flexibility of the trunk and the limbs was gone—and you could only have
raised him up as you would have raised a corpse. In order that he might
escape from the dread of suffocation, they turned him over, and then, in the
midst of that fearful paroxysm, one mighty spasm seemed to have seized his
heart, to have pressed from it the life blood, and the result was—death. And
when he died, his body exhibited the most marked symptoms of this fearful
disease. He was convulsed from head to foot. You could have rested him on
his head and heels—his hands were clasped with a grasp that it required
force to overcome, and his feet assumed an arched appearance. Then, if it
was a case of tetanus—into which fact I will not waste your time by inquiry
—the question arises, was it a case of tetanus produced by strychnia? I will
confine myself for a moment to the exhibition of the symptoms as described
by the witnesses. Tetanus may proceed from natural causes as well as from
the administration of poisons, and while the symptoms last they are the
same. But in the course of the symptoms, and before the disease reaches its
consummation in the death of the patient, the distinction between the two is
marked by characteristics which enable any one conversant with the subject
to distinguish between them. We have been told on the highest authority
that the distinctions are these—natural tetanus is a disease not of minutes,
not of hours, but of days. It takes—say several other witnesses—from three
to four days; and will extend to a period of even three weeks before the
patient dies. Upon that point we have the most abundant and conclusive
evidence of Dr. Curling; we have the evidence of Dr. Brodie; we have the
evidence of Dr. Daniel, a gentleman who has seen something like twenty-
five or thirty cases; we have the evidence of a gentleman who has practised
twenty-five years in India, where these cases, arising from cold, are
infinitely more frequent; and he gives exactly the same description of the
course which this disease invariably takes. Idiopathic or traumatic tetanus is
therefore out of the question, upon the evidence which has been given. But
traumatic tetanus is out of the question for a very different reason.
Traumatic tetanus is brought on by the lesion of some part of the body. But
what is there in this case to show that there was anything like lesion at all.
We have had several gentlemen called, who have come here with an evident
determination to misconceive and misrepresent every fact. We have called
before you an eminent physician, who had Cook under his care.
It seems that, in the spring of the year 1855, Cook, having found certain
small spots manifest themselves in one or two parts of his body, and having
something of an ulcerated tongue and a sore throat, conceived that he was
labouring under symptoms of a particular character. He addressed himself
to Dr. Savage, who found that the course of medicine he had been pursuing
was an erroneous one. He enjoined the discontinuance of mercury. His
injunction was obeyed, and the result was that the patient was suffering
neither from disease nor wrong treatment. But lest there should be any
possibility of mistake, Dr. Savage says that long before the summer
advanced every unsatisfactory symptom had entirely gone; there was
nothing wrong about him, except that affection of the throat, to which
thousands of people are subject. In other respects, the man was better than
he had been, and might be said to be convalescent. On the very day that he
leaves London to go into the country, a fortnight before the races, his
stepfather, who accompanied him to the station, congratulated him upon his
healthy and vigorous appearance, and, the young man, conscious of a
restored state of health, struck his breast, and said “He was well, very well.”
Then he goes to Shrewsbury, and shortly afterwards arose those matters to
which I am about to call your attention. I want to know in what part of the
evidence there is the slightest pretence for saying that this man had an
affection which might bring on traumatic tetanus? It is said that he had
exhibited his tongue to witnesses, and applied for a mercurial wash, but it is
clear that, although he had at one time adopted that course, he had, under
the recommendation of Dr. Savage, got rid of it, and there is no pretence for
saying he was suffering under any syphilitic affection of any kind. That fact
has been negatived by a man of the highest authority and eminence. It is a
pretence for which there was not a shadow of a foundation, and I should
shrink from my duty if I did not denounce it as a pretence unworthy of your
attention. There was nothing about the man which would warrant, for a
single moment, the supposition that there was anything of that character in
any part of his body when the tetanus set in. One or two cases of traumatic
tetanus have been adduced in the evidence which has been brought forward
for the defence. One is the case of a man in the London Hospital, who was
brought into that institution one evening, and died the same night. But what
are the facts? The facts are, that before he had been brought in he had had a
paroxysm early in the morning—that he was suffering from ulcers of the
most aggravated description. The symptoms had run their course rapidly, it
is true, but the case was not one of minutes, but of hours. Another case has
been brought forward in which a toe was amputated, but there we have
disease existing some time before death. But then it is suggested that this
may be a case of idiopathic tetanus proceeding from—what? They say that
Cook was a man of delicate constitution, subject to excitement; that he had
something the matter with his chest; that in addition to having something
the matter with his chest, he had the diseased condition of throat; and
putting all these things together, they say that if the man took cold he might
get idiopathic tetanus.
We are here launched into a sea of speculations and possibilities. Dr.
Nunneley, who comes here for the purpose of inducing you to believe there
was something like idiopathic tetanus, goes through supposed infirmities,
and talks about his excitability, his delicacy of chest, his affection of the
throat, and he says these things would predispose to idiopathic tetanus if he
took colds. But what evidence is there that he did take cold? Not the
slightest in the world. There is not the smallest pretence that he ever
complained of a cold, or was treated for a cold. I cannot help saying that it
seems to me that it is a scandal upon a learned, and distinguished, and
liberal profession, that men should come forward to put forth such
speculations upon these perverted facts, and draw from them sophistical and
unwarrantable conclusions, with a view to deceive you. I have the greatest
respect for science. No man can have more. But I cannot repress my
indignation and abhorrence when I see it perverted and prostituted for the
purposes of a particular case in a court of justice. Dr. Nunneley talked to
you about certain excitements being the occasion of idiopathic tetanus. You
remember the sorts of excitement of which he spoke. They are unworthy of
your notice. They were topics discreditable to be put forward by a witness
as worthy of your consideration. But, suppose for a single moment that
excitement at the time could produce any such effect, where is the
excitement manifested by Cook as leading to the supposed disease? They
say that the man, when he won his money at Shrewsbury, was for a moment
excited. And well he might be. His fortunes depended upon the result of the
race, and I will not deny that he was overpowered with emotions of joy. But
those emotions subsided, and we have no further trace of them from that
time to the moment of his death. The man passed the rest of the day with his
friends in ordinary conversation and enjoyment. No trace of emotion was
found. He is taken ill. He goes to Rugeley. He is taken ill there again. But is
there the slightest symptom of excitement about him, or of depression? Not
the least. When he is ill, like most people, he is low spirited. As soon as he
gets a little better, he is cheerful and happy. He invites his friends and
converses with them. On the night of his death his conversation is cheerful.
He is mirthful and happy, little thinking, poor fellow, of the fate that was
depending over him. He is cheerful, and talks of the future, but not in
language of excitement.
What pretence is there for this idle story about excitement? None
whatever. But even if there were excitement or depression—if these things
were capable of producing idiopathic tetanus, the character of the disease is
so essentially different that it is impossible to mistake the two. What are the
cases which they attempt to set up against us? They brought forward a Mary
Watson, who, with a gentleman, came all the way from some place in
Scotland to tell us that a girl had been ill all day, that she is taken worse at
night, that she gets well in a short time, and goes about her business. That is
a case which they brought here to be compared with the death agony of this
man. These are the sort of cases with which they attempt to meet such a
case as is spoken to here. Gentlemen, I venture, upon the evidence which
has been brought before you, to assert boldly, that the cases of idiopathic
and traumatic tetanus are marked by clear and distinct characteristics
distinguishing them from the tetanus of strychnine; and I say that the
tetanus which accompanied Cook’s death is not referable to either of these
forms of tetanus. You have, upon this point, the evidence of men of the
highest competency and most unquestionable integrity, and upon their
evidence, I am satisfied, you can come to no other conclusion than that this
was not a case of either idiopathic or traumatic tetanus. But, then, various
attempts have been made to set up different causes as capable of producing
this tetanic disease. And first, we have the theory of general convulsions;
and Dr. Nunneley having gone through the beadroll of the supposed
infirmities of Cook, says, “Oh, this may have been a case of general
convulsions—I have known general convulsions assuming a tetanic
character!” I said to him, “Have you ever seen one single case in which
death arising from general convulsions accompanied with tetanic symptoms
has not ended in the unconsciousness of the patient?” He says, “No, I never
heard of such a case, not one; but in some book or other, I am told, there is
some such case reported,” and he cites, for that purpose, as an authority for
general convulsions being accompanied with tetanic symptoms, Dr.
Copland.
Now, Dr. Copland, I apprehend, would stand higher as an authority than
the man who quotes him. Dr. Copland might have been called, but was not
called, notwithstanding the challenge which I threw out, because it is,
unfortunately, easier for the case to gather together from the east and from
the west practitioners of more or less celebrity, than to bring to bear on the
subject the light of science as treasured in the books of the eminent
practitioners whom you have seen. But, I say, as regards general
convulsions, the distinction is plain. If they destroy the patient, they destroy
consciousness. But here, unquestionably, at the very last moment, until
Cook’s heart ceased to beat, his consciousness remained. But then comes
another supposed condition from which death in this form is said to have
resulted, and that is the cause intended to be set up by a very eminent
practitioner, Dr. Partridge. It seems that in the post-mortem examination of
Cook, when the spinal marrow was investigated, some granules were found,
and it is said these may have occasioned tetanic convulsions similar to those
found in Cook. He is called to prove that this was a case of what is called
arachnitis, arising from granules. I asked him the symptoms which he
would find in such a case. I called his attention to what it had evidently not
been called before—namely, the symptoms in Cook’s case; and I asked him,
in simple terms, whether, looking at these symptoms, he would pledge his
reputation, in the face of the medical world, and in the face of this court,
that this was a case of arachnitis. He would not do so, and the case of
arachnitis went. Then we have a gentleman who comes all the way from
Scotland to inform us, as the next proposition, that Cook’s was a case of
epileptic convulsions, with tetanic complications. Well, I asked him the
question, “Did you ever know of epilepsy, with or without tetanic
complications, in which consciousness was not destroyed before the patient
died?” His reply was, “No, I cannot say that I ever did, but I have read in
some book that such a case has occurred.” “Is there anything to make you
think this was epilepsy?—It may have been epilepsy, because I don’t know
what else it was.” “But you must admit that epilepsy is characterised
generally by loss of consciousness; what difference would the tetanic
complications have made?” That he was unable to explain. I remind you of
this species of evidence, in which the witnesses have resorted to the most
speculative reasoning, and put forward the barest possibilities without the
shadow of foundation. But this I undertake to assert, that there is not a
single case to which they have spoken from their experience, or as the result
of their own knowledge, on which there were the formidable and decisive
symptoms of marked tetanus which existed in this case.
Having gone through these three sets of diseases—general convulsions,
arachnitis, epilepsy proper, and epilepsy with tetanic complications, I
supposed we had pretty nearly exhausted the whole of these scientific
theories. But we are destined to have another, and that assumed the
formidable name of angina pectoris. It must have struck you when my
learned friend opened his case, that he never ventured to assert the nature of
the disease to which they refer the death of Cook; and it strikes me as most
remarkable that no less than four distinct and separate theories are set up by
the witnesses who have been called—general convulsions, arachnitis,
epilepsy with tetanic complications, and lastly, angina pectoris. My learned
friend had this advantage in not stating to you what his medical witnesses
would set up, because I admit that one after another they took me by
surprise. The gentleman who was called yesterday, and who talked of
angina pectoris, would not have escaped so easily if I had been in
possession of the books to which he referred, for I should have been able to
expose the ignorance, the presumption, of the assertions he dared to make. I
say ignorance and presumption, and what is worse, an intention to deceive.
I assert it in the face of the whole medical profession, and I am sure I can
prove it. These medical witnesses, one and all, differ in the views they take
on the subject; but there is a remarkable coincidence between the views of
some of them and the views of those who have been examined on the other
side. Dr. Partridge, Dr. Robinson, and Dr. Letheby, the most eminent of the
witnesses whom my learned friend has called, agreed with the statements of
Dr. Brodie and other witnesses, that in the whole of their experience, and in
the whole range of their learning and observations, they know of no known
disease to which the symptoms in Cook’s case can be referred. When such
men as these agree upon any point, it is impossible to exaggerate its
importance. If it be the fact that there is no known disease which can
account for such symptoms as those in Cook’s case, and that they are
referable to poison alone, can you have any doubt that that poison was
strychnia? The symptoms, at all events, from the time the paroxysms set in,
are precisely the same. Distinctions are sought to be made by the sophistry
of the witnesses for the defence between some of the antecedent symptoms
and some of the others. I think I shall show you that these distinctions are
imaginary and that there is no foundation for them. I think I may say that
the witnesses called for the defence admit this, that, from the time the
paroxysms set in, of which Cook died, until the time of his death, the
symptoms are precisely similar to that of tetanus by strychnine. But then
they say—and this is worthy of most particular attention—there are points
of difference which have led them to the conclusion that these symptoms
could not have resulted from strychnine.
In the first place, they say that the period which elapsed between the
supposed administration of the poison and the first appearance of the
symptoms is longer than they have observed in the animals on which they
have experimented. The first observation which arises is this: that there is a
known difference between animal and human life, in the power with which
certain specific things act upon their organisation. It may well be that
poison administered to a rabbit will produce its effect in a given time. It by
no means follows that it will produce the same effect in the same time on an
animal of a different description. Still less does it follow that it will exercise
its baneful influence in the same time on a human subject. The whole of the
evidence on both sides leads to establish this fact, that not only in
individuals of different species, but between individuals of the same
species, the same poison and the same influence will produce effects
different in degree, different in duration, different in power. But, again, it is
perfectly notorious that the rapidity with which the poison begins to work
depends mainly upon the mode of its administration. If it is administered in
a fluid state, it acts with greater rapidity. If it is given in a solid state, its
effects come on more slowly. If it is given in an indurated substance, it will
act with still greater tardiness. Then what was the period at which this
poison began to act after its administration, assuming it to have been
poison? It seems, from Mr. Jones’s statement, that the pills were
administered somewhere about eleven o’clock. They were not administered
on his first arrival, for the patient, as if with an intuitive sense of the death
that awaited him, strongly resisted the attempts to make him take them; and
no doubt these remonstrances, and the endeavours to overcome them,
occupied some period of time. The pills were at last given. Assuming,
which I only do for the sake of argument, that the pills contained
strychnine, how soon did they begin to operate? Mr. Jones says he went
down to supper, and came back again about twelve o’clock. Upon his return
to the room, after a word or two of conversation with Cook, he proceeded to
undress and go to bed, and had not been in bed ten minutes before a
warning came that another of the paroxysms was to take place. The maid
servant puts it still earlier, and it appears that so early as ten minutes before
twelve the first alarm was given, which would make the interval little more
than a quarter of an hour. When these witnesses tell us that it would take an
hour and a half, or two hours, we see here another of those exaggerated
determinations to see the facts only in the way that will be the most
favourable to the prisoner. I find in some of the experiments that have been
made that the duration of time, before the poison begins to work, has been
little, if anything, less than an hour.
In the case of the girl at Glasgow, it was stated that it was three-quarters
of an hour before the pills began to work. There may have been some
reason for the pills not taking effect within a certain period after their
administration. It would be easy to mix them up with substances difficult of
solution, or which might retard their action. I cannot bring myself to believe
that, if in all other respects you are perfectly satisfied that the symptoms,
the consequences, the effects were analogous, and similar in all respects to
those produced by strychnine, it is not because the pills have been taken
only a quarter of an hour that you will say strychnine was not administered
in this case. But they say the premonitory symptoms were wanting, and
they say that in the case of animals, the animal at first manifests some
uneasiness, shrinks, and draws itself into itself as it were, and avoids
moving; that certain involuntary twitchings about the head come on—and
they say there were no premonitory symptoms in Cook’s case. I utterly deny
the proposition, I say there were premonitory symptoms of the most marked
character. He is lying in his bed; he suddenly starts up in an agony of alarm.
What made him do that? Was there nothing premonitory—nothing that
warned him the paroxysm was coming on? He jumps up, says “Go and
fetch Palmer—fetch me help—I am going to be ill as I was last night.”
What was that but a knowledge that the symptoms of the previous night
were returning, and a warning of what he might expect unless some relief
were obtained? He sits up and prays to have his neck rubbed. What was the
feeling about his neck but a premonitory symptom, which was to precede
the paroxysms which were to supervene? He begs to have his neck rubbed,
and that gives him some comfort. But here they say this could not have
been tetanus from strychnia, because animals cannot bear to be touched, for
a touch brings on a paroxysm—not only a touch, but a breath of air, a
sound, a word, a movement of any one near will bring on a return of the
paroxysm.
Now in two cases of death from strychnine we have shown that the
patient has endured the rubbing of his limbs, and received satisfaction from
that rubbing. We produced a third case. In Mrs. Smyth’s case, when her legs
were distorted, she prayed and entreated that she might have them
straightened. The lady at Leeds, in the case which Dr. Nunneley himself
attended, implored her husband, between the spasms, to rub her legs and
arms in order to overcome the rigidity. That case was within his own
knowledge; and yet in spite of it, although he detected strychnine in the
body of the unhappy woman, he dares to say that Cook’s having tolerated
the rubbing between the paroxysms is a proof that he had not taken
strychnia. But there is a third case—the case of Clutterbuck. He had taken
an overdose of strychnia, and suffered from the re-appearance of tetanus,
and his only comfort was to have his legs rubbed. And, therefore, I say that
the continued endeavour to persuade a jury that the fact of Cook’s having
had his neck rubbed proves that this is not tetanus by strychnia, shows
nothing but the dishonesty and insincerity of the witnesses who have so
dared to pervert the facts. But they go further, and say that Cook was able to
swallow. So he was before the paroxysms came on; but nobody has ever
pretended that he could swallow afterwards. He swallowed the pills, and,
what is very curious, and illustrates part of the theory, is this—that it was
the act of swallowing the pills, a sort of movement in raising his head,
which brought on the violent paroxysm in which he died. So far from
militating against the supposition that this was a case of strychnine, the fact
strongly confirms it. Then they call our attention to the appearances after
death, and they say there are circumstances to be found which militate
against this being a case of strychnine. They say the limbs became rigid
either at the time of death or immediately after, and that ought not to be
found in a case of strychnia. Dr. Nunneley says, “I have always found the
limbs of animals become flaccid before death, and have not found them
become rigid after death.” Now, I can hardly believe that statement.
The very next witness who got into the box told us that he had made two
experiments upon cats, and killed them both, and he described them as
indurated and contracted when he found them some hours after death. And
yet the presence of rigidity in the body immediately after death is put forth
by Dr. Nunneley as one of his reasons for saying this is not a death by
strychnia, although Dr. Taylor told us that, in the case of one of the cats, the
rigidity of the body was so great that he could hold it out by the leg in a
horizontal position. Notwithstanding that evidence, Dr. Nunneley has the
audacity to say that he does not believe this is a case of strychnine, because
there was rigidity of the limbs, because the feet were distorted, and the
hands clinched, and the muscles rigid. This shows what you are to think of
the honesty of this sort of evidence, in which facts are selected because they
make in favour of particular hypotheses of the party advancing them. The
next thing that is said is that the heart was empty, and that in the animals
operated upon by Dr. Nunneley and Dr. Letheby, the heart was full. I don’t
think that applies to all cases. But it is a remarkable fact connected with the
history of the poison that you never can rely upon the precise form of its
symptoms and appearances. There are only certain great, leading, marked,
characteristic features. We have here the main, marked, leading,
characteristic features; and we have what is more, collateral incidents,
similar to the cases in which the administration and the fact of death have
been proved beyond all possibility of dispute. Why, in two cases which
have been mentioned—that of Mrs. Smyth and the Glasgow girl—the heart
was congested and empty. We know that in cases of tetanus death may
result from more than one cause. All the muscles of the body are subject to
the exciting action of the poison. But no one can tell in what order these
muscles may be affected, or where the poisonous influence will put forth.
When it arrests the play of the lungs and the breathing of the atmospheric
air, the result will be that the heart is full; but if some spasm siezes on the
heart, the heart will be empty. You have never any perfect certainty as to the
mode in which the symptoms will exhibit themselves. But this is brought
forward as a conclusive fact against death by strychnine, and yet these men
who make this statement under the sanction of scientific authority, have
heard both cases spoken to by the gentlemen who examined the bodies.
Then with regard to congestion of the brain, and other vessels, the same
observation applies. Instead of being killed by action on the respiratory
muscles of the heart, death is the result of a long series of paroxysms, and
you expect to find the brain and other vessels congested by that series of
convulsive spasms. As death takes place from one or other of these causes,
so will the appearances be. There is every reason to believe that the
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

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


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

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


personal growth every day!

ebookbell.com

You might also like