100% found this document useful (3 votes)
33 views

Beginning Sensor Networks With Xbee, Raspberry Pi, and Arduino: Sensing The World With Python and Micropython 2Nd Edition Charles Bell

Raspberry

Uploaded by

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

Beginning Sensor Networks With Xbee, Raspberry Pi, and Arduino: Sensing The World With Python and Micropython 2Nd Edition Charles Bell

Raspberry

Uploaded by

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

Download the full version of the textbook now at textbookfull.

com

Beginning Sensor Networks with XBee,


Raspberry Pi, and Arduino: Sensing the World
with Python and MicroPython 2nd Edition
Charles Bell
https://textbookfull.com/product/beginning-sensor-
networks-with-xbee-raspberry-pi-and-arduino-
sensing-the-world-with-python-and-micropython-2nd-
edition-charles-bell/

Explore and download more textbook at https://textbookfull.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Beginning Robotics with Raspberry Pi and Arduino: Using


Python and OpenCV 2nd Edition Jeff Cicolani

https://textbookfull.com/product/beginning-robotics-with-raspberry-pi-
and-arduino-using-python-and-opencv-2nd-edition-jeff-cicolani/

textbookfull.com

Beginning Robotics with Raspberry Pi and Arduino: Using


Python and OpenCV 2nd Edition Jeff Cicolani

https://textbookfull.com/product/beginning-robotics-with-raspberry-pi-
and-arduino-using-python-and-opencv-2nd-edition-jeff-cicolani-2/

textbookfull.com

Beginning Robotics with Raspberry Pi and Arduino: Using


Python and OpenCV Jeff Cicolani

https://textbookfull.com/product/beginning-robotics-with-raspberry-pi-
and-arduino-using-python-and-opencv-jeff-cicolani/

textbookfull.com

30 Days to Market Mastery A Step by Step Guide to


Profitable Trading 1st Edition Bernstein Jake

https://textbookfull.com/product/30-days-to-market-mastery-a-step-by-
step-guide-to-profitable-trading-1st-edition-bernstein-jake/

textbookfull.com
Caves and Karst of the Upper Midwest, USA: Minnesota,
Iowa, Illinois, Wisconsin Greg A. Brick

https://textbookfull.com/product/caves-and-karst-of-the-upper-midwest-
usa-minnesota-iowa-illinois-wisconsin-greg-a-brick/

textbookfull.com

Greetings Pushkin Stalinist Cultural Politics and the


Russian National Bard 1st Edition Jonathan Brooks Platt

https://textbookfull.com/product/greetings-pushkin-stalinist-cultural-
politics-and-the-russian-national-bard-1st-edition-jonathan-brooks-
platt/
textbookfull.com

Mathematics is the poetry of science First Edition.


Edition Cédric Villani

https://textbookfull.com/product/mathematics-is-the-poetry-of-science-
first-edition-edition-cedric-villani/

textbookfull.com

The year of voting dangerously the derangement of American


politics First Trade Paperback Edition Dowd

https://textbookfull.com/product/the-year-of-voting-dangerously-the-
derangement-of-american-politics-first-trade-paperback-edition-dowd/

textbookfull.com

German Military Geology and Fortification of the British


Channel Islands During World War II Edward P. F. Rose

https://textbookfull.com/product/german-military-geology-and-
fortification-of-the-british-channel-islands-during-world-war-ii-
edward-p-f-rose/
textbookfull.com
Rejected Wolf (Virga’s Doom #1) 1st Edition Rose

https://textbookfull.com/product/rejected-wolf-virgas-doom-1-1st-
edition-rose/

textbookfull.com
TECHNOLOGY IN AC TION™

Beginning Sensor
Networks with
XBee, Raspberry Pi,
and Arduino
Sensing the World with Python
and MicroPython

Second Edition

Charles Bell
Beginning Sensor
Networks with XBee,
Raspberry Pi, and
Arduino
Sensing the World with Python
and MicroPython
Second Edition

Charles Bell
Beginning Sensor Networks with XBee, Raspberry Pi, and Arduino:
Sensing the World with Python and MicroPython

Charles Bell
Warsaw, VA, USA

ISBN-13 (pbk): 978-1-4842-5795-1 ISBN-13 (electronic): 978-1-4842-5796-8


https://doi.org/10.1007/978-1-4842-5796-8

Copyright © 2020 by Charles Bell


This work is subject to copyright. All rights are reserved by the Publisher, whether the whole
or part of the material is concerned, specifically the rights of translation, reprinting, reuse of
illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical
way, and transmission or information storage and retrieval, electronic adaptation,
computer software, or by similar or dissimilar methodology now known or hereafter
developed.
Trademarked names, logos, and images may appear in this book. Rather than use a
trademark symbol with every occurrence of a trademarked name, logo, or image we use the
names, logos, and images only in an editorial fashion and to the benefit of the trademark
owner, with no intention of infringement of the trademark.
The use in this publication of trade names, trademarks, service marks, and similar terms,
even if they are not identified as such, is not to be taken as an expression of opinion as to
whether or not they are subject to proprietary rights.
While the advice and information in this book are believed to be true and accurate at the
date of publication, neither the authors nor the editors nor the publisher can accept any
legal responsibility for any errors or omissions that may be made. The publisher makes no
warranty, express or implied, with respect to the material contained herein.
Managing Director, Apress Media LLC: Welmoed Spahr
Acquisitions Editor: Natalie Pao
Development Editor: James Markham
Coordinating Editor: Jessica Vakili
Distributed to the book trade worldwide by Springer Science+Business Media New York,
233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201)
348-4505, e-mail [email protected], or visit 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 [email protected], or visit http://www.
apress.com/rights-permissions.
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 via the book’s product page, located at www.apress.com/
978-1-4842-5795-1. For more detailed information, please visit http://www.apress.com/
source-code.
Printed on acid-free paper
I dedicate this book to the countless healthcare
professionals, first responders, and many unsung heroes of
this difficult time we face in the world during the COVID-19
crisis. It is my hope this book and others like it help the
millions of people pass the time during the crisis learning
more about science and technology.
Table of Contents
About the Author��������������������������������������������������������������������������������xv

About the Technical Reviewer����������������������������������������������������������xvii


Acknowledgments�����������������������������������������������������������������������������xix
Introduction���������������������������������������������������������������������������������������xxi

Chapter 1: Introduction to Sensor Networks����������������������������������������1


Anatomy of a Sensor Network������������������������������������������������������������������������������2
Examples of Sensor Networks�������������������������������������������������������������������������3
The Topology of a Sensor Network����������������������������������������������������������������12
Communication Media����������������������������������������������������������������������������������������14
Wired Networks���������������������������������������������������������������������������������������������14
Wireless Networks�����������������������������������������������������������������������������������������15
Hybrid Networks��������������������������������������������������������������������������������������������15
Types of Sensor Nodes����������������������������������������������������������������������������������������16
Basic Sensor Nodes���������������������������������������������������������������������������������������16
Data Nodes����������������������������������������������������������������������������������������������������16
Aggregator Nodes������������������������������������������������������������������������������������������17
Sensors���������������������������������������������������������������������������������������������������������������18
How Sensors Measure�����������������������������������������������������������������������������������20
Storing Sensor Data��������������������������������������������������������������������������������������26
Examples of Sensors�������������������������������������������������������������������������������������27
Summary������������������������������������������������������������������������������������������������������������34

v
Table of Contents

Chapter 2: Tiny Talking Modules: An Introduction to


