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

Java on the Raspberry Pi: Develop Java Programs to Control Devices for Robotics, IoT, and Beyond Flurry - Download the entire ebook instantly and explore every detail

The document provides information about an ebook titled 'Java on the Raspberry Pi' by Greg Flurry, which focuses on developing Java programs for controlling devices in robotics and IoT. It includes links to download the ebook and other recommended digital products, as well as a detailed table of contents outlining various chapters related to Raspberry Pi setup and Java programming. The document emphasizes the practical applications of Java in the context of Raspberry Pi and device control.

Uploaded by

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

Java on the Raspberry Pi: Develop Java Programs to Control Devices for Robotics, IoT, and Beyond Flurry - Download the entire ebook instantly and explore every detail

The document provides information about an ebook titled 'Java on the Raspberry Pi' by Greg Flurry, which focuses on developing Java programs for controlling devices in robotics and IoT. It includes links to download the ebook and other recommended digital products, as well as a detailed table of contents outlining various chapters related to Raspberry Pi setup and Java programming. The document emphasizes the practical applications of Java in the context of Raspberry Pi and device control.

Uploaded by

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

Read Anytime Anywhere Easy Ebook Downloads at ebookmeta.

com

Java on the Raspberry Pi: Develop Java Programs to


Control Devices for Robotics, IoT, and Beyond
Flurry

https://ebookmeta.com/product/java-on-the-raspberry-pi-
develop-java-programs-to-control-devices-for-robotics-iot-
and-beyond-flurry/

OR CLICK HERE

DOWLOAD EBOOK

Visit and Get More Ebook Downloads Instantly at https://ebookmeta.com


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

Real-Time IoT Imaging with Deep Neural Networks: Using


Java on the Raspberry Pi 4 1st Edition Nicolas Modrzyk

https://ebookmeta.com/product/real-time-iot-imaging-with-deep-neural-
networks-using-java-on-the-raspberry-pi-4-1st-edition-nicolas-modrzyk/

ebookmeta.com

Java: A Beginner's Guide: Create, Compile, and Run Java


Programs Today Herbert Schildt

https://ebookmeta.com/product/java-a-beginners-guide-create-compile-
and-run-java-programs-today-herbert-schildt/

ebookmeta.com

Raspberry Pi IoT In C 2nd Edition Harry Fairhead

https://ebookmeta.com/product/raspberry-pi-iot-in-c-2nd-edition-harry-
fairhead/

ebookmeta.com

Pediatric Hypertension 5th Joseph T Flynn Julie R


Ingelfinger Tammy M Brady Eds

https://ebookmeta.com/product/pediatric-hypertension-5th-joseph-t-
flynn-julie-r-ingelfinger-tammy-m-brady-eds/

ebookmeta.com
House of Music: Raising the Kanneh-Masons 1st Edition
Kadiatu Kanneh-Mason

https://ebookmeta.com/product/house-of-music-raising-the-kanneh-
masons-1st-edition-kadiatu-kanneh-mason/

ebookmeta.com

Wraparound Guide How to Gather Student Voice Build


Community a Wraparound Service Delivery Handbook for
Helping Students Overcome Barriers to Wellness and
Learning Partnerships and Cultivate Hope 1st Edition Leigh
https://ebookmeta.com/product/wraparound-guide-how-to-gather-student-
Colburn
voice-build-community-a-wraparound-service-delivery-handbook-for-
helping-students-overcome-barriers-to-wellness-and-learning-
partnerships-and-cultivate-hope-1st/
ebookmeta.com

Beautiful Monsters: Imagining the Classic in Musical Media


Michael Long

https://ebookmeta.com/product/beautiful-monsters-imagining-the-
classic-in-musical-media-michael-long/

ebookmeta.com

Thinking Through Images Narrative rhythm embodiment and


landscape in the Nordic Bronze Age Tilley Christopher

https://ebookmeta.com/product/thinking-through-images-narrative-
rhythm-embodiment-and-landscape-in-the-nordic-bronze-age-tilley-
christopher/
ebookmeta.com

Rigorous PBL by Design Three Shifts for Developing


Confident and Competent Learners 1st Edition Michael
Mcdowell
https://ebookmeta.com/product/rigorous-pbl-by-design-three-shifts-for-
developing-confident-and-competent-learners-1st-edition-michael-
mcdowell/
ebookmeta.com
Meredith The Guardians Trust 4 1st Edition Beth Linton

https://ebookmeta.com/product/meredith-the-guardians-trust-4-1st-
edition-beth-linton/

ebookmeta.com
TECHNOLOGY IN AC TION™

Java on the
Raspberry Pi
Develop Java Programs to
Control Devices for Robotics,
IoT, and Beyond

Greg Flurry
Java on the
Raspberry Pi
Develop Java Programs
to Control Devices for
Robotics, IoT, and Beyond

Greg Flurry
Java on the Raspberry Pi: Develop Java Programs to Control Devices for
Robotics, IoT, and Beyond

Greg Flurry
Austin, TX, USA

ISBN-13 (pbk): 978-1-4842-7263-3 ISBN-13 (electronic): 978-1-4842-7264-0


https://doi.org/10.1007/978-1-4842-7264-0

Copyright © 2021 by Greg Flurry


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: Aaron Black
Development Editor: James Markham
Coordinating Editor: Jessica Vakili
Distributed to the book trade worldwide by Springer Science+Business Media New York, 1 NY
Plaza, New York, NY 10014. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@
springer-sbm.com, 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 booktranslations@springernature.com; for
reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com.
Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook
versions and licenses are also available for most titles. For more information, reference our Print
and eBook Bulk Sales web page at http://www.apress.com/bulk-sales.
Any source code or other supplementary material referenced by the author in this book is available
to readers on GitHub via the book’s product page, located at www.apress.com/978-­1-­4842-­7263-­3.
For more detailed information, please visit http://www.apress.com/source-­code.
Printed on acid-free paper
To my wonderful wife Sylvia, who endured many months of
a distracted husband who talked about “the book”
whenever he considered it acceptable.
Table of Contents
About the Author������������������������������������������������������������������������������xvii

About the Technical Reviewer�����������������������������������������������������������xix


Acknowledgments�����������������������������������������������������������������������������xxi

Chapter 1: Motivations�������������������������������������������������������������������������1
Why the Raspberry Pi?������������������������������������������������������������������������������������������2
The “Best” Raspberry Pi for Robotics��������������������������������������������������������������4
The “Best” Raspberry Pi for IoT�����������������������������������������������������������������������6
Why Java?�������������������������������������������������������������������������������������������������������������6
Programmer Productivity���������������������������������������������������������������������������������7
Performance��������������������������������������������������������������������������������������������������13
Industry Acceptance��������������������������������������������������������������������������������������13
The Verdict�����������������������������������������������������������������������������������������������������14
Why Remote Development Using NetBeans?������������������������������������������������������15
Why NetBeans?���������������������������������������������������������������������������������������������18
Summary������������������������������������������������������������������������������������������������������������19

Chapter 2: Raspberry Pi 3 Model B+ Setup����������������������������������������21


Setup Considerations������������������������������������������������������������������������������������������21
Choose the Operating System�����������������������������������������������������������������������������22
Load Raspberry Pi OS on the microSD Card�������������������������������������������������������23
Get Raspberry Pi OS��������������������������������������������������������������������������������������23
Image Raspberry Pi OS����������������������������������������������������������������������������������24

v
Table of Contents

Boot and Configure Raspberry Pi OS������������������������������������������������������������������31


Initial Configuration���������������������������������������������������������������������������������������31
Configure Remote Computing�����������������������������������������������������������������������39
Configure the Interface Capabilities��������������������������������������������������������������40
Install Java on Raspberry Pi OS��������������������������������������������������������������������������43
What Java to Install?�������������������������������������������������������������������������������������44
Check for Prior Java Installations������������������������������������������������������������������44
Install the JDK 11������������������������������������������������������������������������������������������46
Finish Java Installation����������������������������������������������������������������������������������46
Finish Pi3 Setup��������������������������������������������������������������������������������������������������47
Summary������������������������������������������������������������������������������������������������������������48

Chapter 3: Raspberry Pi Zero W Setup�����������������������������������������������49


Setup Considerations������������������������������������������������������������������������������������������49
Choose the Operating System�����������������������������������������������������������������������������50
Load Raspberry Pi OS on the microSD Card�������������������������������������������������������50
Write Raspberry Pi OS�����������������������������������������������������������������������������������50
Finish the Bootable microSD Card����������������������������������������������������������������������54
Boot and Configure Raspberry Pi OS������������������������������������������������������������������56
Find the IP Address����������������������������������������������������������������������������������������56
Connect to the Zero���������������������������������������������������������������������������������������57
Update and Upgrade Raspberry Pi OS�����������������������������������������������������������58
Additional Configuration��������������������������������������������������������������������������������58
Configure the Interface Capabilities��������������������������������������������������������������64
Install Java on Raspberry Pi OS��������������������������������������������������������������������������66
What Java to Install?�������������������������������������������������������������������������������������66
Check for Prior Java Installations������������������������������������������������������������������67
Install the JDK 11������������������������������������������������������������������������������������������67
Summary������������������������������������������������������������������������������������������������������������70

vi
Table of Contents

Chapter 4: Set Up the Workstation�����������������������������������������������������71


Remote Computing with SSH������������������������������������������������������������������������������71
Remote Computing with VNC������������������������������������������������������������������������������73
Start the VNC Server��������������������������������������������������������������������������������������73
Get and Start the VNC Viewer������������������������������������������������������������������������74
Tune the VNC Server��������������������������������������������������������������������������������������77
Summary������������������������������������������������������������������������������������������������������������81

Chapter 5: Remote Java Development with NetBeans�����������������������83


Choose NetBeans and Java Versions������������������������������������������������������������������83
Install Java 11�����������������������������������������������������������������������������������������������������84
Install NetBeans 12.0������������������������������������������������������������������������������������������87
Test the NetBeans Installation����������������������������������������������������������������������������90
Configure the Raspberry Pi As a Remote Platform���������������������������������������������95
Test Remote Development��������������������������������������������������������������������������������100
Debug Remotely������������������������������������������������������������������������������������������������102
Fix Remote Debug���������������������������������������������������������������������������������������102
Successful Debug����������������������������������������������������������������������������������������103
Examine Variables While Debugging�����������������������������������������������������������104
The Debugger Menu������������������������������������������������������������������������������������105
Run on the Raspberry Pi Without NetBeans������������������������������������������������������106
Leverage NetBeans in Complex Projects����������������������������������������������������������108
Create and Test Libraries�����������������������������������������������������������������������������109
Use Libraries������������������������������������������������������������������������������������������������113
Choose Which Program to Run from NetBeans�������������������������������������������������117
Run the Chosen Program on the Raspberry Pi Without NetBeans��������������������118
Just Download with NetBeans��������������������������������������������������������������������������119
Summary����������������������������������������������������������������������������������������������������������121

vii
Table of Contents

Chapter 6: Device Support in Java���������������������������������������������������123


Find Base I/O Libraries for Java������������������������������������������������������������������������124
Select the Best Base I/O Library�����������������������������������������������������������������������125
Functional Coverage������������������������������������������������������������������������������������125
Performance������������������������������������������������������������������������������������������������125
Support��������������������������������������������������������������������������������������������������������126
Ease of Use��������������������������������������������������������������������������������������������������127
The Base I/O Choice for This Book��������������������������������������������������������������������128
A Look at pigpioj������������������������������������������������������������������������������������������129
A Look at diozero�����������������������������������������������������������������������������������������130
Evaluating the Choices��������������������������������������������������������������������������������132
The Final Choice – diozero��������������������������������������������������������������������������134
Configure diozero in NetBeans�������������������������������������������������������������������������135
Find (and Port) Device Libraries������������������������������������������������������������������������141
Java Device Library and diozero Base I/O���������������������������������������������������143
Java Device Library and Non-diozero Base I/O�������������������������������������������143
C/C++ Device Library����������������������������������������������������������������������������������144
Python Device Library����������������������������������������������������������������������������������145
No Device Library����������������������������������������������������������������������������������������146
Summary����������������������������������������������������������������������������������������������������������146

Chapter 7: The diozero Base I/O API�������������������������������������������������149


diozero Utilities�������������������������������������������������������������������������������������������������149
Connect Devices to a Raspberry Pi�������������������������������������������������������������������150
diozero SerialDevice�����������������������������������������������������������������������������������������153
Background on Raspberry Pi Serial I/O�������������������������������������������������������153
Constructors������������������������������������������������������������������������������������������������155
Read and Write Methods�����������������������������������������������������������������������������156
Support for Device Identity��������������������������������������������������������������������������157

viii
Table of Contents

