100% found this document useful (2 votes)
15 views

Arduino and Raspberry Pi Sensor Projects for the Evil Genius 1st Edition Chin instant download

The document provides an overview of the book 'Arduino and Raspberry Pi Sensor Projects for the Evil Genius,' which includes various projects and examples for using Arduino and Raspberry Pi. It covers topics such as programming languages, basic electrical components, and specific sensor projects, along with hands-on examples. The author, Robert Chin, has extensive experience in electronics and programming, making this book a practical guide for enthusiasts and learners in the field.

Uploaded by

diulyyatt
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
15 views

Arduino and Raspberry Pi Sensor Projects for the Evil Genius 1st Edition Chin instant download

The document provides an overview of the book 'Arduino and Raspberry Pi Sensor Projects for the Evil Genius,' which includes various projects and examples for using Arduino and Raspberry Pi. It covers topics such as programming languages, basic electrical components, and specific sensor projects, along with hands-on examples. The author, Robert Chin, has extensive experience in electronics and programming, making this book a practical guide for enthusiasts and learners in the field.

Uploaded by

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

Arduino and Raspberry Pi Sensor Projects for the

Evil Genius 1st Edition Chin install download

https://ebookmeta.com/product/arduino-and-raspberry-pi-sensor-
projects-for-the-evil-genius-1st-edition-chin/

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!

Raspberry Pi Electronics Projects for the Evil Genius


1st Edition Norris

https://ebookmeta.com/product/raspberry-pi-electronics-projects-
for-the-evil-genius-1st-edition-norris/

Beginning Sensor Networks with XBee, Raspberry Pi, and


Arduino, Second Edition: Sensing the World with Python
and MicroPython Charles Bell

https://ebookmeta.com/product/beginning-sensor-networks-with-
xbee-raspberry-pi-and-arduino-second-edition-sensing-the-world-
with-python-and-micropython-charles-bell/

Raspberry Pi Projects for Kids 1st Edition Daniel Bates

https://ebookmeta.com/product/raspberry-pi-projects-for-kids-1st-
edition-daniel-bates/

Swift Apprentice Seventh Edition Eli Ganim

https://ebookmeta.com/product/swift-apprentice-seventh-edition-
eli-ganim/
A Touch of Wrath Vices Virtues 1st Edition Daphne
Elliot

https://ebookmeta.com/product/a-touch-of-wrath-vices-virtues-1st-
edition-daphne-elliot/

Bonds of Secrecy Law Spirituality and the Literature of


Concealment in Early Medieval England The Middle Ages
Series Benjamin A. Saltzman

https://ebookmeta.com/product/bonds-of-secrecy-law-spirituality-
and-the-literature-of-concealment-in-early-medieval-england-the-
middle-ages-series-benjamin-a-saltzman/

A Rainy Day Story Ruth Calderon

https://ebookmeta.com/product/a-rainy-day-story-ruth-calderon/

The observational method in civil engineering:


minimising risk, maximising value First Edition
Powderham

https://ebookmeta.com/product/the-observational-method-in-civil-
engineering-minimising-risk-maximising-value-first-edition-
powderham/

Encyclopedia of Gender in Media 1st Edition Mary Kosut

https://ebookmeta.com/product/encyclopedia-of-gender-in-
media-1st-edition-mary-kosut/
Create Stunning Renders Using V-Ray in 3ds Max: Guiding
the Next Generation of 3D Renderers 1st Edition
Margarita Nikita

https://ebookmeta.com/product/create-stunning-renders-using-v-
ray-in-3ds-max-guiding-the-next-generation-of-3d-renderers-1st-
edition-margarita-nikita/
Arduino and Raspberry Pi Sensor
Projectsfor the Evil Genius™
Arduino and Raspberry Pi Sensor
Projects for the Evil Genius™

Robert Chin

New York Chicago San Francisco Athens London Madrid


Mexico City Milan New Delhi Singapore Sydney Toronto
Library of Congress Control Number: 201794884

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.

Arduino and Raspberry Pi Sensor Projects for the Evil Genius™

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

This book is printed on acid-free paper.

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

Robert Chin has a Bachelor of Science degree in computer engineering and is


experienced in developing projects on the TI CC3200 SimpleLink, Android,
Arduino, Raspberry Pi, and PC Windows platforms using C/C++, Java, Python,
Unreal Script, DirectX, OpenGL, and OpenGL ES 2.0. He is the author of Home
Security System DIY PRO Using Android and TI CC3200 SimpleLink, Home
Security Systems DIY Using Android and Arduino, and Beginning Arduino
ov7670 Camera Development. He is also the author of Beginning Android 3d
Game Development and Beginning IOS 3d Unreal Games Development, both
published by Apress, and was the technical reviewer for UDK Game
Development, published by Course Technology CENGAGE Learning. Beginning
Android 3d Game Development was licensed to Tsinghua University through
Tsinghua University Press.
Contents

1 Introducing the Arduino and Raspberry Pi


What Is an Arduino?
Arduino Uno
Arduino Uno Specifications
Arduino Uno Components
Arduino Development System Requirements
Arduino IDE Software
Hands-on Example:
A Simple Arduino “Hello World” Program with a LED
Playing Around with the Code
What Is Raspberry Pi?
Raspberry Pi 3 Hardware Overview
Raspberry Pi System Setup
Python IDLE Development Environment
Hands-on Example:
A Simple Raspberry Pi “Hello World” Program with a LED
Summary

2 Arduino and Raspberry Pi Programming Language Basics