XBee Wireless Modules����������������������������������������������������������������������35
What Is an XBee?������������������������������������������������������������������������������������������������36
XBee Primer��������������������������������������������������������������������������������������������������������37
Choosing XBee Modules��������������������������������������������������������������������������������38
Interacting with an XBee-ZB Module�������������������������������������������������������������42
Pin Layout������������������������������������������������������������������������������������������������������46
Configuring Modules�������������������������������������������������������������������������������������48
Introducing MicroPython�������������������������������������������������������������������������������������67
An XBee Wireless Chat Room������������������������������������������������������������������������������72
Loading the Firmware for the Modules���������������������������������������������������������72
Capturing Serial Numbers�����������������������������������������������������������������������������77
Configuring the Coordinator��������������������������������������������������������������������������79
Configuring the Router����������������������������������������������������������������������������������80
Let the Chat Begin�����������������������������������������������������������������������������������������80
For More Fun�������������������������������������������������������������������������������������������������82
Building an XBee-ZB Mesh Network�������������������������������������������������������������������84
Loading the Firmware for the Modules���������������������������������������������������������85
Configuring the XBee Modules����������������������������������������������������������������������85
Forming Test Messages���������������������������������������������������������������������������������86
Testing the Network��������������������������������������������������������������������������������������90
For More Fun�������������������������������������������������������������������������������������������������95
Component Shopping List�����������������������������������������������������������������������������������95
Troubleshooting Tips and Common Issues����������������������������������������������������������97
Things to Check���������������������������������������������������������������������������������������������98
Common Issues���������������������������������������������������������������������������������������������99
Summary����������������������������������������������������������������������������������������������������������101

vi
Table of Contents

Chapter 3: Programming in MicroPython�����������������������������������������103


MicroPython Features and Limitations�������������������������������������������������������������105
MicroPython Features���������������������������������������������������������������������������������105
MicroPython Limitations������������������������������������������������������������������������������106
Basic Concepts�������������������������������������������������������������������������������������������������107
Code Blocks�������������������������������������������������������������������������������������������������108
Comments���������������������������������������������������������������������������������������������������110
Arithmetic����������������������������������������������������������������������������������������������������111
Output to Screen������������������������������������������������������������������������������������������112
Variables and Data Types����������������������������������������������������������������������������������114
Variables������������������������������������������������������������������������������������������������������114
Types�����������������������������������������������������������������������������������������������������������116
Basic Data Structures���������������������������������������������������������������������������������������118
Lists�������������������������������������������������������������������������������������������������������������118
Tuples����������������������������������������������������������������������������������������������������������120
Dictionaries�������������������������������������������������������������������������������������������������121
Flow Control Statements�����������������������������������������������������������������������������������123
Conditional Statements�������������������������������������������������������������������������������123
Loops�����������������������������������������������������������������������������������������������������������125
Modularization: Modules, Functions, and Classes��������������������������������������������127
Including Modules���������������������������������������������������������������������������������������127
Functions�����������������������������������������������������������������������������������������������������128
Classes and Objects������������������������������������������������������������������������������������130
Object-Oriented Programming (OOP) Terminology��������������������������������������134
Summary����������������������������������������������������������������������������������������������������������141

vii
Table of Contents

Chapter 4: XBee-Based Sensor Nodes����������������������������������������������143


How to Host Sensors with XBee������������������������������������������������������������������������144
Building an XBee Environment Sensor��������������������������������������������������������������145
Hardware Setup�������������������������������������������������������������������������������������������146
XBee Hardware Option��������������������������������������������������������������������������������150
MicroPython Option�������������������������������������������������������������������������������������155
Example: Using XBee Modules to Gather Data��������������������������������������������������166
Hardware Setup�������������������������������������������������������������������������������������������168
Configuring the XBee Sensor Node�������������������������������������������������������������171
Programming the Sensor Node�������������������������������������������������������������������172
Testing the XBee Sensor Node��������������������������������������������������������������������186
Component Shopping List���������������������������������������������������������������������������������188
Summary����������������������������������������������������������������������������������������������������������191

Chapter 5: Raspberry Pi–Based Sensor Nodes���������������������������������193


What Is a Raspberry Pi?������������������������������������������������������������������������������������194
Noble Origins�����������������������������������������������������������������������������������������������196
Models���������������������������������������������������������������������������������������������������������198
A Tour of the Board��������������������������������������������������������������������������������������200
Required Accessories����������������������������������������������������������������������������������202
Recommended Accessories������������������������������������������������������������������������203
Raspberry Pi Tutorial�����������������������������������������������������������������������������������������207
Getting Started��������������������������������������������������������������������������������������������207
Installing a Boot Image��������������������������������������������������������������������������������208
Booting Up���������������������������������������������������������������������������������������������������213
GPIO Pin Mapping����������������������������������������������������������������������������������������217
Required Software���������������������������������������������������������������������������������������221
Project: Hardware “Hello, World!”����������������������������������������������������������������223

viii
Table of Contents

Hosting Sensors with Raspberry Pi�������������������������������������������������������������������230


Project: Building a Raspberry Temperature Sensor Node���������������������������������232
Hardware Setup�������������������������������������������������������������������������������������������232
Testing the Hardware����������������������������������������������������������������������������������234
Software Setup��������������������������������������������������������������������������������������������236
Testing the Sensor���������������������������������������������������������������������������������������242
For More Fun�����������������������������������������������������������������������������������������������243
Project: Building a Raspberry Barometric Pressure Sensor Node��������������������243
Hardware Setup�������������������������������������������������������������������������������������������245
Testing the Hardware����������������������������������������������������������������������������������245
Software Setup��������������������������������������������������������������������������������������������246
Testing the Sensor���������������������������������������������������������������������������������������251
For More Fun�����������������������������������������������������������������������������������������������251
Project: Creating a Raspberry Pi Data Collector for XBee Sensor Nodes����������252
XBee Sensor Node���������������������������������������������������������������������������������������252
Hardware�����������������������������������������������������������������������������������������������������254
Software������������������������������������������������������������������������������������������������������256
Testing the Final Project������������������������������������������������������������������������������264
For More Fun�����������������������������������������������������������������������������������������������265
Component Shopping List���������������������������������������������������������������������������������266
Summary����������������������������������������������������������������������������������������������������������268

Chapter 6: Arduino-Based Sensor Nodes�����������������������������������������269


What Is an Arduino?������������������������������������������������������������������������������������������269
Arduino Models��������������������������������������������������������������������������������������������271
Arduino Clones��������������������������������������������������������������������������������������������279
So, Which Do I Buy?�������������������������������������������������������������������������������������286
Where to Buy�����������������������������������������������������������������������������������������������287

ix
Table of Contents

Arduino Tutorial�������������������������������������������������������������������������������������������������288
Learning Resources�������������������������������������������������������������������������������������289
The Arduino IDE�������������������������������������������������������������������������������������������290
Project: Hardware “Hello, World!”����������������������������������������������������������������294
Hosting Sensors with Arduino���������������������������������������������������������������������������300
Project: Building an Arduino Temperature Sensor���������������������������������������������302
Hardware Setup�������������������������������������������������������������������������������������������302
Software Setup��������������������������������������������������������������������������������������������304
Writing the Sketch���������������������������������������������������������������������������������������306
Test Execution���������������������������������������������������������������������������������������������310
Project: Using an Arduino As a Data Collector for XBee Sensor Nodes�������������312
XBee Sensor Node���������������������������������������������������������������������������������������312
Coordinator Node�����������������������������������������������������������������������������������������313
Arduino with XBee Shield����������������������������������������������������������������������������314
Testing the Final Project������������������������������������������������������������������������������326
For More Fun�����������������������������������������������������������������������������������������������328
Component Shopping List���������������������������������������������������������������������������������328
Summary����������������������������������������������������������������������������������������������������������331

Chapter 7: Methods for Storing Sensor Data������������������������������������333


Storage Methods�����������������������������������������������������������������������������������������������334
Local Storage Options for the Arduino��������������������������������������������������������������336
Nonvolatile Memory������������������������������������������������������������������������������������336
SD Card��������������������������������������������������������������������������������������������������������337
Project: Saving Data in Nonvolatile Memory�����������������������������������������������338
Project: Writing Data to an SD Card�������������������������������������������������������������356

