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

Arduino Cookbook 1st Edition Michael Margolis pdf download

The 'Arduino Cookbook 1st Edition' by Michael Margolis serves as a comprehensive guide for beginners and experienced users to effectively utilize Arduino technology. It covers essential topics such as setting up the Arduino IDE, programming basics, input/output handling, and using various sensors and actuators. The book is published by O'Reilly Media and includes numerous practical examples and projects to enhance learning.

Uploaded by

dunataskvig
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Arduino Cookbook 1st Edition Michael Margolis pdf download

The 'Arduino Cookbook 1st Edition' by Michael Margolis serves as a comprehensive guide for beginners and experienced users to effectively utilize Arduino technology. It covers essential topics such as setting up the Arduino IDE, programming basics, input/output handling, and using various sensors and actuators. The book is published by O'Reilly Media and includes numerous practical examples and projects to enhance learning.

Uploaded by

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

Arduino Cookbook 1st Edition Michael Margolis

download

https://ebookmeta.com/product/arduino-cookbook-1st-edition-
michael-margolis-3/

Download more ebook from https://ebookmeta.com


We believe these products will be a great fit for you. Click
the link to download now, or visit ebookmeta.com
to discover even more!

Arduino Cookbook 1st Edition Michael Margolis

https://ebookmeta.com/product/arduino-cookbook-1st-edition-
michael-margolis/

Arduino Cookbook 1st Edition Michael Margolis

https://ebookmeta.com/product/arduino-cookbook-1st-edition-
michael-margolis-3/

Arduino Cookbook 1st Edition Michael Margolis

https://ebookmeta.com/product/arduino-cookbook-1st-edition-
michael-margolis-2/

Rossi Cosa Nostra Heirs 4 1st Edition Atlas Rose Raven


Scott

https://ebookmeta.com/product/rossi-cosa-nostra-heirs-4-1st-
edition-atlas-rose-raven-scott/
The Currency Cold War Cash and Cryptography Hash Rates
and Hegemony 1st Edition Birch David

https://ebookmeta.com/product/the-currency-cold-war-cash-and-
cryptography-hash-rates-and-hegemony-1st-edition-birch-david/