Overview of the C/C++ Language for the Arduino
Object-Oriented Programming
Overview of Python for Raspberry Pi
Python Functions
Python Modules
Python Class Overview
Python Class Inheritance
Summary

3 Basic Electrical Components


Electronics Basics
Resistor
LEDs
Piezo Buzzer
Potentiometer
Push Buttons
Breadboards
Hands-on Example:
Arduino Serial Monitor and LED Indicator
Hands-on Example:
Arduino RGB LED
Hands-on Example:
Arduino LED Buzzer Siren
Hands-on Example:
Arduino Random RGB LED Colors Using a Potentiometer
Hands-on Example:
Arduino RGB Light Switch
Hands-on Example:
Raspberry Pi LED Blinker Counter
Hands-on Example:
Raspberry Pi LED Fading
Hands-on Example:
Raspberry Pi RGB LED Color Selector
Hands-on Example:
Raspberry Pi LED Fading Up and Down Using a Button
Summary

4 Touch Sensor Projects


Analog Joystick
Hands-on Example:
Arduino Joystick Test
Hands-on Example:
Arduino “Simon Says” Game
Running the Program
Rotary Encoder Controller (KY-040)
Hands-on Example:
Arduino Rotary Encoder Test
Hands-on Example:
Arduino Rotary Encoder Controlling an RGB LED
Hands-on Example:
Raspberry Pi Rotary Encoder Test
Hands-on Example:
Raspberry Pi Rotary Encoder LED Blinker
Summary

5 Environmental Sensor Projects I


Reed Switch Magnetic Field Sensor
Hands-on Example:
Arduino Reed Switch Test
Hands-on Example:
Arduino Door Buzzer Alarm
Hands-on Example:
Raspberry Pi Reed Switch Test
Hands-on Example:
Raspberry Pi Reed Switch Door Alarm
TMP36 Temperature Sensor
Hands-on Example:
Arduino TMP36 Temperature Sensor Test
Flame Sensor
Hands-on Example:
Arduino Flame Sensor Test
Hands-on Example:
Arduino Fire Alarm
Hands-on Example:
Raspberry Pi Flame Sensor Test
Hands-on Example:
Raspberry Pi Fire Alarm
Infrared Proximity/Collision Sensor
Hands-on Example:
Arduino Infrared Proximity/Collision Detector
Hands-on Example:
Raspberry Pi Infrared Collision/Proximity Sensor Alarm
Temperature and Humidity Sensor (DHT11)
Hands-on Example:
Arduino DHT11 Temperature and Humidity Sensor Test
Summary

6 Environmental Sensor Projects II


Water Detector/Soil Moisture Sensor
Hands-on Example:
Arduino Water Detector Alarm
Hands-on Example:
Arduino Soil Moisture Detector
Light Detector (Photo Resistor)
Hands-on Example:
Arduino Rooster Alarm
Sound Detector
Hands-on Example:
Arduino Light Clapper
Hands-on Example:
Raspberry Pi “Out of Breath” Game
Summary

7 Human Sensor Projects


Hands-on Example:
Arduino Glass Break Alarm
Hands-on Example:
Raspberry Pi Glass Break Alarm
HC-SR501 Infrared Motion Detector
Hands-on Example:
Arduino Infrared Motion Detector Alarm
Hands-on Example:
Raspberry Pi Infrared Motion Detection Alarm
HC-SR04 Distance Sensor
Hands-on Example:
Arduino HC-SR04 Distance Sensor Intruder Alarm
Hands-on Example:
Arduino Collision Alarm
Summary

8 Arduino TFT LCD Display and Image Sensor Projects


Arduino TFT LCD Color Display Screen with SD Card Reader/Writer
Hands-on Example:
Arduino TFT Display and SD Card Reader/Writer Test
Hands-on Example:
Arduino TFT Display Door Entry Alarm with SD Card Logging
Arduino Cameras
Hands-on Example:
Arduino ArduCAM OV2640 Mini Portable Programmable Digital Camera
System
Summary
Index
CHAPTER 1
Introducing the Arduino and Raspberry Pi

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.

Figure 1-1 Official Arduino logo.

Note: The official website of the Arduino is www.arduino.cc.

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.

A number of other companies also manufacture Arduino Uno boards.


Because the Arduino is an open-source item, other companies can legally
manufacture the board, and the boards vary in quality and price. Generally, an
unofficial Arduino Uno costs around $10, and an official Arduino Uno costs
around $20. The distinguishing parts of an official Arduino board are the golden
component and the high-quality Arduino and Genuino logos printed on the board
(Figure 1-4).
Figure 1-4 Key parts of an official Arduino Uno.

Arduino Uno Specifications


Microcontroller: ATmega328P
Operating voltage: 5 V
Input voltage (recommended): 7–12 V
Input voltage limit: 6–20 V
Digital I/O pins: 14 (of which 6 provide PWM output) PWM digital I/O pins:
6
Analog input pins: 6
DC current per I/O pin: 20 mA DC current for 3.3-V pin: 50 mA Flash
memory: 32 kB (ATmega328P) (of which 0.5 kB used by boot loader)
SRAM: 2 kB (ATmega328P) EEPROM: 1 kB (ATmega328P) Clock
speed: 16 MHz Length: 68.6 mm Width: 53.4 mm Weight: 25 g

Arduino Uno Components


This section covers the functional components of the Arduino Uno.

USB Connection Port


The Arduino Uno has a USB connector that is used to connect the Arduino to the
main computer development system via standard USB A male to B male cable
so that it can be programmed and debugged (Figure 1-5).

Figure 1-5 USB connector.

9-V Battery Connector