x
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Table of Contents

Local Storage Options for the Raspberry Pi������������������������������������������������������372


Project: Writing Data to Files�����������������������������������������������������������������������373
Remote Storage Options�����������������������������������������������������������������������������������375
Storing Data in the Cloud�����������������������������������������������������������������������������377
Project: Writing Data to ThingSpeak with an Arduino����������������������������������386
Project: Writing Data to ThingSpeak with a Raspberry Pi����������������������������398
Storing Sensor Data in a Database��������������������������������������������������������������409
Component Shopping List���������������������������������������������������������������������������������409
Summary����������������������������������������������������������������������������������������������������������412

Chapter 8: Turning Your Raspberry Pi into a Database Server���������413


What Is MySQL?������������������������������������������������������������������������������������������������414
Getting Started with MySQL������������������������������������������������������������������������������420
What’s a Relational Database Management System?���������������������������������420
How and Where MySQL Stores Data������������������������������������������������������������422
The MySQL Configuration File���������������������������������������������������������������������428
How to Start, Stop, and Restart MySQL�������������������������������������������������������429
Creating Users and Granting Access�����������������������������������������������������������430
Building a Raspberry Pi MySQL Server�������������������������������������������������������������432
Partitioning and Formatting the Drive���������������������������������������������������������433
Setting Up Automatic Drive Mounting���������������������������������������������������������437
Project: Installing MySQL Server on a Raspberry Pi������������������������������������441
Advanced Project: Using MySQL Replication to Back Up
Your Sensor Data�����������������������������������������������������������������������������������������462
Component Shopping List���������������������������������������������������������������������������������472
Summary����������������������������������������������������������������������������������������������������������472

xi
Table of Contents

Chapter 9: MySQL and Arduino: United at Last!�������������������������������475


Introducing Connector/Arduino�������������������������������������������������������������������������476
Hardware Requirements������������������������������������������������������������������������������477
What About Memory?����������������������������������������������������������������������������������480
Installing MySQL Connector/Arduino�����������������������������������������������������������481
Limitations���������������������������������������������������������������������������������������������������482
Building Connector/Arduino-Enabled Sketches������������������������������������������������485
Database Setup�������������������������������������������������������������������������������������������485
Setting Up the Arduino���������������������������������������������������������������������������������488
Starting a New Sketch���������������������������������������������������������������������������������489
Testing the Sketch���������������������������������������������������������������������������������������496
What About the Ethernet Shield 2?��������������������������������������������������������������501
What About the WiFi Shield?�����������������������������������������������������������������������502
What About the WiFi 101 Shield?����������������������������������������������������������������503
Troubleshooting Connector/Arduino������������������������������������������������������������������504
MySQL Server Configuration�����������������������������������������������������������������������506
MySQL User Account Problems�������������������������������������������������������������������508
Networking Configuration����������������������������������������������������������������������������511
Connector Installation����������������������������������������������������������������������������������513
Others����������������������������������������������������������������������������������������������������������514
None of These Solved My Problem—What Next?���������������������������������������515
A Tour of the MySQL Connector/ Arduino Code�������������������������������������������������516
Library Files�������������������������������������������������������������������������������������������������516
Field Structure���������������������������������������������������������������������������������������������517
Public Methods��������������������������������������������������������������������������������������������518
Example Uses����������������������������������������������������������������������������������������������522

xii
Table of Contents

Project: Building a MySQL Arduino Client����������������������������������������������������������527


Hardware Setup�������������������������������������������������������������������������������������������527
Software Setup��������������������������������������������������������������������������������������������529
Setting Up the Sensor Database������������������������������������������������������������������531
Writing the Code������������������������������������������������������������������������������������������531
Test Execution���������������������������������������������������������������������������������������������538
For More Fun�����������������������������������������������������������������������������������������������540
Project Example: Inserting Data from Variables������������������������������������������������541
Project Example: How to Perform SELECT Queries�������������������������������������������544
Displaying a Result Set in the Serial Monitor����������������������������������������������545
Writing Your Own Display Method���������������������������������������������������������������546
Example: Getting a Lookup Value from the Database����������������������������������551
Component Shopping List���������������������������������������������������������������������������������554
Summary����������������������������������������������������������������������������������������������������������555

Chapter 10: Building Your Network: Arduino Wireless


Aggregator + Wireless Sensor Node + Raspberry Pi Server������������557
Data-Aggregate Nodes��������������������������������������������������������������������������������������558
Local-Storage Data Aggregator�������������������������������������������������������������������560
Project: Data-Aggregate Node with Local Storage��������������������������������������561
Remote-Storage Data Aggregator���������������������������������������������������������������594
Project: Arduino Data-Aggregate Node with Database Storage������������������595
Project: Raspberry Pi Data-Aggregate Node with Database Storage����������617
Component Shopping List���������������������������������������������������������������������������������635
Summary����������������������������������������������������������������������������������������������������������638

xiii
Table of Contents

Chapter 11: Putting It All Together���������������������������������������������������639


Sensor Networks Best Practices�����������������������������������������������������������������������639
Considerations for Data-Aggregate Nodes��������������������������������������������������639
Considerations for Sensor Network Databases�������������������������������������������645
Other Considerations�����������������������������������������������������������������������������������653
Choosing Sensor Nodes������������������������������������������������������������������������������������659
Wired or Wireless?���������������������������������������������������������������������������������������660
Arduino or Raspberry Pi?�����������������������������������������������������������������������������661
Alternative Hosts�����������������������������������������������������������������������������������������666
Project: Home Temperature-Monitoring Network���������������������������������������������673
Planning Considerations������������������������������������������������������������������������������674
Planning the Nodes�������������������������������������������������������������������������������������675
Cost Considerations�������������������������������������������������������������������������������������676
What About Implementation?����������������������������������������������������������������������679
Conclusion���������������������������������������������������������������������������������������������������679
For More Fun�����������������������������������������������������������������������������������������������680
Optional Component Shopping List�������������������������������������������������������������������680
Summary����������������������������������������������������������������������������������������������������������681

Appendix�������������������������������������������������������������������������������������������683
Consolidated Shopping Lists�����������������������������������������������������������������������������683
Alternative Connection Systems�����������������������������������������������������������������������691
Grove�����������������������������������������������������������������������������������������������������������������691
Qwiic�����������������������������������������������������������������������������������������������������������������695
STEMMA QT������������������������������������������������������������������������������������������������������700
Summary����������������������������������������������������������������������������������������������������������701

Index�������������������������������������������������������������������������������������������������703

xiv
About the Author
Charles Bell conducts research in emerging
technologies. He is a principal software
developer of the Oracle MySQL Development
team. He lives in a small town in rural Virginia
with his loving wife. He received his Doctor
of Philosophy in Engineering from Virginia
Commonwealth University in 2005.
Dr. Bell is an expert in the database field
and has extensive knowledge and experience in
software development and systems engineering.
His research interests include microcontrollers, three-dimensional printing,
database systems, software engineering, and sensor networks. He spends his
limited free time as a practicing maker focusing on microcontroller projects
and refinement of three-dimensional printers.

xv
About the Technical Reviewer
Sai Yamanoor is an embedded systems engineer working for an industrial
gases company in Buffalo, NY. His interests, deeply rooted in DIY and
open source hardware, include developing gadgets that aid behavior
modification. He has published two books with his brother, and in his
spare time, he likes to contribute to build things that improve quality of
life. You can find his project portfolio at http://saiyamanoor.com.

