Professional Documents
Culture Documents
Robert Chin
McGraw-Hill Education books are available at special quantity discounts to use as premiums and sales
promotions or for use in corporate training programs. To contact a representative, please visit the Contact
Us page at www.mhprofessional.com.
Copyright © 2018 by McGraw-Hill Education. All rights reserved. Printed in the United States of America.
Except as permitted under the United States Copyright Act of 1976, no part of this publication may be
reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without
the prior written permission of the publisher.
McGraw-Hill Education, the McGraw-Hill Education logo, Evil Genius and TAB, and related trade dress
are trademarks or registered trademarks of McGraw-Hill Education and/or its affiliates in the United States
and other countries and may not be used without written permission. All other trademarks are the property
of their respective owners. McGraw-Hill Education is not associated with any product or vendor mentioned
in this book.
1 2 3 4 5 6 7 8 9 DSS 22 21 20 19 18 17
ISBN 978-1-260-01089-3
MHID 1-260-01089-9
e-ISBN 978-1-260-01090-9
e-MHID 1-260-01090-2
Sponsoring Editor
Michael McCabe
Editorial Supervisor
Donna M. Martone Production Supervisor
Lynn M. Messina
Acquisitions Coordinator
Lauren Rogers
Project Manager
Patricia Wallenburg, TypeWriting
Copy Editor
James Madru
Proofreader
Claire Splan
Indexer
Claire Splan
Art Director, Cover
Jeff Weeks
Composition
TypeWriting
Information contained in this work has been obtained by McGraw-Hill Education from sources believed to
be reliable. However, neither McGraw-Hill Education nor its authors guarantee the accuracy or
completeness of any information published herein, and neither McGraw-Hill Education nor its authors shall
be responsible for any errors, omissions, or damages arising out of use of this information.
About the Author
THIS CHAPTER WILL INTRODUCE YOU to the Arduino and the Raspberry Pi. First, I
give a brief explanation of what the Arduino is. Then I specifically address the
Arduino Uno, discussing its general features, including its capabilities and key
functional components. This is followed by a discussion of the Arduino
Integrated Development Environment (IDE) software, which is needed to
develop programs for the Arduino. Each key function of the Arduino IDE is
reviewed, followed by a hands-on example giving detailed step-by-step
instructions on how to set up the Arduino for development and how to run and
modify an example program using the Arduino IDE. Next comes the Raspberry
Pi. I discuss what the Raspberry Pi is and the specifications for the Raspberry Pi
3. This section tells you how to set up the Raspberry Pi before using it for the
first time. Raspberry Pi hardware features are addressed, including the general
purpose input-output (GPiO) pin specifications. The final section includes a
hands-on example of how to control a light-emitting diode (LED) using the
Raspberry Pi.
What Is an Arduino?
The Arduino is an open-source microcontroller that uses the C and C++
languages to control digital and analog outputs to devices and electronic
components and to read in digital and analog inputs from other devices and
electronic components for processing. For example, an Arduino can read a signal
from a sensor in a home security system that detects the heat that a human being
emits. The sensor sends a signal to the Arduino indicating that a person is in the
home. After receiving this information, the Arduino can send commands to a
camera such as the ArduCAM Mini digital camera to start taking pictures of the
intruder. There are many different Arduino models out there. However, to create
the examples in this book, you will need an Arduino model with enough pins to
connect the components you desire, such as a camera, Bluetooth adapter, and/or
motion sensor. Figure 1-1 shows the official Arduino logo.
Arduino Uno
There are a great many Arduino products out there, ranging from models that are
small and can actually be worn by the user to models with many digital and
analog input-output pins. For the projects in this book, I recommend the Arduino
Uno, which is an open-source microcontroller that has enough digital ports to
accommodate a camera, a Secure Digital (SD) card reader/writer with enough
digital and analog ports for other devices, sensors, lights, and any other gadgets
that you may require for your own custom projects. The official Arduino Uno
board is made by a company called Arduino SRL, formerly Smart Projects,
formed by one of the founders of the Arduino (Figure 1-2). The newer official
Arduino Uno boards are slightly different in that they are more blue-green
instead of blue in color and contain the Genuino logo under the main Arduino
logo. The Genuino trademark is used outside the United States as a result of the
split between Arduino founders.
Figure 1-2 The official Arduino Uno.
There are also unofficial Arduino Uno boards made by other companies. A
good way to tell whether a board is official or unofficial is by the color of a
component that is located near the Arduino’s USB port. This component on an
official Arduino board is a metallic gold color. The component on an unofficial
board is green. The writing on the components also differs (Figure 1-3).
Figure 1-3 Metallic gold colored component on an official Arduino Uno board.
Reset Button
There is a Reset button on the Arduino Uno that you can press to reset the board.
This restarts the program contained in the Arduino’s memory (Figure 1-7).
Digital Pins
The Arduino Uno has many digital pins capable of simulating analog output
through the process of pulse-width modulation (PWM). For example, a LED
light generally has only two modes: on (full brightness) and off (no light
emitted). However, with digital PWM, the LED light can appear to have a
brightness in between on and off. For instance, with PWM, a LED can start from
an off state and slowly brighten until it is at its highest brightness level and then
slowly dim until back to the off state. The digital pins on the Arduino Uno are
pins 0 through 13. These PWM-capable digital pins are circled in Figure 1-8.
Communication
The communication section of the Arduino Uno contains pins for serial
communication between the Arduino and other devices, such as a Bluetooth
adapter or a personal computer. The Tx0 and Rx0 pins are connected to the USB
port and are used for communication between your Arduino and your computer
by means of a USB cable. The Serial Monitor that can be used for sending data
to the Arduino and reading data from the Arduino uses the Tx0 and Rx0 pins.
Thus you should not connect anything to these pins if you want to use the Serial
Monitor to debug your Arduino programs or to receive user input (Figure 1-9). I
will talk more about the Serial Monitor later in this book.
Figure 1-9 Arduino Uno serial communication.
The I2C interface consists of an SDA pin (which is pin 4) that is used for
data and an SCL pin (which is pin 5) that is used for clocking or driving the
device or devices attached to the I2C interface. The SDA and SCL pins are
circled in Figure 1-10.
Figure 1-10 Arduino Uno I2C interface.
Analog Input
The Arduino Uno has six analog input pins that can read in a range of values
instead of just digital values of 0 or 1. The analog input pin uses a 10-bit analog-
to-digital converter to transform voltage input in the range of 0 to 5 V into a
number in the range between 0 and 1,023 (Figure 1-11).
Figure 1-11 Arduino Uno analog input.
Power
The Arduino Uno has outputs for 3.3 and 5 V. One section that provides power is
located on the side of the Arduino. You can also provide a separate power source
by connecting the positive terminal of the power source to the Vin pin and the
ground of the power source to the Arduino’s ground. Make sure that the voltage
being supplied is within the Arduino’s voltage range (Figure 1-12).
Figure 1-12 Arduino Uno 3.3- and 5-V power outputs.
The ground connections on the Arduino Uno are shown circled in Figure 1-
13.
Figure 1-13 Arduino Uno ground connections.
Windows
Windows Installer. This is an .exe file that must be run to install the Arduino
IDE.
Windows zip file for non-administrator install. This is a zip file that must be
uncompressed in order to install the Arduino IDE. 7-zip is a free file
compression and uncompression program available at www.7-zip.org that can
be used to uncompress this program.
An Important Note: For Windows XP, I recommend the 1.0.5 r2 version of the Arduino IDE.
Later versions may not be stable and may terminate unexpectedly, behave erratically, or
may not be able to compile Arduino source code.
Mac
Mac OS X 10.7 Lion or newer. This is a zip file that must be uncompressed
and installed for users of the Mac operating system.
Linux
Linux 32 bits. Installation file for the Linux 32-bit operating system.
Linux 64 bits. Installation file for the Linux 64-bit operating system.
The easiest and cheapest way to start Arduino development is probably by
using the Windows version on an older operating system such as Windows XP.
In fact, the examples in this book were created using the Windows version of the
Arduino IDE running on Windows XP. There are in fact many sellers on Ebay
from whom you can buy a used Windows XP computer for around $50 to $100.
If you are starting from scratch and are looking for an inexpensive development
system for the Arduino, consider buying a used computer with Windows XP. The
only caution is that support for Windows XP has ended in the United States and
some other parts of the world. In China, Windows XP may still be supported
with software updates such as security patches.
The Verify button checks to see whether the program you have entered into
the Arduino IDE is valid and without errors (Figure 1-15). These uncompiled
programs are called sketches.
Figure 1-15 The Verify button.
The Upload button first verifies that the program in the IDE is a valid C/C++
program with no errors, compiles the program into a form the Arduino can
execute, and then finally transfers the program via the USB cable connected to
your computer to your Arduino board (Figure 1-16).
The New File button creates a new blank file or sketch inside the Arduino
IDE, where you can create your own C/C++ program for verification,
compilation, and transfer to the Arduino (Figure 1-17).
The Open File button is used to open and load the Arduino C/C++ program
source code from a file or load various sample source codes from example
Arduino projects that are included with the IDE (Figure 1-18).
Another random document with
no related content on Scribd:
CONSTITUTION OF BELGIUM:
The working of its' electoral provisions.
CONSTITUTION OF CUBA:
The grant of autonomous government by Spain in 1897.
CONSTITUTION OF CUBA:
Outline of the draft reported to the Convention of 1900-1901.
CONSTITUTION OF IDAHO:
Adoption of Woman Suffrage.
CONSTITUTION OF LOUISIANA:
Its discriminating educational qualification.
{165}
ARTICLE 79.
ARTICLE 80.
Should the default of the President be absolute, the
substitute appointed by Congress shall terminate the
constitutional period.
ARTICLE 82.
The President, upon taking possession of his office, shall
swear before Congress under the following formula:
First.
Section III. of article 111 of the federal constitution is
amended, and an addition made to the said article in the
following terms: The States shall not—
{166}
Second.
Article 124 of the federal constitution is amended in the
following terms:
ARTICLE 124.
It is the exclusive faculty of the federation to obstruct
merchandise, imported or exported, or which passes in transit
through the national territory, likewise to regulate at all
times, and even to prohibit for reasons of policy and
security, the circulation within the Republic of all
merchandise from whatever source; but the said federation
cannot establish or decree in the district or federal
territories the taxes and laws expressed in Sections VI. and
V. of Article 111.
Transitory article.
These amendments and additions shall take effect on the 1st of
July, 1896.
{167}
ARTICLE 1.
This State shall bear the name of the South African Republic.
ARTICLE 2.
The form of government of this State shall be that of a
republic.
ARTICLE 3.
It desires to be recognized and respected by the civilized
world as an independent and free people.
ARTICLE 4.
The people seek for no extension of territory, and desire it
only in accordance with just principles, when the interest of
the Republic makes such extension desirable.
ARTICLE 5.
The people desire to retain and maintain their territory in
South Africa unimpaired. The boundaries thereof are fixed by
proclamation.
ARTICLE 6.
Its territory is open for every foreigner who obeys the laws
of this Republic. All who are within the territory of this
Republic have equal claims to protection of person and
property.
ARTICLE 7.
The land or farms situate in this territory which have not yet
been given out, are declared to be the property of the State.
ARTICLE 8.
The people claim the utmost social freedom, and expect the
result from the maintenance of their religious belief, from
the observance of their obligations, from submission to law,
order and right, and the maintenance of the same. The people
permit the spread of the Gospel among the heathen under fixed
precautions against deceit or misleading.
ARTICLE 9.
The people will not allow any equalization of the coloured
inhabitants with the white.
ARTICLE 10.
The people will not suffer any slave trade or slavery in this
Republic.
ARTICLE 11.
The people reserve to themselves the protection and defence of
the independence and inviolability of the State, subject to
the laws.
ARTICLE 12.
The people entrust the legislation to a Volksraad—the highest
authority in the land—consisting of representatives or
deputies of the people, chosen by the enfranchised burghers;
but with the reservation that a period of three months shall
be left to the people to enable them if they so wish to
communicate to the Volksraad their verdict on a proposed law;
except those laws which can suffer no delay.
ARTICLE 13.
The people charge the President with the task of proposing and
executing the laws; he also brings before the Volksraad the
appointments of all civil servants for ratification.
ARTICLE 14.
The people entrust the maintenance of order to the military
force, the police, and other persons appointed by the law for
that purpose.
ARTICLE 15.
The people place the judicial power in the hands of a Supreme
Court, Circuit Court, Landrosts, Juries, and such other
persons as shall be entrusted with judicial powers, and leave
all these free to discharge their function according to their
judgment and consciences, according to the laws of the land.
ARTICLE 16.
The people shall receive from the Volksraad an estimate of the
general income and expenses of the State, and learn therefrom
how much every man's taxes shall amount to.
ARTICLE 17.
Potchefstrom, situated on the Mooi River, shall be the capital
of the Republic, and Pretoria the seat of Government.
ARTICLE 18.
All services rendered on behalf of the public are remunerated
by the public.
ARTICLE 19.
Freedom of the press is granted provided the printer and
publisher remain responsible for all the documents which
contain defamation, insult, or attacks against anyone's
character.
ARTICLE 20.
The people shall only appoint as representatives in the
Volksraad those who are members of a Protestant Church.
ARTICLE 21.
The people desire the growth, prosperity, and welfare of the
State, and with this view provision for suitable school
teachers.
ARTICLE 22.
Providing also that in time of peace precautionary measures
are taken to enable the State to wage or withstand a war.
ARTICLE 23.
In case of a hostile attack from outside, everyone, without
distinction, shall be held bound to lend his assistance on the
promulgation of martial law. …
ARTICLE 26.
The Volksraad shall be the highest authority of the country,
and the legislative power.
ARTICLE 27.
No civil servants are to be representatives of the people.
ARTICLE 28.
The Volksraad shall consist of at least twelve members, who
must possess the following qualifications:-They must have
attained the age of thirty years, and be born in the Republic,
or have for fifteen consecutive years been burghers entitled
to vote, be members of a Protestant Church, reside, and
possess immovable property, in the Republic. No persons of
notoriously bad character, or who have had a dishonouring
sentence pronounced against them, and no uncertified or
unrehabilitated insolvents shall be eligible. They may not be
related to each other in the relationship of father and son or
stepson. No coloured persons or bastards shall be admitted
into our Assemblies. In like manner no military officer or
official of the State, who draws a fixed annual or monthly
salary, shall be eligible as member of the Volksraad.
ARTICLE 29.
The members of the Volksraad are elected by a majority of
votes from among the electors of each district. No one shall
be considered as elected who has not obtained at least sixty
votes. Everyone who is born in the country and has attained
the age of twenty-one years, or has become naturalized, shall
be a burgher qualified to vote. The members of the Volksraad
are elected for the period of four years. … [The above
provisions of the Constitution, relating to the Volksraad and
the representation of the people, were modified by the
following among other provisions of an Act of the Volksraad
passed in 1891:
ARTICLE 1.
The legislative power shall rest with a representation of the
people, which shall consist of a First Volksraad and a Second
Volksraad.
{168}
ARTICLE 2.
The First Volksraad shall be the highest authority in the
State, just as the Volksraad was before this law came into
operation. The First Volksraad shall be the body named the
Volksraad until this law came into operation. From the period
of this law coming into operation, the name of that body shall
be altered from the Volksraad to the First Volksraad. The
persons forming that body as members shall, however, remain
the same, only they shall, from the said period, be named
members of the First Volksraad instead of members of the
Volksraad. All laws and resolutions having reference to the
Volksraad and the members thereof shall remain in force and
apply to the First Volksraad and the members thereof, except
in so far as a change is or shall be made by this and later
laws. …
ARTICLE 4.
The number of the members of the Second Volksraad shall be the
same as of the First Volksraad. This number shall be fixed
later by the First Volksraad for both Volksraads. …
ARTICLE 9.
The members of the First Volksraad are chosen by those
enfranchised burghers who have obtained the burgher right,
either before this law came into operation, or thereafter by
birth, and have reached the age of sixteen years. The
franchise for the First Volksraad can besides also be obtained
by those who have during ten years been eligible for the
Second Volksraad, by resolution of the First Volksraad, and
according to rules to be fixed later by law.
ARTICLE 10.
The members of the Second Volksraad are chosen by all
enfranchised burghers who have reached the age of sixteen
years. …
ARTICLE 27.
The Second Volksraad shall have the power to pass further
regulations on the following subjects as is necessary, either
by law or resolution:
(1) The department of mines.
(2) The making and support of wagon and post roads.
(3) The postal department.
(4) The department of telegraphs and telephones.
(5) The protection of inventions, samples and trademarks.
(6) The protection of the right of the author.
(7) The exploitation and support of the woods and salt-pans.
(8) The prevention and coping with contagious diseases.
(9) The condition, the rights, and obligations of companies.
(10) Insolvency.
(11) Civil procedure.
(12) Criminal procedure.
(13) Such other subjects as the First Volksraad shall decide
later by law or resolution, or the First Volksraad shall
specially refer to the Second Volksraad.
ARTICLE 28.
All laws or resolutions accepted by the Second Volksraad are
as soon as possible, that is to say at the outside within
forty-eight hours, communicated both to the First Volksraad
and to the President.
ARTICLE 29.
The President has the right, when he has received notice from
the Second Volksraad of the adoption of a law or a resolution,
to bring that law or resolution before the First Volksraad for
consideration within fourteen days after the receipt of such
notice. The President is in any case bound, after the receipt
of such a notice, to communicate it to the First Volksraad
within the said time.
ARTICLE 30.
If the President has not brought the law or resolution as
communicated before the First Volksraad for consideration, and
the First Volksraad has not on its own part thought it
necessary to take said law or resolution into consideration,
the President shall, unless with the advice and consent of the
Executive Council he thinks it undesirable in the interests of
the State, be bound to have that law or resolution published
in the first succeeding Volksraad, unless within the said
fourteen days the First Volksraad may be adjourned, in which
case the publication in the "Stasts Courant" shall take place
after the lapse of eight days from the commencement of the
first succeeding session of the First Volksraad.
ARTICLE 31.
The law or resolution adopted by the Second Volksraad shall
have no force, unless published by the President in the
"Staats Courant."
ARTICLE 43.
The President shall bring forward for discussion the proposals
for laws which have come in before the Volksraad, whether the
latter have been made known to the public three months before
the commencement of the session, or whether the same have come
in during the session of the Volksraad.
ARTICLE 44.
When the notices of laws and Government notices to the public
have not been given in time, the President shall examine with
whom the blame of that delay lies. A Landrost found guilty
hereof shall have a fine of Rds. 50 inflicted and a
Field-Cornet or lesser official of Rds. 25. …
ARTICLE 56.
The executive power resides in the State President, who is
responsible to the Volksraad. He is chosen by a majority of
the burghers entitled to vote, and for the term of five years.
He is eligible for reelection. He must have attained the age of
thirty years, and need not be a burgher of the State at the
time of his nomination, and must be a member of a Protestant
Church, and have no dishonouring sentence pronounced against
him. [By a subsequent law the President must be chosen from
among the burghers.]
ARTICLE 57.
The President is the first or highest official of the State.
All civil servants are subordinate to him; such, however, as
are charged with exercise of the judicial power are left
altogether free and independent in its exercise.
ARTICLE 58.
As long as the President holds his position as such he shall
fill no other, nor shall he discharge any ecclesiastical
office, nor carry on any business. The President cannot go
outside the boundaries of the State without consent of the
Volksraad. However, the Executive Council shall have the power
to grant him leave to go outside the boundaries of the State
upon private affairs in cases of necessity. …
ARTICLE 60.
The President shall be discharged from his post by the
Volksraad after conviction of misconduct, embezzlement of
public property, treachery, or other serious crimes, and be
treated further according to the laws.
ARTICLE 61.
If in consequence of transgression of the Constitution or
other public misdemeanors the Volksraad resolve that the
President shall be brought to trial, he shall be tried before
a special court composed of the members of the High Court, the
President and another member of the Volksraad, while the State
Attorney acts as Public Prosecutor. The accused shall be
allowed to secure assistance of a lawyer at his choice.
ARTICLE 62.
The President is charged with the proposing of laws to the
Volksraad, whether his own proposals or others which have come
in to him from the people; he must make these proposals known
to the public by means of the "Staats Courant" three months
before presenting them to the Volksraad, together with all
such other documents as are judged useful and necessary by
him.
{169}
ARTICLE 63.
All proposals for a law sent in to the President shall, before
they are published, be judged by the President and Executive
Council as to whether publication is necessary or not.
ARTICLE 64.
The President submits the proposals for laws to the Volksraad,
and charges the official to whose department they belong first
and foremost, with their explanation and defence.
ARTICLE 65.
As soon as the President has received the notice of the
Volksraad that the proposed law is adopted, he shall have that
law published within two months, and after the lapse of a
month, to be reckoned from the publication, he shall take
measures for the execution of the same.
ARTICLE 66.
Proclamation of martial law, as intended in Article 23, shall
only be made by the President with the assent of the members
of the Executive Council. …
ARTICLE 67.
The President, with advice of the Executive Council, declares
war and peace, with reference to Article 66 of the
Constitution; the Government having first, if possible,
summoned the Volksraad before the declaration of war. Treaties
of peace require the ratification of the Volksraad, which is
summoned as soon as possible for that purpose. …
ARTICLE 70.
The President shall submit, yearly, at the opening of the
Volksraad, estimates of general outgoings and income, and
therein indicate how to cover the deficit or apply the
surplus.
ARTICLE 71.
He shall also give a report during that session of that
Volksraad, of his actions during the past year, of the
condition of the Republic and everything that concerns its
general interest. …
ARTICLE 75.
The President and one member of the Executive Council shall,
if possible, visit the towns and villages of the Republic
where Landrost's officers are, once in the year; he shall
examine the state of those offices, inquire into the conduct
of the officials, and on these circuits give the inhabitants
during their stay an opportunity to bring before him anything
they are interested in. …
ARTICLE 82.
The President exercises his power along with the Executive
Council. An Executive Council shall be joined to the
President, consisting of the Commandant-General, two
enfranchised burghers, a Secretary, and a Notekeeper
(notulenhouder), who shall have an equal vote, and bear the
title of members of the Executive Council. The Superintendent
of Native Affairs and the Notekeeper shall be ex-officio
members of the Executive Council. The President and members of
the Executive Council shall have the right to sit, but not to
vote, in the Volksraad. The President is allowed, when