diozero I2CDevice���������������������������������������������������������������������������������������������164
Background on Raspberry Pi I2C�����������������������������������������������������������������164
Constructors������������������������������������������������������������������������������������������������167
Read and Write Methods�����������������������������������������������������������������������������168
diozero SpiDevice���������������������������������������������������������������������������������������������170
Background on Raspberry Pi SPI�����������������������������������������������������������������170
Constructors������������������������������������������������������������������������������������������������171
Read and Write Methods�����������������������������������������������������������������������������172
GPIO������������������������������������������������������������������������������������������������������������������173
Background on Raspberry Pi GPIO��������������������������������������������������������������174
diozero GPIO Classes�����������������������������������������������������������������������������������177
Device Library and Application Structure����������������������������������������������������������182
RuntimeIOException������������������������������������������������������������������������������������183
Safety Nets��������������������������������������������������������������������������������������������������184
Safety Net Guidelines����������������������������������������������������������������������������������188
Summary����������������������������������������������������������������������������������������������������������190

Chapter 8: A DC Motor Controller�����������������������������������������������������191


Choose the Device��������������������������������������������������������������������������������������������192
Understand the Device��������������������������������������������������������������������������������������193
Find a Device Library����������������������������������������������������������������������������������������195
Search for Java Libraries�����������������������������������������������������������������������������195
Search for Non-Java Libraries���������������������������������������������������������������������196
And the Answer Is …����������������������������������������������������������������������������������201
Porting Issues���������������������������������������������������������������������������������������������������202
Device Library Interface������������������������������������������������������������������������������202
Device Instances�����������������������������������������������������������������������������������������205
Verbatim vs. Cleansing Port������������������������������������������������������������������������206
Porting Approach�����������������������������������������������������������������������������������������207

ix
Table of Contents

Play with the Device�����������������������������������������������������������������������������������������208


Device Library Development�����������������������������������������������������������������������������209
RoboClaw Class�������������������������������������������������������������������������������������������212
Constructor Analysis and Implementation���������������������������������������������������214
Mid-level Methods Analysis�������������������������������������������������������������������������218
CRC-Related Methods���������������������������������������������������������������������������������218
Low-Level Methods Analysis�����������������������������������������������������������������������220
Mid-level Methods Implementation�������������������������������������������������������������220
Finish the Core��������������������������������������������������������������������������������������������224
Test the Core������������������������������������������������������������������������������������������������226
Complete the Implementation���������������������������������������������������������������������235
Summary����������������������������������������������������������������������������������������������������������246

Chapter 9: An Inertial Measurement Unit�����������������������������������������249


Understand the Device��������������������������������������������������������������������������������������250
Find a Device Library����������������������������������������������������������������������������������������252
A Search for Java Libraries�������������������������������������������������������������������������252
A Search for Non-Java Libraries�����������������������������������������������������������������������254
A Look at the C++ Libraries������������������������������������������������������������������������254
A Look at the C Libraries�����������������������������������������������������������������������������255
And the Answer Is …����������������������������������������������������������������������������������255
Device Library Port��������������������������������������������������������������������������������������������256
Play with the Device (FXAS21002C)������������������������������������������������������������������257
Device Library Development (FXAS21002C)�����������������������������������������������������259
Constructor Analysis and Implementation���������������������������������������������������260
Configuration�����������������������������������������������������������������������������������������������265
Read a Sample��������������������������������������������������������������������������������������������268
Test the Core������������������������������������������������������������������������������������������������271

x
Table of Contents

Additional Thoughts�������������������������������������������������������������������������������������276
Address Zero Offset and Noise��������������������������������������������������������������������291
Get Real�������������������������������������������������������������������������������������������������������302
What Next?��������������������������������������������������������������������������������������������������306
Device Library Development (FXOS8700CQ)�����������������������������������������������������306
Constructor Analysis and Implementation���������������������������������������������������311
Configuration�����������������������������������������������������������������������������������������������313
Read Sample and Status�����������������������������������������������������������������������������316
Test the Core������������������������������������������������������������������������������������������������318
Events Again������������������������������������������������������������������������������������������������323
What Next?��������������������������������������������������������������������������������������������������329
Summary����������������������������������������������������������������������������������������������������������331

Chapter 10: A Lidar Unit�������������������������������������������������������������������333


Understand the Device��������������������������������������������������������������������������������������334
Find a Device Library����������������������������������������������������������������������������������������334
Device Library Design���������������������������������������������������������������������������������������335
Interface������������������������������������������������������������������������������������������������������335
Common Methods���������������������������������������������������������������������������������������337
Other Considerations�����������������������������������������������������������������������������������338
Play with the Device�����������������������������������������������������������������������������������������339
Device Library Development�����������������������������������������������������������������������������342
Development Approach�������������������������������������������������������������������������������342
Lidar Core����������������������������������������������������������������������������������������������������343
Implementation�������������������������������������������������������������������������������������������344
Test the Core������������������������������������������������������������������������������������������������348
Additional Methods��������������������������������������������������������������������������������������352

xi
Table of Contents

Test the Additional Methods������������������������������������������������������������������������356


Additional Thoughts�������������������������������������������������������������������������������������360
What Next?��������������������������������������������������������������������������������������������������������369
Summary����������������������������������������������������������������������������������������������������������369

Chapter 11: An Environmental Sensor����������������������������������������������371


Understand the Device��������������������������������������������������������������������������������������371
Find a Device Library����������������������������������������������������������������������������������������373
Use the diozero BME280�����������������������������������������������������������������������������������376
Play with I2C and SPI����������������������������������������������������������������������������������������381
To the Datasheet������������������������������������������������������������������������������������������382
I2CDevice�����������������������������������������������������������������������������������������������������383
SpiDevice�����������������������������������������������������������������������������������������������������387
A Step Beyond Play�������������������������������������������������������������������������������������392
Summary����������������������������������������������������������������������������������������������������������395

Chapter 12: An Analog-to-Digital Converter�������������������������������������397


Understand the Device��������������������������������������������������������������������������������������398
Finding a Device Library�����������������������������������������������������������������������������������398
Use the diozero McpAdc�����������������������������������������������������������������������������������400
Play with SPI�����������������������������������������������������������������������������������������������������403
Turn Play into Reality����������������������������������������������������������������������������������������408
Summary����������������������������������������������������������������������������������������������������������412

Chapter 13: A Stepper Motor Driver�������������������������������������������������413


Understand the Device��������������������������������������������������������������������������������������413
Find a Device Library����������������������������������������������������������������������������������������416
Search for Non-Java Libraries���������������������������������������������������������������������416
And the Answer Is …����������������������������������������������������������������������������������417

xii
Table of Contents

Device Library Design���������������������������������������������������������������������������������������417


Interface Design������������������������������������������������������������������������������������������418
Device Library Development�����������������������������������������������������������������������������419
Play with the Device������������������������������������������������������������������������������������419
SilentStepStick Implementation������������������������������������������������������������������422
Constructor Implementation������������������������������������������������������������������������423
Test SilentStepStick�������������������������������������������������������������������������������������428
What Next?��������������������������������������������������������������������������������������������������������432
Speed Profiles���������������������������������������������������������������������������������������������437
Summary����������������������������������������������������������������������������������������������������������439

Chapter 14: A Project�����������������������������������������������������������������������441


The Metronome�������������������������������������������������������������������������������������������������441
Mechanical Design��������������������������������������������������������������������������������������������442
Electronic Design����������������������������������������������������������������������������������������������446
Software Design������������������������������������������������������������������������������������������������447
Project Component Testing�������������������������������������������������������������������������������448
Test waitForActive���������������������������������������������������������������������������������������448
Test whenActivated�������������������������������������������������������������������������������������452
Test addListener������������������������������������������������������������������������������������������455
Metronome Development����������������������������������������������������������������������������������458
Go Beyond Initial Requirements������������������������������������������������������������������������463
Get Closer to the Real World�����������������������������������������������������������������������������467
Summary����������������������������������������������������������������������������������������������������������472

xiii
Table of Contents

Appendix A1: Arduino Command Server������������������������������������������473


S
 ome Arduino Background�������������������������������������������������������������������������������474
Choose an Arduino��������������������������������������������������������������������������������������������475
The Command Server Pattern���������������������������������������������������������������������������476
The command_server Sketch���������������������������������������������������������������������������477
command_server File����������������������������������������������������������������������������������480
cmd_executor.h File������������������������������������������������������������������������������������484
cmd_executor file����������������������������������������������������������������������������������������485
Test the Command Server���������������������������������������������������������������������������������487
The Command Server As a “Device”�����������������������������������������������������������������489
Test the “Device” from Raspberry Pi�����������������������������������������������������������������489
Summary����������������������������������������������������������������������������������������������������������492

Appendix A2: Custom Lidar Unit�������������������������������������������������������493


The Hardware Design����������������������������������������������������������������������������������������493
Some Harsh Reality�������������������������������������������������������������������������������������������496
The Lidar Unit Sketch����������������������������������������������������������������������������������������497
cmd_executor.h�������������������������������������������������������������������������������������������499
cmd_executor����������������������������������������������������������������������������������������������499
lidar.h�����������������������������������������������������������������������������������������������������������504
lidar�������������������������������������������������������������������������������������������������������������505
servo.h���������������������������������������������������������������������������������������������������������507
servo������������������������������������������������������������������������������������������������������������509
Test�������������������������������������������������������������������������������������������������������������������512
Lidar Unit “Datasheet”��������������������������������������������������������������������������������������514
Power����������������������������������������������������������������������������������������������������������������514
Interface������������������������������������������������������������������������������������������������������������515
Summary����������������������������������������������������������������������������������������������������������519

xiv
Table of Contents

Appendix A3: NetBeans and Maven��������������������������������������������������521


Create a NetBeans Project Using Maven and diozero���������������������������������������523
Develop a Device Library����������������������������������������������������������������������������������526
Test the Device Library�������������������������������������������������������������������������������������529
Run TestLED with a diozero Remote Provider����������������������������������������������532
Run TestLED on a Raspberry Pi�������������������������������������������������������������������������535
Automate Build, Download, Run������������������������������������������������������������������������542
Summary����������������������������������������������������������������������������������������������������������546

Index�������������������������������������������������������������������������������������������������549

xv
About the Author
Greg Flurry, an IBM employee for 40 years,
retired as a Distinguished Engineer in 2013.
At IBM, his roles included research, product
development, and client services. While
at IBM, Greg authored over 50 articles in
both IBM and non-IBM publications on
topics ranging from “getting started” in Java
programming to designing enterprise system
architectures; he was granted over 30 patents
worldwide.
After retiring, Greg explored robotics. He used the Raspberry Pi as
the brain in autonomous robots, initially programming in Python. As
the robots became more complex, he yearned for Java and professional
development tools. In 2015, he began using Java and Eclipse on a
workstation for robotics projects. In 2017, he began using Java on the
Raspberry Pi, with NetBeans on a workstation, for robotics projects. Greg
continues to use Java and NetBeans to build complex robotics systems
based on the Raspberry Pi.

xvii
About the Technical Reviewer
Joshua Willman is a software engineer with
more than 12 years of experience developing
applications in Python, Java, and C++.
His career has allowed him to participate
in many different fields, from robotics,
machine learning, and computer vision to UI
development, game development, and more.
In recent years, his passion for
programming and all things visual has allowed
him to participate in numerous projects.
These include designing educational courses
for mobile robotics and computer vision using Arduino and Raspberry Pi,
building GUI applications, and working as a solo indie game developer. He
currently works as a freelance developer, a technical writer, and a content
creator (learning web development in his spare time in order to build his
own platform, redhuli.io). When he’s not working, he enjoys tinkering on
robotics projects and spending time with his wonderful wife and daughter.
He is also the author of two books with Apress:

• Beginning PyQt: A Hands-on Approach to GUI


Programming

• Modern PyQt: Create GUI Applications for Project


Management, Computer Vision, and Data Analysis

xix
Acknowledgments
This book was built on a foundation laid by many others. Some are
obvious: the professional developers of Java, Raspberry Pi, NetBeans, and
various devices. Some are not so obvious: the thousands of "volunteer"
developers that form communities around these technologies, expanding
the collective knowledge base with supplemental technology, books,
tutorials, examples, recommendations, and troubleshooting tips.
I must especially thank one "volunteer" developer, Matt Lewis from the
UK. Matt created diozero, the technology used in this book to provide Java
access to devices connected to a Raspberry Pi. During my investigation of
such technologies, he helped me learn diozero, and we became colleagues.
As a result of our collaboration, he enhanced his already great technology;
he reviewed two key book chapters; he wrote an important appendix.
Without Matt's herculean efforts, the book would have been harder to
write, harder to understand, and harder to apply to the real world.

xxi
CHAPTER 1