The Arduino Uno has a 9-V battery connector where you can attach a 9-V
battery to power the Arduino (Figure 1-6).
Figure 1-6 Arduino Uno 9-V battery connector.

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).

Figure 1-7 Arduino Uno Reset button.

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.

Figure 1-8 Arduino Uno digital pins.

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.

Arduino Development System Requirements


Arduino projects can be developed on Windows, Mac, and Linux operating
systems. The software needed to develop programs that run on the Arduino can
be downloaded from the main website at www.arduino.cc/en/Main/Software.
The following is a summary of the different types of Arduino IDE
distributions that are available for download. You will only need to download
and install one of these files. The file you choose will depend on the operating
system your computer is using.

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.

Arduino IDE Software


Arduino IDE is the program used to develop the program code that runs on and
controls the Arduino. For example, to have your Arduino control the lighting
state of a LED, you will need to write a computer program in C/C++ using the
Arduino IDE. Then you will need to compile the program into a form that the
Arduino is able to execute and then transfer the final compiled program using
the Arduino IDE. From there the program automatically executes and controls
the LED that is connected to the Arduino.
New versions of the Arduino IDE are compiled daily or hourly and are
available for download. Older versions of the IDE are also available for
downloading at www.arduino.cc/en/Main/OldSoftwareReleases.
This section discusses the key features of the Arduino IDE software. The
IDE you are using may be slightly different from the version discussed in this
section, but the general functions should still be the same. I won’t go in depth
into every detail of the IDE because this section is meant as a quick-start guide
and not a reference manual. I will cover the critical features of the Arduino IDE
that you will need to get started on the projects in this book (Figure 1-14).
Figure 1-14 The Arduino IDE.

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).

Figure 1-16 The Upload button.

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).

Figure 1-17 The New File button.

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).
Figure 1-18 The Open File button.

The Save button saves the sketch on which you are currently working to
disk. A File Save dialog is brought up first, and then you will be able to save the
file on your computer’s hard drive (Figure 1-19).

Figure 1-19 The Save button.

The Serial Monitor button brings up the Serial Monitor debug program,
where you can examine the output of debug statements from the Arduino
program. The Serial Monitor can also accept user input that can be processed by
the Arduino program (Figure 1-20). I will discuss the Serial Monitor and how to
use it as a debugger and input console later in this book.

Figure 1-20 The Serial Monitor button.

The main window of the Arduino IDE also includes other important features.
The title bar of the IDE window contains the Arduino IDE version number. In
Figure 1-21, the Arduino version number is 1.0.5 r2. The sketch name is
displayed in the source code tab and is “Blink,” which is one of the sample
sketches that comes with the Arduino IDE. The source code area, which is the
large white area with scrollbars on the right side and bottom, is where you enter
your C/C++ source code that will control the behavior of the Arduino. The
bottom black area in the IDE is where warning and errors are displayed from the
code verification process. At the bottom left-hand corner of the IDE is a number
that represents the line number in the source code where the user’s cursor is
currently located. In the lower right-hand corner of the IDE is the currently
selected Arduino model and COM port to which the Arduino is attached.

Figure 1-21 The general IDE.


Hands-on Example:
A Simple Arduino “Hello World” Program with a
LED
In this hands-on example, I will show you how to set up the Arduino
development system on your Windows-based PC or Mac. First, you need to
obtain an Arduino board and USB cable. Then you must install the Arduino IDE
and Arduino hardware device drivers. Then I will show you how to load in the
“Blink” example sketch. I tell you how to verify that the program is without
syntax errors, how to upload it onto the Arduino, and how to tell whether the
program is working. Finally, I discuss how the Blink program code works and
show you how to modify it.

Get an Arduino Board and USB Cable


You can purchase an official Arduino Uno board from a distributor listed on
www.arduino.cc/en/Main/Buy or www.Arduino.org. The first website is still
generally considered the main website for Arduino. However, the second website
is run by the people actually making Arduino boards. The split among the
founders of the Arduino mentioned earlier can be seen here in terms of who is
designated as a distributor of an “official” Arduino board.
A second option is to buy an unofficial Arduino Uno made by a seller not
listed as an official distributor by either arduino.cc or arduino.org. These boards
are generally a lot cheaper than “official” Arduino boards. However, the quality
may vary widely between manufacturers or even between production runs of the
same manufacturer.
Official Arduino boards generally do not come with a USB cable, but many
unofficial boards do come with a short USB cable. Longer Arduino-compatible
USB cables (such as 6- or 10-foot cables) can be bought on Amazon.com or
eBay.com. I purchased a “Mediabridge USB 2.0 – A Male to B Male Cable (10
Feet) – High-Speed with Gold-Plated Connectors – Black” from Amazon.com
for my “official” Arduino Uno, and its seems to work well. Make sure that you
get the right kind of USB cable with the right connectors on each end. The
rectangular end of the USB cable is connected to your computer, and the square
end is connected to your Arduino (Figure 1-22).
Figure 1-22 Arduino USB cable.

Install the Arduino IDE


The Arduino IDE has versions that can run on Windows, Mac, and Linux
operating systems. The Arduino IDE can be downloaded from
www.arduino.cc/en/Main/Software. I recommend installing the Windows-
executable version if you have a Windows-based computer. Follow the
directions in the pop-up windows.

Note: The Arduino website also contains links to instructions for installing the Arduino IDE
for Windows, Mac, and Linux at www.arduino.cc/en/Guide/HomePage. The installation for
Linux depends on the exact version of Linux being used.

Install the Arduino Drivers