xvii
Acknowledgments
I would like to thank all of the many talented and energetic professionals
at Apress. I appreciate the understanding and patience of my managing
editor, Natalie Pao; coordinating editor, Jessica Vakili; and development
editor, James Markham. Each was instrumental in the success of this
project. I appreciate their encouragement and guidance as well as patience
in dealing with my many questions. I would also like to thank the small
army of publishing professionals at Apress for making me look so good in
print. Thank you all very much!
I’d like to especially thank the technical reviewer, Sai Yamanoor, for
his patience, insight, and impressive attention to detail. Most importantly,
I want to thank my wife, Annette, for her unending patience and
understanding during the many hours I spent hunched over my laptop or
conducting science experiments on the dining table.

xix
Introduction
The world of microcontrollers and increasingly capable and popular small
computing platforms is enabling many more people to learn, experience,
and complete projects that would previously have required dedicated (and
expensive) hardware. Rather than purchase a commercial or made-for-­
consumers kit, enterprising developers can now build their own solutions
to meet their needs. Sensor networks are just one example of how these
small, powerful, and inexpensive components have made it possible for
anyone with a moderate skill set to build their own sensor network.
This book presents a beginner’s guide to sensor networks. I cover topics
including what types of sensors exist, how they communicate their values
(observations or events), how they can be used in Arduino and Raspberry Pi
projects, and how to build your own home temperature sensor network.
I also include an introduction to the MySQL database server and how
you can connect to, store, and retrieve data. Why, I even show you how to
do it directly from an Arduino!
Better still, this edition has been updated to include updated tools
and software, project examples, as well as the latest use and programming
of the XBee 3 modules. Yes, we’re writing code to control them in
MicroPython. There’s an entire chapter dedicated to MicroPython as well
as extended coverage of the XBee platform.

Who This Book Is For


I have written this book with a wide variety of readers in mind. It is
intended for anyone who wants to get started building their own sensor
networks or those who want to learn how to use components, devices, and
sensors with an Arduino or Raspberry Pi.

xxi
Introduction

Whether you have already been working with sensor networks, or


maybe have taken an introductory electronics course, or even have read a
good Apress book on the Arduino or Raspberry Pi, you will get a lot out of
this book. Best of all, if you ever wanted to know how to combine sensors,
Arduinos, XBee, MySQL, and Raspberry Pi to form a cohesive solution, this
book is just what you need!
Most importantly, I wrote this book to meet my own needs. Although
there are some excellent books on Arduino, Raspberry Pi, sensors, and
MySQL, I could not find a single reference that showed how to put all of
these together. The second edition kicks it up yet another notch with more
coverage of these topics with the latest versions of the tools and libraries
available.

About the Projects


There are 11 chapters, 9 of which include projects that demonstrate and
teach key concepts of building sensor networks. Depending on your skill
level with the chapter topic, you may find some of the projects easier to
complete than others. It is my hope that you find the projects challenging
and enlightening (but, more importantly, informative) so that you can
complete your own sensor network projects.
In this section, I present some guidance on how best to succeed and
get the most out of the projects.

Strategies
I have tried to construct the projects so that the majority of readers can
accomplish them with little difficulty. If you encounter topics that you are
very familiar with, I recommend working through the projects anyway
instead of simply reading or skipping through the instructions. This is
because some of the later projects build on the earlier projects.

xxii
Introduction

On the other hand, if you encounter topics that you are unfamiliar
with, I recommend reading through the chapter or section completely at
least once before attempting the project. Take some time to fully absorb
the material, and pay particular attention to the numerous links, tips, and
cautionary portions. Some of those are pure gold for beginners.
Perhaps the most significant advice I can offer when approaching the
projects is to attempt them one at a time. By completing the projects one
at a time, you gain knowledge that you can build on for future projects.
It also helps you establish a pace to work through the book. Although
some accomplished readers can probably complete all the projects in a
weekend, I recommend working through the book at a pace best suited for
your availability (and enjoyment).
With some exceptions, the earlier chapters are independent and can be
tackled in any order. This is especially true for the Raspberry Pi (Chapter 5)
and Arduino (Chapter 6) chapters. Regardless, it is a good idea to read the
book and work on the projects in order.

Tips for Buying Hardware


The hardware list for this book contains a number of common components
such as temperature sensors, breadboards, jumper wires, and resistors.
Most of these items can be found in electronics stores that stock supplies
for electronics enthusiasts. The list also includes a number of specialized
components such as XBee modules, XBee adapters, XBee shields, Arduino
boards, and Raspberry Pi boards.
Each chapter has a list of the components used at the end of the
chapter. In some cases, you reuse the hardware from previous chapters. I
include a separate list for these items. I have placed the component lists
at the end of each chapter to encourage you to read the chapter before
attempting the projects.

xxiii
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
Introduction

The lists include the name of each component and at least one link
to an online vendor that stocks the component. In addition, I include the
quantity needed for the chapter and an estimated cost. If you add up all
the components needed and sum the estimated cost, the total may be a
significant investment for some readers.
The following sections are for anyone looking to save a little on the cost
of completing the projects in this book or wanting to build up their own
inventory of sensor network hardware on a budget.

Buy Only What You Need When You Need It


One way to mitigate a significant initial investment in hardware is to pace
your buying. If you follow previous advice and work on one project at a time,
you can purchase only the hardware needed for that project. This will allow
you to spread the cost over however long you plan to work through the book.
However, if you are buying your hardware from an online retailer,
you may want to balance ordering the hardware for one project at a time
against the potentially higher total shipping cost for multiple orders.
As mentioned, the more common electronics like LEDs, breadboards,
and so on can be found in traditional brick-and-mortar stores, but the cost
may be a little higher. Once again, the cost of shipping to your location may
dictate whether it would be cheaper to buy the higher-priced items from a
local electronics shop vs. an online retailer.

Online Auctions
One possible way to save money is to buy your components at a discount
on online auction sites. In many cases, the components are the very same
ones listed. In other cases, the components may be from vendors that
specialize in making less expensive alternatives. I have had a lot of success
in buying quality hardware from online auction sites (namely, eBay).

xxiv
Introduction

If you are not in a hurry and have time to wait for auctions to close
and the subsequent shipping times, you can sometimes find major
components like Arduinos, shields, power supplies, and the like at a
reduced price by bidding for them. For example, open source hardware
manufacturers sometimes offer their products via auctions or at special
pricing for quantities. I have found a number of Arduino clones and
shields at nearly half the cost of the same boards found on other sites or in
electronics stores.

Hey, Buddy, Can You Spare an Arduino?


Another possible way to save some money on the hardware is to
borrow it from your friends! If you have friends who are electronics,
Arduino, or Raspberry Pi enthusiasts, chances are they have many of
the components you need. Just be sure you return the components in
working order!1

A NOTE ABOUT NEWER ARDUINO BOARDS

The projects in this book are designed for a current, readily available
version of the Arduino as well as the most recently retired boards. The
projects can be completed with the Uno or Mega 2560 boards without
modification. Although you can use the Leonardo (see specific notes in the
chapters about the differences), you should consider the newer boards
carefully before buying.

1
 nd replace the components you implode, explode, or otherwise turn into silicon
A
slag. Hey, it happens.

xxv
Introduction

D
 ownloading the Code
The code for the examples shown in this book is available on the Apress
website, www.apress.com. A link can be found on the book’s information
page under the Source Code/Downloads tab. This tab is located
underneath the Related Titles section of the page.

R
 eporting Errata
Should you find a mistake in this book, please report it through the Errata
tab on the book’s page at www.apress.com. You will find any previously
confirmed errata in the same place.

xxvi
CHAPTER 1