Motivations
This book primarily focuses on using the Raspberry Pi and Java for robotics
projects and Internet of Things (IoT) projects. A secondary focus is remote
code development using Apache NetBeans. I’ve found the combination of
the Raspberry Pi, Java, and NetBeans to be a very powerful and productive
means of developing robotics projects. I believe the combination applies
to IoT projects as well. In this chapter, I’ll discuss the motivation, in the
context of robotics and IoT projects, for

• Using the Raspberry Pi as the primary provider of


computing resources

• Using Java as the primary programming language

• Using Apache NetBeans for remote development of


Java programs running on the Raspberry Pi

Before discussing motivations in depth, I want to emphasize


something very important. Most of this book explores finding or
creating support for the devices used in robotics and IoT projects. As a
consequence, much of the device-related material applies even if you
don’t do remote development, don’t use NetBeans, don’t use Java, or don’t
use the Raspberry Pi.
That said, on to motivations!

© Greg Flurry 2021 1


G. Flurry, Java on the Raspberry Pi, https://doi.org/10.1007/978-1-4842-7264-0_1
Chapter 1 Motivations

Why the Raspberry Pi?


To understand why the Raspberry Pi is a great match for robotics and IoT
projects, we must explore the needs of such projects. I won’t delve too
deeply into the definition of the term robotics, as it can have a broad or
narrow scope, depending on context, and it is evolving. For example, to
my grandson, a toy bird that waves its wings because a microcontroller
drives two servos is a robot. To me, unless a system senses its environment
and reacts to that environment autonomously, it is not a robot. To some,
possibly now, and certainly within a few years, unless a system learns as
it senses and reacts adaptively to its environment based on its informed
experience (i.e., unless it includes artificial intelligence and machine
learning), it cannot be a robot.
For the purposes of this book, robotics always implies

• Sensors to sample the environment in various ways

• Actuators that enable reacting to the environment

• Intelligence to interpret the output of the sensors and


drive the actuators to achieve the desired goals

IoT is also loosely defined and still evolving. Fundamentally, IoT is about
things (e.g., a door lock, a thermostat, or a refrigerator) communicating over
the Internet. Things sense their environment and send data for analysis.
The data gets analyzed to inform people and things, and zero or more things
react, although it is not necessarily the things that did the sensing. As in
robotics, artificial intelligence and machine learning are becoming an
important aspect of IoT, but usually in the cloud, not in the things.
For the purposes of this book, IoT implies

• Sensors to sample the environment in various ways,


always

2
Chapter 1 Motivations

• Communication to communicate over the “Internet,”


always

• Actuators that allow reacting to the environment,


sometimes

Clearly there is overlap between the two disciplines. In fact, a robot


may be a thing. Even if not a thing, for some robots, communication is just
as important as it is for IoT projects. For example, a robot could cooperate
with other robots, or leverage cloud services, like image processing or even
artificial intelligence.
There are other common needs for robotics and IoT. Many robotics
systems and some IoT systems are mobile, so wireless communication and
small size and low weight are often considerations. Such systems must be
battery powered. Some IoT systems are stationary but deployed in remote
locations; these too require wireless communication and battery power.
This book assumes projects that require wireless communications and
battery power.
So, what makes the Raspberry Pi a good choice for robotics and IoT?

• All models support many types of base I/O used to


interact with sensors and actuators (devices). The
relevant base I/O types are digital input and output
(a.k.a. GPIO), the UART protocol (serial port or just
serial), and more complex serial protocols, that is,
the Inter-Integrated Circuit bus (I2C1) and the Serial
Peripheral Interface bus (SPI).

• Most models offer modern wireless communications


technologies, that is, Wi-Fi, Bluetooth, and Bluetooth
low energy (BLE).

1
I2C is the most common acronym; I2C and IIC are sometimes used.

3
Chapter 1 Motivations

• All models support multiple operating systems and


multiple programming languages.

• Various models offer a choice of memory and


processing capacity, as well as physical size, to
support a wide range of needs, from relatively simple
controllers to desktop computing.

• All models have reasonably low power consumption.

• All models have quite good price/performance ratios.

• The user community is enormous, and supportive.

To be fair, there are competing products that have faster processors,


more memory, better I/O capabilities, or a lower price. I, however, know
of no product that comes close to the size of the Raspberry Pi community
(over 40 million have been sold as of May 2021). When you encounter
a problem, you almost always find that someone, somewhere, has
encountered the problem and addressed it.
So, for your project, you might find a competing product that seems
a better fit. However, you will likely do more work, and find less support,
than if you choose a Raspberry Pi.

The “Best” Raspberry Pi for Robotics


If your project focuses on robotics, the salient characteristics are low
power consumption, base I/O capability, communications capability, and
as much compute power as possible so that the Pi can provide the “brains”
of the project. All modern Raspberry Pi families have the same base I/O
capability but vary in other areas. In my opinion, at the time of writing, one
of the three models of the Raspberry Pi 3 family is the best compromise
between low electrical power consumption and high compute power.

4
Chapter 1 Motivations

You can find full descriptions of the models on the Raspberry


Pi Foundation’s website (see www.raspberrypi.org/products/).
Table 1-1 shows a comparison of the salient features of the models. The
table does not list equivalent features, such as base I/O, audio, camera,
and display support.

Table 1-1. Comparison of Raspberry Pi 3 models


Feature 3B 3B+ 3A+

CPU speed 1.2 GHz 1.4 GHz 1.4 GHz


RAM 1 GB 1 GB 512 MB
Wi-Fi 2.4 GHz 2.4 GHz and 5 GHz 2.4 GHz and 5 GHz
Bluetooth BLE Bluetooth 4.2 and BLE Bluetooth 4.2 and BLE
Ethernet 100 base Gigabit Ethernet over NA
USB 2.0
USB 2.0 4 4 1
ports
Size 56 mm x 85 mm 56 mm x 85 mm 56 mm x 65 mm
Cost (US$) 35 35 25

As you can see, models B+ and A+ have a superior CPU speed and
better wireless communication features than model B. If you have a model
B already, however, it is most likely acceptable. If you must purchase a Pi,
either the model B+ or A+ would be a better option. The choice between
the B+ and the A+ becomes a matter of the amount of RAM, physical size,
and connectivity needed for the project, as well as the cost sensitivity of the
project.
For the purposes of this book, all three models are equivalent. I will use
a Raspberry Pi 3 Model B+ (Pi3B+). Chapter 2 shows you how to set it up.

5
Chapter 1 Motivations

Note You might wonder why I don’t recommend a member of the


Raspberry Pi model 4 family. At the time of writing, any Pi4, compared
to the Pi3B+, cost more, required more power (thus bigger batteries),
and required heat sinks or even a fan. Pi4 prices have decreased,
though the other differences have not changed. If you wish to use the
Pi4, the vast majority of the book’s content regarding the Pi3B+ apply
to the Pi4 as well.

The “Best” Raspberry Pi for IoT


If your project focuses on IoT, the salient characteristics are low power
consumption, base I/O capability, wireless communications capability,
and modest compute power. In my opinion, at the time of writing, only one
model, the Raspberry Pi Zero W (Zero W), is a candidate. It also is roughly
40% (30 mm x 65 mm) of the size and as little as 20% of the weight of a Pi3B+.
You do have one choice to make. You can purchase the Zero W with
(US$14) or without (US$10) the GPIO header populated with pins. If you
plan to connect only to I2C or SPI devices, or use only a few GPIO pins, you
might be better off getting the Zero W and soldering just the pins you need.
If you need a lot of GPIO pins or hate soldering, get the Zero WH with pre-
soldered header pins. Chapter 3 shows you how to set up a Zero W.

W
 hy Java?
I admit that I have a difficult time being objective (no pun intended) about
Java. I started programming in Java when it was introduced in 1995. I’m
still programming in Java. My most ambitious robotics projects are mostly
written in Java, sometimes with a bit of C/C++ (for an Arduino) and Python
in the mix. That said, I shall try to be objective in the following discussion.

6
Chapter 1 Motivations

The Raspberry Pi supports a broad spectrum of programming languages.


In fact, a primary goal of the Raspberry Pi is to enable people of all ages to
learn how to program. Rather than try to compare Java to that spectrum, I
will limit the discussion to what I’ll term professional grade programming
languages that target standalone programs, support multitasking, support
robotics and IoT device access, support network access, are supported by
professional grade development tools, etc. I claim that limits the choice of a
programming language to Java, Python, or C/C++.
What are the criteria for the choice? There are a few; the ones I’ll use,
mostly in order of importance:

• Programmer productivity

• Performance

• Industry acceptance

Programmer Productivity
Programmer productivity is multifaceted, difficult to define precisely, and
somewhat subjective to measure. I’ll discuss what I think are the most
compelling facets.

Object-Oriented Programming (OOP)


OOP is self-explanatory. While somewhat contradicting the goal of high
performance, I consider the benefits of OOP well worth the trade-off.
Those benefits include improved modularity, maintainability, quality,
reusability, and flexibility – basically a huge boost for programmer
productivity.
Java was designed from its inception to promote OOP and in fact
mandates OOP. Python supports OOP but, in my opinion, does not
emphasize it. Thus, while present in Python, OOP is better supported in
Java.

7
Chapter 1 Motivations

C of course is not object oriented at all. C++ arrived prior to Java


(although it was not standardized until 1998) and seems like an
afterthought, in effect an object-oriented “wrapper” around C. So, my
opinion is that while present in C++, OOP is better supported in Java.

Safety
Safety refers to the probability of introducing difficult to diagnose, or even
dangerous bugs into a program. The benefits of a safer language mean less
time debugging and less danger of crashing software or even hardware
systems – in effect better programming productivity.
Python has some characteristics that I (subjectively) dislike as I feel
they introduce the possibility of bugs. Python’s loose or dynamic typing
is the best example; I much prefer Java’s static typing. Even Python’s
seemingly desirable use of whitespace as part of its syntax can introduce
logic bugs, as it makes it more difficult for development tools to find errors
before running; Java’s admittedly more verbose syntax eliminates this
problem. Thus, I claim Java is safer than Python.
C, in my opinion, is basically a “high-level machine language” that
is very close to the system hardware and the operating system. You can
do pretty much anything. That means that you are only an obscure bug
(e.g., bad pointer arithmetic, an errant memcpy, or a missing free for
a corresponding malloc) away from potentially crashing the program
or even the entire system (I’ve done it!). C++ does little, if anything, to
eliminate the hazards of C. Java prevents such hazards, so Java is much
safer than C/C++.

Write Once, Run Anywhere


Java is famous for the promise of “write once, run anywhere.” In the context
of this book, that means you can write, and build, code and then run the
executable on any platform – your Raspberry Pi, a macOS workstation,
a Windows 10 workstation, or some Linux machine. And that promise is

8
Chapter 1 Motivations

kept – except when platform specifics become involved. Obviously, you


must use platform-specific base I/O when attaching robotics and IoT
devices to the Raspberry Pi. However, my experience in robotics has been
that maybe 10–20% of a project works with hardware, so as much as 90% of
the project can be written and tested on a high-performance workstation
rather than a Raspberry Pi. This can result in a very large increase in
programmer productivity. I believe the increase would not be as large for
IoT projects, however.
Python, as an interpreted language, enjoys the same advantages as
Java in this area. Thus, Java and Python roughly tie.
C/C++, as compiled languages, do not compare to Java in this area.
While it is possible to develop and test platform-agnostic code on a high-­
performance workstation, to make it run on a Raspberry Pi, the code must
be copied to and compiled on the Pi. It is possible to cross compile for the
Pi on the workstation and then copy to the Pi. In either case, it is prudent to
test again on the Pi. This is an unpleasant hit to programmer productivity.

Libraries
While perhaps not as important in the context of robotics and IoT as
the preceding productivity facets, Java’s extensive collection of standard
libraries is unrivaled by C/C++ or Python. You name it, Java likely has
a standard library for it; to mention just a few, networking, database,
security, cryptography, concurrency, and collections. C forces you to roll
your own support or find a third-party library. C++ and Python have less
extensive support than Java. Java’s extensive set of libraries definitely give it
the edge in programmer productivity in this facet.

9
Chapter 1 Motivations

L imitations
Are there limitations to programmer productivity when using Java? The
answer is yes. To explain the limitations, we need to examine the idealized
software architecture this book assumes for robotics and IoT projects; it is
illustrated in Figure 1-1. The Raspberry Pi OS layer represents the OS and
its kernel. The layer provides a low-level C API2 for the Raspberry Pi’s base
I/O capabilities (GPIO, serial, I2C, SPI). The layer, naturally, knows nothing
about specific devices.

Figure 1-1. Idealized software architecture

The Application layer represents the Java application program(s) you