The next step is to connect your Arduino to your computer using the USB cable.
If you are using Windows, it will try to automatically install your new Arduino
hardware. Follow the directions in the pop-up windows to install the drivers.
Decline to connect to Windows Update to search for drivers. Select “Install the
software automatically” as recommended. If you are using XP, ignore the pop-up
window warning about the driver not passing Windows logo testing to verify its
compatibility with XP.
If this does not work, then instead of selecting “Install the software
automatically,” specify a specific driver location, which is the “drivers/FTDI”
directory under your main Arduino installation directory.
Load the “Blink” Arduino Sketch Example
Next, we need to load the “Blink” sketch example into the Arduino IDE. Click
the Open file button to bring up the menu. Under “01. Basics,” select the “Blink”
example to load (Figure 1-23).

Figure 1-23 Loading the “Blink” sketch.

The code that is loaded into the Arduino IDE should look like the code in
Listing 1-1.

Listing 1-1 ”Blink” Sketch


/*
Blink
Turns an LED on for one second, then off for one second, repeatedly.
This example code is in the public domain.
*/

// Pin 13 has an LED connected on most Arduino boards.


// give it a name:
int led = 13;

// the setup routine runs once when you press reset:


void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

Verify the “Blink” Arduino Sketch Example


Click the Verify button to verify that the program is valid C/C++ code and is
error-free (Figure 1-24).

Figure 1-24 Verifying the “Blink” sketch.

Upload the “Blink” Arduino Sketch Example


Before uploading the sketch to your Arduino, make sure the type of Arduino
under the “Tools > Board” menu item is correct. In our case, the board type
should be set to be “Arduino Uno” (Figure 1-25).

Figure 1-25 Set the Arduino type to “Arduino Uno.”


Next, make sure that the serial port is set correctly to the one that is being
used by your Arduino. Generally, Com1 and Com2 are reserved, and the serial
port to which the Arduino will be connected is Com3 or higher (Figure 1-26).

Figure 1-26 Set the serial (Com) port.

If you are using a Mac, then the serial port selection should be something
like “/dev/tty.usbmodem” instead of a COMxx value.
Next, with the Arduino connected, press the Upload button to verify,
compile, and then transfer the “Blink” example program to the Arduino. After
the program has finished uploading, you should see a message that the upload
has been completed in the Warnings/error window at the bottom of the IDE
inside the black window (Figure 1-27).

Figure 1-27 Upload to the Arduino.

Note: The Upload button does the job of the Verify button and also uploads the final
compiled program to the Arduino.
Final Result
The final result will be a blinking light on the Arduino board near digital pin 13.
By design, the Arduino board has a built-in LED connected to pin 13. So this
example did not require you to connect an actual separate LED to the Arduino
board (Figure 1-28).

Figure 1-28 Built-in LED.

Playing Around with the Code


The default of the program is to turn on the LED for 1 second and then turn it off
for 1 second. The code that controls the timing is located in the loop() function.
The digitalWrite() function sets the variable LED, which is pin 13, to either
on, which is HIGH, or off, which is LOW. The delay() function suspends
execution of the program for 1,000 milliseconds, or 1 second, so that the LED is
set on for 1 second and off for 1 second (Listing 1-2).

Listing 1-2 loop() Function


void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}

Play around with the values in the delay() functions, lengthening or


shortening the time the LED stays on and/or lengthening or shortening the time
the LED stays off. For example, to have the LED flash briefly, shorten the first
delay value to 100. This will shorten the time that the LED stays on. Upload the
new sketch to the Arduino by pressing the Upload button. After it has finished
uploading, you will see a message in the black Warnings/error message window
at the bottom of the IDE. Look at the LED on the Arduino. The timing of the
LED on/off pattern should have changed.

What Is Raspberry Pi?


Raspberry Pi is a small, inexpensive computer based on the Linux operating
system. The computer itself sells for around $35 and was originally designed as
a learning tool to get young people and students interested in pursuing a career in
computer programming. The official website for the Raspberry Pi is located at
www.raspberrypi.org.

Raspberry Pi 3 Model B
Many models of the Raspberry Pi have been produced, but the type of Raspberry
Pi that I will use in this book is the newest and most popular Raspberry Pi: the
Raspberry Pi 3 Model B. This model replaces the Raspberry Pi 2 and is
recommended for use in schools and for general purpose use. For those who
want to embed a Raspberry Pi as part of a larger project or require a Raspberry
Pi that uses low power, then the Raspberry Pi 0 or Model A+ is recommended.
The specifications of the Raspberry Pi 3 Model B are as follows:
1.2-GHz 64-bit quad-core ARMv8 CPU
802.11n wireless LAN
Bluetooth 4.1
Bluetooth Low Energy (BLE) 1-GB RAM
Four USB ports 40 GPiO pins Full HDMI port Ethernet port Combined
3.5-mm audio jack and composite video Camera interface (CSI) Display
interface (DSI)
Micro SD card slot (now push-pull rather than push-push) VideoCore IV 3D
graphics core

Raspberry Pi 3 Hardware Overview


The Raspberry Pi 3 is manufactured as a small single board similar to the size of
a credit card without a case containing all the above-mentioned components
(Figure 1-29).

Figure 1-29 Top view of the Raspberry Pi 3 hardware layout.

The Raspberry Pi 3 consists of the following major components, which are