Introduction
to Sensor Networks
Sensor networks are no longer expensive industrial constructs. You can
build a simple sensor network from easily procured, low-cost hardware.
All you need are some simple sensors and a microcontroller or computer
with input/output capabilities. Yes, your Arduino and Raspberry Pi are
ideal platforms for building sensor networks. If you’ve worked with either
platform and have ever wanted to monitor your garden pond, track
movement in your home or office, monitor the temperature in your house,
monitor the environment, or even build a low-cost security system, you’re
halfway there!
As inviting and easy as that sounds, don’t start warming up the
soldering iron just yet. There are a lot of things you need to know about
sensor networks. It’s not quite as simple as plugging things together and
turning them on. If you want to build a reliable and informative sensor
network, you need to know how such networks are constructed.
In addition, you may have heard of something called the Internet of
Things (IoT). This phrase refers to the use of devices that can communicate
over a network (local or Internet). IoT devices are therefore network-aware
devices that can send data to other resources, thereby virtualizing the
effects of the devices on users and their experience. Sensor networks play
a prominent role in the IoT. What you will learn in this book will provide a
firm foundation for building IoT solutions using sensor networks.

© Charles Bell 2020 1


C. Bell, Beginning Sensor Networks with XBee, Raspberry Pi, and Arduino,
https://doi.org/10.1007/978-1-4842-5796-8_1
Chapter 1 Introduction to Sensor Networks

If you want to know more about IoT in general, several books have
been written on the topic, including the following. If you’re interested in
learning more about the IoT and how sensor networks are used, check out
some of these titles:
• Building Internet of Things with the Arduino by
Charalampos Doukas (CreateSpace Independent
Publishing Platform, 2012)

• Architecting the Internet of Things by Dieter Uckelmann,


Mark Harrison, and Florian Michahelles (Springer,
2011)

• Getting Started with the Internet of Things: Connecting


Sensors and Microcontrollers to the Cloud by Cuno
Pfister (O’Reilly, 2011)

In this chapter, we will explore sensor networks through a brief


description of what they are and how they are constructed. We will also
examine the components that make up a sensor network including an
overview of sensors, the types of sensors available, and the things that they
can sense.

Anatomy of a Sensor Network


Sensor networks are everywhere. They’re normally thought of as
complicated monitoring systems for manufacturing and medical
applications. However, they aren’t always complicated, and they’re all
around you.
In this section, we will examine the building blocks of a sensor network
and how they’re connected (logically). First, let’s look at some examples of
sensor networks to visualize the components.

2
Random documents with unrelated
content Scribd suggests to you:
The zircon can be distinguished from the garnet by its peculiar
diamond-like brilliancy and its specific gravity.
Turquois.
The turquois is never found in crystals, but in reniform or
stalactitic masses. The color varies from pea- and apple-green to
greenish-blue, sky-blue and dark-blue.
The hardness of the turquois is 6., specific gravity 2.6 to 2.8,
lustre waxy, and condition opaque to slightly translucent.
Before the reducing flame of the blow-pipe, the turquois does not
melt, but becomes brown and colors the flame green. With borax
and salts of phosphorus the turquois melts to a clear glass, while it
is also soluble in hydrochloric acid. Oriental or mineral turquois is
composed of:
Alumina 47.45
Phosphoric acid 27.34
Water 18.18
Oxide of copper 2.02
Iron 1.10
Oxide of manganese 0.50
Phosphate of lime 3.41
100.00
The best color is a clear deep sky-blue, and in the true turquois
this color improves by artificial light; imitation turquoises, however,
lose their fine color under the same conditions.
The finest gem turquoises come from the northeastern part of
Persia, between Nishapoor and Meshed. Here they are mined and
partly cut, and then the Persian merchants carry them to Russia,
where they are sold at the great annual fair of Nijni-Novgorod and in
Moscow. Mineral turquoises are also found in New Mexico, Arizona,
and Nevada, but not of sufficient size or sufficiently good color to
make gem stones, although they are prized for collections.
Specimens are also found in Burmah, Khorassan, Thibet, China,
Silesia, Saxony, and on the Isthmus of Suez. The stones from these
places have, as a rule, but little value, as the color fades or turns
green from exposure to the light. Of late however, some very good
turquoises have come from Egypt. The color of a faded Persian
turquois can sometimes be restored by simply repolishing the stone.
Occidental or bone turquoises called new rock or odontolites, to
distinguish them from the Persian or old rock stones, are of organic
origin.
They are cut from the teeth of mammoths, mastodons,
dinotheriums, etc., and are found near the town of Simor, in Lower
Languedoc, France.
These teeth, the enamel of which is nearly as hard as the mineral
turquois, are colored by contact with phosphate of iron and copper,
which gives them a dark-blue, light-blue, and bluish-green color.
They are easily attacked by a file, and totally destroyed by aqua-
fortis.
When heated, the fossil turquois or odontolite gives an offensive
odor, owing to the decomposition of animal matter.
The odontolite is lighter than the mineral turquois, changes color
by artificial light, loses color in distilled water and alcohol, and is
translucent on the edges.
This fossil turquois does not fade like the mineral turquois, but by
artificial light appears of a dirty grayish-blue.
Turquoises are sometimes artificially stained, but this can be
detected by applying a drop of ammonia to the back of the stone,
and if the color is artificial the ammonia will eat it off, leaving a
green spot. Ammonia does not affect the color of the Persian
turquois. The so-called “reconstructed” turquoises are very close
imitations of the real, but are easily distinguished, as they change
rapidly to a deeper blue when immersed in water, and while wet the
surface of the stone shows cracks in every direction. These stones
become softer through soaking in water or alcohol. The original
color, however, returns when the stone is dry, but the cracks remain
in faint outline.
Tourmaline.
The tourmaline or precious schorl is known under many different
names, and no other mineral has such a suite of colors.
The colorless variety is known as achroite; the red, as rubellite or
siberite; the blue, indicolite or Brazilian sapphire; the green, Brazilian
emerald; and the yellowish-green, Ceylon chrysolite or Ceylon
peridot. Besides the above colors and their shadings, the tourmaline
occurs in black and brown.
The crystallization is obtuse rhomboid, and generally forms six-,
nine-, and twelve-sided prisms.
Some of the crystals are very large, specimens over eight inches
long having been mined.
The tourmaline crystals are remarkable for their varied and
beautiful groupings of colors. Some are internally blue or brown,
surrounded by a bright carmine red or dull yellow; others are red
internally and are enveloped by a green exterior; crystals are
sometimes pink at the summit and light green at the base, or
crimson tipped with black, or white at one end shading into green
and finally into red at the other end. The hardness of the tourmaline
is 7 to 7.5, specific gravity 3 to 3.1, and lustre vitreous.
The tourmaline becomes decidedly electric by heating or rubbing,
and will readily attract small pieces of paper and other small objects.
The rubellite or red tourmaline is composed of:
Silica 42.13
Alumina 36.43
Boracic acid 5.74
Oxide of manganese 6.32
Lime 1.20
Potash 2.41
Lithia 2.04

The green tourmaline is composed of


