Post comments on this article and find any associated files and/or downloads at
sections correspond to those shown in the block diagram
for an Arduino UNO’s ATmega328p in Figure 2.
Much of what you see in these illustrations is well
beyond the scope of this series, but they help understand
the general concept that there are separate entities on the
silicon that surround and work with the CPU.
So, in this boss/employee analogy, how does the boss
find out about the status of the employee’s work? There
are two ways to do this. One is for the boss to stop
working and go see what the employees are doing. In the
computer world, when the CPU (boss) checks on the
peripherals (employee), it is called polling.
The other way to do this is for the employees to knock
on the boss’ door and interrupt his workflow; for
computers this is called an interrupt. The boss responds to
the racket by setting the current work aside — perhaps
marking the task list so the work can be resumed when the
interruption is taken care of — then, the boss deals with the
interruption. Once it’s dealt with, the boss looks back at
the task list and resumes where the mark he left shows the
interruption occurred. For a computer interrupt, the CPU
A hardware interrupt can be generated by a voltage
change on either Arduino pin 2 or 3. We will use this to
detect when our light sensor indicates that — after being
dark— it suddenly becomes light again. Imagine a design
that is used only when the light comes on in a room.
The Arduino could sit there and continuously check
the light sensor (polling), or the light sensor could be
connected to a pin with hardware interrupt capability. This
way, the Arduino only has to deal with the light change
when a light change actually happens and sends an
interrupt to the CPU. We will use the Arduino
attachInterrupt library to do this in Lab 1.
A timer interrupt is generated when a timer reaches a
certain preset value. For example, you might program a
timer to interrupt the CPU after one second has passed.
We will use the Arduino TimerOne library to do this in
Lab 2. In later labs, we will use this kind of interrupt to
generate sound in the background while the CPU does
A musical tone is characterized by its pitch, duration,
intensity, and timbre. Pitch is a human perception based
on the frequency of a sound. Duration at its simplest is
the length of time for a musical note. Intensity is the
loudness. Timbre refers to perceived qualities of the tone
that differentiate between various musical sources. For
instance, a given pitch may be produced by both a violin
and a trumpet but the timbre is different.
Our piezo speaker has many problems associated
with creating a musical tone. The intensity of each pitch
varies significantly; far greater intensity for pitches are near
the resonant frequency (frequency that is physically
amplified by the box containing the piezo element) and
then are very diminished elsewhere. We do have decent
control over the duration, but the timbre can only be
described as awful — certainly not Hi-Fi (High Fidelity =
really good sound).
Nonetheless, we can use a piezo element to produce
something that people will generally recognize as music —
albeit awful sounding music, but still recognizable.
For our purposes here, music theory even in its most
elementary form is beyond the scope of what we are
trying to accomplish. We will thus just say that music
involves tones played for discrete periods of time.
An example of this would be the tune, Happy
Birthday which can be played with 26 notes — each held
58 December 2014
■ FIGURE 2: ATmega328p block diagram.