labeled in Figure 1-29 as:
Item 1: Two USB ports stacked on top of each other Item 2: A second set of
two USB ports stacked on top of each other Item 3: Ethernet socket for
connecting to a network router Item 4: A 3.5-mm jack for audio and video
output to a monitor or television Item 5: An MIPi camera serial interface
(CSI) Item 6: A High Definition Multimedia Interface (HDMI) port for
video output to a monitor or television Item 7: GPiO pins that will be used
to connect sensor devices to the Raspberry Pi in this book Item 8: A Display
Serial Interface (DSI) that is used to connect the Raspberry Pi to a liquid-
crystal display (LCD) Item 9: A micro USB socket used for power input to
the Raspberry Pi
The bottom of the Raspberry Pi 3 contains a micro SD card reader/writer that
serves as a storage device like a hard drive would on a desktop computer. The
micro SD stores the Raspberry Pi’s operating system, program applications, and
data generated by the program applications and the user. On the Raspberry Pi 3,
the micro SD card reader/writer is of the push-pull type. This means that you
will need to push the SD card into the slot to have the SD card be read from and
written to, and then you will need to pull the card out to remove it from the SD
card slot (Figure 1-30).

Figure 1-30 Bottom view of the Raspberry Pi 3.

With the Raspberry Pi oriented like the one in Figure 1-29, the GPiO pin
specifications are as shown in Figure 1-31.
Figure 1-31 Raspberry Pi 2 and Raspberry Pi 3 GPiO pin numbering.

The symbols on the pins denote the following:


5V: This is a 5-V output source from the Raspberry Pi that can be used to
power your custom circuit.
3.3V: This is a 3.3-V output source from the Raspberry Pi that can be used to
power your custom circuit.
G: Ground pin.
EE: EEPROM-related pin (which will not be used in this book).
Number: This is the number of the GPiO pin.

Raspberry Pi System Setup


This section will tell you what you will need to set up your Raspberry Pi
computer system and how to perform the actual setup. At the bare minimum,
you will need
A Raspberry Pi 3 board A USB keyboard A USB mouse A micro USB
power adapter that can provide 2.5-A power An HDMI-compatible monitor
or TV (which I recommend) or a monitor with composite inputs or a VGA
monitor and an HDMI-to-VGA adapter (I recommend an HDMI monitor
because it provides sharp resolution and sound output. The composite output is
of a lower-quality resolution, and using a VGA monitor with a Raspberry Pi
requires you to make some changes to the Raspberry Pi’s configuration file.)
A micro SD card with new out of box software (NOOBS) on it Preferably
some kind of case for your Raspberry Pi 3 board to protect it against static
electricity and small spills of liquid
If you are just beginning in Raspberry Pi development, then I recommend
that you get one of the Raspberry Pi 3 starter kits, which are widely available
online on such websites as Amazon.com. Many of the starter kits have all of the
items listed above. In addition, if you do not have an HDMI monitor, you can
usually find a small one for around US$50 on Amazon.com. These monitors are
generally around 10 inches in display size and can be used as portable monitors
for your Raspberry Pi 3 system.
To start using your Raspberry Pi, you should
1. Connect the keyboard, mouse, and HDMI monitor to your Raspberry Pi.
2. Insert your SD card with the NOOBS into the Raspberry Pi’s micro SD card
reader/writer.
3. Turn on your Raspberry Pi by plugging in the micro USB power adapter. An
important thing to note is that the Raspberry Pi does not have an on/off switch.
4. The NOOBS setup program will start running. This program will install the
actual Raspberry Pi operating system, which is called Raspbian. Follow the
directions that appear on the screen to install the software. You should see a
pop-up window that looks like the one shown in Figure 1-32. Check the box
next to the Raspbian selection, and click on the Install button.

Figure 1-32 The NOOBS operating system installation screen.

Python IDLE Development Environment


The programming language that we will be using in this book for projects
involving the Raspberry Pi is the Python programming language. The Raspberry
Pi has a Python development environment called IDLE. IDLE provides you with
a read-evaluate-print-loop (REPL) that allows you to continuously enter Python
statements and have them executed by the Python language. The output of these
statements is also displayed within IDLE. You can start the Python IDLE
program by clicking on “Python 3” under the Menu > Programming menu
(Figure 1-33).

Figure 1-33 The Python 3 development environment.

From within the IDLE program you can also create and save new files. An
alternative to using IDLE to create Python programs is to use a text editor such
as Vim, Nano, or LeafPad and execute the Python program by typing “python
filename.py” on the command line.

Hands-on Example:
A Simple Raspberry Pi “Hello World” Program
with a LED
This section presents a simple hands-on example of creating a blinking LED
using the Raspberry Pi 3.
Parts List
For this hands-on example, you will need
One LED
One breadboard Two wires with one end having a female plug to connect to
the Raspberry Pi’s GPiO pins and the other end having a male plug to connect
to the breadboard

Setting Up the Hardware


1. Insert the short leg of the LED, which is the negative side, into a hole on the
breadboard.
2. Insert the long leg of the LED, which is the positive side, into a different hole
on the breadboard that is disconnected from the node in step 1. Note:
Breadboards generally have horizontal rows of nodes of about five holes each
that are connected together. Some breadboards have a positive row of holes
that are connected together and a negative row of holes that are connected
together.
3. Attach a wire from a ground pin on the Raspberry Pi to the ground node on the
breadboard that contains the negative side of the LED.
4. Attach a wire from GPiO pin number 14 to the node on the breadboard that
contains the positive side of the LED.

Figure 1-34 shows a simplified graphic representation of how to hook the


LED up to the Raspberry Pi 3 board.
Figure 1-34 Blinking LED on a Raspberry Pi 3 board.

Setting Up the Software