Silica 40.
Alumina 39.16
Lithia and potash 3.59
Protoxide of iron 5.96
Protoxide of manganese 2.14
Boracic acid 4.59
Volatile matter 1.58
The tourmaline possesses double refraction to a high degree, and
its power of polarizing light is so great that, cut into slices, it is used
in the polariscope for analyzing other minerals.
If two slices of tourmaline, cut parallel to their axis, be laid one
on the other in one direction, both are transparent; if laid in another
direction they become opaque, and if a doubly refracting crystal be
placed between the two plates of tourmaline, the part covered by
the crystal is transparent while the other is opaque.
Tourmaline melts with borax into a transparent glass; the
rubellite turns white, and the indicolite and green tourmalines turn
black, under the blow-pipe.
Tourmalines can be distinguished from other gems by their
specific gravity, but principally by their property of assuming polaric
electricity after being heated, one end becoming positive and the
other negative.
The history of the discovery of the tourmaline and its electric
property is a curious one.
On a warm summer day, early in the eighteenth century, some
children were playing in a courtyard in Amsterdam. Amongst their
playthings were some precious stones which the Dutch navigators
had brought from Ceylon. Some of the stones seemed to be
possessed of the strange power of attracting and repelling small bits
of straw, ashes, and other light substances. The little ones called
their parents to witness this strange phenomenon, and the stolid
Dutch lapidaries, themselves puzzled at the sight, called the stones
aschentreckers or ash-drawers.
A number of years afterwards, careful experiments disclosed the
wonderful electric powers of the aschentreckers or tourmalines.
Purple, green, and blue tourmalines are found in Brazil. In Ceylon
the stones are found in gravel beds. Rubellites or siberites are found
in Siberia.
Tourmalines are also found in Moravia, the island of Elba,
Sweden, Burmah, Tyrol, Canada, and the United States.
The first tourmaline deposits known in the United States were
discovered at Paris, Maine, in 1820. Another wonderful deposit was
found at Mt. Apatite in Maine in 1882, and up to the present time
the finest tourmaline crystals have been discovered in the United
States.
Really fine specimens of red, blue, or green tourmalines are
uncommon and command very good prices.
Opal.
The precious or noble opal, fire opal, common opal, hydrophane,
and cachelong are different varieties of a mineral that is composed
of about nine parts silica and one part water.
The colors vary from chalky-white to bluish-white, from yellow to
red, and from a slight play of colors to the beautiful mingling of
green, blue, and red with the most remarkable kaleidoscopic effects.
The opal is 5.5 to 6 in hardness, specific gravity 2 to 2.1, lustre
glassy, and translucent from a slight to a very high degree.
The opal is found in an amorphous state and never crystallizes;
in fact from the condition of the pockets in which this mineral is
found, the indications are that the substance was once a fluid.
Under the blow-pipe the opal loses its translucency and cracks
but does not melt. Sulphuric acid will cause it to turn black, and in a
cold solution of caustic potash the opal is almost entirely soluble.
The precious or noble opal is found chiefly in the mines of
Czernowitza, between Kaschau and Eperies, in Hungary, and in
Gracias á Dios, a province in Honduras.
In olden times, the Greek and Turkish merchants carried opals
from Hungary to the Orient, and then they were shipped to Holland
and sold in Europe as Oriental opals.
The fire opal is of a yellowish-red color, and is found chiefly in
Mexico, although it also occurs in Hungary, the Faroe Islands,
Honduras, and Guatemala.
The common opal is found in Ireland, Denmark, Frankfurt,
Guatemala, and South Australia, and also in Hungary and Mexico.
These opals are translucent without fire or reflection.
The hydrophane is an opal that has lost color and brilliancy by
reason of the evaporation of its water. If placed in water or alcohol,
this stone becomes transparent, only to lose this quality when the
water or alcohol has evaporated.
The hydrophane becomes transparent more quickly in warm than
in cold water, but most rapidly in alcohol. If boiled in oil, the
hydrophane is said to retain its brilliancy for years.
The cachelong is milky-white, and nearly opaque, and is found in
small masses in the river Cach, in Bucharia, and also in Iceland.
Although one of the most magnificent of the gem stones, the
opal for many years was under the ban of superstition. Now, this
splendid stone once more commands a foremost place in the
jewelers’ art, and the opal mines of Hungary and Queensland are
being worked to their fullest extent to supply the demand.
Pearl.
Although an organic product, the pearl is always ranked amongst
the most precious of gems, and is distinguished by being the only
gem that does not require the lapidary’s touch to bring out its
beauties.
Ancient writers have accounted for the origin of pearls by saying
that they were formed of angels’ tears, or drops of dew from
heaven, which, during the midsummer nights, fell into the gaping
mouths of the pearl-oysters.
According to modern scientific investigation, the formation of the
pearl does not seem to be the result of healthy natural causes, but
comes from the efforts of the oyster to rid itself of some foreign
substance, like a grain of sand, a bit of shell or vegetation, or some
unwelcome visitor in the shape of a small water insect.
When annoyed by an intruding substance, the oyster begins to
deposit its nacre, or mother-of-pearl, in regular concentric layers
around the intruder, these layers gradually increasing in
circumference and forming the pearl. Thus, like an onion, the pearl
is merely a succession of layers or skins, starting from a small core,
or nucleus, which is always present, though often only of
microscopical size.
Pearls have sometimes been found where the outer layer, or skin,
as it is technically called, has been discolored or otherwise injured,
and when this top skin has been carefully removed the result was a
somewhat smaller but perfect pearl.
This, however, is a very delicate operation, and at the pearling
grounds is only resorted to by men of experience. The composition
of the pearl is carbonate of lime, with a small proportion of organic
matter, and the specific gravity 2.5 to 2.7.
The pearl is affected by acids, and is easily calcined on exposure
to heat.
In color, the pure white, slightly transparent, is the most highly
prized; while in India and China the bright yellow colors are sought
after.
Decided colors, however, such as black, pink, and golden-yellow
bring a high price, and, in fact, black pearls, if perfect in color and
shape, are at present more valuable than any other kind.
The beauty and value of a pearl depend on form, quality of
texture or skin, color, transparency or water, and lustre or orient.
In form, the perfectly round shape comes first in value, then a
finely formed drop or pear shape, and lastly the oval or egg shape.
Pearls that are flat on one side and rounded on the other are
called boutons or button pearls. These are frequently found attached
to the shell, and are cut out and the bottom part smoothed and
polished.
It is easy, however, to detect this class of pearls by the lack of
pearly lustre on the side that was attached to the shell.
When a pearl is rough and odd-shaped it is called a baroque, and
some extremely fantastic shapes are found, especially in fresh-water
oysters.
The texture or skin of a fine pearl should be perfectly smooth
and free from all spots, indentations, wrinkles, or scratches.
Pure white is the desirable color for a gem pearl, but many
others that are slightly tinted with blue, pink, or yellow will pass for
gems if they are otherwise perfect.
The transparency or “water” of a pearl, while not existing in fact,
is still one of the requisites of a fine pearl; there must be an
appearance of transparency, which adds to the beauty of the gem.
To describe the lustre or orient of the pearl, the author can only
use the term pearly, as there is no other substance that approaches
the brilliancy and color of a pearl, excepting, of course, mother-of-
pearl—the nacre in the pearl-oyster.
Without orient or lustre, the pearl of finest form and color has
but little value.
Lustre is to the pearl what brilliancy is to the diamond; when the
orient is absent there is no life, no beauty.
Pearls are principally supplied by two groups of pearl-oysters or
mussels: the marine or meleagrina margaritifera, a round-cornered
square shell with very thick sides, measuring six to eight inches in
length.
The color of this shell is mostly blackish-green, but it is also
sometimes yellowish; the edges of the inner part of the shell are
black, but the rest of the interior is the beautiful mother-of-pearl.
The oyster itself is small for the size of the shell.
This specimen is found on the coast of Ceylon, Persian Gulf,
Japanese, Mexican and California coasts, the western shores of
South America, Brazil, West Indian Islands, Panama, Sooloo
Archipelago, and the northeast and northwestern coast of Australia.
The fresh-water or unio margaritifera is an even, egg-shaped
mussel found in brooks, rivers, and lakes in temperate zones in
nearly all parts of the world.
Some fine river pearls have been found in the United States, but
most of the American pearls are of a button or elongated shape, or
are baroques or fancy-shaped.
In China many people engage in the business of making small
pellets of clay or metal images, which in the month of May are
introduced into the river mussels (mytilus cygneus).
The mussels are replanted, and in November they are taken up
again. Some of the oysters die, but most of them are found to have
been actively at work covering the little pellets or metal figures with
nacre, and while no strictly first-class pearls are formed in this way,
many curious little pearl figures or gods are made and sold to the
curious or devout.
Pink or conch pearls are found in the Gulf of California and coasts
of Mexico, Bahama Islands, West Indian Islands, and in some rivers
in South America.
They seldom occur in regular shapes, and although they are
termed pink pearls, they range in color from red to pale yellow, and
are often found of a china-white color.
The pink pearl displays a wavy appearance and a peculiar sheen,
something like watered silk. As the pink pearl is seldom found
perfectly round and of a good color, such a specimen is very
valuable.
Chrysolite.
The chrysolite, peridot, and olivine differ in color, but are
practically of the same composition.
The chrysolite proper is of a pale greenish-yellow color, the
peridot a deep olive-green, and the olivine of a yellowish or light
olive-green color; these stones also shade into brown. They
crystallize on the rhombic system, are transparent to translucent, 6.5
to 7. in the scale of hardness, and 3.3 to 3.5 in specific gravity.
The cleavage is distinct, fracture conchoidal, refraction double,
and lustre vitreous, and in the olivines somewhat greasy.
These stones are easily affected by sulphuric acid, but are
infusible before the blow-pipe, excepting some kinds containing
much iron.
With borax, they melt to a pale-green transparent glass.
Chrysolites are composed of silica, magnesia, and oxide of iron.
Perfectly crystallized chrysolites are brought from Constantinople,
but the exact locality where they are found is unknown.
Less distinct specimens occur at Vesuvius, Mexico, the isle of
Bourbon, Auvergne, Egypt, Natolia, Brazil, Germany, Pegu, Ceylon,
Switzerland, and North America.
Peridots are distinguished by being the only precious stones that
have literally dropped from heaven, as they have been found in
meteorites.
The Oriental chrysolite of commerce is true chrysoberyl, and is
harder and heavier than chrysolite, and the stone called Ceylon
chrysolite is a greenish-yellow tourmaline, which is easily
distinguished, as it is also harder while considerably lighter than the
chrysolite.
The green garnet is of a pronounced green color, and is harder
and heavier than the olivine or chrysolite. Although suitable for
mounting in brooches and other ornaments, these stones are not
sufficiently hard for the rough usage as ring-stones.
Garnet.
Almandine, almandite, Syrian garnet, essonite, cinnamon-stone,
pyrope, Bohemian garnet, vermeille, Cape garnet, Cape ruby,
Arizona ruby, American ruby, carbuncle, uwarowite, demantoide,
grossularite, and Bobrowska garnet are some of the scientific and
commercial names for different species and colors of the garnet
group.
The crystallization of the garnet is isometric, refraction single,
specific gravity 3.15 to 4.3, hardness 5 to 8, lustre vitreous, fracture
uneven, colors red, violet, brown, yellow, green, and white, and the
various shadings of these colors.
Most varieties fuse easily to a brown or black glass; the
uwarowite fuses with borax to a clear chrome-green glass.
Syrian, almandine, almandite, and carbuncle are different names
for the iron-alumina garnet.
In colors, these stones shade from deep-red to violet and
brownish-red, and are composed of:
Silica 36.01
Alumina 20.06
Protoxide of iron 43.03
The specific gravity is 4. to 4.2, and hardness 7.5.
This garnet, sometimes called the precious garnet, is found in
Ceylon, Pegu, Brazil, Greenland, Hindustan, Bohemia, Tyrol, Œtzthal,
Carinthia, Styria, Switzerland, Ariolo, Canaria, Maggia, Hungary,
Sweden, Norway, Scotland, Spain, and the United States.
Grossularite, or lime-alumina garnet, is known in commerce as
essonite, or cinnamon-stone. The color is yellow, of various shades;
specific gravity 3.5 to 3.65, and hardness 6.5.
These stones are sometimes sold for jacinths, but they are softer
than the jacinth, and melt easily before the blow-pipe. Essonites
come principally from Ceylon, but are also found in other places.
Pyrope or Bohemian garnet is the magnesia-alumina variety, and
is of a uniform dark blood-red color. This stone is found in Bohemia,
and although quantities of small pieces are found, large specimens
are rare, and a piece that will cut into a four- or five-carat stone is
seldom met with and commands a high price.
These garnets are found at Stiefelburg by Meronitz, Triblitz,
Podsedlitz, and Neupaka.
The pyrope turns black under the blow-pipe, then red again, and
melts with difficulty into a black glass. With borax it melts to an
emerald-green glass. The specific gravity of this garnet is 3.69 to
3.78, and hardness 7.5.
Vermeille is a name given to the orange-red almandine, Cape
garnet to the bright red-yellow variety, Cape ruby to the pyrope, and
American ruby to the blood-red kind found in New Mexico, Montana,
and Arizona. Carbuncle is a term applied to all garnets cut with a
smooth rounding top, sometimes called, after the French, cabochon.
Uwarowite or lime-chrome garnet is one of the rarest and most
beautiful of the garnet group.
The color of this stone is emerald-green, hardness 7.5, and
specific gravity 3.41 to 3.52. Uwarowites are found near Bissersk in
the Urals of Russia, but rarely in specimens of sufficient size to cut
into gems.
This garnet is heavier and harder than the true emerald.
Demantoide or Bobrowska garnet is a soft garnet, olive-green to
brown and blackish-green in color, sometimes light green. It is found
in the Bobrowska River in the Urals. The specific gravity is 3.85, and
hardness about 6, its softness making it undesirable for many
ornaments. Before the blow-pipe it fuses into a black bead.
These garnets are often sold as olivines; they are heavier than
olivines and softer.
Demantoide is composed of:
Silica 35.44
Lime 32.85
Sesquioxide of iron 32.85
Magnesia .20
Topaz.
Topaz belongs to the rhombic system of crystallization. Its
cleavage is basal and perfect, fracture uneven, hardness 8,
scratching quartz distinctly, specific gravity 3.4 to 3.6, lustre
vitreous, refraction double, and colors ranging from colorless or
white to bluish-white, light blue, wine-yellow, straw-yellow, golden-
yellow, greenish- and pale-red to pink.
Topaz becomes electric from rubbing or pressure, and retains
electricity for twenty-four hours. Before the blow-pipe topaz partly
loses color, but does not melt, and with borax it fuses slowly to a
white bead.
Topaz is partially attacked by sulphuric acid, and dissolves in salts
of phosphorus.
The composition of topaz is:
Silicon 15.05
Aluminium 30.02
Oxygen 36.08
Fluorine 17.05
Goutte d’eau or colorless topaz, sometimes called “slaves
diamond,” Siberian or bluish-white, Brazilian or golden to reddish-
yellow, Saxony or pale-wine yellow, Brazilian ruby or pink, Brazilian
sapphire or light blue, and aquamarine or greenish, are the various
commercial names for topaz.
Most of the Brazilian rubies or pink topazes are produced by
heating the reddish or dark-yellow variety, either in a crucible or by
enveloping the stone in German tinder and setting fire to the tinder.
If heated too much, the stone is apt to become colorless, and if
suddenly cooled it may crack.
Colorless or white topaz takes a very high polish, and is
wonderfully clear and transparent.
The great Portuguese diamond, “The Braganza,” of about 1,680
carats, is supposed to be a white topaz.
Topaz is found in the Urals, Kamschatka, Alabaschka, Miask,
Nestschinsk, Adun Tschilon, Villa Rica, Boa Vista, Capao, Lana, Minas
Novas, Cairngorm Mts., Schlackenwald, Zinnwald, Schneckenstein,
Ehrenfriedensdorf, Altenburg, Orenburg, Mourne Mts.—Ireland,
Australia, New South Wales, Ceylon, Mexico, and the United States.
False topaz, or the ordinary topaz of commerce, is yellow quartz
resembling yellow topaz, but lacking its brilliancy and hardness; it is
also very much lighter, being only 2.5 to 2.7 in specific gravity.
Beryl and chrysolite are often mistaken for topaz, but as they are
softer and beryl is much lighter, they are easily distinguished from
the topaz. The strong electric property of the topaz is also a
conclusive test.
Oriental topaz, or yellow corundum, is harder and heavier than
the occidental or true topaz.
Apatite.
Apatite, which is seldom used as a gem stone, sometimes
resembles the beryl and emerald, but is much softer and rarely has
the color and brightness combined of the former gems.
This mineral, composed principally of subsesquiphosphate of
lime, is 4.5 to 5. in hardness, has the specific gravity of 2.95 to 3.25,
is transparent to opaque, vitreous in lustre, infusible before the
blow-pipe, and dissolves slowly in nitric acid. In colors, apatite varies
from colorless to sea-green, bluish-green, violet-blue, gray, yellow,
red, and brown.
Apatite is found in Saxony, the Hartz Mts., Bohemia, Norway,
Bavaria, England, St. Gothard in Switzerland, and in the United
States.
Felspar.
Four varieties of felspar are used as gem stones—moonstone or
orthoclase, sunstone or avanturine felspar, Amazon stone or green
felspar, and Labrador or Labrador spar.
Moonstone.
This variety of felspar is called orthoclase, adularia, and orthose,
besides the commercial names of fish-eye, Ceylon or water opal, and
in the yellow and red tints sunstone. Moonstone occurs in crystals
and crystalline fragments, also massive and granular; its hardness is
6. to 6.5, specific gravity 2.4 to 2.6, refraction double, is not
attacked by acids, and is composed of:
Silica 64.5
Alumina 18.5
Potash 17.
With traces of soda.
This beautiful stone is the clearest of all varieties of felspar. It is
colorless, or only slightly tinted with blue, green, yellow, and flesh-
red, and is transparent to translucent.
The lustre is vitreous, and a brilliant pearly streak of white light
plays from side to side.
The yellowish- and reddish-tinted specimens are called
sunstones, and are quite rare. These sunstones must not be
confounded with the avanturine or felspar sunstone.
Moonstones are found principally in Ceylon and on the St.
Gothard in Switzerland, but also occur in Bavaria, Greenland, Tyrol,
Dauphine, Norway, and the United States.
During the past few years, large quantities of moonstone balls,
cut like whole pearls, have been used for jewelry—the stones being
much sought as well because of their beauty as on the ground of the
popular superstition that they will bring good luck to the wearer.
Small pieces or balls are not very valuable, but large perfect
specimens command a good price.
Sunstone.
(AVANTURINE FELSPAR.)