write for your project. An application wants to use an API that presents an
abstraction of a device; that is, an application cares only about what the
device does, not about how it does it. Some examples:

2
 I am, for better or worse, using the modern definition of “API,” which in effect
means any programming interface, at the level of the application or anywhere
else in a software stack.

10
Chapter 1 Motivations

• For an LED connected via GPIO, the application wants


“turn on” or “turn off” – not “set GPIO pin 8 high” or
“set GPIO pin 8 low.”

• For a temperature sensor connected via I2C, the


application wants to “read the temperature” – not “read 2
bytes from the device at address 0x42 on I2C bus 1 starting
at register 0x0E, assemble a 14-bit value from the 2 bytes,
apply compensation factors to produce the temperature.”

The Base I/O layer represents a base I/O library, the “magic” code3 that
provides a Java API for the Raspberry Pi base I/O capabilities available via
the C API of the Raspberry Pi OS layer. Fundamentally, the layer abstracts
a Java programmer from the scary and difficult-to-use OS C API. Like the
Raspberry Pi OS layer, the Base I/O layer knows nothing about specific
devices; it simply offers a Java API for GPIO, serial, I2C, and SPI via a single
base I/O library, or via multiple base I/O libraries.
The Device layer represents a device library. A device library knows
everything about a device, both what it does and how it does it. A device library
offers a high-level Java API to an application with the desired abstraction for
what a device does. The device library leverages its device-­specific knowledge
to use the base I/O API provided by the Base I/O layer to implement the how.
So, fundamentally, a device library allows the application programmer to
focus on what the device does rather than how it does it.
You might ask at this point why there are two layers, Device and
Base I/O, instead of one layer, between the Application and Raspberry Pi
OS layers. One reason: reuse! Accessing the Base I/O C API from Java is
nontrivial, and using that API can be nontrivial. Repeating that work for
every device would be extremely counterproductive. Encapsulating that
work in a Java base I/O library allows reuse across all devices and saves a
lot of work and time, in effect improving programmer productivity.

3
The “magic” includes the Java Native Interface (JNI) framework.

11
Chapter 1 Motivations

So, what are the limitations?

1. Java has no standard base I/O library providing


access to the Raspberry Pi OS base I/O C interfaces.
Given Java’s “run anywhere” mantra, that is no
surprise, but it inhibits device library development.

2. I’ve not found a manufacturer or vendor that offers


Java device libraries for their devices. I think it is a
matter of low demand. Most devices target a broad
market, well beyond the Raspberry Pi. Further, the
Java community is a small part of the overall Pi
community.

Fortunately, the limitations are not insurmountable. The “Java for the
Raspberry Pi” community is surprisingly large, skilled, dedicated, and
active. I have found, and you can find, a base I/O library that supports your
project’s needs. In fact, you may find multiple options.
Once you’ve chosen a base I/O library or a set of base I/O libraries that
work for your devices, it is sometimes possible to find a Java device library
from a third party that you can use or adapt, especially for popular devices.
If you can’t find a Java library, you can almost always find a non-Java
device library that you can port to Java on your base I/O library or libraries
with what is almost always an acceptable amount of work. I’ll discuss the
subject in depth in Chapter 6.
The conclusion is that Java offers the best programmer productivity,
followed by Python, then C/C++.

12
Chapter 1 Motivations

P
 erformance