Now you will need to set up the software that will run on the Raspberry Pi itself
to control the hardware you just set up. In order to control the blinking of a LED
from the Raspberry Pi, you need to do the following:
1. Import the LED class from the gpiozero library.
2. Import the sleep function from the time library.
3. Create a new LED object that is connected to GPiO pin 14, and then assign
this object to the led variable.
4. Execute the following in an infinite loop: a. Turn the LED on by calling the
led.on() function.

b. Wait for 1 second by calling the sleep() function with 1 as a parameter.


c. Turn off the LED by calling the led.off() function.
d. Wait for 1 second by calling the sleep() function with 1 as a parameter.
See Listing 1-3.

Listing 1-3 Blinking LED


from gpiozero import LED
Random documents with unrelated
content Scribd suggests to you:
Here is no Day, nor minute of the Day,
In which, there are not many sent away
From Life to Death; or, many drawing-on,
Which, must within a little while, bee gone.
You, often, view the Grave; you, often, meet
The Buriers, and the Mourners, in the street,
Conveying of some Neighbour, to that home,
Which must, e're long, your dwelling-place become.
You see the Race, of many a youthfull Sonne
Is finish'd, e're his Father's Course is done;
And, that, the hand of Death, regardeth neither
Sexe, Youth, nor Age; but, mingleth all together.
You, many times, in your owne houses, heare
The groanes of Death, and, view your Children, there,
Your loving Parents, or, beloved Wives,
To gaspe for breath, and, labour for their lives.
Nay, you your selves, do sometime find the paines
Of Sicknesse, in your Bowels, and your Vaines.
The Harbingers of Death, sometime, begin
To take up your whole Bodie, for their Inne.
You beare their heavie Aches, on your back;
You feele their twinges, make your heartstrings crack;
And, sometime, lye imprison'd, and halfe dead,
With Age, or with Diseases, on your bed:
Yet you deferre your ends; and, still contrive,
For temp'rall things; as if you thought to live
Sixe Ages longer: or, had quite forgot,
That, you, and others, draw one common-Lot.
But, that, you might not, still, the same forget,
This Emblem, and this Motto, here were set.
Finis Libri tertij.
THE THIRD
LOTTERIE.

1
he Wreathes of Glory, you affect,
But, meanes to gaine them, you neglect;
And, (though in doing, you delight)
You doe not, alwayes, what is right:
Nor are you growne, as yet, so wise,
To know, to whom the richest Prize
Doth appertaine; nor what it is.
But, now, you are inform'd of This.
See, Emblem I.

2
Though you are weake, you much may doe,
If you will set your Wits thereto.
For, meaner Powres, than you have had,
And, meaner Wits, good shift have made,
Both to contrive, and compasse that,
Which abler men have wondred at.
Your Strength, and Wit, unite, therefore,
And, both shall grow improov'd the more.
See, Emb. II.