Sunstone or avanturine felspar is a variety of oligoclase; grayish-


white to reddish-gray in color, usually the latter; containing minute
crystals of hematite, göthite or mica, which are imbedded and
scattered through the stone, and give forth golden-yellow, reddish,
or prismatic reflections. The hardness is 6 to 7, specific gravity 2.56
to 2.72, and lustre pearly or waxy to vitreous.
Sunstones are found near Stockholm, in Finland, the Urals,
Ceylon, the Alps, Iceland, the United States, and other places.
Amazon Stone.
(GREEN FELSPAR.)

The Amazon stone is a green variety of felspar, which was first


found on the banks of the Amazon River, but now comes from
Siberia and the United States. This stone consists of potash,
alumina, and silex—is green in color but rarely clean, being
discolored in places and usually covered with small white spots.
The Amazon stone is harder than glass, but is scratched by rock
crystal. Its specific gravity is 2.5 to 2.6; acids do not affect it, and it
melts with difficulty before the blow-pipe.
Labradorite.
Labrador stone or labradorite is sometimes known as opaline
felspar, and was first discovered on the island of St. Paul on the
coast of Labrador.
Labradorite is translucent to opaque, gray-green or brown in
color, and has beautiful chatoyant reflections of brilliant blue, sea-
green, and sometimes red and yellow, changing from one color to
another. Labradorite is 6 in hardness, has a specific gravity of 2.62 to
2.76; a vitreous to pearly lustre, is brittle, fuses with difficulty before
the blow-pipe, and is decomposed by muriatic acid. It is composed
of:
Silica 52.9
Alumina 30.3
Lime 12.3
Soda 4.5
Large masses of this stone are found on the coast of Labrador. It
is also found in Finland, Russia, and the United States. Because of
the dark chatoyant appearance the name of œil de bœuf or ox-eye is
sometimes applied to labradorite. Handsome specimens, cut
cabochon, form pretty ring stones, and many effective engraved
cameos have been produced by using the bright portion for the relief
work and the gray dead part for the base.
Cyanite.
This stone is the transparent variety of disthene, and is
sometimes commercially known as sappare. Cyanite is colorless to
bluish-white, sky-blue, berlin blue, yellowish- and reddish-white,
gray, and green.
The hardness is 5 to 7, specific gravity 3.45 to 3.70, lustre
vitreous and pearly; it is infusible before the blow-pipe, but fuses
with borax; is not attacked by acids, and is composed of:
Silica 36.8
Alumina 63.2
Cyanite is found in Switzerland, the Tyrol, Styria, Carinthia,
Bohemia, Norway, Finland, France, South America, Scotland, Ireland,
Siberia, the East Indies, and the United States. Clean specimens are
not plentiful, and fine blue pieces have frequently been sold for
sapphires. The cyanite can be distinguished from the sapphire by its
inferior hardness and lighter weight.
Lapis Lazuli.
Lapis lazuli, the sapphire of the ancients, is a mineral, translucent
to opaque, ranging in color from colorless to an azure-blue, violet-
blue, green, and red.
The principal color, however, is a rich, azure blue, sometimes
shading into green, and having a vitreous to greasy lustre.
Its hardness is 5 to 5.5, specific gravity 2.38 to 2.42; it is
decomposed by muriatic acid, and fuses before the blow-pipe to a
white glass. It is rarely found clean, but has usually a number of
veins and spots of a metallic nature. It is composed of:
Silica 45.
Alumina 31.76
Soda 9.09
Lime 3.52
Sulphuric acid 5.89
and traces of iron, soda, and potash.
This mineral is found in Siberia, Transylvania, Persia, China,
Thibet, Tartary, South America, India, and Brazil.
Lapis lazuli is sometimes employed for jewelry, and was for some
centuries ground up and used to make the mineral paint known as
genuine ultramarine. This paint is now produced chemically, and the
more costly mineral compound is rarely used.
The imitation of lapis lazuli for jewelry purposes is also very easy,
as metal filings can be readily introduced into the azure blue glass,
and thus an imitation of the genuine stone produced, which is
perfect excepting in hardness.
Hiddenite.
The hiddenite is a variety of spodumene that has only been
found in one locality, namely, Alexander County, North Carolina. This
mineral was discovered by W. E. Hidden, and has been named after
him.
The hiddenite is perfectly transparent, and varies from a pale
yellowish- to a deep emerald-green, being very brilliant, and
approaching the emerald in color. As this stone is rarely found large
enough for cutting into gems, it is highly prized, and good specimens
command a large price.
The hardness of the hiddenite is 6.5 to 7, and specific gravity
3.13 to 3.19; before the blow-pipe it melts to a clear glass, and it is
attacked by salts of phosphorus. It is composed of:
Silica 64.35
Alumina 26.58
Lithia 7.05
with traces of iron and soda.
Spodumene.
Spodumene is sometimes cut and polished as a gem, but its
peculiar cleavage makes it a bad stone for the lapidary to cut and
the jeweler to mount.
Its hardness is 6.5 to 7, specific gravity 3.13 to 3.19, and lustre,
vitreous to pearly.
Grayish-green, greenish-white, and sometimes yellow or faint red
are the colors. Its composition is:
Silica 64.2
Alumina 29.4
Lithia 6.4
Acids do not attack spodumene, and under the blow-pipe it fuses
to a white glass.
This mineral is found in Sweden, the Tyrol, Ireland, Scotland, and
the United States.

You might also like