Performance is self-explanatory, and it is easy to be objective when
discussing performance. For any task, the performance must be adequate
to complete the task in a timely manner. My experience has been, however,
that performance requirements are often difficult to predict accurately. As
a result, you should generally pick the best performing language, unless
that choice is contradicted by other criteria.
Java is the clear choice over Python. Comparison benchmarks
(https://benchmarksgame-­team.pages.debian.net/benchmarksgame/
fastest/python3-­java.html) show that Java is almost always faster than
Python 3 and in fact can run hundreds of times faster, depending on the
benchmark.
C has a clear performance advantage over Java. Comparing
benchmarks for C (https://benchmarksgame-­team.pages.debian.
net/benchmarksgame/fastest/c.html) to benchmarks for Java
(benchmarks for Java (https://benchmarksgame-­team.pages.debian.
net/benchmarksgame/fastest/java.html), C runs up to six times as fast
as Java. Those benchmarks show C++ is slower than C, but still is usually
faster than Java.
Basically, if you want the utmost in performance, then C or even C++ is
the best choice. Java is a much better choice than Python.

I ndustry Acceptance
Industry acceptance refers to how widespread the language usage is
among professional programmers. A corollary is how attractive experience
in the language might make you to potential employers.
For a long time, Java was the number one programming language
worldwide among professional programmers. With the emergence of a
number of new languages and changing requirements, the rankings have
changed. Polls in October 2020 and December 2020 had C ranked first,

13
Chapter 1 Motivations

Java second, and Python third (C++ was fourth). A poll in November 2020
ranked C first, Python second, and Java third. Java will be an important and
well-supported language for years to come. So, I’ll consider the industry
acceptance contest a tie, at least for the next few years.

The Verdict
Java offers much better programmer productivity than Python. Java is
much faster than Python. Java is roughly as popular (among experienced
programmers) as Python. Overall, Java wins over Python.
Java offers much, much better programmer productivity than C/C++.
Java is slower than C/C++. Java is roughly as popular (among experienced
programmers) as C (and more popular than C++). Overall, Java wins over
C/C++.
The verdict: Java is the best primary programming language for
complex robotics and IoT projects on the Raspberry Pi.
You might wonder why I include the adjective “primary” in the verdict.
Neither Java nor the Raspberry Pi OS guarantees “real-time” behavior.
It is common in robotics to find situations that require “real-time” or
require parallel processing. In such situations, you can delegate tasks to a
microcontroller like an Arduino that can perform tasks independent of the
Raspberry Pi and better approach “real-time” behavior. Using an Arduino
means using C/C++ as a secondary programming language.
You might also wonder why I included the adjective “complex.” I have
to be honest. There are IoT projects that are not complex (e.g., require only
one or two sensors and require very little data processing). In such cases,
you won’t be writing or running a lot of code. Programmer productivity,
performance, and popularity don’t matter much. In such cases, Python
can be a better choice, unless your Java environment is already in place.

14
Chapter 1 Motivations

Why Remote Development Using NetBeans?


Can you develop Java programs on the Raspberry Pi? The short answer is
“yes.” The better answer is “yes, but ….” Consider the following factors:

• The complexity of your program

• The compute power and memory size of the Raspberry


Pi running your program

Assume your program is a single class, with a few 10s of lines. Then,
even with a Zero W that has modest compute power and only 512 MB of
memory, you could do everything on the Pi and do it manually. That means

• Iterate between using a simple text editor to edit the


class and using the javac command to compile the
class to find simple syntax errors as well as more
serious errors until you have something that can run.

• Use the java command to run the class.

Unfortunately, a single class for an interesting project of any sort is


almost certainly unrealistic.
Assume the complexity increases a bit so that now you have multiple
classes or must use libraries not included in the Java Runtime Environment
(JRE) (and for robotics and IoT, you will need libraries). You could still do
everything on the Pi manually. That now means

• Iterate between a text editor and javac for each of the


multiple classes.

• Build the executable using the multiple classes, or one


or more libraries, or both, using the jar command.

• Use the java command to run the executable.

This becomes painful and unproductive. Even for some IoT projects,
this might be unacceptable.

15
Chapter 1 Motivations

The harsh reality of developing code for projects of even modest


complexity motivated the emergence of integrated development
environments (IDEs) for various programming languages long before Java.
Modern, professional grade IDEs4 in effect compile as you type so that you
see syntax and other errors immediately, offer code completion, automate
the build process, and allow you to run and debug the program within
the IDE. Such IDEs deliver a huge increase in programmer productivity,
and the vast majority of developers today use an IDE no matter the
programming language or project complexity.
So, the answer is run an IDE on the Raspberry PI! Unfortunately, no!
Consider some more harsh reality. All modern IDEs require a graphical
user interface (GUI). A GUI requires a windowing system (often called a
desktop) that supports GUI-based applications like an IDE. It takes a fair
amount of CPU power and memory to support a desktop. You will see in
Chapter 2 that the Pi3B+ provides reasonable support for a desktop; the
same cannot be said for the Zero W.
Even worse, professional grade IDEs can require at least as much
computing resource (CPU and memory) as the desktop. For example,
NetBeans 12 (see Chapter 5) running on macOS consumes up to 4 GB of
memory;5 I believe other professional grade IDEs would be similar. I think
it fair to say that even the Pi3B+, with its 1 GB of physical memory, would
have trouble providing an adequate user experience. On a Zero W, forget it.
But, assume for a moment that you could reasonably run the desktop
and an IDE on a Raspberry Pi (and you might well do so on a Pi 4 with 8
GB). Your project, when running, would compete with them for computing
resources. As a result, you could never do realistic performance testing and
might even experience random errors due to multitasking induced delays

4
 I do not consider the IDEs that come with the Raspberry Pi OS professional
grade.
5
 NetBeans 8.2 had a memory leak and could consume as much as 12 GB of
memory!

16
Chapter 1 Motivations

while running the IDE. That means to do realistic testing, you’d need to
shut down at least the IDE and most likely the desktop as well. And if you
need to fix a bug, everything has to be restarted. Painful!
The solution: remote development. What does that mean? In a broad
sense, remote development means

• All code writing, compiling, and executable building


take place in an IDE that runs on a workstation with
adequate resources to deliver a productive and
pleasant user experience.

• The executable (including all library dependencies


when necessary) gets pushed from the workstation to
the target system.

• The executable is run on the target system, without any


extraneous programs competing for resources on the
target.

In this book, I use a narrower definition of remote development where

• The IDE runs on a workstation.

• The IDE automatically pushes the executable to the


remote target system.

• The IDE automatically runs the executable on the


target system and connects to the running program to
control and monitor execution and debug.

Thus, with remote development, the developer gets the best of both
worlds – a professional IDE running on a capable workstation and the
project executable running on the Raspberry Pi in a realistic environment.

17
Chapter 1 Motivations

W
 hy NetBeans?
At the time of writing, depending on the organization or individual doing
the assessment, the top three professional-grade cross-platform Java
IDEs were Eclipse (www.eclipse.org/eclipseide), NetBeans (https://
netbeans.org), and IntelliJ (www.jetbrains.com/idea). Eclipse is
almost universally first, and either NetBeans or IntelliJ is second, and the
other third. In the spirit of full disclosure, I started using Eclipse for Java
development at its initial release in 2001; in 2014, I began using NetBeans
as well as Eclipse; in 2017, I switched to NetBeans exclusively, solely based
on its support for remote development on the Raspberry Pi. I must confess
I’ve never used IntelliJ.
Fundamentally, of the three IDEs, only NetBeans supports my narrow
definition of remote development “out of the box.” Remote development
with NetBeans is little different than local development. You can create
multiple classes in multiple NetBeans projects and require multiple
external jar files (libraries). At the click of a single button, NetBeans
compiles all the classes, builds the executable, downloads the executable
(and any dependent libraries as needed) to the Raspberry Pi, and runs and
even debugs the executable. That said, there are limitations. However, I’ve
found these limitations a problem only for some testing.
The bottom line is that remote development delivers a huge increase in
programmer productivity. Further, only NetBeans supports a very efficient
form of remote development “out of the box,” delivering an additional
increase in programmer productivity. I’ll show you how to set up and use
NetBeans in Chapter 5.

18
Chapter 1 Motivations

Note If you are more skilled than I am, you can create NetBeans-­
like behavior in Eclipse and IntelliJ. Doing so involves fairly deep
knowledge of the IDE and your chosen build tool, plus fair knowledge
of script building for your workstation OS. I have not pursued this
because NetBeans makes it unnecessary. That said, see Appendix A3
for an example of how it can be done.

S
 ummary
In this chapter, I discussed the motivation for recommendations for several
aspects of robotics and IoT projects:

• Using a Raspberry Pi for overall control, due to a great


match of the requirements for such projects and the
massive support network for the Pi

• Using Java as the primary programming language, due


to its programmer productivity and performance

• Doing remote development, due to the programmer


productivity gains, and using NetBeans, due to its
best-in-class support for remote development, further
increasing programmer productivity

The rest of the book assumes you want to use a Raspberry Pi, use Java,
and do remote development using NetBeans. A preview of the content:

• Chapter 2 shows you how to set up a Pi3B+.

• Chapter 3 shows you how to set up a Zero W.


• Chapter 4 discusses remote computing techniques,
most of which are relevant only to the Pi3B+.

19
Chapter 1 Motivations

• Chapter 5 shows you how to set up NetBeans.

• Chapter 6 explores options for Java base I/O support.

• Chapter 7 examines the choice for Java base I/O


support in this book and also offers useful detail about
the Raspberry PI base I/O capabilities.

• Chapters 8 through 14 look at support for specific


devices used in robotics and IoT.

• Appendixes A1 and A2 discuss off-loading tasks to an


Arduino.

• Appendix A3 examines the use of Maven as a build tool


in NetBeans.

Enjoy!

20
CHAPTER 2

Raspberry Pi 3 Model
B+ Setup
I assume you are reading this chapter because you are interested in
building robotics projects using a Raspberry Pi 3 Model B+ (I’ll use Pi3 in
the rest of this chapter) and Java. In this chapter, you will learn how to

• Choose the “best” operating system for the Pi3

• Install Raspberry Pi OS

• Configure Raspberry Pi OS for remote development

• Install Java on Raspberry Pi OS

S
 etup Considerations
Every Raspberry Pi project of course requires the “basics”:

• A Raspberry Pi

• A microSD card for the file system storage

• A power source

During setup and some project development, you can provide power
from an electrical outlet (via a suitable power supply) or a battery. During
the setup approach I’ll describe in this chapter, you will need to connect an

© Greg Flurry 2021 21


G. Flurry, Java on the Raspberry Pi, https://doi.org/10.1007/978-1-4842-7264-0_2
Chapter 2 Raspberry Pi 3 Model B+ Setup

HDMI compatible monitor or TV, a USB keyboard, and a USB mouse. You
won’t need any of those during project development.

Choose the Operating System


What operating system (OS) should you use? The Raspberry Pi runs a
number of operating systems. However, the default OS, formerly called
Raspbian, now called Raspberry Pi OS, draws the vast majority of users and
the vast majority of support available online. I recommend using it unless
you have a very good reason to use another. All the material in this book
assumes Raspberry Pi OS and has not been tested on any other OS.
There are three versions of Raspberry Pi OS:

• Full includes the core operating system, the desktop


graphical user interface, and lots of useful tools and
applications. It boots to the desktop by default.

• Recommended (a somewhat informal term) includes


the core operating system, the desktop, and a few
useful tools and applications. It boots to the desktop by
default.
• Lite includes only the core operating system. It boots
to a command line interface (CLI). You’ll have to install
any non-OS tool or application you need.

A foundation of this book is remote development, where all the heavy-


duty tools run on a robust workstation, leaving the Pi CPU cycles and
storage available for your project. So, in truth, Lite is almost certainly the
correct choice for most projects. However

• I find the initial configuration after the first boot to


be much, much easier using the desktop available in
Recommended and Full. I’ll show you how to turn off

22
Exploring the Variety of Random
Documents with Different Content
present and future occasions of joy be valued by me in
proportion as they may become subservient to that
object, and to the affection I bear your most illustrious
Lordship, whose hands I kiss, praying the Lord God of
his grace to vouchsafe you a happy accomplishment of
all your desires. From Pesaro, the 15th of January,
1571.
"Your most illustrious and most reverend Lordship's
most humble servant,
"The Duchess of Urbino."

"My most illustrious and most reverend Lord,


"The Marquis of Villa Franca, who has handed me your
most illustrious Lordship's letter, will likewise report to
you my unceasing desire for your service, and the
pleasure wherewith I have received the courteous duty
you have been pleased on this occasion to send me,
for which I certainly am under many obligations, as
the Marquis will more fully show you. I, however, pray
your illustrious Lordship to afford me frequent
opportunities of effectually proving to you my good
will; and I kiss your hands, beseeching for you from
our Lord God all the happiness you may desire. From
Pesaro, the 15th of January, 1571.
"Your most illustrious and most reverend Lordship's
most affectionate servant,
"The Prince of Urbino."

"Most illustrious and most reverend Lord,


"Whatever pleasure my affairs may afford your most
illustrious Lordship is only the consequence of your
great kindness and courtesy; and as regards the
expression of it, which you have thought fit to
communicate to me by the Marquis of Villa Franca, and
by your own letters, I can but say that I kiss your hand
for all your affection, assuring you that every occasion
of happiness you may enjoy will afford me cause for
quite as much congratulation as I now have received
from you: and referring you to whatever more that
gentleman will say in my behalf, I remain, praying God
to gratify you in all your desires,
"Your most illustrious Lordship's very obedient,
"Lucrezia d’Este.
"From Pesaro, the 16th of January, 1571."
Renée of France, mother of Princess Lucrezia, had embraced the
doctrines of Calvin, who visited Ferrara about the time of her
daughter's birth, and Francesco Porta da Creta, preceptor of the
young Princess, was discovered to be tinged with the same
principles. Alarmed for the orthodoxy of his daughters, Duke Ercole
dismissed their instructor, and secluded his escort, in a wing of the
palace, from all intercourse with the children. A cloud of mystery
hangs over these transactions.
"Soon after his return to Pesaro from his marriage, the Pope, the
King of Spain, and the Venetians having [on the 20th of May]
leagued together against the Turk, Don John of Austria came into
Italy as commander-in-chief, and Francesco Maria, with his father's
permission, set out on the 8th of July, to join him at Genoa. There
he embarked in the Savoyard frigate[79] that had carried him to
Spain, commanded by the same Monsignor de Leini, who had orders
from the Duke of Savoy to receive him with that affectionate
courtesy which both he and his sovereign ever displayed towards
him. Having touched at Naples, he was there welcomed with the
utmost favour and distinction, and passed his time most agreeably.
From thence the fleet sailed to Messina, where he assisted at a
general council of war, as indeed he often subsequently did.[80]
Leaving Sicily, the expedition in a few days arrived at Corfu, and on
the morning of the 7th of October fell in with the Turk. Don John
drew up the Christian fleet in order of battle, the Proveditore
Agostino Barbarigo, of Venice, having the landward squadron, and
Giovanni Andrea Doria the opposite and heavier one, with Don
Alvarez di Bassano as a reserve; the centre he kept for himself,
where was also Francesco Maria, in the foresaid frigate. Here was
the thick of the fight, as at this point the two admirals met. The
Turkish at first selected the frigate in which was Francesco Maria,
whom he well knew, and who warmly received his attack; but as
soon as he distinguished the flag-ship, he turned to engage it: and,
after fighting for two hours, the Turks struck, their admiral, Pacha
Ali, having been killed by an arquebus; the others were all put to the
sword; and so was this long very doubtful victory secured to the
Christians. Meanwhile the Savoyard frigate fought two galleys, one
ahead and the other astern, and had enough to do, most of her
company being killed or wounded. The squadron under Barbarigo
drove on shore many galleys, sinking and taking others; but he was
wounded by a splinter in the eye, of which he soon after died. Doria
had at first run out to sea, fighting all the while; but seeing the wing
exposed, he returned and made good use of the opportunity, cutting
up several galleys, and getting off uninjured. Such is an abstract of
this battle, wherein Francesco Maria acquitted himself becomingly,
for which Don John distinguished him with many marks of regard,
and assigned him, among other favours, twenty-four Turkish slaves.
The Admiral bearing for Sicily, he sailed from Corfu in a Venetian
galley to Otranto, and returned home by land in November, to await
orders, and rejoin the fleet the following year."
The naval engagement of which Francesco Maria has given the
preceding sketch was that of Lepanto or Curzolari, where Passeri
states that he had with him a large body of his father's subjects, a
fact which, although passed over in his own account of this his only
military service, is confirmed by Armanni, who tells us that there
were in the fleet above fifty from Gubbio alone, thirty of whom were
officers, a circumstance on which the Prince was complimented by
Don John. It is unnecessary here to add to the Prince's details. The
general result of the engagement was most conclusive: the enemy's
loss has been calculated at thirty thousand killed, ten thousand
wounded, and fifteen thousand Christian slaves rescued from
bondage, besides the destruction or capture of six hundred sail, and
a vast booty. The Christian fleet consisted of above two hundred
war-galleys, besides many other vessels of various sorts.
"On bringing his wife from Ferrara to Pesaro [in January, 1572], they
were magnificently received, and passed a gay carnival. In Lent he
repaired to Rome, after visiting the holy house of Loreto, and was
there entertained by his uncles, the Cardinals of Urbino and Farnese.
Pius V. insisted upon very graciously admitting him to an audience,
notwithstanding an illness of which he soon died....[81] Francesco
Maria was also distinguished by his successor, Gregory XIII., but, on
suddenly being recalled by his father, he at once, though reluctantly,
obeyed. Soon afterwards, he was attacked by a severe illness, which
lasted for three months, aggravated by a false rumour of another
naval engagement."
The part taken by the Prince in the unhappy disturbances of Urbino
has been already shown from his own pen, and that of other
narrators, as well as his attendance upon his father's death-bed.[*82]
We have now, therefore, to enter upon his reign, and here again we
have recourse to his memoirs:—"The new Duke departed from
Urbino, where he showed himself at the archiepiscopal palace in his
robes of sovereignty, and then, as was usual, rode through the
streets, on a milk-white steed, dressed in white, and under canopy,
thereafter receiving the oaths of allegiance in the great hall of the
palace: all this he repeated at Sinigaglia." Among the Oliverian MSS.
is this account of the ceremonial, curiously illustrative of the
manners of the age:—"After mass of the Holy Spirit had been sung,
the Archbishop, Felice of Cagli, advanced to the door of the
cathedral, and thence, accompanied by the Gonfaloniere, the three
priors, and the people, went to bring forth the Prince from the
palace. He wore a riband and scarf of white damask; on his head a
crown of pearls, from behind which there hung some bands; and on
his shoulders a short cloak of white fur. When he reached the head
of the stair in the archiepiscopal palace, on which was a carpet and
a cushion, the Archbishop held the Cross for him to kiss. He then
entered the church, and approached the high altar, on which was the
Holy Sacrament, where, after the usual devotions, accompanied with
beautiful sacred music, the Primate read certain prayers and
pronounced the benediction, and his Highness made offertory of a
piece of ten scudi. He then retired to an adjoining chapel, and,
changing his dress, put on a mantle of white, with cap and feathers,
in which he issued from the church, and mounted a handsome
charger. The Gonfaloniere preceded him on horseback, his drawn
sword in his hand, calling aloud, 'Long live the Duke of Urbino!' and
the people followed, repeating the cry. Thus they went through the
city and returned to the palace. The populace then took off his
cloak; and M[aestr]o Antonio Fazino asked his cap, and received it.
In like manner he was stripped of his spurs; and his Highness then
presented his horse to the city youths, and Mo. Calber Galler
mounted it. Mo. Antonio Corboli and the Cavaliere Guido Staccoli
next put him on his spurs, Mo. Flaminio Bonaventura his mantle, and
Mo. Antonio Fazino held his horse. Having been by this formality
elected, he went into the great hall, where the Gonfaloniere and
priors, with all the deputies of other cities, by a formal instrument
gave their oaths of allegiance, whilst he, in a letter read in his
presence by Mo. Giulio Veterani, his secretary, promised to be to
them a loving sovereign; after which, all the people came one by
one to kiss his hand. All this was done with much rejoicing on the
part of the public, and of his Highness, to whom may God grant
grace to rule his subjects to the contentment of all."
The following letter, to the young Duke upon his succession, is
printed in the correspondence of Girolamo Muzio, his preceptor,
whose advices, though somewhat long, well merit attention, totally
opposed as they are in spirit to then prevailing principles of
government, and anticipating opinions even in our day charily
developed in Italy. It is, above all, interesting to discover, on such
satisfactory evidence, the political views which must have been
inculcated on Francesco Maria from his early years, and which bore
some seed in after life, notwithstanding the natural defects of his
temper, and the crotchets imbibed from a false philosophy. Had such
counsels been generally given and followed, constitutional
government in Italy would now have been neither a mockery nor a
bone of contention.
"Men tried by difficulties and crosses nerve themselves
to endure them; yet, knowing how your Excellency has
long suffered from many troubles and annoyances, I
shall undertake no vain task in wishing to offer
consolation in this your new vexation and trial. I need
not now say with what grief I have heard of the late
sad event, knowing as you do how true a servant I
was of his Excellency our Sovereign. On the contrary, I
shall address myself to talk of certain considerations
which appear to me beseeming the succession you
have obtained, through a long and noble ancestry,
meaning to speak to you with the freedom and loyalty
which a servant should display when his master's
interests are at stake; and upon this understanding I
shall begin.
"I remember more than once, while conversing with
the illustrious Duchess your mother, to have lamented
the manner in which I observed the government of the
state conducted, praying the Almighty to protect you
from the risk of being expelled from it, as there would
have been no reasonable hope of the people recalling
you again; a fact of which her good sense was fully
aware. It would be long and irksome were I to repeat
the various matters that I disapproved of, but from
them I can deduce certain rules which it seems to me
you ought to adopt for regulation of your authority,
and the maintenance of justice, so as to reacquire and
preserve the affection of your subjects. But, Sire,
permit me to drop ceremonious designations, in order
more readily to express my views.
"Let it be your first care, then, to endow the
magistrates and city authorities with the ample
jurisdiction which their duties require, enjoining upon
them to execute justice without respect to persons;
command also your courtiers not to interfere in private
suits, and do you in like manner yourself forbear
meddling with such, leaving the judges to proceed
therein by the usual course. Further, should the judge
be suspected by either party, let the cause be remitted
to another, or let an assessor be named; and, to such
alleged suspicion, it is no sufficient answer that any
one may be doubted by anybody. In short, it is enough
that the judges proceed to pronounce sentence in the
regular way; and for such as feel aggrieved, the
common and appropriate remedies are open. In my
time the custom was abolished—I know not at whose
recommendation—of sending causes to be inquired
into by a council of skilled persons [a jury?]; it was an
excellent and much approved mode of judging, and on
that account it would be more advisable to return to it
than to leave it off. Statutory penalties have also been
changed to arbitrary ones, which has effected great
alterations; for where the statutes condemned ten,
caprice has multiplied by hundreds, with what justice I
know not. This was, indeed, by advice of certain
doctors, who declared that the Prince's will ought to be
held as law,—a diabolical sentiment, since it is not the
absolute will, but the virtuous and upright opinion of
the Prince that should be deemed law; nor do I see
how any virtuous and honest opinion can contravene
statutes confirmed by mutual agreement, and
sanctioned by oaths.
"Be specially attentive in hearing those who bring
complaints of oppression or injury received from your
ministers or courtiers, and refuse not to listen even to
such as accuse those most dear to you; on the
contrary, lend them all your ears, for in proportion as
your favourites can reckon upon you, they are likely to
consider themselves safe in committing outrages and
insults. Think not you can have about you persons who
will never make a slip, whether from love, or hatred, or
dishonesty. Hear, therefore, by all means hear, and
punish him who has either done amiss, or who has
brought a false charge. And such audiences you may
give at all seasons and places, even when going to
mass, or in your moments of recreation, without
engaging yourself for a future day; for quarrels may
arise requiring prompt remedy, and which cannot wait
a future day or hour. By these means you may easily
secure the execution of justice, because there will
eventually not be many such disputes, when once, by
a few examples of severity, you have brought your
magistrates, your court, and consequently the rest of
your subjects, into such discipline that you will have
few complaints to listen to, and will be able to govern
your state with little trouble. But see in the
commencement to give proof of your vigour, that
matters may subsequently proceed favourably.
"When others have suffered injury or offence, do them
justice, punishing offenders for the general
satisfaction; for you may be sure that to visit offences
committed upon others protects yourself from the like,
whilst impunity gives security to offenders. In the
matter of third parties, clemency need not be thought
of, forgiveness of a fault being a favour bestowed,
which affects the interest of the party offended; thus,
he who pardons injuries done to me, disposes of what
I alone should dispose of, which is unjust. It may be
well to remit injuries done to yourself, for that is your
own affair, and it is worthy of a magnanimous prince to
pardon when he might punish; but a sovereign ought
never to forgive offences against others without their
special consent, which cannot be freely given if he
intimates such to be his desire. Should disputes arise
among your people involving individual honour, you
must be judge of this, as much as of charges touching
their life and property. Indeed, you ought to decide
judicially as to whose reputation is intact and whose
compromised; and by chastising any unworthy action,
you will at once promote justice and give satisfaction
to the injured party. I am touching briefly upon
matters which require ample consideration, but it is
enough that I moot certain points, knowing well that
you have good sense to weigh and decide them. And
now to pass to another topic.
"You ought to calculate the amount of your revenues,
and so proportion your expenses that at the end of the
year you have rather a surplus of ten than a deficiency
of one; for a short-coming of one to-day, and another
to-morrow, and another the day following, will bring
you to ruin. Surround yourself with a court more
distinguished by the qualities than the number of its
members; let it not be larger than you can support,
and see that you maintain the mastery, letting none
there gain an ascendancy over you. Let each have his
department, and be satisfied to do his own duty well,
the chamberlain not interfering with the counsellor, nor
the sewer with the secretary. See that all have their
allowances punctually. Never aggrieve merchants,
citizens, nor peasants, by laying hands upon their
effects. True generosity will satisfy first those who
have rightful claims, not squandering upon gamblers
or buffoons; and when these are satisfied, will give to
the needy, and to other works of charity. Do not, to
gain an empty name for liberality, lavish your means
on costly hospitalities towards great personages: those
who have hundreds of millions do not so, while you
who scarcely have tens would do it! Entertain the
master at dinner or supper with yourself, but let the
rest go to the hotel at their own expense, and so will
you avoid vast trouble and great expense.
"In towns all innovations are unpopular and annoying,
but especially new imposts; you cannot do anything
more generally offensive than to raise them, nor more
acceptable than to replace on their original footing
those which have been augmented. New taxes and
extraordinary escheats seem at first sight useful, but
by a providential dispensation they absorb ordinary
revenues, making these incomprehensibly to disappear.
Let all keep their own; resort to no compulsion of
property nor of person; interfere not with marriages;
seek not to reward friends or benefit servants out of
other people's means: and be it ever graven on your
memory, that princes are sent for the people's weal,
not people for the benefit of princes.
"These few observations have occurred to me, most
excellent Sire, for your remembrance. And I have to
observe generally and in fine, that you should render
yourself amiable to your subjects, being kind,
considerate, affable, and doing your utmost to recover
their pristine affection, which appears to a great
degree lost. You could not by force maintain this state
against a powerful foe: let the attachment of your
people then supplement your strength; and it can only
be acquired by justice, equity, mildness, and clemency.
In the present juncture, you might by a single act gain,
confirm, and augment the good will and devotion of all
your subjects. That act is a grand amnesty, and
restoration of exiles and emigrants, embracing all as
your children, forgetful of the past. Ah, do this, Sire!
do it; it will be a welcome favour to your people, to
your friends, to your servants. On the strength of such
generosity, you will gain the name of a benign and a
magnanimous prince; and, besides having to hope
from the Almighty an eternal reward, I can ensure
your receiving from the Pope thanks and approbation.
"I pray God that this letter of mine may be received by
your Excellency with the same feelings as those which
dictated it, and that He would vouchsafe you a long
life and happy reign; and I kiss your hands. From
Rome, the 11th of October, 1574."
Alinari
DUKE FRANCESCO MARIA II. RECEIVING THE
ALLEGIANCE OF HIS FOLLOWERS
After the fresco by Girolamo Genga in the Villa
Imperiale, Pesaro
[Enlarge]

Let us now see from his own narrative what effect these blunt but
precious counsels, and the prudent advices of his uncle Ottavio,
Duke of Parma, had upon his early measures. "His first act on
assuming the government was to raze those fortifications at Urbino
which had been made during the insurrection, and to reduce the
impost laid on by his father in his necessity; and this although the
late Duke's liberality had imposed upon him many burdensome
expenses to which his revenues were scarcely equal, besides heavy
debts at interest. He was thus obliged to restrict himself to the
unavoidable state expenses.
"Further, he was disappointed of those aids he looked for from the
kindness of his Catholic Majesty, in whose service his father had
died, at whose court he had himself been brought up, for whom he
had fought in the battle of Lepanto, and to whose service he had
ever professed his intention steadily to adhere. But, during eight
long years his hopes dragged on without any result from that
quarter, and thus was he compelled to attend closely to his private
affairs, and prevented from carrying into execution an intention he
had always entertained of following the career of arms, which he
was on the point of commencing in Flanders, where he was already
looked for when he lost his father. He, however, succeeded in
contenting his subjects, and in effacing from their minds whatever
bitterness remained in consequence of the recent measures; and
this chiefly from their being aware that these events had been
displeasing to him, and that he had studied to assist their cause in
so far as his parental duty permitted."
The moderate and self-denying measures to which the Duke thus
modestly alludes are the subject of more detailed commendation by
Zane, who was commissioned by the Venetians to congratulate him
upon his succession. At the moment of receiving the oaths of fidelity,
he abolished those imposts which had occasioned the recent
discontents. They were five in number, all upon exciseable
commodities, yielding about 16,000 scudi to the revenue. This
course he followed up by various grants and immunities to the
respective cities, but especially to Urbino. Even before his father's
death he had obtained a commutation there of the duties on casking
wine and cheese, and of the quatrino per lb. upon butcher-meat, for
an equivalent of 20,000 scudi payable in ten years; but he now
remitted entirely this contribution. He restored to their property and
privileges most of the outlaws and their families; he recalled the
proclamations disarming the district; and, by destroying the
fortifications erected after the rebellion, he at once relieved the
people of a garrison, and demonstrated his renewed confidence in
their fidelity. But what had still happier effect, was his repeatedly
visiting that capital with but one or two attendants, in full and well-
placed reliance upon the affection of his subjects, of whom he ever
spoke in public and private with the most affectionate regard.
Himself deeply imbued with sentiments of religion, it was his aim to
encourage the same among his people. Nor was he indifferent to
personal accomplishments, or to the reputation which his
predecessors had established, and which Castiglione has
immortalised. "There are ever at his court some persons
distinguished in arms or in letters, and it is the taste for all to
cultivate a refined urbanity of manner, and to be in every respect
perfect courtiers, a fashion of old observance there, yet more than
ever in repute since the Prince visited Spain." But it is time to
resume the Autobiography.

Alinari
DUKE FRANCESCO MARIA II. RECEIVING THE
ALLEGIANCE OF HIS FOLLOWERS
After the fresco by Girolamo Genga in the Villa
Imperiale, Pesaro
[Enlarge]

"Notwithstanding this state of affairs, he discovered a conspiracy


against his person, originating with men who had reason to
apprehend the consequences of their former proceedings. These
were Pietro Bonarelli of Ancona, on whom the late Duke had
bestowed the countship of Orciano, with other estates and great
wealth, and Antonio Stati, Count of Montebello. Orciano saved
himself by flight, and was condemned in absence; the other was put
upon trial, and at length, in due execution of justice, he was
beheaded, and some of his accomplices hanged.[83] Francesco
Maria, nevertheless, laboured for the good government of his
people, with due economy of his time. In the morning he gave
audience to his counsellors and secretaries, and in the evening to all
who desired it, dismissing these with despatch; and thus business
went on well and rightly." We are told by Gozze,[84] who seems to
have been a contemporary, that at this period he occupied himself
much with criminal police, and exerted himself to repress
brigandage, and to reform the abuses arising from privileged
sanctuaries. His rigorous perseverance in such measures, and his
stern demeanour towards the nobility, acquired for him, with many,
a reputation for severity, which the infirmities of his temper must
have served to confirm. The only other reference to his system of
administration which the Autobiography contains, is as follows:—"He
attended assiduously to the government of his state, maintaining
peace, and administering justice with integrity and impartiality. He
passed the summer at Urbino, the winter between Pesaro and Castel
Durante. At intervals he visited his other residences, and when he
omitted doing this in person, he despatched one of the judges on a
sort of circuit, who in one year went to Gubbio, Cagli, Fossombrone,
and La Pergola; in another to Sinigaglia and Mondavio; and in a third
to the province of Montefeltro."
CHAPTER XLV
The unsatisfactory results of his marriage—He separates
from the Duchess—His court and habits—Death of the
Duchess—He remarries.

H
AVING thus thrown together all that the Duke has thought fit
to detail regarding the principles of his government and the
early events of his reign, we now proceed to narrate in their
order, from his Diary and from other sources, the few incidents
afforded by those peaceful and monotonous pursuits wherein many
subsequent years were passed. The first of these was of a painful
domestic character, arising out of the unsatisfactory terms upon
which he had during several years been with the Duchess. That love
formed no ingredient in the match has been already shown, and
perhaps his speedy and voluntary departure on a distant military
expedition may be taken as a proof that his indifference did not
diminish after wedlock had riveted his chains. In 1573, Lucrezia was
laid up at Novilara with a feverish cold, and was attended by her
husband, who with great reluctance consented to her return to
Ferrara, on the excuse of change of air being requisite for re-
establishment of her health. The truth seems to have been, that her
marriage appearing unlikely to give an heir to the family, the Prince
was confirmed in his original distaste, and this is said to have
occasioned some disagreeable scenes with his father, whom he
blamed for having forced upon him so unfortunate an alliance. The
scandal to which these probably gave rise, and the example of
coldness towards her which he most assuredly set, had, no doubt,
rendered her position sufficiently unpleasant, and, after exchanging
it for the freedom of her brother's elegant court, it is scarcely to be
wondered that she hesitated to return, even after her husband had
succeeded to the sovereignty of Urbino. That rumour was busy with
gossip and conjectures is pretty obvious, and the countenance which
Muratori gives to an allegation of Lucrezia's jealousy of his supposed
infidelities may be taken as the version current at Ferrara of their
mysterious non-adherence. Of this suspicion the life and character of
Francesco afford an ample refutation, but its existence induced an
endeavour on his part to bring about a better understanding with his
wife.
In 1577, accordingly, he employed the Bishop of Pesaro and Father-
general del Carmine to persuade her to return to his home. In a
paper of instructions for their guidance, preserved among the
Oliveriana MSS., he declares that the excuses she pleaded were of
no weight, and could not be the real motives of her absence. In
reference to pecuniary arrangements, he urges the great economy
and self-denial which his father's embarrassments imposed upon
him, but offers her the same establishment as his mother enjoyed,
besides Novilara and its dependencies, in all about 6000 scudi a-
year. But, in consideration of the slanderous and groundless
imputations against himself to which her absence had given rise, he
intimates his intention to select for her a suitable suite of respectable
persons, leaving her, however, to choose eight or ten from them to
be more immediately about her person. This negotiation having
failed, the affair was next year submitted for the decision of
Cardinals Farnese, Sforza, and d'Este: it would appear that an
amicable separation was then determined upon; at all events, the
Duchess returned no more to her husband's state.
The notice of this disagreeable topic in the diary of Francesco Maria
is as follows:—"Meanwhile the Duchess wished to return to Ferrara,
where she subsequently chose to remain, a resolution which gave no
annoyance to her husband; for, as she was unlikely to bring him a
family, her absence mattered little. Her provision was amicably
arranged, and their intercourse continued uniformly on the most
courteous terms." In support of this last statement the following
letter from Lucrezia is conclusive.
"To the most serene Lord my Consort the Duke of
Urbino.
"My most serene Lord and affectionate Consort,
"I could not have heard any message with more
satisfaction than that which Count Alessandro della
Massa has brought me in your Highness's name, on
presenting your affectionate letters, nor could any
present have been more gratifying than the picture
which you were pleased to send me: both on account
of its subject, and as coming from your hands, it will
be ever the most valued that I possess. On all
accounts, therefore, do I kiss your Highness's hand,
recommending myself to your goodness; and I pray
the Lord to preserve you ever in all happiness. From
Ferrara, 28th of May, 1586.
"Your most loving and obedient consort and servant,
"Lucrezia d’Este."
The Oliveriana MSS. contain many other letters from Lucrezia; but,
as usual with such princely documents, they are more rich in
mannered phrases of compliment than in those natural sentiments
which form the charm of epistolary composition, and afford a correct
index of individual character. Most of them are commendatory
introductions of priests and friars, a class of acquaintances more
congenial to her husband's disposition than her own, the chief foible
in her character being an immoderate addiction to those festive and
exciting pleasures, which, although the business of her brother's
court, met with little encouragement at that of her consort. Her
intercourse with Tasso will fall to be noticed in our fifty-first chapter,
when describing the sorrows of that wayward genius. After her
return to Ferrara, she interested herself in establishing at San Matteo
an asylum for wives, who, like herself, were separated by
incompatibility of character. Soon after his separation from the
Duchess had been arranged, Francesco Maria paid a visit to the
court of Tuscany, where he met with a distinguished reception, and
spent fifteen days very agreeably amid the many attractions of
Florence, varied by comedies and amusements of the chase. During
the ensuing carnival he introduced unwonted gaiety at Pesaro,
holding a tournament, at which he entered the lists in person. About
this time, too, his finances were recruited by a donative of 10,000
scudi granted to him by that city.

Anderson
FRANCESCO I. DE’ MEDICI
After the picture by Bronzino in the
Pitti Gallery, Florence

The Duke's autograph Diary, from which we have recently quoted,


and to which we shall frequently refer, having been carried to
Florence with his other personal effects in 1631, remains in the
Magliabechiana Library (Class xxv., No. 76). It is a narrow folio
volume, like an index book, containing about two hundred pages
entirely in his own hand. The entries are limited to a bare notice of
facts without comment. The topics most frequently registered are
the passage of remarkable strangers through Pesaro; the births,
marriages, and deaths of persons of rank; his own periodical
movements to his various residences, and visits to other parts of the
duchy; his frequent hunting parties in autumn and winter, chiefly
from Castel Durante; his taking medicine, including regular semestral
purgations in spring and autumn. His taste for the physical sciences
is illustrated by noting the occurrence of earthquakes, unusual
storms, or other phenomena of nature, the recurrence of frost and
snow, of the cigala and the nightingale, of mosquitoes, and similar
signs of the seasons; also the appearance of any rare animal or
monstrous production of nature. The Journal commences in April,
1583, and is continued without interruption until March, 1623, when
it terminates abruptly.
The disappointment felt by the Duke at the fruitlessness of his family
friendship with the crown of Spain was removed by receiving,
towards the close of 1582, a military commission from his Catholic
Majesty. This was the only relic of the condottiere system that
survived the changes of the sixteenth century upon the political and
military aspect of Europe. It was the intervening link between
mercenary bands of the middle ages and standing armies of modern
times. No plan could have better suited all parties. The great powers
were thus enabled to command on sudden exigencies an ample
force, without waste of time or treasure. The petty sovereigns by it
eked out their inadequate revenues, without further burden to their
subjects than an occasional call upon the military services of those
who regarded arms as a pastime, and whose restless spirits, if not
thus employed, would have been dangerous at home. The people,
without abandoning the arts of peace, reaped a portion of the fruits
of war. These benefits were, indeed, purchased by a surrender of
the last vestige of independence, for the salary paid to the princes in
name of stipend was, in fact, the price of their political subserviency.
Yet it was but a nominal compromise, to sell the shadow when the
substance had long departed; and we find the example of Spain in
retaining friends throughout La Marca, for pecuniary considerations,
recommended for the imitation of Venice by one of her ambassadors
about this very time. The conditions of the Duke's service were an
annual pay of 12,000 scudi, which, in 1599, was augmented to
15,000, a company of men-at-arms in the kingdom of Naples, and
ample protection in all his undertakings; in return for which he was
bound to provide, when called upon by Philip II., three thousand
militia, and to take the field with them when his Majesty appeared
there in person. The amount of troops thus actually raised in the
duchy for the Spanish service during the next thirty years has been
calculated at seven thousand two hundred men, a sufficient proof
that the benefits accruing from the arrangement were mutual. The
Pope now granted Francesco Maria the honourable prefix of "Most
Serene" to the title of Highness, which he had enjoyed in common
with other minor sovereigns, a distinction said to have been
accorded with difficulty, and after long entreaty. The establishment
of a Swiss guard is another illustration of his partiality at this period
to pomps which he subsequently little esteemed.
In the following year, the court of Pesaro was enlivened by the
Princess Lavinia's nuptials with Felice d'Avalos, Marquis del Vasto,
when twelve poetesses were said to have tuned their lyres at the
Imperiale, in honour of the joyous occasion. His marriage presents
to his bride, mentioned in her brother's Diary, consisted of a
necklace of jewels, a bag or muff of sable skin—the head and feet
studded with precious stones, called a zebellino, and similar to that
represented in Titian's beautiful portrait of her grandmother,
Duchess Leonora,—a set of fan-sticks, a gem mounted as a sun, two
pearls for ear-drops, a diamond cross and eagle, and an order for
3000 scudi: the whole was valued at 10,000 scudi. The happy pair
spent some months at the court of Urbino, while the Marquis often
joined the hunting parties from Castel Durante. But the sun that rose
thus brightly was soon clouded by his wretched and tyrannical
temper, which embittered his consort's life. Many years after, she
married, in her widowhood, the gallant Marquis of Pescara, her
brother's long-tried friend, and, finally, with her two daughters,
sought repose and peace in the convent of Sta. Chiara at Urbino,
where she died in 1633. In the end of 1583 the Duke began to build
the Vedetta, on the most commanding eminence of Monte Bartolo,
which he had obtained for this purpose from the Gerolimini convent.
Of this casino only the foundation remains, but it would seem to
have been an appendage of the Imperiale palace, whither the court
ascended in the summer heats, to inhale gentle breezes from the
blue Adriatic, which sparkled some hundred feet beneath. For such a
purpose no spot could have been better chosen, and the magnificent
prospect, which we have elsewhere noticed without attempting to
describe, renders it probably the most attractive site in all the fair
duchy.
As a further mark of favour, Philip II. of Spain sent him, in 1586, the
decoration of the Golden Fleece; and in order to confer it in manner
at once honourable and complimentary to his personal feelings, his
Majesty requested the investiture to be given him by his uncle the
Duke of Parma. That Duke was then suffering from gout, and
drawing towards his death, which occurred in the following autumn;
so Francesco Maria showed respect at once for the King and for his
relation, whom he revered as a parent, by proceeding to meet him
at Bologna. The two princely guests were magnificently entertained
by the authorities of that city, as well as by the Cardinal Legate
Salviati and the Archbishop Palotta: they were lodged in the palace
of the latter, who performed high mass in the cathedral at the
investiture. The collar and girdle of the order were set with brilliants,
and were accompanied by a rich present of jewels to the Duchess,
consisting of four hundred and twenty-six pearls, and a handsome
necklace, girdle, two pendants, and sixty buttons, all enamelled in
red and white upon gold, and studded with diamonds.
Although, on the whole, a more popular sovereign than his father,
we have seen Francesco Maria subjected, in the early years of his
reign, to seditious movements on the part of some discontented
nobles. Of a similar attempt in 1586, few particulars have been
preserved; but this notice of it in his Diary exhibits him as a stern
dispenser of justice. "Count Giovanni de' Thomasi was beheaded in
the fortress of Pesaro for homicide, sedition, and bad service
towards his master; he died as a Christian and a brave man, and
may God pardon his sins." But, though of hard, and even stern
manners, the Duke retained the affection of his household, most of
whom remained long in his service. From a catalogue of the chief
officers at his court, compiled by Lazzari, we learn the emoluments
belonging to the principal places.

Scudi.
The superintendent of the household
1000
had yearly
The master of the chamber 400
The master of the household 200
The gentlemen cuirassiers 250
The chamberlains 224
The sewer or carver for visitors 250
The philosopher or dilettante of poetry 300
The physician 250
The chaplain 150
The auditors or judges 500
The eight counsellors 400
The chief secretary 400
The secretary of justice 350
The treasurer 250
The fiscal advocate 350
The captains of the guard 232
The commandants of garrisons 300
The castellans, besides perquisites 150
The ambassador to Spain 1000
The ambassador to Venice 400
The agent in Rome 100

Francesco Maria had now reached the flower of manhood, and this
may be considered the most fortunate period of his reign. During the
next twelve years no untoward incident interrupted the smooth
current of his life, or the prosperity of his government. The healthful
exercise of the chase constituted his favourite relaxation from the
cares of state, and his Diary preserves more minute information on
this than on any other topic. He had within reach of Pesaro eighteen
preserves, stocked with roe-deer, goats, foxes, hares, pheasants,
and partridges, all of which were, in those days, considered fair
game. The more exciting sport of wild-boar was found in greatest
perfection near Mondolfo, and the following entry occurs in January,
1588. "Hunted in the chase of S. Costanzo, and, in three hours,
killed nine wild boars, weighing 2580 lbs., besides offal. The largest
one weighed overhead 917 lbs. We cut off its head close behind the
ears, and hung it in the castle window over the great street of
Mondolfo; its weight was 59½ lbs."
But red deer were the Duke's noblest and favourite sport, which,
being only found in the highlands of his duchy, was his original
attraction to Castel Durante, whence the best forest coverts were
easily accessible. It was on that account selected as his chief
residence during his father's life, and continued his annual resort in
autumn so long as he could follow the game. When increasing years
precluded such pastimes, we shall find that he there provided other
appliances more befitting his circumstances, and that these
preserved for Castel Durante a partiality which increased to the
latest hours of his life. He was in use there to spend the autumnal
months, returning to Pesaro before the carnival, and moving to
Urbino towards midsummer. In the interval from the 7th of
September, 1588, till the end of the following January, twenty-eight
hunting parties are mentioned in his Journal, at some of which
wolves and smaller game were killed. Red deer must have been in
great abundance: thus, November, 1587, "We killed a dozen, six of
them males, the largest weighing 464 lbs., besides 380 lbs. of offal.
We left Castel Durante about noon, and returned at dusk, after
losing nearly an hour in watching a hind which took refuge in the
broken ground of the Lady's Park, when fell dead the famous hound
Box-cur, the only British one I had. The twelve deer weighed 2914
lbs., without offal." In the subsequent season, "hunted red deer in
the valley of S. Martino with greyhounds, but without canvas or nets.
Saw twelve, and chased five of them; but, though the dogs came up
with them, they were not able to hold any." The park which he had
inclosed in the beautiful vale of the Metauro, just out of Castel
Durante, was stocked with fallow-deer: which, however, seem to
have been kept chiefly for ornament, though occasionally resorted to
for greyhound coursing, when age had relaxed his limbs for the
rougher mountain sport. The last hunting party he mentions was in
1615.
Though reserved in manner, and little apt to indulge his court in
amusements uncongenial with his own unsocial temperament, he
sometimes relaxed so far as to have dancing fêtes at the Imperiale,
where he mentions three hundred ladies as having on one occasion
been present. The representation of comedies was a frequent
carnival pastime. The manner of conducting these theatricals, and
the methodical punctuality of the Duke's character, are at once
illustrated in the following extract. In February, 1589, "a comedy by
the late Maestro Fabio Bagnano was recited in the great hall of
Pesaro, beginning at 4 p.m. The first act lasted an hour and ten
minutes; after which came an interlude for twenty minutes, from the
fable of Ulysses hearing his wanderings foretold by Tiresias; then act
second, in fifty minutes, with a musical interlude for ten minutes;
then act third, in half-an-hour, with, for interlude, the marriage of
Eolus and Deiopeia, in twelve minutes; then act fourth, in forty-eight
minutes, and its musical interlude, in seven minutes; lastly, act fifth,
in thirty-eight minutes, with its interlude of the gods allotting their
various dominions; but this was not finished in consequence of a
cloud which, by some mismanagement, did not descend properly."
Among the performances noted about this period are the comedies
of I falsi Sospetti by Pino; another by the Cavaliere Ludovico Odasio,
I Suppositi; and an eclogue entitled La Myrtia. The interludes
between the acts were frequently moresque dances or ballets
representing mythological subjects, such as the fable of Prometheus,
that of Calisto, the birth of Venus; varied by more familiar themes,
as hunting the owl. In 1597, we find noticed, among other gay
doings during carnival, a tournament in the great hall of Pesaro,
wherein ten or twelve knights ran each three courses, and which
was followed by an exhibition of various pleasing conceits.
Of Francesco Maria's literary pursuits we have various pleasing
memorials. Not satisfied with the valuable library of MSS. that had
descended to him from the Feltrian dukes, he formed another of
standard printed works. Indeed, he became an assiduous book
collector; and the letters of his librarian Benedetto Benedetti, in the
Oliveriana Library, are full of lists which his agents in Venice,
Florence, and even Frankfort are urged to supply. In his own
voluminous correspondence, we find constant offers from authors of
dedications or copies of their productions, the tone of which is highly
complimentary to his taste for letters. In 1603, the Archbishop of
Monreale, in Spain, transmits him the regulations he proposed to
prescribe in bequeathing his library to a seminary he had founded in
his diocese, expressing a hope that they might prove useful to the
Duke's collection, "at this moment without parallel in the world."[85]
Instead of quoting the vague testimony of courtly compliment, as to
the use which this philosophic Prince made of these acquisitions, let
us cite the brief records of his studies, preserved in his own Diary. In
1585, "terminated an inspection of the whole works of Aristotle, on
which I have laboured no less than fifteen years, having had them
generally read to me by Maestro Cesare Benedetti, of Pesaro." But
his reading was not limited to such speculative topics, and we
presently find him imbibing knowledge from a purer source. In 1587,
"I finished my examination of the whole Bible, with various
commentaries, on which I have spent three years and ten months."
Again, on the "15th of December, 1598, completed my second
perusal of the entire Bible, which I read this time with the
commentary of Dionysio the Carthusian, occupying upon it eight
years." A curious inference of the contemplative character of his
mind may be drawn from the devices he successively assumed as
emblematic of his feelings. In youth he used a flame vanishing into
air, with the motto Quies in sublime, "There is rest on high:" after he
succeeded to the dukedom, he took a terrestrial globe with the
legend Ponderibus librata suis, "Self-poised."
The position of Pesaro, on the principal high road to Loreto and
Rome, exposed it to the constant passage of travellers of all ranks.
The former was the habitual resort of Roman Catholics, to whom
holy impulses, the hope of any specific blessing, or gratitude for
mercies vouchsafed, suggested an unusual devotional observance.
The annual functions of Easter, St. Peter's day, and Christmas,
besides the great occasional jubilees, attracted to the latter crowds
of pious pilgrims from all Christendom. The dukes were thus laid
open to frequent calls upon their hospitality, which the state
maintained by passing visitors often rendered most onerous. Thus,
in 1589, Duke Alfonso II. of Ferrara, on his way to and from Loreto,
spent four days at Pesaro, with his suite, consisting of fifty carriages,
and one hundred and fifty mounted attendants, at an expense to his
host of 3000 scudi. All royal pilgrims did not, however, thus mingle
worldly pomp with religious duties: ten years after, Ranuccio, Duke
of Parma, arrived incognito, in company with three others, who wore
red sack dresses, and travelled on foot. After passing the night at
Pesaro, they proceeded to Sinigaglia, on their way to the opening of
the holy door at Rome, in the jubilee of 1600. Eighteen years later,
Francesco Maria's Diary thus notes a more interesting visit: "9th
June, 1618, the Galileo arrived at Pesaro, on his return from Loreto
to Florence." The philosopher was then resident at the Villa Segni,
near his native capital, and suffered much from the effects of a
chronic illness caught in Lombardy some years previously, while
sleeping with an open window. Perhaps his pilgrimage to the holy
house may have been influenced by this circumstance.

"'Twas he who, risking life and fame to crush


The idol-worship that enslaved mankind,
Restored its native freedom to the mind."

In October, 1597, the direct line of the dukes of Ferrara closed on


the death of Alfonso II., whose object had been to secure to his
cousin Cesare, Marquis of Montecchio, the succession of his states,
as well as his private heritage. He had been able to obtain from the
Emperor a new investiture in his favour of Modena, Reggio, and
Carpi, but failed in procuring the like boon from Gregory XIV. as to
the Ferrarese holding. Immediately upon the vacancy, Cesare
assumed the dukedom, with full consent of his people, who dreaded
the descent to provincial rank which must have followed upon their
annexation to the papal state. Clement VIII., who then filled the
chair of St. Peter, answered a conciliatory embassy sent him by the
claimant, with a summons to appear at Rome, and, on his non-
compliance, thundered excommunication against him and his
abettors. These decided steps were followed up by a levy of nearly
thirty thousand men, but ere they could be brought into the field,
Cesare d'Este gained some partial successes near Bologna. Finding,
however, that his position was hopeless, he availed himself of the
mediation of Lucrezia Duchess of Urbino, who succeeded in
reconciling him with the Legate. The devolution of Ferrara to the
Holy See was harmoniously completed in February; but the lady has
been accused of sacrificing the interests of her cousin to an old
grudge against his father, and to a promise of the fief of Bertinoro.
She did not, however, live to receive the bribe, and her death is thus
dryly noted in her husband's Diary:—
"February 14th, I sent the Abbé Brunetti to Ferrara, to visit the
Duchess, my wife, who was sick.
"—— 15th, Heard that Madame Lucrezia d'Este, Duchess of Urbino,
my wife, died at Ferrara during the night of the 11th.
"—— 19, The Abbé Brunetti returned from Ferrara."
In his Memoirs she is the subject of still more brief remark:—"Her
death occurred after some years, leaving him [the Duke] executor by
her will of many pious bequests." Considering that the largest
bequest was in his own favour, a less chilling notice might have been
bestowed! The sum she left him was 30,000 scudi: to her various
attendants and servants she gave 12,000 in small legacies, and
20,000 among several convents, in masses for her soul. There was
also a fund to be mortified for the endowment of poor girls, half at
Ferrara and half at Urbino, and Cardinal Pietro Aldobrandini, the
Pope's nephew, was named residuary legatee, a selection which has
been ingeniously ascribed to the countenance bestowed by his
family on Tasso, in the closing scenes of that minstrel's troubled life.
The anxiety which had long been generally felt on the prospect of a
failure of the ducal family began to show itself after the death of
Lucrezia. The impediment of a childless marriage having thus been
providentially removed, men's hopes were again awakened, and
their wishes were not long in finding a unanimous expression. When
Francesco Maria appeared in public, his ears were greeted with
murmurs from the populace, which at length broke out in
enthusiastic demands for his marriage, and Serenissimo, moglie, "A
wife, your Highness," became the universal cry.[*86] The ferment
thus created was greatly increased by a circumstance which at first
sight does not appear much connected with the welfare of the
duchy. In the spring of 1598, Clement VIII., on his passage to take
possession of Ferrara, paid a visit to the court of Pesaro, where the
magnificent reception accorded him, and the long confidential
interviews he had with the Duke, were construed by popular
jealousy into preparatives for political changes. The extinction of the
reigning line would infer a lapse of their sovereignty to the Pope,
similar to that which had just degraded Ferrara: Francesco Maria's
disinclination for state-toils had already begun to show itself: the
readiness of his Holiness to secure so valuable a reversion, or even
to anticipate it by providing for the Duke an honourable retreat from
duties which he considered onerous, scarcely admitted of a doubt,
an appetite for annexation being naturally whetted by the recent
acquisition of territory. These ideas became a theme of discussion
among the multitudes who crowded from all quarters of the state to
witness the courtly shows at Pesaro; and when the Duke returned to
the city from escorting the Pope towards Ferrara, he was met at the
gate by a host of his subjects, whose loyalty and patriotism burst
forth afresh in tumultuous shouts of "Serenissimo! moglie."
That the object of Clement's visit had been faithfully construed by
the general voice seems more than probable from the document we
are about to quote; but upon this point the Memoirs throw no light.
They merely notice his reception of the Pontiff with all distinction,
and the remarkably friendly bearing of his Holiness towards himself
and the Duchess mother during a day spent at their court: mutual
presents passed between them, and Clement dwelt on the good
service which his father had afforded to Duke Guidobaldo. From the
Duke's Diary we learn that after meeting his Holiness on his
southern frontier, and again escorting him out of Sinigaglia, where
he had slept with a suite of sixteen cardinals, he took boat and
hastened to Pesaro. Next morning he proceeded to meet his visitor,
who had spent the night at Fano, and welcomed him to his capital.
Passing back to Rome in the end of the year, the Pope halted at
Pesaro only to say mass in the cathedral; and on both occasions he
was preceded one day by the Holy Sacrament. In the following year
the Pontiff, in acknowledgment, perhaps, of these hospitalities,
accorded to his host a dispensation, whereby the indulgences, to
which the use of certain rosary prayers and ave maria's entitled him,
were united and concentrated in a single cavaliere.[87]
The predominant feeling of Francesco Maria, even at this period of
his life, appears to have been a selfish attachment to solitary habits
and pursuits, tempered by sincere anxiety to discharge his public
duties for the benefit of his people. An argument addressing itself to
both motives readily occurred to the wily Pontiff. An immediate
abdication would secure to the Duke personal ease, and the
consequent devolution of his government to the Camera Apostolica
might be guarded by stipulations for the public weal, which such
voluntary demission alone could entitle him to dictate. The art with
which these considerations had been urged, and the impression they
made upon the Duke, may be best gathered from a circular he
addressed to the magistrates of each city in his state, curiously
exemplifying him in that character of royal philosopher which it
seems to have been his ambition to attain.[*88]
"Most magnificent and well-beloved,
"Ever since we understood that you so affectionately
long for the continuation and maintenance of our
house, we have had no wish more urgent than to
conform to your desires; and although for some time
past we have been always anxious to facilitate this
resolution, yet the more we consider it, the greater do
the difficulties daily appear, not only by reason of our
age and infirmities, but much more from the obligation
laid upon us to take no step that might turn to your
prejudice, as we know this would do: for, upon
weighing the advantages that would accrue to you by
being placed after our death immediately under the
sway of the Church, there cannot, in our opinion, be a
doubt that this would be most beneficial; since,
besides being rid of the present inconvenient
restrictions on trade in grain, salt, oil, and similar
commodities, you might well hope, from a sovereign
so powerful as his Holiness, many exemptions and
facilities which we, however well-disposed, cannot,
with due attention to the suitable maintenance of our
rank, accord you. Wherefore, we exhort and pray you,
to take all this into your most serious consideration;
and, along with it, those suggestions which your
affectionate devotion may prompt, in conjunction with
our delicate and advanced age, as these might, at all
events, render vain the hope of a succession, or at
least might occasion you to be some day left under a
minority (ever a judgment of God upon a nation), and
us to die with such pain as you may conceive the
predicament of leaving a minor would occasion us:
whereas, on the other hand, were we to remain in our
present condition, looking, so long as God may
vouchsafe us life, for no other children than

You might also like