3
Perhaps, thou mayst be one of them,
Who, Civill Magistrates contemne;
And sleighteth, or else, flouteth at
The Ceremonies of Estate.
That, thou maist, therefore, learne to get,
Both better Manners, and more Wit,
The Sword, and Mace, (by some despiz'd)
Is, for thy sake, now moralliz'd.
See, Emb. III.

4
By this thy Lot, wee may misdoubt,
Thou look'st not warily about;
But, hudlest onward, without heed,
What went before, or may succeed;
Procuring losse, or discontent,
Which, Circumspection, might prevent.
Therefore, with gratefulnesse, receive
Those counsells, which our Moralls give.
See, Emb. IV.

5
Thou hast, unworthily, repin'd,
Or, been displeased in thy mind,
Because, thy Fortunes doe not seeme
To fit thy Worth (in thy esteeme:)
And loe, to check thy discontent,
Thy Lot, a Morall, doth present;
And shewes, that, if thou vertuous bee,
Good-Fortune, will attend on thee.
See, Emb. V.

6
When thy Desires have good successe,
Thine owne Endeavors, thou dost blesse;
But, seldome unto God thou giv'st
Due thanks, for that, which thou receiv'st.
Thine Emblem, therefore, tells from whom
The fruits of good Endeavours, come:
And, shewes (if thou to thrive intend)
On whom, thou, alwayes, must depend.
See, Emb. VI.

7
It may bee, thou art one of those,
Whose Faith, more bold, than fruitfull growes;
And (building on some false Decree)
Disheartnest those, that Workers be
To gaine (with awfull-joy) that PriZe,
Which, unto no man, God denies,
That workes in Hope; and, lives by Faith.
Marke, therefore, what thine Emblem saith.
See, Emb. VII.

8
Thou hast been willing, that thy Name,
Should live the life of Honest-Fame;
And, that, thy labours (to thy praise)
Continue might, in future dayes.
Behold; the Lot, thou hapnest on,
Hath showne, how this may well bee done.
Pursue the Course, which there is taught,
And, thy desires to passe are brought.
See, Emb. VIII.

9
Thou, many things, hast well begun;
But, little, to good purpose, done:
Because, thou hast a fickle braine,
And, hands that love to take no paine.
Therefore, it chanceth not amisse,
That, thou hast such a Chance, as this:
For, if thou want not Grace, or Wit,
Thou maist, in time, have good of it.
See, Emb. IX.

10
Whatev'r you seeme to others, now,
It was the Harrow, and the Plough,
By which, your Predecessors got,
The fairest portion of your Lot:
And, (that, it may encrease your Wit)
They haunt you, in an Emblem, yet.
Peruse our Morall; and, perchance,
Your Profit, it will much advance.
See, Emb. X.

11
Much labour, and much time you spend,
To get an able-constant Friend:
But, you have ever sought him, there,
Where, no such precious Iewells are:
For, you, without have searching bin,
To finde, what must be found within.
This Friend, is mention'd by this Lot,
But, God knowes where he may be got.
See, Emb. XI.

12
Thou seek'st for Fame; and, now art showne,
For what, her Trumpet shall be blowne.
Thine Emblem, also, doth declare,
What Fame they get, who vertuous are,
For Praise alone; and, what Reward,
For such like Studies, is prepar'd.
Peruse it; And, this Counsell take;
Bee vertuous, for meere Vertues sake.
See, Emb. XI.

13
This Lot, those persons, alwayes finds,
That have high thoughts, and loftie minds;
Or, such as have an itch to learne,
That, which doth nothing them concerne;
Or, love to peepe, with daring eyes,
Into forbidden Mysteries.
If any one of these thou bee,
Thine Emblem, lessons hath for thee.
See, Emb. XIII.

14
If all be true, these Lots doe tell us,
Thou shouldst be of those Fidling-fellowes,
Who, better practised are growne,
In others matters, than their owne:
Or, one, that covets to be thought,
A man, that's ignorant of nought.
If it be so, thy Morall showes
Thy Folly, and what from it flowes.
See, Emb. XIV.

15
Thou hast some Charge, (who e're thou be)
Which, Tendance may expect from thee.
And, well, perhaps, it may be fear'd,
Tis often left, without regard:
Or, that, thou dost securely sleep,
When, thou should'st watch, more strictly, keep.
Thou knowest best, if it be so:
Take therefore heed, what is to doe.
See, Emb. XV.

16
In secret, thou dost oft complaine,
That, thou hast hop'd, and wrought in vaine;
And, think'st thy Lot, is farre more hard,
Than what for others is prepar'd.
An Emblem, therefore, thou hast got,
To shew, it is our common-Lot,
To worke and hope; and, that, thou hast
A Blessing by it, at the last.
See, Emb. XVI.

17
That thou hast Honestie, we grant;
But, Prudence, thou dost often want:
And, therefore, some have injur'd thee,
Who farre more Wise, than honest bee.
That, now, Discretion thou mayst add,
To those good-meanings thou hast had;
The Morall of thine Emblem, view;
And, what it counsels, that, pursue.
See, Emb. XVII.

18
To your Long-home, you nearer are,
Than you (it may bee) are aware:
Yea, and more easie is the Way,
Than you, perchance, conceive it may.
Lest, therefore, Death, should grim appeare,
And, put you in a causelesse feare;
(Or out of minding wholly passe)
This Chance, to you allotted was.
See, Emb. XVIII.

19
In slippery Paths, you are to goe;
Yea, they are full of danger too:
And, if you heedfull should not grow,
They'l hazzard much, your overthrow.
But, you the mischiefe may eschew,
If wholsome Counsell, you pursue.
Looke, therefore, what you may be taught,
By that, which this your chance hath brought.
See, Emb. XIX.

20
This present Lot, concernes full neere,
Not you alone, but all men here;
For, all of us, too little heed
His love, who for our sakes, did bleed.
Tis true, that meanes, hee left behind him,
Which better teacheth how to minde him:
Yet, if wee both by that, and this,
Remember him, 'tis not amisse.
See, Emb. XX.

21
Tis hop'd, you just, and pious are,
More out of Conscience, than for feare;
And, that you'l vertuous courses take,
For Goodnesse, and for Vertue-sake.
Yet, since the best men, sometimes may
Have need of helpes, in Vertues way,
Those usefull Moralls, sleight you not,
Which are presented by this Lot.
See, Emb. XXI.

22
This Lot pertaineth unto those,
(And who they bee, God onely knowes)
Who, to the world, have no desire;
But, up to heav'nly things aspire.
No doubt, but you, in some degree,
Indow'd with such affections bee;
And, had this Emblem, that you might
Encourag'd bee, in such a Flight.
See, Emb. XXII.

23
The state of Temp'rall things to shew,
Yee have them, still, within your view;
For, ev'ry object that wee see,
An Emblem, of them, serves to bee.
But, wee from few things, helps doe finde,
To keepe Eternitie in minde.
This Lot, an Emblem brings, therefore,
To make you thinke upon it more.
See, Emb. XXIII.

24
Vnlesse you better looke thereto,
Dis-use, and Sloth, will you undoe.
That, which of you despayred was,
With ease, might have bin brought to passe;
Had but so much bin done, as may
Bee equall'd with One Line a day.
Consider this; and, to that end,
The Morall of your Lot attend.
See, Emb. XXIV.

M 25
If wee mistake not, thou art one,
Who loves to court the Rising-Sunne;
And, if this Lot, thy nature finde,
Thou to Preferment hast a minde:
If so; learne hence, by whose respect
(Next God) thou mayst thy hopes effect:
Then, seeke to winn his grace to thee,
Of what estate soe're thou bee.
See, Emb. XXV.

26
Thou to a double-path art come;
And, peradventure, troublesome,
Thou findest it; for thee to know,
On whether hand thou oughtst to goe.
To put thee out of all suspect,
Of Courses that are indirect;
Thy Morall points thee to a path,
Which hardship, but, no perill hath.
See, Emb. XXVI.

27
You warned are of taking heede,
That, never, you your Bounds exceed;
And, also, that you be not found,
To come within your Neighbours Bound.
There may be some concealed Cause,
That, none but you, this Emblem drawes.
Examine it; And, If you see
A fault, let it amended be.
See, Emb. XXVII.

28
Your Emblems morall doth declare,
When, Lovers fitly matched are;
And, what the chiefest cause may be,
Why, Friends and Lovers disagree.
Perhaps, you somewhat thence may learne,
Which your Affection doth concerne.
But, if it Counsell you too late,
Then, preach it at your Neighbours gate.
See, Emb. XXVIII.

M 29
Some, vrge their Princes on to Warre,
And weary of sweet Peace, they are.
Some, seeke to make them, dote on Peace,
(Till publike Danger more encrease)
As if the World were kept in awe,
By nothing else but preaching Law.
Thy Morall (if of those thou art)
Doth act a Moderators part.
See, Emb. XXIX.

30
Tis feared, thou dost lesse esteeme,
Vpright to bee, than so to seeme;
And, if thine actions, faire appeare,
Thou carest not how foule they are.
Though this bee not thy fault alone,
Yet have a care of mending One:
And, study thou, Vpright to grow,
As well in Essence, as in Show.
See, Emb. XXX.

31
Some, all their time, and wealth have spent,
In giving other men content;
And, would not grudge to waste their Blood,
To helpe advance the Common-good.
To such as these, you have been thought,
Not halfe so friendly as you ought.
This Lot therefore befalls, to shew,
How great respects, to such, are due.
See, Emb. XXXI.

32
You have been tempted (by your leave)
In hope of Lucre, to deceive:
But, much, as yet, you have not swerv'd
From Faith, which ought to be observ'd.
If well, hereafter, you would speed,
In dealing-honestly, proceed:
For, by your Emblem, you shall see,
That, Honest-men, the richest bee.
See, Emb. XXXII.

33
We hope, no person, here, beleeves,
That, you are of those wealthy Theeves,
Who, Chaines of gold, and pearle doe weare.
And, of those Theeves, that, none you are,
Which weares a Rope, wee, plainly see;
For, you, as yet unhanged bee:
But, unto God, for Mercie crie,
Else hang'd you may bee, e're you die.
See, Emb. XXXIII.

34
You, willing are, to put away,
The thinking on your latter-day:
You count the mention of it, Folly;
A meanes of breeding Melancholly;
And, newes unfit for men to heare,
Before they come to sixtie-yeare.
But, minde what Counsels now are sent,
And, mend, lest you too late repent.
See, Emb. XXXIV.

35
Your Wits, your Wishes, and your Tongue,
Have run the Wild goose-chase, too long;
And (lest all Reason, you exceed)
Of Rules, and Reines, you now have need.
A Bridle, therefore, and a Square,
Prime Figures, in your Emblem, are.
Observe their Morall, and I pray,
Be Wise, and Sober, if you may.
See, Emb. XXXV.

36
Because her Ayd makes goodly showes,
You, on the World, your trust repose;
And, his dependance, you despise,
Who, meerly, on God's helpe, relies.
That, therefore, you may come to see,
How pleas'd, and safe, those men may bee,
Who have no ayd, but God, alone;
This Emblem, you have lighted on.
See, Emb. XXXVI.

37
Some, thinke your Vertue very much;
And, there is cause to thinke it such:
For, many wayes it hath been tride;
And, well the Triall doth abide.
Yet, think not, but some brunts there are,
Which, your owne strength shall never beare.
And, by the Morall of your Lot,
Learne, where, Assistance may bee got.
See, Emb. XXXVII.

38
Thou hast been grieved, and complain'd,
Because, the Truth hath wrong sustain'd.
But, that, dismayd thou shouldst not be,
Thine Emblem will declare to thee,
That, though the Truth may suffer spite,
It shall not bee depressed quite;
But, by opposing, spread the more,
And, grow more pow'rfull than before.
See, Emb. XXXVIII.

39
By Rashnesse, thou hast often err'd,
Or, else, thou hadst been more preferr'd.
But, future errours, to prevent,
Thou to the slow-pac'd Oxe art sent,
To learne more Staydnesse; and, to doe
Thy Workes, with Perseverance, too.
Hee that this creatures Vertue scornes,
May want it all, except his Hornes.
See, Emb. XXXIX.

40
Dame Fortunes favour seemes to bee
Much lov'd, and longed for, of thee;
As if, in what, her hand bestowes,
Thou mightst thy confidence repose.
But, that, her manners may bee knowne,
This Chance, upon thee, was bestowne.
Consider well, what thou hast got,
And, on her flattrings, dote thou not.
See, Emb. XL.

41
The Steele and Flint, declare, in part,
The Temper of a Stony-heart;
And, shewe, that thence, no Vertue flowes,
Till it be forced out, with blowes.
Some other, Moralls thou maist learne,
Thereby, which will thy good, concerne:
Marke, therefore, what they doe declare,
And, minde it, as occasions are.
See, Emb. XLI.

42
Thou thinkst thy Witt, had made thee great,
Had Povertie not beene some let:
But, had thy Wealth as ample beene,
As, thou thy Witt, didst overweene;
Insteed of thy desired Height,
Perhaps, thou hadst beene ruin'd quite.
Hereafter, therefore, be content,
With whatsoever God hath sent.
See, Emb. XLII.

43
To Discord, thou art somewhat prone,
And, thinkst thou mayst subsist alone;
Regarding not how safe they bide,
Who, fast, in Concords bands are tide.
But, that thou mayst the better heed,
What Good, from Vnion doth proceed,
An Emblem is become thy Lot,
From which, good Caveats may be got.
See, Emb. XLIII.

44
Thou wouldst be lov'd; and, to that end,
Thou dost both Time, and Labour spend:
But, thou expect'st (as wee beleeve)
More Love, than thou dost meane to give.
If so thou then, art much to blame:
For, Love affects a muturall-flame;
Which, if it faile on either side,
Will never, long time, true abide.
See, Emb. XLIV.

45

You might also like