Arduino Software Internals A Complete Guide to How Your Arduino Language and Hardware Work Together 2nd Edition Norman Dunbar pdf download
Arduino Software Internals A Complete Guide to How Your Arduino Language and Hardware Work Together 2nd Edition Norman Dunbar pdf download
https://ebookname.com/product/arduino-software-internals-a-
complete-guide-to-how-your-arduino-language-and-hardware-work-
together-2nd-edition-norman-dunbar/
https://ebookname.com/product/make-arduino-bots-and-gadgets-six-
embedded-projects-with-open-source-hardware-and-software-1st-
edition-tero-karvinen/
https://ebookname.com/product/arduino-cookbook-2nd-edition-
michael-margolis/
https://ebookname.com/product/beginning-arduino-2nd-edition-
michael-mcroberts-auth/
https://ebookname.com/product/evolution-what-the-fossils-say-and-
why-it-matters-2-edition-donald-r-prothero/
The Fisherman s Cause Atlantic Commerce and Maritime
Dimensions of the American Revolution 1st Edition
Christopher P. Magra
https://ebookname.com/product/the-fisherman-s-cause-atlantic-
commerce-and-maritime-dimensions-of-the-american-revolution-1st-
edition-christopher-p-magra/
https://ebookname.com/product/the-powerscore-gmat-critical-
reasoning-bible-a-comprehensive-system-for-attacking-the-gmat-
critical-reasoning-questions-1st-edition-david-m-killoran/
https://ebookname.com/product/a-course-in-mathematical-analysis-
volume-ii-metric-and-topological-spaces-functions-of-a-vector-
variable-1st-edition-d-j-h-garling/
https://ebookname.com/product/coaching-skills-1st-edition-jenny-
rogers/
https://ebookname.com/product/american-drama-in-the-age-of-
film-1st-edition-zander-brietzke/
Welfare States under Pressure 1st Edition Peter Taylor-
Gooby
https://ebookname.com/product/welfare-states-under-pressure-1st-
edition-peter-taylor-gooby/
MAKER
I N N O VAT I O N S
SERIES
Arduino
Software
Internals
A Complete Guide to How Your Arduino
Language and Hardware Work Together
—
Second Edition
—
Norman Dunbar
Maker Innovations Series
Jump start your path to discovery with the Apress Maker Innovations series! From the basics of
electricity and components through to the most advanced options in robotics and Machine Learning,
you’ll forge a path to building ingenious hardware and controlling it with cutting-edge software. All
while gaining new skills and experience with common toolsets you can take to new projects or even
into a whole new career.
The Apress Maker Innovations series offers projects-based learning, while keeping theory and
best processes front and center. So you get hands-on experience while also learning the terms of the
trade and how entrepreneurs, inventors, and engineers think through creating and executing hardware
projects. You can learn to design circuits, program AI, create IoT systems for your home or even city,
and so much more!
Whether you’re a beginning hobbyist or a seasoned entrepreneur working out of your basement
or garage, you’ll scale up your skillset to become a hardware design and engineering pro. And often
using low-cost and open-source software such as the Raspberry Pi, Arduino, PIC microcontroller,
and Robot Operating System (ROS). Programmers and software engineers have great opportunities
to learn, too, as many projects and control environments are based in popular languages and operating
systems, such as Python and Linux.
If you want to build a robot, set up a smart home, tackle assembling a weather-ready meteorology
system, or create a brand-new circuit using breadboards and circuit design software, this series has all
that and more! Written by creative and seasoned Makers, every book in the series tackles both tested
and leading-edge approaches and technologies for bringing your visions and projects to life.
Second Edition
Norman Dunbar
Rawdon
West Yorkshire, UK
Distributed to the book trade worldwide by Apress Media, LLC, 1 New York Plaza, New York, NY 10004, U.S.A. Phone
1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer-sbm.com, or visit https://www.springeronline.com. Apress
Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM
Finance Inc). SSBM Finance Inc is a Delaware corporation.
For information on translations, please e-mail booktranslations@springernature.com; for reprint, paperback, or audio rights,
please e-mail bookpermissions@springernature.com.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also
available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/
bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available to readers on Github
(https://github.com/Apress). For more detailed information, please visit https://www.apress.com/gp/services/source-code.
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 Arduino Installation Paths . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 Coding Style . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
1.2.1 Number Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3 The Arduino Language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.4 Coming Up . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2 Arduino Compilation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1 Settings.json . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
2.1.1 Finding Other Hidden Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.1.2 Setting Tab Stops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
2.2 Globally Defined Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
2.3 Boards.txt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.3.1 Arduino Uno Example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.4 Boards.local.txt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.5 Platform.txt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.5.1 Build Recipes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.5.2 Pre- and Post-Build Hooks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.6 Programmers.txt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.7 Compiling a Sketch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.7.1 Arduino Sketch (*.ino) Preprocessing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
2.7.2 Arduino Sketch (*.ino) Build . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.7.3 After the Build . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
2.8 The Arduino main() Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.9 Header File Arduino.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
2.9.1 Header File avr/pgmspace.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
2.9.2 Header File avr/io.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
2.9.3 Header File avr\interrupt.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
2.9.4 Header File binary.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
2.9.5 Header File WCharacter.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
2.9.6 Header File WString.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
2.9.7 Header File HardwareSerial.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
2.9.8 Header File USBAPI.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
2.9.9 Header File pins_arduino.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
2.10 The init() Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
2.10.1 Enabling the Global Interrupt Flag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
2.10.2 Enabling Timer 0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
vii
viii Contents
H NormDuino . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 367
I No ICSP? No Problem! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 371
J Breadboard 8 MHz Board Setup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 375
K AVRAssist . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 379
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 383
About the Author
xiii
About the Technical Reviewer
xv
Acknowledgments
I would like to thank everyone involved in the production of this book—the people you almost never
hear about. Without them, there would be no book.
I’m grateful to the following people at Apress/Springer:
Miriam Haidara who convinced me to update Arduino Software Internals to cover changes for the
new version of the IDE and software. Jessica Vakili who has had the misfortune to have worked with
me on three books now, thanks! Also, Joseph Quatela, James Markham, and Nirmal Selvaraj who kept
answering my silly questions!
The people who turned my manuscript into a proper book, who did the indexing for me, the people
running the print machines, and the cover designers. You never get named or mentioned, but authors
do appreciate you—thanks.
Finally, to my wife Alison and Wesley the cockapoo, thanks for letting me write an update and
keeping me exercised!
xvii
Preface
There are many books which discuss the abilities of the Arduino hardware and how best the maker
can use this to their benefit. I have many of them in my bookcase and digital versions on my phone
and tablet—in case I get bored with life and need something interesting to read. Many of these books
explain what the hardware does, and some even dig deeper into the hardware to explain how, in fairly
easy-to-understand terms, it does it.
There are no books which take a similar view of the Arduino software. There is now!
This book takes you on a journey (why do we always have to be on a journey these days?) into the
world of Arduino sketches and the various files involved in the compilation process. It will delve deep
into the supplied software and look at the specific parts of the Arduino Language which deal with the
underlying hardware, the ATmega328P (or ATmega328AU) microcontrollers—henceforth, referred
to as ATmega328P.
Once the Arduino Language has been explained, the book takes a short look at how you can
strip away the Arduino hand-holding and get down and dirty with the naked hardware. It’s not easy,
but equally it’s not too difficult. Don’t worry; this is still the C/C++ language; there’s no assembly
language required. Perhaps!
xix
Preface to the Second Edition
Since the first edition of Arduino Software Internals was published in 2020, the Arduino environment
has moved onward with new microcontroller boards being added, numerous bugs being fixed, new
bugs introduced—albeit, not deliberately—and many improvements made.
One of the bigger changes has been to the IDE itself; it is now at release 2.1.0 and has changed
completely from the old 1.x releases. It now provides a much more modern experience with code
completion, IntelliSense, and much, much more. It still has drawbacks—when you open a new sketch,
you get a new IDE—but progress has indeed been made in lots of areas.
Another big change is the Arduino Command Line Interface. It has moved on from version 0.6
to version 0.30, and it has become a very usable tool. A couple of major improvements that come
immediately to mind are the ability to upload code with an ICSP device and the ability to burn
bootloaders. It has improved so much that the Arduino IDE has replaced the old preprocessing and
compilation subsystems with the “arduino-cli” under the covers. Sadly, it still cannot upload EEPROM
data.
PlatformIO, another alternative to the Arduino IDE, has itself improved and now, at the time of
writing—May 2023—supports over 1,500 boards, 50 platforms, and 24 different frameworks, not to
mention over 13,400 libraries!
The standard IDE for use with PlatformIO is Visual Studio Code (VSCode) rather than Atom or
the command line, although those are still available. Don’t worry if you don’t like or use VSCode;
PlatformIO Core—the command-line option—can still generate project files for an even larger number
of common IDEs such as Atom, CLion, Code::Blocks, Eclipse, Emacs, NetBeans, Qt Creator, Sublime
Text, Vim, Visual Studio, and VSCode.
The first edition of this book occasionally mentioned Windows, and at that time, I had limited
access to Windows 7. The current version, as of May 2023, is Windows 11, but unfortunately, I no
longer have access to any versions of Windows.
I hope you find the second edition as useful as, if not more than, the first edition.
xxi
Introduction
1
The Arduino is a great system for getting people into making with electronics and microcontrollers. I
was reintroduced to a long-lost hobby when I was gifted an Arduino Duemilanove (a.k.a. 2009) by my
wife’s late grandmother, and since then, I’ve had lots of fun learning and attempting to build things.
I’ve even built a number of Arduino clones based on just AVR microcontrollers and a few passive
components—it’s cheaper than fitting a new Arduino into a project!
Much has changed over the intervening years; LEDs used to cost about £10 each and came in one
color, red. These days, I can get a pack of 100 LEDs for about £2 in various different colors. Even
better, my old faithful Antex 15W soldering iron still worked, even after 35 years. Sadly, after the first
edition was published, it finally died. I bought another one, exactly the same!
The Arduino—and I’m concentrating on either the Uno version 3 or the Duemilanove here
as those are two which I’ve actually purchased (or been given)—is based around an Atmel
ATmega328 microcontroller. On the Uno, it’s the ATmega328PAU, while the Duemilanove uses the
ATmega328PPU.
Roughly, the only difference between the two is the Uno’s ATmega328PAU version is a surface
mount, while the ATmega328PPU version is a 28-pin through-hole device. They are, or should be,
identical to program, although the ATmega328PAU version does have two additional analog pins that
are not present on the ATmega328PPU.
Occasionally though, I may mention in passing the Mega 2560 R3—as I have a cheap Chinese
clone of one of these—which is based on the Atmel ATmega2560 microcontroller.
Some older Arduino boards had the ATmega168 microcontroller, which also was a 28-pin through-
hole version, but it only had 16 Kb of flash memory as opposed to the 32 Kb in the later 328 chips.
The EEPROM and RAM size is also half that of the ATmega328P devices.
The Arduino was designed for ease of use, and to this end, the software and the “Arduino
Language” hides an awful lot from the maker and developer. Hopefully, by the time you have finished
reading this book, you will understand more about what it does and why and, when necessary, how you
can bypass the Arduino Language (it’s just C or C++ after all) and use the bare-metal AVR-specific
C or C++ code instead. Doing this can lead to more space for your code, faster execution, and lower
power requirements—some projects can be run for months on a couple of batteries.
The version of the Arduino IDE described in this book is 2.1.0. The version of the underlying Arduino
Language is 1.8.6.
I used an installation on Linux Mint while writing this book as Linux is my operating system of
choice, plus I do not have access to Windows anymore. The IDE was installed by downloading the
zip file version, as opposed to the flatpak version, and extracted. The location I extracted into is
• /home/norman/arduino-2.1.0/arduino-ide
On first execution, the IDE will create two new hidden directories—if they don’t already exist:
• /home/norman/.arduino15 which will contain the appropriate Arduino Language files for
your chosen board(s)
• /home/norman/.arduinoIDE which holds installation log files and is now where the IDE
preferences are stored
When I compiled a sketch for my Uno board, I was prompted to install the AVR package
required by my Uno. I agreed, and AVR package version 1.8.6 was installed into /home/norman/
.arduino15, which just happens to be the same location used by the 1.x version of the IDE.
The range of preferences offered by the new IDE is not as large as previous versions. Well, it seems
that that is the case, but all is not as it seems. This shall be explained soon!
Within this book, there are references to various files provided by the Arduino software. Because of
the way I’ve installed my software and the fact that the installer versions of the download may install to
a different location, most paths used in this book will be relative to /home/norman/.arduino15.
Paths used will be as follows:
When executing the IDE, it will be found in /home/norman/arduino-2.1.0/
arduino-ide where the downloaded zip file was extracted. However, most of the interesting
files, those for the Arduino Language, are to be found elsewhere.
• $ARDBASE is /home/norman/.arduino15, the location where the IDE installed the AVR
packages for the Uno and other AVR boards.
• $ARDINST is /home/norman/.arduino15/packages/arduino/hardware/avr/
1.8.6, the location of the main Arduino files for AVR microcontrollers. This is where the various
cores, bootloaders, and so on can be found, beneath this directory.
• $ARDINC is /home/norman/.arduino15/packages/arduino/hardware/avr/1.
8.6/cores/arduino, the location of many of the *.h header files and most of the *.
c and *.cpp files that comprise the Arduino Language for AVR microcontrollers. This is
$ARDINST/cores/arduino.
• $TOOLS is where the AVR tools reside in the downloaded packages for the AVR boards. Here, you
will find avrdude and the AVR Library which underlies a lot of the Arduino Language itself. On
my system, this is /home/norman/.arduino15/packages/arduino/tools.
• $AVRINC is where the header files for the version of the AVR Library provided by the Arduino
IDE are located. In the new IDE, these are now dependent on the version of the compiler in use—
avr-g++ by default—so the path can be quite convoluted.
The Arduino Language (eventually) compiles down to calling functions within the AVR
Library (henceforth referred to as AVRLib), and the header files are to be found in location
1.2 Coding Style 3
/home/norman/.arduino15/packages/arduino/tools/avr-gcc/xxxxx/avr/
include/avr.
Here, “xxxxx” is the avr-g++ compiler version and name, currently 7.3.0-atmel3.6.
1-arduino7, but this may change as new releases of the compiler are implemented by the IDE.
So, if you see a file referred to as $ARDINC/Arduino.h in the text, you will know that this
means the file
• /home/norman/.arduino15/packages/arduino/hardware/avr/1.8.6/cores/
arduino/Arduino.h on Linux.
You can see why I’m using abbreviations now, can’t you?
If you wish to examine the files on your system that I am discussing in the book, see Appendix A
for a couple of useful tips on how to avoid always having to type the full paths.
(1) This is a callout that attempts to bring your attention to something in the code which will be
described beneath the code listing in question.
(2) This is another callout; there can be more than one.
In the book’s main text, where you see words formatted like USCR0A or PORTB, then these are
examples of Arduino pin names, AVR microcontroller registers, bits within those registers, and/or
flags within the ATmega328P itself, as well as references to something listed in the data sheet for the
device. Where code listings are being explained, then variables from the code will be shown in this
style too.
Arduino pin numbers will be named Dn or An as appropriate. This is slightly different from the
normal usage of the digital pins, which normally just get a number; I prefer to be a little more formal
and give the digital pins their full title. <grin>
4 1 Introduction
Tip
Tips are exactly that. They give you a clue about something that may not be too well known in
the Arduino world, but which might be incredibly useful. (Or, maybe, just slightly useful!)
Note
This is a note. It brings your attention to something that may require a little more information.
It could be useful to pay attention to these notes. Maybe!
Warning
Warnings are there to highlight potential problems with something in the software or just
something that the data sheet needs you to take extra care over. There may be a possibility
of damage to your Arduino if you don’t pay particular attention. Occasionally, the data sheet
warns against doing something—so it’s best not to do what it says not to do!
Throughout this book, I need to refer to numbers in decimal, binary, or hexadecimal, from time to
time. To this end
Binary Binary numbers are written with a prefix of “0b” and a space every four bits, for
example, 0b0101 1011 0000 1101. All binary numbers will have this prefix, apart
from those which are single bit, that is, 0 and 1.
Hexadecimal Hexadecimal numbers are written with a prefix of “0x”. There are no spaces in
hexadecimal numbers, for example, 0x5B0E.
Decimal These numbers are written as you and I would normally write them, with no prefixes.
Commas will be used to separate the major groupings, for example, 23,310.
I should perhaps point out that there isn’t really such a thing as the Arduino Language. I may refer
to it frequently within the pages of this book, but technically, it doesn’t exist. What it is is simply an
abstraction of the C/C++ language, written in such a way as to make life easier for people learning to
make stuff with their Arduino. Which of the following is easier to understand?
digitalWrite(13, HIGH);
or
PORTB |= (1 << PORTB5);
1.4 Coming Up 5
The first is definitely the easiest to understand; however, the latter is by far the quicker of the
two as it just does what it says; it sets pin 5, on PORTB of the ATmega328P, to HIGH. The name,
digitalWrite(), appears to be a different language, but it isn’t; it’s that abstraction away from
plain AVR C/C++ which makes life easier for us all.
1.4 Coming Up
In Chapter 2, I explain how a sketch gets massaged into a proper C++ program and how the libraries
used in the sketch are incorporated into it. Following the brief overview of how compiling a sketch
operates, I then document the Arduino’s main() function, the various header files that it includes,
and the initialization carried out by the init() function. These initializations are part of every sketch
that you compile, so it helps if you know what the Arduino system is doing, hidden in the background,
just for you.
In Chapter 3, I explain about the features and facilities of the Arduino Language. This will include
all the commands such as pinMode(), digitalWrite(), and so on. I talk through all the
functions that relate to the Arduino, with particular emphasis on the code that applies to the standard
Arduino boards, those based on the ATmega328P family of AVR microcontrollers.
Chapter 4 looks into a number of the C++ classes (or objects) which are supplied with, and
used by, the Arduino Language. The classes of main interest here are the HardwareSerial
class which provides us with the Serial interface and its commands like Serial.begin() or
Serial.println(). However, the HardwareSerial class is not fully self-contained, so the
other, lesser known, supporting classes are also explained in this chapter.
Chapter 5 takes a brief look at how to cast off the bonds of the Arduino Language and delve into
the brazen world of AVR C++ itself, where you bypass the likes of pinMode() calls and talk to the
AVR microcontroller in something akin to its own language. Here, you will learn how you can set
the pinMode() for up to eight pins with a single instruction or how to digitalWrite() those
same eight pins, again with one instruction, and other efficient methods of communication with your
board.
Chapter 6 demonstrates a couple of alternatives to the Arduino IDE. Some people don’t get on
with it; I myself have a sort of love-hate relationship with it as I find versions 1.x of the editor a little
clumsy and slow for my liking. The new, improved versions 2.x of the IDE are much, much better,
however.
In this chapter, I will show you how you can write code for Arduino boards in both the Arduino
Language and plain AVR C/C++ code using the “PlatformIO” system and also give you a hefty
overview of the latest release of the arduino-cli utility used in versions 2.x of the IDE but available
for stand-alone use in Makefiles.
Chapter 7 is where I delve deeper into some features of the ATmega328P which, while not strictly
software, are fundamental to configuring the ATmega328P how you might like it and not as the
Arduino designers, however talented they may be, have decided.
In this chapter, I’ll be looking at the ATmega’s fuses, power reduction modes, sleep modes, and
similar features which determine how the ATmega328P works, but not necessarily what it does.
Chapters 8 and 9 are where I delve deeper into some more features of the ATmega328P which,
while not strictly software, are either important in understanding the Arduino Language or just useful
to know about. Hardware features such as the Analog Comparator (AC), Timer/counters—referred to
as timers henceforth—the Analog-to-Digital Converter (ADC), and the Universal Synchronous/Asyn-
chronous Receiver/Transmitter (USART) are covered in some detail.
6 1 Introduction
Finally, in the Appendixes, there are a number of topics that may be of interest or are kept together
in one place for reference. In here, you will find all the helpful reference material you might need,
such as pinout diagrams, and potentially useful (or unusual) code to upload to your Arduino.
There’s even an index!
Without any further ado, let’s dive in to what happens when you want to compile a sketch in the
Arduino IDE.
Arduino Compilation
2
This chapter is all about what happens when you compile an Arduino sketch and how the various
header files are used. Hopefully, by the time you have read (and understood) this part of the book,
you’ll have a much better idea of what happens during the compilation of an Arduino sketch. However,
before we dive into the gory details of a sketch’s compilation, we need to understand a bit about some
of the text files that live in and around the $ARDINST directory.
These files are used to set up the IDE’s menu options and to define the AVR microcontroller and
Arduino board to be used. Additionally, the IDE needs to know how to compile and upload sketches,
and with lots of different boards nowadays, not just those with AVR microcontrollers, these numerous
text files help the IDE configure the build tools and so on, for the specific board chosen from the
Boards menu in the IDE.
Once we have discussed the various text files, we can then get down and dirty in the compilation
process and also take a look at the hidden C++ files that the Arduino environment keeps well away
from us.
2.1 Settings.json
The file settings.json holds all the preferences for the Arduino IDE, and under versions
2.x of the IDE, it is found in /home/norman/.arduinoIDE which is a new hidden
directory, created on the first run of the version 2 IDE. On Windows, this would be
C:\Users\norman\.arduinoIDE.
You should be able to find the file after the first run of the IDE; if you have not yet done so, there
will not be a settings.json file to be found.
As you may have guessed, the file is in JSON format, which is still a text format, but has a different
layout to the preferences.txt file in previous versions of the IDE.
In the IDE, if you click File Preferences, a dialog will be displayed showing the current
preferences. These have been read from settings.json. Just like the old preferences.txt
file, there are limited preferences that can be set on this dialog. However, there are a lot more
preferences than meets the eye!
The new IDE has a hidden preferences system similar to that in VSCode. You access it via the
CTRL+SHIFT+P key combination. This opens a new search bar in the editor and waits for you to
type something. Type “settings” without the quotes, which will give you a number of options. For
example:
The last option will allow you to edit the settings.json file directly in the IDE; this is very
useful and, at times, quicker than using CTRL+SHIFT+P. The others all appear to display the same
dialog in the IDE, and there are numerous settings available, too many to be honest.
A small example of using this option follows where we will search for the current tab size and
change it to “4,” but inserting spaces instead of a hard TAB character.
Now, you would think that an editor, for writing code, would at least allow you the ability to easily
adjust the width of the tab stops—not so the Arduino IDE!
All is not lost, as we do have that ability, but it involves editing the settings.json file;
however, we don’t have to edit it manually. These instructions only apply to version 2.x of the IDE:
A new tab named “Preferences” will open in the IDE. There are two main options to the left side:
• User
• Workspace
The former will affect everything the current user does in the IDE; the latter will affect only the
current workspace or sketch.
• Click “User” and note that there are a number of categories of settings that can be changed.
• In the search box, type “tab size” without quotes. One of the displayed options is “Editor: Tab
Size.”
• Change the default of “2” to some other value that you prefer; I like four spaces, so I’ve configured
mine to be “4.”
Another useful setting to search for is “spaces.” This will allow you to configure the IDE to insert
spaces instead of actual tab characters. “Editor: Insert Spaces” is the appropriate setting.
Another Random Document on
Scribd Without Any Related Topics
Jacksonville, Fla., December 29, 1886.
Permission is hereby granted E. Wheaton and associates to
preach the gospel within the city limits at such places as they
may select; provided the streets and sidewalks are not
obstructed and the rights of private property are not disturbed
and there is no violation of City ordinances or statutes of the
State.
P. McQuaid, Mayor.
Josephine Cowgill.
Haifo, Palestine.
CONVERTED TO CHRIST.
A WONDERFUL CONVERSION.
BECAME A PREACHER.
One of the worst women I ever knew was converted in the spring of
1885 on the streets of Kansas City, Mo., where I was holding
meetings. She came to the meeting to abuse and ridicule me. She
heard my voice, she said, two blocks away, and became convicted.
She came to where I was standing on a box preaching. I asked if
there was any one there who would seek God and live a Christian
life. I said if there was one such, let them come and kneel with me
by the box and I would pray for them. She knelt there and cried
mightily to God for mercy. But she went away unsaved and prayed
and wept day and night. She could neither eat nor sleep. She saw
herself a lost sinner. Her father had been a minister of the Gospel,
but had died when she was very young. She had drifted to this
wicked city in search of work, and you may know the rest. For it is
but the story of many a poor orphan girl in her struggle for bread.
She fell as thousands fall with none to pity or care. She was driven
from one sin to another, until at last disgraced and filled with shame,
she had tried twelve times to take her own life. Thus I found her a
miserable woman. She came again to the meeting, this time alone,
and was gloriously saved, and is still saved so far as I know. She
became a successful preacher of righteousness, for she knew how to
reach such as she had been. She became a terror to evil doers,
brave in danger, and hopeful before discouraging obstacles. She has
since told me she has saved many young girls' lives and characters
by taking them in and giving them food and shelter when every
other door except brothels and saloons was closed against them.
Bless God for the homes open to shelter and protect the unfortunate
girls.
Once, in a city, another lady and myself were walking along a very
lonesome street late at night. When passing a large dark building
she remarked that it was a very dangerous gambling den. My heart
burned within me. I was seized with an impulse to go in that place
of iniquity and warn those men of their souls' danger. No sooner
thought than done! I was soon in the room which proved to be
vacant, but I could see light through the cracks of a closed door
leading into the next room. I passed quietly across the room and
opened the door and stood confronting a number of rough looking
men who were seated at a long gambling table. Without a word I
crossed the room with noiseless footsteps and dropping my Bible on
the table and falling on my knees before them began to cry to God
in their behalf. The men seemed to take an unexpected view of the
situation, and rising simultaneously to their feet, they rushed wildly
from the room upsetting their chairs in their haste, and I was left
alone. The next day the report went out that a ghost had been seen
there the night before, and some of the men vowed they would
never touch a pack of cards again as long as they lived—that money
could not hire them to do it. Truly "The wicked flee when no man
pursueth."
HURT BY A SALOONKEEPER.
IN JAIL.
I have several times been arrested for holding services in the open
air, but have been taken to prison but twice—once in Glasgow,
Scotland, as related elsewhere, and once in Belleville, Illinois.
In 1889, Sister Anna Kinne wrote me from Belleville that they were
holding meetings at that place, but had seen but little stir, that it
seemed to be a hard field, and that she believed the Lord wanted
me to come and help them in the meetings. I was, at the time, in
Mississippi, but after praying over the matter I felt that I should go
to Belleville in answer to her request.
The first Sabbath after reaching there I tried to hold services in the
open air, but was stopped by policemen. I tried again with the same
results. Then I went to the mayor, but was refused permission to
hold any such meetings. When I asked him if he would take the
responsibility on the day of judgment, he said, "Yes." I then went to
the jail and held services, and the sheriff kindly inquired about my
work and showed considerable interest, and took down some notes.
I then asked him for permission to hold meetings on the court house
steps. This was readily granted, and I took Sister Kinne with me. The
marshal of the town had bitterly opposed my work, and while we
were singing he very rudely and unceremoniously came and took me
by the arm and dragged me down from the steps.
I told him that the sheriff had given me permission to hold services,
but he was very angry and refused to let me go on.
I said to those who had gathered, "We will have no open air
meeting, but come to Buchanan Hall to-night, and we will have a
meeting there."
I think it was the following night that I was impressed just before
the opening of our services, to sing a hymn, standing in the mission
door. I spoke to Sister Kinne of this and she said, "God bless you,
Sister Wheaton, I will pray for you."
I went quietly down to the door and was standing there singing an
old-time hymn, when out of the darkness there came two
policemen. Without saying a word they took hold of me and dragged
me along the street. I had no bonnet on, and my shawl was
dragging along in the mud. I said, "Please let me get my shawl, and
will you please let me ask one of the ladies at the mission to go with
me?" But they refused and seemed glad to think that I was being
disgraced. As I met two or three Christian people, one of them
spoke kindly to me and I replied that I was suffering for Jesus' sake.
"You seem to be well acquainted with the men," one of the
policemen said. "No," I said, "only with a few Christians."
When we arrived at police headquarters they gave in the report that
I was on the street holding a meeting and was having a row, etc.,
which was, of course, utterly false.
I was, of course, surprised at the treatment I was receiving. I
opened my Bible, which I still held, and began reading in silence.
The officer said, "Are you making all of this ado and trouble?" I
replied, "I was standing in our mission door singing." He said, "Will
you give bail for your good behavior?" I said, "I have no money for
bail." Then he asked me if I had no friends. I told him I was a
stranger in the city. "Then," he said, "I will have to send you to jail,
or what will you do?" I said I did not know. He then told another
policeman to take me to the jail across the square, and only a few
blocks away. This policeman said to some boys who were standing
outside, "You boys stay here, we do not want a mob." But the
marshal said, "Go along boys. She wants notoriety—give it to her."
And so I went to the jail with a mob crying after me.
Arriving at the jail the kind jailor was shocked to see me in the
officer's charge, and said, "You are not a prisoner?" I said, "Yes, I
was singing in our mission door, but they arrested me." His wife
came in and kindly said, "Come into the parlor, and I will make ready
for you the spare bedroom." I was, of course, surprised and deeply
touched. "No, indeed," I said, "I am a prisoner. Take me into the cell
with the other women." Her little daughter came in and knelt down
by my side and kissed my hand, saying how very sorry she was for
me. It was on a Christmas eve, and the child was going to the
Christmas tree.
Soon the sheriff came in in a hurry and said, "You are a free
woman!" He, finding I had been arrested, had notified friends who
had given bail and secured my release. Not understanding the
sheriff, I said, "No, I am here in disgrace, and I want you to put me
in the woman's cell." But he insisted that I was free. Then I said,
"They have put me here in disgrace, and I want some one to come
and take me to our mission, as it is dark." They then sent for
someone to come for me, and such a shout as went up when I again
entered the mission hall. One good old Christian friend said, "I told
you that if she was a woman of God, and I knew she was, she would
return to the hall before the meeting was over."
It seems that a reporter who was at the police station at the time of
my arrest and heard the abuse of the officers had hurried to the
sheriff's office, and he, as I have said, had secured my release.
We give here a verbatim copy of the paper signed by friends, the
original of which I still have in my possession. Somehow the case
was dismissed, and I was never brought to trial:
ASSAULTED IN A DIVE.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookname.com