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
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
com
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
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
https://ebookmeta.com/product/java-a-beginners-guide-create-compile-
and-run-java-programs-today-herbert-schildt/
ebookmeta.com
https://ebookmeta.com/product/raspberry-pi-iot-in-c-2nd-edition-harry-
fairhead/
ebookmeta.com
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
https://ebookmeta.com/product/beautiful-monsters-imagining-the-
classic-in-musical-media-michael-long/
ebookmeta.com
https://ebookmeta.com/product/thinking-through-images-narrative-
rhythm-embodiment-and-landscape-in-the-nordic-bronze-age-tilley-
christopher/
ebookmeta.com
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
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
v
Table of Contents
vi
Table of Contents
vii
Table of Contents
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
ix
Table of Contents
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
xi
Table of Contents
xii
Table of Contents
xiii
Table of Contents
xiv
Table of Contents
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:
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
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
2
Chapter 1 Motivations
1
I2C is the most common acronym; I2C and IIC are sometimes used.
3
Chapter 1 Motivations
4
Chapter 1 Motivations
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
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
• 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.
7
Chapter 1 Motivations
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++.
8
Chapter 1 Motivations
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.
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
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
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
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
This becomes painful and unproductive. Even for some IoT projects,
this might be unacceptable.
15
Chapter 1 Motivations
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
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:
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:
19
Chapter 1 Motivations
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
• Install Raspberry Pi OS
S
etup Considerations
Every Raspberry Pi project of course requires the “basics”:
• A Raspberry Pi
• 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
HDMI compatible monitor or TV, a USB keyboard, and a USB mouse. You
won’t need any of those during project development.
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."
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]
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
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.