The Mountain Man's Muse (Deep Woods Alpha's (Mountain


Man Stories) Book 3) 1st Edition Scarlett Winters
[Winters

https://ebookmeta.com/product/the-mountain-mans-muse-deep-woods-
alphas-mountain-man-stories-book-3-1st-edition-scarlett-winters-
winters/

Journeys with Emperors: Tracking the World's Most


Extreme Penguin 1st Edition Gerald L. Kooyman

https://ebookmeta.com/product/journeys-with-emperors-tracking-
the-worlds-most-extreme-penguin-1st-edition-gerald-l-kooyman/

Orthopedic Physical Assessment David J. Magee

https://ebookmeta.com/product/orthopedic-physical-assessment-
david-j-magee/

Strange World Meet the Clades Disney

https://ebookmeta.com/product/strange-world-meet-the-clades-
disney/
Systematically Analysing Indirect Translations: Putting
the Concatenation Effect Hypothesis to the Test James
Luke Hadley

https://ebookmeta.com/product/systematically-analysing-indirect-
translations-putting-the-concatenation-effect-hypothesis-to-the-
test-james-luke-hadley/
www.it-ebooks.info
www.it-ebooks.info
Arduino Cookbook
by Michael Margolis

Copyright © 2011 Michael Margolis and Nicholas Weldin. All rights reserved.
Printed in the United States of America.

Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.

O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions
are also available for most titles (http://my.safaribooksonline.com). For more information, contact our
corporate/institutional sales department: (800) 998-9938 or corporate@oreilly.com.

Editors: Simon St. Laurent and Brian Jepson Indexer: Lucie Haskins
Production Editor: Teresa Elsey Cover Designer: Karen Montgomery
Copyeditor: Audrey Doyle Interior Designer: David Futato
Proofreader: Teresa Elsey Illustrator: Robert Romano

Printing History:
March 2011: First Edition.

Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’Reilly Media, Inc. Arduino Cookbook, the image of a toy rabbit, and related trade dress are trademarks
of O’Reilly Media, Inc.
Many of the designations used by manufacturers and sellers to distinguish their products are claimed as
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc., was aware of a
trademark claim, the designations have been printed in caps or initial caps.

While every precaution has been taken in the preparation of this book, the publisher and authors assume
no responsibility for errors or omissions, or for damages resulting from the use of the information con-
tained herein.

ISBN: 978-0-596-80247-9

[LSI]

1299267108

www.it-ebooks.info
Table of Contents

Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiii

1. Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Installing the Integrated Development Environment (IDE) 4
1.2 Setting Up the Arduino Board 6
1.3 Using the Integrated Development Environment (IDE) to Prepare
an Arduino Sketch 8
1.4 Uploading and Running the Blink Sketch 11
1.5 Creating and Saving a Sketch 13
1.6 Using Arduino 15

2. Making the Sketch Do Your Bidding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19


2.1 Structuring an Arduino Program 20
2.2 Using Simple Primitive Types (Variables) 21
2.3 Using Floating-Point Numbers 23
2.4 Working with Groups of Values 25
2.5 Using Arduino String Functionality 28
2.6 Using C Character Strings 30
2.7 Splitting Comma-Separated Text into Groups 32
2.8 Converting a Number to a String 34
2.9 Converting a String to a Number 36
2.10 Structuring Your Code into Functional Blocks 38
2.11 Returning More Than One Value from a Function 41
2.12 Taking Actions Based on Conditions 44
2.13 Repeating a Sequence of Statements 45
2.14 Repeating Statements with a Counter 47
2.15 Breaking Out of Loops 49
2.16 Taking a Variety of Actions Based on a Single Variable 50
2.17 Comparing Character and Numeric Values 52
2.18 Comparing Strings 54
2.19 Performing Logical Comparisons 55

www.it-ebooks.info
2.20 Performing Bitwise Operations 56
2.21 Combining Operations and Assignment 58

3. Using Mathematical Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61


3.1 Adding, Subtracting, Multiplying, and Dividing 61
3.2 Incrementing and Decrementing Values 62
3.3 Finding the Remainder After Dividing Two Values 63
3.4 Determining the Absolute Value 64
3.5 Constraining a Number to a Range of Values 65
3.6 Finding the Minimum or Maximum of Some Values 66
3.7 Raising a Number to a Power 67
3.8 Taking the Square Root 68
3.9 Rounding Floating-Point Numbers Up and Down 68
3.10 Using Trigonometric Functions 69
3.11 Generating Random Numbers 70
3.12 Setting and Reading Bits 72
3.13 Shifting Bits 75
3.14 Extracting High and Low Bytes in an int or long 77
3.15 Forming an int or long from High and Low Bytes 78

4. Serial Communications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
4.1 Sending Debug Information from Arduino to Your Computer 86
4.2 Sending Formatted Text and Numeric Data from Arduino 89
4.3 Receiving Serial Data in Arduino 92
4.4 Sending Multiple Text Fields from Arduino in a Single Message 95
4.5 Receiving Multiple Text Fields in a Single Message in Arduino 98
4.6 Sending Binary Data from Arduino 101
4.7 Receiving Binary Data from Arduino on a Computer 105
4.8 Sending Binary Values from Processing to Arduino 107
4.9 Sending the Value of Multiple Arduino Pins 109
4.10 How to Move the Mouse Cursor on a PC or Mac 112
4.11 Controlling Google Earth Using Arduino 115
4.12 Logging Arduino Data to a File on Your Computer 121
4.13 Sending Data to Two Serial Devices at the Same Time 124
4.14 Receiving Serial Data from Two Devices at the Same Time 128
4.15 Setting Up Processing on Your Computer to Send
and Receive Serial Data 131

5. Simple Digital and Analog Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133


5.1 Using a Switch 136
5.2 Using a Switch Without External Resistors 139
5.3 Reliably Detecting the Closing of a Switch 141
5.4 Determining How Long a Switch Is Pressed 144

vi | Table of Contents

www.it-ebooks.info
5.5 Reading a Keypad 149
5.6 Reading Analog Values 152
5.7 Changing the Range of Values 154
5.8 Reading More Than Six Analog Inputs 155
5.9 Displaying Voltages Up to 5V 158
5.10 Responding to Changes in Voltage 161
5.11 Measuring Voltages More Than 5V (Voltage Dividers) 162

6. Getting Input from Sensors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165


6.1 Detecting Movement 167
6.2 Detecting Light 170
6.3 Detecting Motion (Integrating Passive Infrared Detectors) 171
6.4 Measuring Distance 173
6.5 Measuring Distance Accurately 176
6.6 Detecting Vibration 180
6.7 Detecting Sound 181
6.8 Measuring Temperature 185
6.9 Reading RFID Tags 187
6.10 Tracking the Movement of a Dial 190
6.11 Tracking the Movement of More Than One Rotary Encoder 193
6.12 Tracking the Movement of a Dial in a Busy Sketch 195
6.13 Using a Mouse 197
6.14 Getting Location from a GPS 201
6.15 Detecting Rotation Using a Gyroscope 206
6.16 Detecting Direction 208
6.17 Getting Input from a Game Control Pad (PlayStation) 211
6.18 Reading Acceleration 213

7. Visual Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217


7.1 Connecting and Using LEDs 220
7.2 Adjusting the Brightness of an LED 223
7.3 Driving High-Power LEDs 224
7.4 Adjusting the Color of an LED 226
7.5 Sequencing Multiple LEDs: Creating a Bar Graph 229
7.6 Sequencing Multiple LEDs: Making a Chase Sequence (Knight
Rider) 232
7.7 Controlling an LED Matrix Using Multiplexing 234
7.8 Displaying Images on an LED Matrix 236
7.9 Controlling a Matrix of LEDs: Charlieplexing 239
7.10 Driving a 7-Segment LED Display 245
7.11 Driving Multidigit, 7-Segment LED Displays: Multiplexing 248
7.12 Driving Multidigit, 7-Segment LED Displays Using MAX7221 Shift
Registers 250

Table of Contents | vii

www.it-ebooks.info
7.13 Controlling an Array of LEDs by Using MAX72xx Shift Registers 253
7.14 Increasing the Number of Analog Outputs Using PWM Extender
Chips (TLC5940) 255
7.15 Using an Analog Panel Meter As a Display 259

8. Physical Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 261


8.1 Controlling the Position of a Servo 264
8.2 Controlling One or Two Servos with a Potentiometer
or Sensor 266
8.3 Controlling the Speed of Continuous Rotation Servos 267
8.4 Controlling Servos from the Serial Port 269
8.5 Driving a Brushless Motor (Using a Hobby Speed Controller) 271
8.6 Controlling Solenoids and Relays 272
8.7 Making an Object Vibrate 273
8.8 Driving a Brushed Motor Using a Transistor 276
8.9 Controlling the Direction of a Brushed Motor
with an H-Bridge 277
8.10 Controlling the Direction and Speed of a Brushed Motor with an
H-Bridge 280
8.11 Using Sensors to Control the Direction and Speed of Brushed
Motors (L293 H-Bridge) 282
8.12 Driving a Bipolar Stepper Motor 287
8.13 Driving a Bipolar Stepper Motor (Using the EasyDriver Board) 290
8.14 Driving a Unipolar Stepper Motor (ULN2003A) 293

9. Audio Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 297


9.1 Playing Tones 299
9.2 Playing a Simple Melody 301
9.3 Generating More Than One Simultaneous Tone 303
9.4 Generating Audio Tones and Fading an LED 305
9.5 Playing a WAV File 308
9.6 Controlling MIDI 311
9.7 Making an Audio Synthesizer 314

10. Remotely Controlling External Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 317


10.1 Responding to an Infrared Remote Control 318
10.2 Decoding Infrared Remote Control Signals 321
10.3 Imitating Remote Control Signals 324
10.4 Controlling a Digital Camera 327
10.5 Controlling AC Devices by Hacking a Remote Controlled Switch 330

11. Using Displays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 333


11.1 Connecting and Using a Text LCD Display 334

viii | Table of Contents

www.it-ebooks.info
11.2 Formatting Text 337
11.3 Turning the Cursor and Display On or Off 340
11.4 Scrolling Text 342
11.5 Displaying Special Symbols 345
11.6 Creating Custom Characters 347
11.7 Displaying Symbols Larger Than a Single Character 349
11.8 Displaying Pixels Smaller Than a Single Character 352
11.9 Connecting and Using a Graphical LCD Display 355
11.10 Creating Bitmaps for Use with a Graphical Display 359
11.11 Displaying Text on a TV 361

12. Using Time and Dates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367


12.1 Creating Delays 367
12.2 Using millis to Determine Duration 368
12.3 More Precisely Measuring the Duration of a Pulse 372
12.4 Using Arduino As a Clock 373
12.5 Creating an Alarm to Periodically Call a Function 380
12.6 Using a Real-Time Clock 384

13. Communicating Using I2C and SPI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 389


13.1 Controlling an RGB LED Using the BlinkM Module 392
13.2 Using the Wii Nunchuck Accelerometer 397
13.3 Interfacing to an External Real-Time Clock 401
13.4 Adding External EEPROM Memory 404
13.5 Reading Temperature with a Digital Thermometer 408
13.6 Driving Four 7-Segment LEDs Using Only Two Wires 412
13.7 Integrating an I2C Port Expander 416
13.8 Driving Multidigit, 7-Segment Displays Using SPI 418
13.9 Communicating Between Two or More Arduino Boards 421

14. Wireless Communication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425


14.1 Sending Messages Using Low-Cost Wireless Modules 425
14.2 Connecting Arduino to a ZigBee or 802.15.4 Network 431
14.3 Sending a Message to a Particular XBee 438
14.4 Sending Sensor Data Between XBees 440
14.5 Activating an Actuator Connected to an XBee 446

15. Ethernet and Networking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 451


15.1 Setting Up the Ethernet Shield 453
15.2 Obtaining Your IP Address Automatically 455
15.3 Resolving Hostnames to IP Addresses (DNS) 458
15.4 Requesting Data from a Web Server 462
15.5 Requesting Data from a Web Server Using XML 466

Table of Contents | ix

www.it-ebooks.info
15.6 Setting Up an Arduino to Be a Web Server 469
15.7 Handling Incoming Web Requests 471
15.8 Handling Incoming Requests for Specific Pages 474
15.9 Using HTML to Format Web Server Responses 479
15.10 Serving Web Pages Using Forms (POST) 483
15.11 Serving Web Pages Containing Large Amounts of Data 486
15.12 Sending Twitter Messages 493
15.13 Sending and Receiving Simple Messages (UDP) 496
15.14 Getting the Time from an Internet Time Server 502
15.15 Monitoring Pachube Feeds 507
15.16 Sending Information to Pachube 510

16. Using, Modifying, and Creating Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515


16.1 Using the Built-in Libraries 515
16.2 Installing Third-Party Libraries 517
16.3 Modifying a Library 518
16.4 Creating Your Own Library 522
16.5 Creating a Library That Uses Other Libraries 527

17. Advanced Coding and Memory Handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 531


17.1 Understanding the Arduino Build Process 532
17.2 Determining the Amount of Free and Used RAM 535
17.3 Storing and Retrieving Numeric Values in Program Memory 537
17.4 Storing and Retrieving Strings in Program Memory 540
17.5 Using #define and const Instead of Integers 542
17.6 Using Conditional Compilations 543

18. Using the Controller Chip Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 547


18.1 Storing Data in Permanent EEPROM Memory 551
18.2 Using Hardware Interrupts 554
18.3 Setting Timer Duration 557
18.4 Setting Timer Pulse Width and Duration 559
18.5 Creating a Pulse Generator 562
18.6 Changing a Timer’s PWM Frequency 565
18.7 Counting Pulses 567
18.8 Measuring Pulses More Accurately 569
18.9 Measuring Analog Values Quickly 571
18.10 Reducing Battery Drain 572
18.11 Setting Digital Pins Quickly 574

A. Electronic Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 579

B. Using Schematic Diagrams and Data Sheets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585

x | Table of Contents

www.it-ebooks.info
C. Building and Connecting the Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 591

D. Tips on Troubleshooting Software Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 595

E. Tips on Troubleshooting Hardware Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 599

F. Digital and Analog Pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603

G. ASCII and Extended Character Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 607

Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 611

Table of Contents | xi

www.it-ebooks.info
Preface

This book was written by Michael Margolis with Nick Weldin to help you explore the
amazing things you can do with Arduino.
Arduino is a family of microcontrollers (tiny computers) and a software creation envi-
ronment that makes it easy for you to create programs (called sketches) that can interact
with the physical world. Things you make with Arduino can sense and respond to
touch, sound, position, heat, and light. This type of technology, often referred to as
physical computing, is used in all kinds of things, from the iPhone to automobile elec-
tronics systems. Arduino makes it possible for anyone—even people with no program-
ming or electronics experience—to use this rich and complex technology.

Who This Book Is For


Unlike in most technical cookbooks, experience with software and hardware is not
assumed. This book is aimed at a broad range of readers interested in using computer
technology to interact with the environment. It is for people who want to quickly find
the solution to hardware and software problems.
You may have no programming experience—perhaps you have a great idea for an in-
teractive project but don’t have the skills to develop it. This book will help you learn
what you need to know to write code that works, using examples that cover the kinds
of tasks you want to perform.
If you have some programming experience but are new to Arduino, the book will help
you become productive quickly by demonstrating how to implement specific Arduino
capabilities for your project.
People already using Arduino should find the content helpful for quickly learning new
techniques, which are explained using practical examples. This will help you to embark
on more complex projects by showing how to solve problems and use capabilities that
may be new to you.
Experienced C/C++ programmers will find examples of how to use the low-level AVR
resources (interrupts, timers, I2C, Ethernet, etc.) to build applications using the
Arduino environment.

xiii

www.it-ebooks.info
How This Book Is Organized
The book contains information that covers the broad range of the Arduino’s capabili-
ties, from basic concepts and common tasks to advanced technology. Each technique
is explained in a recipe that shows you how to implement a specific capability. You do
not need to read the content in sequence.
Chapter 1, Getting Started, introduces the Arduino environment and provides help on
getting the Arduino development environment and hardware installed and working.
The next couple of chapters introduce Arduino software development. Chapter 2,
Making the Sketch Do Your Bidding, covers essential software concepts and tasks, and
Chapter 3, Using Mathematical Operators, shows how to make use of the most common
mathematical functions.
Chapter 4, Serial Communications, describes how to get Arduino to connect and com-
municate with your computer and other devices. Serial is the most common method
for Arduino input and output, and this capability is used in many of the recipes
throughout the book.
Chapter 5, Simple Digital and Analog Input, introduces a range of basic techniques for
reading digital and analog signals. Chapter 6, Getting Input from Sensors, builds on this
with recipes that explain how to use devices that enable Arduino to sense touch, sound,
position, heat, and light.
Chapter 7, Visual Output, covers controlling light. Recipes cover switching on one or
many LEDs and controlling brightness and color. This chapter explains how you can
drive bar graphs and numeric LED displays, as well as create patterns and animations
with LED arrays. In addition, the chapter provides a general introduction to digital and
analog output for those who are new to this.
Chapter 8, Physical Output, explains how you can make things move by controlling
motors with Arduino. A wide range of motor types are covered: solenoids, servo motors,
DC motors, and stepper motors.
Chapter 9, Audio Output, shows how to generate sound with Arduino through an out-
put device such as a speaker. It covers playing simple tones and melodies and playing
WAV files and MIDI.
Chapter 10, Remotely Controlling External Devices, describes techniques that can be
used to interact with almost any device that uses some form of remote controller, in-
cluding TV, audio equipment, cameras, garage doors, appliances, and toys. It builds
on techniques used in previous chapters for connecting Arduino to devices and
modules.
Chapter 11, Using Displays, covers interfacing text and graphical LCD displays. The
chapter shows how you can connect these devices to display text, scroll or highlight
words, and create special symbols and characters.

xiv | Preface

www.it-ebooks.info
Chapter 12, Using Time and Dates, covers built-in Arduino time-related functions and
introduces many additional techniques for handling time delays, time measurement,
and real-world times and dates.
Chapter 13, Communicating Using I2C and SPI, covers the Inter-Integrated Circuit
(I2C) and Serial Peripheral Interface (SPI) standards. These standards provide simple
ways for digital information to be transferred between sensors and Arduino. This chap-
ter shows how to use I2C and SPI to connect to common devices. It also shows how to
connect two or more Arduino boards, using I2C for multiboard applications.
Chapter 14, Wireless Communication, covers wireless communication with XBee. This
chapter provides examples ranging from simple wireless serial port replacements to
mesh networks connecting multiple boards to multiple sensors.
Chapter 15, Ethernet and Networking, describes the many ways you can use Arduino
with the Internet. It has examples that demonstrate how to build and use web clients
and servers and shows how to use the most common Internet communication protocols
with Arduino.
Arduino software libraries are a standard way of adding functionality to the Arduino
environment. Chapter 16, Using, Modifying, and Creating Libraries, explains how to
use and modify software libraries. It also provides guidance on how to create your own
libraries.
Chapter 17, Advanced Coding and Memory Handling, covers advanced programming
techniques, and the topics here are more technical than the other recipes in this book
because they cover things that are usually concealed by the friendly Arduino wrapper.
The techniques in this chapter can be used to make a sketch more efficient—they can
help improve performance and reduce the code size of your sketches.
Chapter 18, Using the Controller Chip Hardware, shows how to access and use hard-
ware functions that are not fully exposed through the documented Arduino language.
It covers low-level usage of the hardware input/output registers, timers, and interrupts.
Appendix A, Electronic Components, provides an overview of the components used
throughout the book.
Appendix B, Using Schematic Diagrams and Data Sheets, explains how to use schematic
diagrams and data sheets.
Appendix C, Building and Connecting the Circuit, provides a brief introduction to using
a breadboard, connecting and using external power supplies and batteries, and using
capacitors for decoupling.
Appendix D, Tips on Troubleshooting Software Problems, provides tips on fixing com-
pile and runtime problems.
Appendix E, Tips on Troubleshooting Hardware Problems, covers problems with elec-
tronic circuits.

Preface | xv

www.it-ebooks.info
Appendix F, Digital and Analog Pins, provides tables indicating functionality provided
by the pins on standard Arduino boards.
Appendix G, ASCII and Extended Character Sets, provides tables showing ASCII
characters.

What Was Left Out


There isn’t room in this book to cover electronics theory and practice, although guid-
ance is provided for building the circuits used in the recipes. For more detail, readers
may want to refer to material that is widely available on the Internet or to books such
as the following:
• Make: Electronics by Charles Platt (O’Reilly)
• Getting Started in Electronics by Forrest Mims (Master Publishing)
• Physical Computing by Tom Igoe (Cengage)
• Practical Electronics for Inventors by Paul Scherz (McGraw-Hill)
This cookbook explains how to write code to accomplish specific tasks, but it is not an
introduction to programming. Relevant programming concepts are briefly explained,
but there is insufficient room to cover the details. If you want to learn more about
programming, you may want to refer to the Internet or to one of the following books:
• Practical C Programming by Steve Oualline (O’Reilly)
• A Book on C by Al Kelley and Ira Pohl (Addison-Wesley)
My favorite, although not really a beginner’s book, is the book I used to learn
C programming:
• The C Programming Language by Brian W. Kernighan and Dennis M. Ritchie
(Prentice Hall)

Code Style (About the Code)


The code used throughout this book has been tailored to clearly illustrate the topic
covered in each recipe. As a consequence, some common coding shortcuts have been
avoided, particularly in the early chapters. Experienced C programmers often use rich
but terse expressions that are efficient but can be a little difficult for beginners to read.
For example, the early chapters increment variables using explicit expressions that are
easy for nonprogrammers to read:
result = result + 1; // increment the count

Rather than the following, commonly used by experienced programmers, that does the
same thing:
result++; // increment using the post increment operator

xvi | Preface

www.it-ebooks.info
Feel free to substitute your preferred style. Beginners should be reassured that there is
no benefit in performance or code size in using the terse form.
Some programming expressions are so common that they are used in their terse form.
For example, the loop expressions are written as follows:
for(int i=0; i < 4; i++)

This is equivalent to the following:


int i;
for(i=0; i < 4; i = i+1)

See Chapter 2 for more details on these and other expressions used throughout the
book.
Good programming practice involves ensuring that values used are valid (garbage in
equals garbage out) by checking them before using them in calculations. However, to
keep the code focused on the recipe topic, very little error-checking code has been
included.

Arduino Platform Release Notes


The code has been tested using Arduino releases from version 0018 through version
0020. This book was written before Arduino v1.0 was finalized, and although almost
all of the examples should still work, small changes required for running with v1.0 will
be published on the site for the book:
http://www.oreilly.com/catalog/9780596802479/
There’s also a link to errata there. Errata give readers a way to let us know about typos,
errors, and other problems with the book. Errata will be visible on the page immedi-
ately, and we’ll confirm them after checking them out. O’Reilly can also fix errata in
future printings of the book and on Safari, making for a better reader experience pretty
quickly.
If you have problems making examples work, check the web link to see if the code has
been updated. If that doesn’t fix the problem, see Appendix D, which covers trouble-
shooting software problems. The Arduino forum is a good place to post a question if
you need more help: http://www.arduino.cc.
We hope to keep this book updated for future Arduino versions, and we will also
incorporate suggestions and complaints into future editions.
If you like—or don’t like—this book, by all means, please let people know. Amazon
reviews are one popular way to share your happiness (or lack of happiness), or you can
leave reviews at the site for the book.

Preface | xvii

www.it-ebooks.info
Exploring the Variety of Random
Documents with Different Content
TWO NEW BALLETS
The Examiner.

February 9, 1817.
There have been two new ballets this week, one at each Theatre. That at Drury-
Lane, Patrick’s Return, is one of the prettiest things we have seen a long time. The
dancing and pantomime are very delightfully adapted to a number of old Irish
melodies, which we are never tired of hearing.—Zephyr and Flora, at Covent-
Garden, is too fine by half for our rude tastes. There are lusty lovers flying in the
air, nests of winged Cupids, that start out of bulrushes, trees that lift up their
branches like arms:—we suppose they will speak next like Virgil’s wood. But in the
midst of all these wonders, we have a more amiable wonder, the three Miss
Dennetts, as nymphs,

‘Whom lovely Venus at a birth


To ivy-crowned Bacchus bore.’

They might represent Love, Hope, and Joy. There is one part in which they seem
to dance on the strings of the harp which plays to them; the liquid sounds and the
motion are the same. These young ladies put us in mind of Florizel’s praise of
Perdita:—

‘When you do dance, I wish you a wave o’ th’ sea,


That you might ever do nothing but that;
Move still, still so, and own no other function.’
MR. BOOTH’S DUKE OF GLOSTER
The Examiner.

(Covent Garden) February 16, 1817.


A Gentleman of the name of Booth, who we understand has been acting with
considerable applause at Worthing and Brighton, came out in Richard Duke of
Gloster, at this Theatre, on Wednesday. We do not know well what to think of his
powers, till we see him in some part in which he is more himself. His face is
adapted to tragic characters, and his voice wants neither strength nor musical
expression. But almost the whole of his performance was an exact copy or parody
of Mr. Kean’s manner of doing the same part. It was a complete, but at the same
time a successful piece of plagiarism. We do not think this kind of second-hand
reputation can last upon the London boards for more than a character or two. In
the country these doubles of the best London performers go down very well, for
they are the best they can get, and they have not the originals to make invidious
comparisons with. But it will hardly do to bring out the same entertainment that
we can have as it is first served up at Drury-Lane, in a hashed state at Covent-
Garden. We do not blame Mr. Booth for borrowing Mr. Kean’s coat and feathers to
appear in upon a first and trying occasion, but if he wishes to gain a permanent
reputation, he must come forward in his own person. He must try to be original,
and not content himself with treading in another’s steps. We say this the rather,
because, as far as we could judge, Mr. Booth, in point of execution did those
passages the best, in which he now and then took leave of Mr. Kean’s decided and
extreme manner, and became more mild and tractable. Such was his recitation of
the soliloquy on his own ambitious projects, and of that which occurs the night
before the battle. In these he seemed to yield to the impulse of his own feelings,
and to follow the natural tones and cadence of his voice. They were the best parts
of his performance. The worst were those where he imitated, or rather caricatured
Mr. Kean’s hoarseness of delivery and violence of action, and affected an energy
without seeming to feel it. Such were his repulse of Buckingham, his exclamation,
‘What does he in the north,’ &c. his telling the attendants to set down the corse of
King Henry, &c. The scene with Lady Anne, on the contrary, which was of a softer
and more insinuating kind, he was more successful in, and though still a palpable
imitation of Mr. Kean, it had all the originality that imitation could have, for he
seemed to feel it. His manner of saying ‘good night,’ and of answering, when he
received the anonymous paper, ‘A weak invention of the enemy,’ we consider as
mere tricks in the art, which no one but a professed mimic has a right to play. The
dying scene was without effect.—The greatest drawback to Mr. Booth’s acting is a
perpetual strut, and unwieldy swagger in his ordinary gait and manner, which,
though it may pass at Brighton for grand, gracious, and magnificent, even the
lowest of the mob will laugh at in London. This is the third imitation of Mr. Kean
we have seen attempted, and the only one that has not been a complete failure. The
imitation of original genius is the forlorn hope of the candidates for fame:—its
faults are so easily overdone, its graces are so hard to catch. A Kemble school we
can understand: a Kean school is, we suspect, a contradiction in terms. Art may be
taught, because it is learnt: Nature can neither be taught nor learnt. The secrets of
Art may be said to have a common or pass key to unlock them; the secrets of
Nature have but one master-key—the heart.
Drury-Lane.
The charming afterpiece of Figaro, or the Follies of a Day, has been revived here,
and revived with all its gloss and lustre. Miss Kelly, Mrs. Alsop, and Mrs. Orger,
were all very happy in it. This play was written by a man who drank light French
wines: in every line you see the brisk champagne frothing through green glasses.
The beads rise sparkling to the surface and then evaporate. There is nothing in it to
remember, and absolutely nothing to criticise; but it is the triumph of animal
spirits: while you see it, you seem to drink ether, or to inhale an atmosphere not
bred of fogs or sea-coal fires. This is the secret of the charm of Figaro. It promotes
the circulation of the blood, and assists digestion. We would by all means advise
our readers to go and try the experiment. The best scene in it, is that in which the
Page jumps from his concealment behind the arm-chair into the arm-chair itself.
The beauty of this is in fact the perfect heartfelt indifference to detection; and so of
the rest.—We never saw Mr. Rae play better.
MR. BOOTH’S IAGO
The Examiner.

(Drury-Lane) February 23, 1817.


The Managers of Covent-Garden Theatre, after having announced in the bills,
that Mr. Booth’s Richard the Third had met with a success unprecedented in the
annals of histrionic fame, (which, to do them justice, was not the case), very
disinterestedly declined engaging him at more than two pounds a week, as report
speaks. Now we think they were wrong, either in puffing him so unmercifully, or in
haggling with him so pitifully. It was either trifling with the public or with the
actor. The consequence, as it has turned out, has been, that Mr. Booth, who was to
start as ‘the fell opposite’ of Mr. Kean, has been taken by the hand by that
gentleman, who was an old fellow-comedian of his in the country, and engaged at
Drury-Lane at a salary of ten pounds per week. So we hear. And it was in evident
allusion to this circumstance, that when Mr. Booth, as Iago, said on Thursday
night, ‘I know my price no less’—John Bull, who has very sympathetic pockets,
gave a loud shout of triumph, which resounded all along the benches of the pit. We
must say that Mr. Booth pleased us much more in Iago than in Richard. He was, it
is true, well supported by Mr. Kean in Othello, but he also supported him better in
that character than any one else we have seen play with him. The two rival actors
hunt very well in couple. One thing which we did not expect, and which we think
reconciled us to Mr. Booth’s imitations, was, that they were here performed in the
presence, and as it were with the permission of Mr. Kean. There is no fear of
deception in the case. The original is there in person to answer for his identity, and
‘give the world assurance of himself.’ The original and the copy go together, like the
substance and the shadow. But then there neither is nor can be any idea of
competition, and so far we are satisfied. In fact, Mr. Booth’s Iago was a very close
and spirited repetition of Mr. Kean’s manner of doing that part. It was indeed the
most spirited copy we ever saw upon the stage, considering at the same time the
scrupulous exactness with which he adhered to his model in the most trifling
minutiæ. We need only mention as instances of similarity in the bye-play, Mr.
Booth’s mode of delivering the lines, ‘My wit comes from my brains like birdlime,’
or his significant, and we think improper pointing to the dead bodies, as he goes
out in the last scene. The same remarks apply to his delivery, that we made last
week. He has two voices; one his own, and the other Mr. Kean’s. His delineation of
Iago is more bustling and animated; Mr. Kean’s is more close and cool. We suspect
that Mr. Booth is not only a professed and deliberate imitator of Mr. Kean, but that
he has in general the chameleon quality (we do not mean that of living upon air, as
the Covent-Garden Managers supposed, but) of reflecting all objects that come in
contact with him. We occasionally caught the mellow tones of Mr. Macready rising
out of the thorough-bass of Mr. Kean’s guttural emphasis, and the flaunting,
degagé robe of Mr. Young’s oriental manner, flying off from the tight vest and
tunic of the little ‘bony prizer’ of the Drury-Lane Company.
Of Mr. Kean’s Othello we have not room to speak as it deserves, nor have we the
power if we had the room: it is beyond all praise. Any one who has not seen him in
the third act of Othello (and seen him near) cannot have an idea of perfect tragic
acting.
MR. BOOTH’S RICHARD
The Examiner.

(Covent Garden) March 2, 1817.


This Theatre was a scene of the greatest confusion and uproar we ever witnessed
(not having been present at the O. P. rows) on Tuesday evening, in consequence of
the re-appearance of Mr. Booth here, after he had entered into an engagement and
performed at Drury-Lane. For our own parts, who are but simple diplomatists,
either in theatricals or politics, the resentment and disapprobation of the audience
appear to us to have been quite well-founded. The only fault we find with the
expression of the public indignation is, that it was directed solely against Mr.
Booth, whereas the Managers of the Theatre were entitled to the first and fullest
share. Mr. Booth may have been only their dupe: they have wilfully trifled with the
public, and tried to make a contemptible tool of a person belonging to a profession
by which they exist, and from which they derive all their importance with the
public. Their only excuse for inveigling an actor whom they refused to engage, from
another Theatre where he had been engaged in consequence of such refusal, is,
that by the rules of theatrical proceeding, one theatre has no right to engage an
actor who has been in treaty for an engagement at the other, within a year after the
breaking off of such treaty, without leave of the Managers. First, it appears that no
such understanding exists, or is acted upon: that the pretext, as a mere pretext, is
not true: secondly, such a mutual understanding, if it did exist, would be most
unjust to the profession, and an insult to the public. For at this rate, any Manager,
by once entering into an agreement with an actor, may keep him dangling on his
good pleasure for a year certain, may prevent his getting any other engagement, by
saying that they are still in a progress of arrangement, though all arrangement is
broken off, may deprive an ingenious and industrious man of his bread, and the
public of the advantage of his talents, till the Managers, at the expiration of this
probationary year of non-performance, once more grant him his Habeas Corpus,
and release him from the restrictions and obligations of his non-engagement. The
obvious questions for the public to decide are these: Why, having announced Mr.
Booth as a prodigy of success after his first appearance in Richard, the Managers
declined to give Mr. Booth any but a very paltry salary? In this they either deceived
the town, or acted with injustice to Mr. Booth, because they thought him in their
power. Why, the instant he was engaged at the other Theatre at a handsome salary,
and on his own terms, and had played there with success, they wanted to have him
back, employed threats as it should seem to induce him to return, and gave him a
larger salary than he had even obtained at Drury-Lane? Whether, if he had not
been engaged at the other theatre, they would have engaged him at their own upon
the terms to which they have agreed to entice him back? Whether, in short, in the
whole proceeding, they have had any regard either to professional merit, or to
public gratification, or to any thing but their own cunning and self-interest? The
questions for Mr. Booth to answer are, why, after his treatment by the Covent-
Garden Company, he applied to the Drury-Lane Company; and why, after their
liberal behaviour, he deserted back again, on the first overture, to the company
that had discarded him? Why he did not act on Saturday night, if he was able: or at
any rate, state, to prevent the charge of duplicity, his new engagement with his old
benefactors? Whether, if Mr. Booth had not made this new arrangement, he would
not have acted in spite of indisposition or weak nerves? Lastly, whether the real
motive which led Mr. Booth to fall in so unadvisedly with the renewed and
barefaced proposals of the Covent-Garden Company, was not the renewed hope
dawning in his breast, of still signalising himself, by dividing the town with Mr.
Kean, instead of playing a second part to him, which is all he could ever hope to do
on the same theatre? But enough of this disagreeable and disgraceful affair. The
only way to make it up with the public would be, as we are convinced, not by
attempts at vindication, but by an open apology.
Drury-Lane.
The new farce of Frightened to Death, is the most amusing and original piece of
invention that we have seen for a long time. The execution might be better, but the
idea is good, and as far as we know, perfectly new. Harley, Jack Phantom, in a
drunken bout, is beaten by the watch, and brought senseless to the house of his
mistress, Mrs. Orger, who, in order to cure him of his frolics, determines to dress
him up in an old wrapping-gown like a shroud, and persuade him that he is dead.
When he awakes, he at first does not recollect where he is: the first thing he sees is
a letter from his friend to his mistress, giving an account of his sad catastrophe,
and speaking of the manner in which order is to be taken for his burial. Soon after,
his mistress and her maid come in in mourning, lament over his loss, and as has
been agreed beforehand, take no notice of Phantom, who in vain presents himself
before them, and thus is made to personate his own ghost. The servant, Mumps
(Mr. Knight), who is in the secret, also comes in, and staggers Phantom’s belief in
his own identity still more, by neither seeing nor hearing him. The same machinery
is played off upon him in a different mood by Munden’s coming in, and taking him
for a ghost. A very laughable dialogue and duet here take place between the Ghost
and the Ghostseer, the latter inquiring of him with great curiosity about his
ancestors in the other world, and being desirous to cultivate an acquaintance with
the living apparition, in the hope of obtaining some insight into the state of that
state ‘from which no traveller returns.’ There was a foolish song about ‘Kisses’ at
the beginning, which excited some little displeasure, but the whole went off with
great and deserved applause.
DOUBLE GALLANT
The Examiner.

(Drury-Lane) April 13, 1817.


Cibber’s Comedy of the Double Gallant has been revived at this Theatre with
considerable success. Pope did Cibber a great piece of injustice, when he appointed
him to receive the crown of dullness. It was mere spleen in Pope; and the
provocation to it seems to have been an excess of flippant vivacity in the
constitution of Cibber. That Cibber’s Birth-day Odes were dull, seems to have been
the common fault of the subject, rather than a particular objection to the poet. In
his Apology for his own Life, he is one of the most amusing of coxcombs; happy in
conscious vanity, teeming with animal spirits, uniting the self-sufficiency of youth
with the garrulity of age; and in his plays he is not less entertaining and agreeably
familiar with the audience. His personal character predominates indeed over the
inventiveness of his muse; but so far from being dull, he is every where light,
fluttering, and airy. We could wish we had a few more such dull fellows; they would
contribute to make the world pass away more pleasantly! Cibber, in short, though
his name has been handed down to us as a bye-word of impudent pretension by the
classical pen of his rival, who did not admit of any merit beyond the narrow circle
of wit and friendship in which he moved, was a gentleman and a scholar of the old
school; a man of wit and pleasantry in conversation; an excellent actor; an
admirable dramatic critic; and one of the best comic writers of his age. Instead of
being a caput mortuum of literature, (always excepting what is always to be
excepted, his Birth-day Odes), he had a vast deal of its spirit, and too much of the
froth. But the eye of ill-nature or prejudice, which is attracted by the shining points
of character in others, generally transposes their good qualities, and absurdly
denies them the very excellences which excite its chagrin.—Cibber’s Careless
Husband is a master-piece of easy gaiety; and his Double Gallant, though it cannot
rank in the first, may take its place in the second class of comedies. It is full of
character, bustle, and stage-effect. It belongs to the composite style, and very
happily mixes up the comedy of intrigue, such as we see it in Mrs. Centlivre’s
Spanish plots, with a tolerable share of the wit and sentiment of Congreve and
Vanburgh. As there is a good deal of wit, there is a spice of wickedness in this play,
which was the privilege of the good old style of comedy, when vice, perhaps from
being less common, was less catching than it is at present. It was formerly a thing
more to be wondered at than imitated; and behind the rigid barriers of religion and
morality might be exposed freely, without the danger of any serious practical
consequences; but now that the safeguards of wholesome prejudices are removed,
we seem afraid to trust our eyes or ears with a single situation or expression of a
loose tendency, as if the mere mention of licentiousness implied a conscious
approbation of it, and the extreme delicacy of our moral sense would be debauched
by the bare suggestion of the possibility of vice. The luscious vein of the dialogue in
many of the scenes is stopped short in the revived play, though not before we
perceive its object—

——‘In hidden mazes running,


With wanton haste and giddy cunning!’

We noticed more than one of these double meanings, which however passed off
without any marks of reprobation, for unless they are made pretty broad, the
audience, from being accustomed to the cautious purity of the modern drama, are
not very expert in decyphering the equivocal allusion.—All the characters in the
Double Gallant are very well kept up, and they were most of them well supported
in the representation. At-All and Lady Dainty are the two most prominent
characters in the original comedy, and those into which Cibber has put most of his
own nature and genius. They are the essence of active impertinence and sickly
affectation. At-All has three intrigues upon his hands at once, and manages them
all with the dexterity with which an adept shuffles a pack of cards. His cool
impudence is equal to his wonderful vivacity. He jumps, by mere volubility of
tongue and limbs, under three several names into three several assignations with
three several incognitas, whom he meets at the same house, as they happen to be
mutual friends. He would succeed with them all, but that he is detected by them all
round, and then he can hardly be said to fail, for he carries off the best of them at
last (Mrs. Mardyn), who not being able to seduce him from her rivals by any other
means, resorts to a disguise, and vanquishes him in love by disarming him in a
duel. The scene in which At-All, who had made love to Clorinda as Colonel
Standfast, is introduced to her by her cousin (who is also in love with him) as Mr.
Freeman, and while he is disowning his personal identity, is surprised by the
arrival of Lady Sadlife, to whom he had been making the same irresistible
overtures, is one of the best coup d’œils of the theatre we have seen for a long time.
Harley acts this character laughably, but not very judiciously. He bustles through it
with the liveliness of a footman, not with the manners of a gentleman. He never
changes his character with his dress, but still he is a pleasant fellow in himself, and
is so happy in the applause he receives, that we are sorry to find any fault with him.
Mrs. Alsop’s Lady Dainty was a much better, but a much less agreeable piece of
acting. The affected sensibility, the pretended disorders, the ridiculous admiration
of novelty, and the languid caprices of this character, were given by the actress
with an overpowering truth of effect. The mixture of folly, affectation, pride,
insensibility, and spleen which constitute the character of the fine lady, as it
existed in the days of Cibber, and is delineated in this comedy, is hardly to be
tolerated in itself, with every advantage of grace, youth, beauty, dress, and fashion.
But Mrs. Alsop gave only the inherent vice and ridiculous folly of the character,
without any external accomplishments to conceal or adorn it. She has always the
same painful ‘frontlet’ on: the same uneasy expression of face and person. Her
affected distortions seemed to arise from real pain; nor was her delight in mischief
and absurdity counteracted by any palliating circumstances of elegance or beauty.
A character of this description ought only to appeal to the understanding, and not
to offend the senses. We do not know how to soften this censure; but we will add,
that Mrs. Alsop, in all her characters, shews sense, humour, and spirit.
Dowton and Miss Kelly, as Sir Solomon Sadlife and Wishwell, are two for a pair.
We do not wish to see a better actor or actress. The effect which both these
performers produce, is the best and strongest that can be, because they never try to
produce an effect. Their style of acting is the reverse of grimace or caricature. They
never overcharge or force any thing, and their humour is so much the more
irresistible in its appeal, as it seems to come from them in spite of themselves.
Instead of wanting to shew their talents to the audience, they seem hardly
conscious of them themselves. All their excellence is natural, unaffected,
involuntary. When the sense of absurdity is so strong that it cannot be contained
any longer, it bursts out; and the expression of their feelings commands our
sympathy, because they do not appear to court it. Their nature is downright sturdy,
sterling, good old English nature, that is, the sort of nature that we like best. In the
present play, it is hard to determine which is the best—Miss Kelly’s sulky
suppressed abigail airs as Wishwell, her adroit irony and contemptuous expression
of pity for Sir Solomon’s credulity, or Dowton’s deliberate manner of digesting his
disgraces, chewing the cud of his misfortunes, and pocketing up his branching
horns, in the latter character. Wishwell’s tingling fingers, uplifted eyes, pouting
mouth, bridling chin, and Sir Solomon’s bronzed face, curling lips, blank looks,
nods, winks, and shrugs, told their own story and kept their own secret (to
themselves), as well as heart could wish. We have a stronger relish for this kind of
dry pungent humour, than we have for the taste of olives.

The Inn-keeper’s Daughter is a melo-drame founded on Mr. Southey’s ballad of


Mary the Maid of the Inn. The ballad is better than the melo-drame. The interest of
the story is less in the latter, and the machinery is complicated, and moves slow.
Robinson Crusoe, the new melo-drame at Covent-Garden, is not the old
favourite with the public. It has not the striking incident of the notched post, nor of
the print of a human footstep in the sand; but there is a poodle dog in it, and
innumerable savages, English and Caribbee.
DON JUAN
The Examiner.

(King’s Theatre) April 20, 1817.


Mozart’s celebrated Opera of Don Juan has been brought forward at this Theatre
with every attraction, and with all the success which could be anticipated. The
house was crowded to excess on Saturday week (the day of its being first brought
out): on Tuesday it was but thinly attended. Why was this? Was it because the first
representation did not answer the expectation of the public? No; but because
Saturday is the fashionable day for going to the Opera, and Tuesday is not. On
Saturday, therefore, the English are a musical public; and on Tuesday they are not
a musical public: on Saturday they are all rapture and enthusiasm; and on Tuesday
they are all coldness and indifference,—impose a periodical penance on themselves
for the plenary indulgence of their last week’s ecstasies, and have their ears
hermetically sealed to the charms of modulated sounds. Yet the writer of the
preface to the translation of Don Juan assures us, that ‘the people of this country
who frequent the Opera, are inferior to those of no other nation in their taste for
fine music.’ That may be so. But still we doubt, if Don Juan, ‘the matchless work of
its immortalized author,’ had been presented to the English public for the first time
on Saturday week, without those wonderful helps to public taste and discernment,
the name and reputation of the composer, whether it would have met with any
better success than it did in Prague in 1787, or at Paris some years after, and
whether we might not have had to observe of its representation at the King’s
Theatre, as Gerat, the singer, did of its representation at the Academie de Musique;
Don Juan a paru incognito à l’Opera! The only convincing proof that the public,
either in this country or on the Continent, are become more alive to ‘the refined
and intellectual music’ of Don Giovanni than they were thirty years ago, is—that
the author is dead.
What inclines us the more to believe that the admiration of Mozart’s music in
this instance is more a thing of rote than the consequence of any general feeling on
the subject, is, that we hear of nothing but the sublimity and Shakespearian
character of Don Juan. Now we confess that, with the single exception of the Ghost
scene, we not only do not feel any such general character of grand or strongly-
contrasted expression pervading the composition, but we do not see any
opportunity for it. Except the few words put into the mouth of the great
Commander (Don Pedro) either as the horseman ghost, or the spectre-guest of
Don Juan, which break upon the ear with a sort of awful murmur, like the sound of
the last trumpet ringing in the hollow chambers of the dead, but which yet are so
managed, that ‘airs from heaven’ seem mingled with ‘blasts from hell,’ the rest of
the Opera is scarcely any thing but gaiety, tenderness, and sweetness, from the first
line to the last. To be sure, the part of the great Commander is a striking and lofty
catastrophe to the piece; he does in some sort assume a voice of stern authority,
which puts an end to the mirth, the dancing, the love and feasting, and drowns the
sounds of the pipe, the lute, and the guitar, in a burst of rattling thunder; but even
this thunder falls and is caught among its own echoes, that soften while they
redouble the sound, and by its distant and varied accompaniment, soothes as much
as it startles the ear. This short episode, which is included in four or five sentences
printed in capital letters, is the only part of the opera which aims at the tragic: this
part is not of a pure or unmixed species, but is very properly harmonised with the
rest of the composition, by middle and reflected tones; and all the other scenes are
of one uniform, but exquisite character, a profusion of delicate airs and graces.
Except, then, where the author reluctantly gives place to the Ghost-statue, or
rather compromises matters with him, this opera is Mozart all over; it is no more
like Shakespear, than Claude Lorraine is like Rubens or Michael Angelo. It is idle
to make the comparison. The personal character of the composer’s mind, a light,
airy, voluptuous spirit, is infused into every line of it; the intoxication of pleasure,
the sunshine of hope, the dancing of the animal spirits, the bustle of action, the
sinkings of tenderness and pity, are there, but nothing else. It is a kind of scented
music; the ear imbibes an aromatic flavour from the sounds. It is like the breath of
flowers; the sighing of balmy winds; or Zephyr with Flora playing; or the liquid
notes of the nightingale wafted to the bosom of the bending rose. To show at once
our taste or the want of it, the song of ‘La ci darem’ gives us, we confess, both in
itself, and from the manner in which it is sung by Madame Fodor, more pleasure
than all the rest of the opera put together. We could listen to this air for ever—with
certain intervals: the first notes give a throb of expectation to the heart, the last
linger on the sense. We encore it greedily, with a sort of childish impatience for
new delight, and drink in the ethereal sounds, like draughts of earthly nectar. The
heart is intoxicated through the ear; and feels in the tremulous accents of Zerlina’s
voice, all the varying emotions of tenderness, of doubt, of regret, and giddy
rapture, as she resigns herself to her new lover. Madame Fodor’s execution of her
part of this duet was excellent. There is a clear, firm, silvery tone in her voice, like
the reverberation of a tight-strung instrument, which by its contrast gives a
peculiar effect to the more melting and subdued expression of particular passages,
and which accords admirably with the idea of high health and spirits in the rustic
character of Zerlina. We are tempted to say of her in this character, what Spenser
says of Belphebe,

‘——And when she spake,


Sweet words like dropping honey she did shed,
And ’twixt the pearls and rubies softly brake
A silver sound, that heav’nly music seem’d to make.’

She was less successful in the execution of the song to Massetto just after, ‘Batte,
batte, Massetto:’ for she seemed to sing it as if she had hardly learned it by heart.
To this, however, she gave a characteristic simplicity of expression; she appeared
in the first part as if she would willingly stand like a lamb, come agnellina, to be
beaten by her provoked lover, and afterwards, when she is reconciled to him, as if
she was glad she had escaped a beating. Her song, Vedrai carino, promising him a
remedy, when Massetto himself gets beaten, by offering him her heart, was
charming, both from the execution of the air, and from the action with which she
accompanied it.
Of the other performers we cannot speak so favourably. Signor Ambrogetti gave
considerable life and spirit to the part of Don Giovanni; but we neither saw the
dignified manners of the Spanish nobleman, nor the insinuating address of the
voluptuary. He makes too free and violent a use of his legs and arms. He sung the
air, Finche dal vino, in which he anticipates an addition to his list of mistresses
from the success of his entertainment, with a sort of jovial turbulent vivacity, but
without the least ‘sense of amorous delight.’ His only object seemed to be, to sing
the words as loud and as fast as possible. Nor do we think he gave to Don Juan’s
serenade, Deh vieni alla finestra, any thing like the spirit of fluttering
apprehension and tenderness which characterises the original music. Signor
Ambrogetti’s manner of acting in this scene was that of the successful and
significant intriguer, but not of an intriguer—in love. Sensibility should be the
ground-work of the expression: the cunning and address are only accessories.
Naldi’s Laporello was much admired, and it was not without its merits, though
we cannot say that it gave us much pleasure. His humour is coarse and boisterous,
and is more that of a buffoon than a comic actor. He treats the audience with the
same easy cavalier airs that an impudent waiter at a French table-d’hôte does the
guests as they arrive. The gross familiarity of his behaviour to Donna Elvira, in the
song where he makes out the list of his master’s mistresses, was certainly not in
character; nor is there any thing in the words or the music to justify it. The tone
and air which he should assume are those of pretended sympathy, mixed with
involuntary laughter, not of wanton undisguised insult.
Signor Crivelli and Madame Camporese did not add any particular prominence
to the serious parts of Don Octavio, and Donna Anna. Signora Hughes’s Donna
Elvira was successful beyond what we could have supposed. This lady at the Italian
Opera is respectable: on the English stage she was formidable. Signor Angrisani
doubles the part of Massetto and the Ghost. In the former, he displayed much
drollery and naiveté; and in the latter, he was as solemn, terrific, and mysterious
as a ghost should be. A new translation accompanies the Opera House edition of
Don Giovanni. It is very well executed. But as it is not in verse, it might have been
more literal, without being less elegant.
THE CONQUEST OF TARANTO
The Examiner.

(Covent Garden) April 27, 1817.


The Conquest of Taranto continues to be acted here with a success proportionate
to its merits. It is from the pen of Mr. Dimond, whose productions are well known
to the public, and which have so strong a family-likeness, that from having seen
any one of them, we may form a tolerably correct idea of the rest. Ex uno omnes.
His pieces have upon the whole been exceedingly popular, and we think deservedly
so; for they have all the merit that belongs to the style of the drama to which he has
devoted his talents,—a style which is a great favourite with an immense majority of
the play-going public. This style may be called the purely romantic; there is little
or nothing classical in it. The author does not profess to provide a public
entertainment at his own entire expense, and from his own proper funds, but
contracts with the managers to get up a striking and impressive exhibition in
conjunction with the scene-painter, the scene-shifter, the musical composer, the
orchestra, the choruses on the stage, and the lungs of the actors! It is a kind of pic-
nic contribution, to which we sit down with a good appetite, and from which we
come away quite satisfied, though our attention is somewhat distracted in the
multitude of objects to which our gratitude is due for the pleasure we have
received. The art of the romantic dramatist seems to be, to put ordinary characters
in extraordinary situations, and to blend commonplace sentiments with
picturesque scenery. The highest pathos is ushered in, and the mind prepared to
indulge in all the luxury of woe, by the chaunting of music behind the scenes, as
the blowing up of a mine of gunpowder gives the finishing stroke to the progress of
the passions. The approach of a hero is announced by a blast of trumpets; the flute
and flageolet breathe out the whole soul of the lover. Mr. Dimond is by no means
jealous of the exclusive honours of the Tragic Muse; he is not at all disposed to
make a monopoly of wit, genius, or reputation: he minds little but the conducting
of his story to the end of the third act, and loses no opportunity of playing the game
into the hands of his theatrical associates, so that they may supply his deficiencies,
and all together produce a perfect piece. In the Conquest of Taranto the scene lies
almost the whole time upon the beautiful sea-coast of Spain, and we do not feel the
lack of descriptive poetry, while the eye is regaled with one continued panorama.
In a word, the author resembles those painters of history who pay more attention
to their back-ground than their figures, to costume and drapery than to the
expression of thought and sentiment.
The romantic drama, such as we have here described it, admits of various
gradations, from the point where it unites with the pure tragic down to the melo-
drame, and speaking pantomime, nor do we think that as it descends lower in its
pretensions, its interest necessarily grows less. Where the regular drama studiously
avails itself of the assistance of other arts, as painting and music, where the
dialogue becomes the vehicle for connecting scenery, pantomime, and song in one
dazzling and overpowering appeal to all our different faculties and senses, we are
satisfied if the tout ensemble produces its effect, and do not enquire whether the
work of the author alone, in a literary point of view, is proof against criticism. He is
supposed to write for the stage ‘with all appliances and means to boot,’ not for the
loneliness of the closet, and is little more than the ballet-master of the scene. He is
not to enter into a competition with his assistants in the several departments of his
art, but to avail himself of their resources. In the division of labour it is ridiculous
to expect the same person to do the whole work. This would be double toil and
trouble, and would, besides, answer no end. An appeal to the understanding or the
imagination is superfluous, where the senses are assailed on all sides. What is the
use of painting a landscape twice—to the ear as well as to the eye? What signify ‘the
golden cadences of verse,’ when only employed to usher in a song? The gleams of
wit or fancy glimmer but feebly on a stage blazing with phosphorus; and surely the
Tragic Muse need not strain her voice so deep or high, while a poodle dog is
barking fit to break his heart, in the most affecting part of the performance. We
cannot attend to sounding epithets while a castle is tumbling about our ears, and it
is sufficiently alarming to see an infant thrown from a precipice or hanging bridge
into the foaming waves—reflections apart. Commonplace poetry is good enough as
an accompaniment to all this; as very indifferent words are equally well set to the
finest tunes.—So far then from joining in the common cry against Mr. Dimond’s
poetry as not rising above mediocrity, we should be sorry if he wrote better than he
does. And what confirms us in this sentiment is, that those who have tried to do
better have succeeded worse. The most ambitious writers of the modern romantic
drama are Mr. Coleridge and Mr. Maturin. But in the Remorse of the one, all Mr.
Coleridge’s metaphysics are lost in moonshine; and in Bertram and Don Manuel,
the genius of poetry crowned with faded flowers, and seated on the top of some
high Gothic battlement, in vain breathes its votive accents amidst the sighing of the
forest gale and the vespers of midnight monks. But enough of this.
There is considerable interest in the outline of the present play, and the events
are ingeniously and impressively connected together, so as to excite and keep alive
curiosity, and to produce striking situations. But to this production of external
effect, character and probability are repeatedly sacrificed, and the actions which
the different persons are made to perform, like stage-puppets, have no adequate
motives. For instance, it is quite out of our common calculation of human nature,
that Valencia (Mr. Macready) should betray his country to an enemy, because he is
jealous of a rival in love; nor is there any thing in the previous character of
Valencia to lead us to expect such an extreme violation of common sense and
decency. Again, Rinaldo is betrayed to his dishonour, by acting contrary to orders
and to his duty as a knight, at the first insidious suggestion of Valencia. The
entrance of the Moors through the subterranean passage, and the blowing up of
the palace while the court are preparing to give a sort of fête champêtre in the
middle of a siege, is not only surprising but ridiculous. Great praise is due to Mr.
Young as Aben Hamet, to Mr. Macready as Valencia, and to Mr. Booth as Rinaldo,
for the force of their action, and the audibleness of their delivery:—perhaps for
something more.—Miss Stephens, as Oriana’s maid, sang several songs very
prettily.
THE TOUCH-STONE
The Examiner.

(Drury-Lane) May 11, 1817.


Mr. Kenney’s new Comedy called the Touch-stone, or the World as it goes, has
been acted here with great success. It possesses much liveliness and pleasantry in
the incidents, and the dialogue is neat and pointed. The interest never flags, and is
never wound up to a painful pitch. There are several coups de théatre, which shew
that Mr. Kenney is an adept in his art, and has the stage and the actors before him
while he is writing in his closet. The character of Dinah Cropley, which is
admirably sustained by Miss Kelly, is the chief attraction of the piece. The author
has contrived situations for this pretty little rustic, which bring out the exquisite
naiveté and simple pathos of the actress in as great a degree as we ever saw them.
Mr. Kenney, we understand, wrote this Comedy abroad; and there is a foreign air
of homely contentment and natural gaiety about the character of poor Dinah, like
the idea we have of Marivaux’s Paysanne parvenue. She seemed to have fed her
chickens and turned her spinning-wheel in France, under more genial and better-
tempered skies. Perhaps, however, this may be a mere prejudice in our minds,
arising from our having lately seen Miss Kelly in such characters taken from
French pieces. Her lover, Harley, (Peregrine Paragon), is of undoubted home
growth. He is a very romantic, generous, amorous sort of simpleton, while he is
poor; and for want of knowing better, thinks himself incorruptible, till temptation
falls in his way, and then he turns out a very knave: and only saves his credit in the
end by one of those last act repentances which are more pleasing than probable.
He is in the first instance a poor country schoolmaster, who is engaged to marry
Dinah Cropley, the daughter of a neighbouring farmer. They cannot, however,
obtain the consent of their landlord and his sister (Holland and Mrs. Harlowe), the
one a town coquette, the other a commercial gambler; when just in the nick of
time, news is brought that Holland is ruined by the failure of an extravagant
speculation, and that a distant relation has left his whole fortune to Harley. The
tables are now turned. Harley buys the mansion-house, furniture, and gardens,
takes possession of them with highly amusing airs of upstart vanity and self-
importance; is flattered by the Squire’s sister, who discards and is discarded by a
broken fortune-hunting lover of the name of Garnish (Wallack), makes proposals
of marriage to her, and thinks no more of his old favourite Dinah. Garnish in the
mean time finding the pliability of temper of Peregrine Paragon, Esq., and to make
up for his disappointment in his own fortune-hunting scheme, sends for his sister
(Mrs. Alsop) whom he introduces to the said Peregrine Paragon. The forward
pretensions of the two new candidates for his hand, form an amusing contrast with
the sanguine hopes and rejected addresses of the old possessor of his heart, and
some very ridiculous scenes take place, with one very affecting one, in which Miss
Kelly makes a last vain appeal to her lover’s fidelity, and (Oxberry) her father
watches the result with a mute wonderment and disappointed expectation
infinitely natural, and well worth any body’s seeing. By-and-bye it turns out that
the fortune has been left not to Harley, but by a subsequent will to Miss Kelly, who
is also a relation of the deceased, when instantly his two accomplished mistresses
give over their persecution of him, their two brothers set off to make love to the
new heiress, who exposes them both to the ridicule they deserve, and Harley,
without knowing of the change of fortune, is moved by a letter he receives from
her, to repent just in time to prove himself not altogether unworthy of her hand.
Such is the outline of this Comedy. Dowton acts the part of a friendly mediator,
and spectator in the scene; and Hughes makes a very fit representative of a
shuffling, officious, pettifogging attorney. The most unpleasant part of the play was
the undisguised mercenary profligacy of the four characters of Wallack, Holland,
Mrs. Alsop, and Mrs. Harlowe: and a precious partie quarrée they are. The scrapes
into which their folly and cunning lead them are, however, very amusing, and their
unprincipled selfishness is very deservedly punished at last.
THE LIBERTINE
The Examiner.

(Covent Garden) May 25, 1817.


The Libertine, an after-piece altered from Shadwell’s play of that name, and
founded on the story of Don Juan, with Mozart’s music, was represented here on
Tuesday evening. Almost every thing else was against it, but the music triumphed.
Still it had but half a triumph, for the songs were not encored; and when an
attempt was made by some rash over-weening enthusiasts to encore the
enchanting airs of Mozart, that heavy German composer, ‘that dull Beotian genius,’
as he has been called by a lively verbal critic of our times, the English, disdaining
this insult offered to our native talents, hissed—in the plenitude of their pampered
grossness, and ‘ignorant impatience’ of foreign refinement and elegance, they
hissed! We believe that unconscious patriotism has something to do with this as
well as sheer stupidity: they think that a real taste for the Fine Arts, unless they are
of British growth and manufacture, is a sign of disaffection to the Government, and
that there must be ‘something rotten in the state of Denmark,’ if their ears, as well
as their hearts, are not true English. We have heard sailors’ songs by Little Smith,
and Yorkshire songs by Emery, and the Death of Nelson by Mr. Sinclair, encored
again and again at Covent-Garden, so as almost ‘to split the ears of the
groundlings,’ yet the other night they would not hear of encoring Miss Stephens,
either in the Duet with Duruset, La ci darem, nor in the song appealing for his
forgiveness, Batte, Massetto; yet at the Opera they tolerate Madame Fodor in
repeating both these songs, because they suppose it to be the etiquette, and would
have you believe that they do not very warmly insist on the repetition of the last
song she sings there, out of tenderness to the actress, not to spare their own ears,
which are soon cloyed with sweetness, and delight in nothing but noise and fury.
We regard Miss Stephens’s Zerlina as a failure, whether we compare her with
Madame Fodor in the same part, or with herself in other parts. She undoubtedly
sung her songs with much sweetness and simplicity, but her simplicity had
something of insipidity in it; her tones wanted the fine, rich, pulpy essence of
Madame Fodor’s, the elastic impulse of health and high animal spirits; nor had her
manner of giving the different airs that laughing, careless grace which gives to
Madame Fodor’s singing all the ease and spirit of conversation. There was some
awkwardness necessarily arising from the transposition of the songs, particularly
of the duet between Zerlina and Don Giovanni, which was given to Massetto,
because Mr. Charles Kemble is not a singer, and which by this means lost its
exquisite appropriateness of expression. Of Mr. Duruset’s Massetto we shall only
say, that it is not so good as Angrisani’s. He would however have made a better
representative of the statue of Don Pedro than Mr. Chapman, who is another
gentleman who has not ‘a singing face,’ and whom it would therefore have been
better to leave out of the Opera than the songs; particularly than that fine one,
answering to Di rider finira pria della Aurora, which Mr. Chapman was mounted
on horseback on purpose, it should seem, neither to sing nor say!
Mr. Charles Kemble did not play the Libertine well. Instead of the untractable,
fiery spirit, the unreclaimable licentiousness of Don Giovanni, he was as tame as
any saint;

‘And of his port as meek as is a maid.’

He went through the different exploits of wickedness assigned him with evident
marks of reluctance and contrition; and it seemed the height of injustice that so
well meaning a young man, forced into acts of villainy against his will, should at
last be seized upon as their lawful prize by fiends come hot from hell with flaming
torches, and that he should sink into a lake of burning brimstone on a splendid car
brought to receive him by the devil, in the likeness of a great dragon, writhing
round and round upon a wheel of fire—an exquisite device of the Managers,
superadded to the original story, and in striking harmony with Mozart’s music! Mr.
Liston’s Leporello was not quite what we wished it. He played it in a mixed style
between a burlesque imitation of the Italian Opera, and his own inimitable
manner. We like him best when he is his own great original, and copies only
himself—

‘None but himself can be his parallel.’

He did not sing the song of Madamira half so well, nor with half the impudence of
Naldi. Indeed, all the performers seemed, instead of going their lengths on the
occasion, to be upon their good behaviour, and instead of entering into their parts,
to be thinking of the comparison between themselves and the performers at the
Opera. We cannot say it was in their favour.

You might also like