100% found this document useful (6 votes)
32 views

(FREE PDF Sample) Beginning Robotics With Raspberry Pi and Arduino: Using Python and OpenCV 2nd Edition Jeff Cicolani Ebooks

Python

Uploaded by

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

(FREE PDF Sample) Beginning Robotics With Raspberry Pi and Arduino: Using Python and OpenCV 2nd Edition Jeff Cicolani Ebooks

Python

Uploaded by

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

Download the full version of the textbook now at textbookfull.

com

Beginning Robotics with Raspberry Pi and


Arduino: Using Python and OpenCV 2nd Edition
Jeff Cicolani

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

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


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

Beginning Robotics with Raspberry Pi and Arduino: Using


Python and OpenCV 2nd Edition Jeff Cicolani

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

textbookfull.com

Beginning Robotics with Raspberry Pi and Arduino: Using


Python and OpenCV 2nd Edition Jeff Cicolani

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

textbookfull.com

Beginning Sensor Networks with XBee, Raspberry Pi, and


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

Consolidated B 24 Liberator 1st Edition Edward Shacklady

https://textbookfull.com/product/consolidated-b-24-liberator-1st-
edition-edward-shacklady/

textbookfull.com
Cornerstones of financial accounting Fourth Edition Jay S.
Rich

https://textbookfull.com/product/cornerstones-of-financial-accounting-
fourth-edition-jay-s-rich/

textbookfull.com

Digital Twin Driven Smart Design 1st Edition Fei Tao


(Editor)

https://textbookfull.com/product/digital-twin-driven-smart-design-1st-
edition-fei-tao-editor/

textbookfull.com

SQL in 10 Minutes a Day, Sams Teach Yourself 5th Edition


Ben Forta

https://textbookfull.com/product/sql-in-10-minutes-a-day-sams-teach-
yourself-5th-edition-ben-forta/

textbookfull.com

The Palgrave Handbook of Wine Industry Economics Adeline


Alonso Ugaglia

https://textbookfull.com/product/the-palgrave-handbook-of-wine-
industry-economics-adeline-alonso-ugaglia/

textbookfull.com

Desegregating Chicago s Public Schools Policy


Implementation Politics and Protest 1965 1985 1st Edition
Dionne Danns (Auth.)
https://textbookfull.com/product/desegregating-chicago-s-public-
schools-policy-implementation-politics-and-protest-1965-1985-1st-
edition-dionne-danns-auth/
textbookfull.com
3D photorealistic rendering. Volume 1, Interiors &
exteriors with V-Ray & 3ds Max 1st Edition Cardoso

https://textbookfull.com/product/3d-photorealistic-rendering-
volume-1-interiors-exteriors-with-v-ray-3ds-max-1st-edition-cardoso/

textbookfull.com
TECHNOLOGY IN AC TION™

Beginning Robotics
with Raspberry Pi
and Arduino
Using Python and OpenCV

Second Edition

Jeff Cicolani
Beginning Robotics
with Raspberry Pi
and Arduino
Using Python and OpenCV
Second Edition

Jeff Cicolani
Beginning Robotics with Raspberry Pi and Arduino: Using Python
and OpenCV
Jeff Cicolani
Pflugerville, TX, USA

ISBN-13 (pbk): 978-1-4842-6890-2 ISBN-13 (electronic): 978-1-4842-6891-9


https://doi.org/10.1007/978-1-4842-6891-9

Copyright © 2021 by Jeff Cicolani


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 [email protected]; for
reprint, paperback, or audio rights, please e-mail [email protected].
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-­6890-­2. For more detailed information, please visit http://www.apress.com/
source-­code.
Printed on acid-free paper
For Martha, my beautiful and patient wife,
for putting up with random robot parts strewn
about the house, pretty much constantly
Table of Contents
About the Author���������������������������������������������������������������������������������xi
About the Technical Reviewer�����������������������������������������������������������xiii
Introduction����������������������������������������������������������������������������������������xv

Chapter 1: Introduction to Robotics�����������������������������������������������������1


Robotics Basics�����������������������������������������������������������������������������������������������������2
Linux and Robotics������������������������������������������������������������������������������������������3
Sensors and GPIO��������������������������������������������������������������������������������������������4
Motion and Control������������������������������������������������������������������������������������������5
Raspberry Pi and Arduino�������������������������������������������������������������������������������������5
Project Overview���������������������������������������������������������������������������������������������������7
The Robot��������������������������������������������������������������������������������������������������������8
Bill of Materials (BOM)�������������������������������������������������������������������������������������9
Summary������������������������������������������������������������������������������������������������������������14

Chapter 2: An Introduction to Raspberry Pi����������������������������������������15


Downloading and Installing Raspberry Pi OS������������������������������������������������������15
Raspberry Pi OS with OpenCV�����������������������������������������������������������������������16
The “Hard” Way���������������������������������������������������������������������������������������������17
The “Easy” Way���������������������������������������������������������������������������������������������20
Connecting Raspberry Pi�������������������������������������������������������������������������������������21

v
Table of Contents

Configuring Your Pi����������������������������������������������������������������������������������������������23


Users�������������������������������������������������������������������������������������������������������������28
Going Headless���������������������������������������������������������������������������������������������������30
Remote Access����������������������������������������������������������������������������������������������30
Summary������������������������������������������������������������������������������������������������������������38

Chapter 3: A Crash Course in Python��������������������������������������������������39


Python Overview�������������������������������������������������������������������������������������������������41
Downloading and Installing Python���������������������������������������������������������������������41
Python Tools��������������������������������������������������������������������������������������������������������42
The Python Shell��������������������������������������������������������������������������������������������43
The Python Editor������������������������������������������������������������������������������������������44
The Zen of Python������������������������������������������������������������������������������������������47
Writing and Running a Python Program��������������������������������������������������������������48
Hello World����������������������������������������������������������������������������������������������������49
Basic Structure����������������������������������������������������������������������������������������������50
Running a Program����������������������������������������������������������������������������������������53
Programming in Python��������������������������������������������������������������������������������������54
Variables��������������������������������������������������������������������������������������������������������54
Data Types�����������������������������������������������������������������������������������������������������55
A Final Note on Variables�������������������������������������������������������������������������������66
Control Structures�����������������������������������������������������������������������������������������67
Functions�������������������������������������������������������������������������������������������������������73
Adding Functionality Through Modules���������������������������������������������������������77
Classes����������������������������������������������������������������������������������������������������������83
Styling�����������������������������������������������������������������������������������������������������������91
Summary������������������������������������������������������������������������������������������������������������93

vi
Table of Contents

Chapter 4: Raspberry Pi GPIO�������������������������������������������������������������95


Raspberry Pi GPIO�����������������������������������������������������������������������������������������������95
Pin Numbering�����������������������������������������������������������������������������������������������97
Connecting to the Raspberry Pi���������������������������������������������������������������������98
Limitations of Raspberry Pi’s GPIO����������������������������������������������������������������99
Accessing GPIO with Python������������������������������������������������������������������������100
Simple Output: LED Example�����������������������������������������������������������������������102
Simple Input������������������������������������������������������������������������������������������������108
Summary����������������������������������������������������������������������������������������������������������118

Chapter 5: Raspberry Pi and Arduino�����������������������������������������������119


Raspberry Pi’s GPIO in Review��������������������������������������������������������������������������120
Real-Time or Near-Real-Time Processing���������������������������������������������������120
Analog Input������������������������������������������������������������������������������������������������121
Analog Output����������������������������������������������������������������������������������������������121
Arduino to the Rescue���������������������������������������������������������������������������������������122
Using Arduino����������������������������������������������������������������������������������������������������124
Installing the Arduino IDE����������������������������������������������������������������������������125
Connecting an Arduino��������������������������������������������������������������������������������125
Programming Arduino����������������������������������������������������������������������������������126
Sketches������������������������������������������������������������������������������������������������������135
A Brief Introduction to the Arduino Language���������������������������������������������������139
Including Other Files������������������������������������������������������������������������������������140
Variables and Data Types�����������������������������������������������������������������������������140
Control Structures���������������������������������������������������������������������������������������145
Working with Pins����������������������������������������������������������������������������������������153

vii
Table of Contents

Objects and Classes������������������������������������������������������������������������������������157


Serial�����������������������������������������������������������������������������������������������������������158
Arduino to Pi and Back Again����������������������������������������������������������������������162
Pinguino������������������������������������������������������������������������������������������������������������172
Setting Up the Circuit����������������������������������������������������������������������������������173
Summary����������������������������������������������������������������������������������������������������������176

Chapter 6: Driving Motors����������������������������������������������������������������179


Motors and Drivers��������������������������������������������������������������������������������������������180
Types of Motors�������������������������������������������������������������������������������������������180
Motor Properties������������������������������������������������������������������������������������������184
Motor Drivers�����������������������������������������������������������������������������������������������187
Working with Motor Controllers������������������������������������������������������������������������187
Adafruit DC & Stepper Motor HAT����������������������������������������������������������������188
L298N Generic Motor Driver������������������������������������������������������������������������208
Summary����������������������������������������������������������������������������������������������������������219

Chapter 7: Assembling the Robot�����������������������������������������������������221


Assembling the Chassis������������������������������������������������������������������������������������222
Choosing a Material�������������������������������������������������������������������������������������222
The Whippersnapper�����������������������������������������������������������������������������������223
Mounting the Electronics����������������������������������������������������������������������������������231
Wiring����������������������������������������������������������������������������������������������������������������238
Mounting Sensors���������������������������������������������������������������������������������������������241
The Finished Robot�������������������������������������������������������������������������������������������244
Making the Robot Mobile�����������������������������������������������������������������������������245
Summary����������������������������������������������������������������������������������������������������������258

viii
Table of Contents

Chapter 8: Working with Infrared Sensors���������������������������������������259


Infrared Sensors�����������������������������������������������������������������������������������������������259
Types of IR Sensors�������������������������������������������������������������������������������������260
Working with IR Sensors�����������������������������������������������������������������������������������264
Connecting an IR Sensor�����������������������������������������������������������������������������264
Mounting the IR Sensors�����������������������������������������������������������������������������267
The Code������������������������������������������������������������������������������������������������������269
Understanding PID Control��������������������������������������������������������������������������������280
Control Loops����������������������������������������������������������������������������������������������280
Implementing the PID Controller�����������������������������������������������������������������283
Summary����������������������������������������������������������������������������������������������������������287

Chapter 9: An Introduction to OpenCV����������������������������������������������289


Computer Vision������������������������������������������������������������������������������������������������289
OpenCV��������������������������������������������������������������������������������������������������������291
Selecting a Camera�������������������������������������������������������������������������������������297
Installing the Camera����������������������������������������������������������������������������������298
OpenCV Basics��������������������������������������������������������������������������������������������������299
Working with Images�����������������������������������������������������������������������������������300
Capturing Images����������������������������������������������������������������������������������������302
Image Transformations��������������������������������������������������������������������������������311
Working with Color��������������������������������������������������������������������������������������314
Blobs and Blob Detection����������������������������������������������������������������������������320
Ball-Chasing Bot�����������������������������������������������������������������������������������������������328
Summary����������������������������������������������������������������������������������������������������������336

ix
Table of Contents

Chapter 10: Conclusion���������������������������������������������������������������������337


Types of Robotics����������������������������������������������������������������������������������������������338
Tools������������������������������������������������������������������������������������������������������������������338
Software������������������������������������������������������������������������������������������������������339
Hardware�����������������������������������������������������������������������������������������������������345
Summary����������������������������������������������������������������������������������������������������������348

Index�������������������������������������������������������������������������������������������������349

x
Visit https://textbookfull.com
now to explore a rich
collection of eBooks, textbook
and enjoy exciting offers!
About the Author
Jeff Cicolani currently lives in the Austin,
Texas, area with his wife, two dogs, and
dozen or so robots. He is currently working
as an embedded systems engineer, building
robotic and automated platforms for an AI
(artificial intelligence) company in Austin.
His journey to robotics was circuitous, taking
him through an odd career path that included
systems analysis and design and database
programming. In 2012, he joined The Robot
Group in Austin, where he joined a group of
robotics enthusiasts and began building robots as a hobby. In 2016, he
became president of The Robot Group. In this role, he leads the group in
their mission to promote STEM (science, technology, engineering, and
mathematics) education through robotics. He is currently working to
develop a better understanding of advanced robotics through ROS
(Robot Operating System) and machine learning.

xi
About the Technical Reviewer
Massimo Nardone has more than 22 years
of experience in security, web/mobile
development, cloud, and IT architecture. His
true IT passions are security and Android.
He has been programming and teaching
how to program with Android, Perl, PHP, Java,
VB, Python, C/C++, and MySQL for more than
20 years.
He holds a Master of Science degree in
Computing Science from the University of
Salerno, Italy.
He has worked as a project manager, software engineer, research
engineer, chief security architect, information security manager, PCI/
SCADA auditor, and senior lead IT security/cloud/SCADA architect for
many years.

xiii
Introduction
Robotics does not have to be difficult. In this book, I introduce you to the
field of robotics. The journey will be challenging; it’s intended to be. But
by the end of the book, you will have hands-on exposure to many of the
fundamental—and not so fundamental—aspects of robotics. You will work
with hardware, assemble and solder a circuit board, write code in two
programming languages, install and configure a Linux environment, and
work with computer vision. Everything else you do with robots will be an
extension of the lessons learned in this book.

Whom This Book Is For


This book is for those who are new to electronics and IoT, those who have
never used a Raspberry Pi or Arduino separately, let alone together.
This book is for the hobbyist who is interested in learning a little more
about working with robots. Perhaps you’ve built a few circuits with an
Arduino or a custom home entertainment system with a Raspberry Pi, and
now you are curious about what goes into building a robot. You will learn
how these two devices work together to provide very powerful capabilities.
This book is for the entrepreneur who needs to learn more about
technology; someone who doesn’t necessarily have the time to read
through many different books on Arduino, Raspberry Pi, electronics,
or programming; someone who is looking for a broad yet condensed
introduction to some of the fundamentals.

xv
Introduction

This book is also for the student who wants to take their robot-building
experience beyond bricks and puzzle-piece programming, someone who
wants to work with hardware and software that more closely resembles
what they might see in college or in the professional world.
No assumptions are made about experience or background in
technology. As you go through the chapters, you may find parts that you
are already familiar with and you can skip ahead. But if you are new to
these topics, I try to provide you with a quick but easy introduction.

C
 hapter Overview
You start by learning about the Raspberry Pi and how to work with it.
You download and install the Raspbian operating system (OS) and then
configure the Pi for our project. The goal is to set up your system to be able
to easily access your robot and write your code directly on it.
Once you are able to access your Pi remotely, in Chapter 3, you delve
into programming with Python. I show you how to write simple programs
on the Raspberry Pi. I also take you beyond the basics and cover some
intermediate topics, such as modules and classes. This is one of the longest
chapters since there is a lot of material to cover.
From there, you learn how to interface the Raspberry Pi with external
electronics, such as sensors and LEDs, through the Pi’s GPIO (general-­
purpose input/output) header. Chapter 4 discusses the different ways
of addressing the pins on the header, some of the functionality exposed
through the header, and how to use an ultrasonic rangefinder to detect
objects. This gets you ready for the next chapter, which introduces the
Arduino.
In Chapter 5, you connect the Arduino to the Raspberry Pi. I discuss
some of the reasons you want to do this. I show you how to work with the
Arduino IDE (integrated development environment) to write programs.

xvi
Introduction

I cover serial communication between the two boards and how to pass
information back and forth between them. We do this using the same
ultrasonic rangefinder used in the previous chapter.
Chapter 6 has you turning motors with your Raspberry Pi. You use a
special board called a hat, or plate, to control the motors. This is where I
introduce another skill that you will inevitably need in robotics: soldering.
The header and terminals need to be soldered onto the board that was
selected for this purpose. The nice thing about soldering headers and
terminal blocks is that it’s hard to damage anything, and you will get plenty
of practice.
Chapter 7 is where we bring it all together. You build the robot, and I
discuss some of the physical characteristics of robotics. I cover some of
the design considerations that you will need to keep in mind when you
design your own chassis. Although I am listing a specific chassis kit for this
project, you do not need to use the same one. In fact, I encourage you to
explore other options to find the one that is right for you.
In Chapter 8, I introduce another type of sensor—the IR sensor—and
I show you how to use a very common control algorithm called a PID
(proportional, integral, and derivative) controller. I talk about the various
types of IR sensors and where you want to use them. This chapter also
discusses what PID control is and why you want to use it.
Chapter 9 is about computer vision, where you see the true power of
the Raspberry Pi. In this chapter, I cover an open source package called
OpenCV. By the end of this chapter, your little robot will be chasing a ball
around the table.
I leave you with some parting thoughts in Chapter 10. I provide a few
tips that I picked up, and I give you a glimpse into my workflow and tools.
After that, you will be ready to begin your own adventures in robotics.

xvii
Introduction

Second Edition Notes


This book has been updated for the Raspberry Pi 4. In updating the board,
I also updated to the most recent version of the OS. Since the writing of the
first edition, there were several changes in downloading the OS, now called
Raspberry Pi OS, as well as changes in the installation.
The motor controller libraries have been updated to the newer Adafruit
MotorKit libraries. This means there have been updates to the motor driver
code. These changes do make the board easier to use.

xviii
CHAPTER 1

Introduction
to Robotics
The word robotics can mean a lot of things. For some people, it is anything
that moves by itself; kinetic art is robotics. To other people, robotics means
something that is mobile or something that can move itself from place to
place. There is actually a field called mobile robotics; automatic vacuum
cleaners, such as a Roomba or a Neato, fall into this category. To me,
robotics falls somewhere in between kinetic art and mobile robotics.
A robot is technology that applies logic to perform a task in an
automated manner. This is a fairly broad definition, but robotics is a fairly
broad field. It can cover everything from a child’s toy to the automatic
parallel parking capabilities in some automobiles. We build a small mobile
robot in this book.
Many of the principles that you are exposed to in this book are easily
transferable to other areas. In fact, we will go through the entire process
of building a robot from beginning to end. A little later in this chapter, I go
over the project that we will build. At that time, I will provide a list of the
parts used in this book. These parts include sensors, drivers, motors, and
so forth. You are welcome to use whatever you have on hand because, for
the most part, everything we go through in this book can be applied to
other projects.

© Jeff Cicolani 2021 1


J. Cicolani, Beginning Robotics with Raspberry Pi and Arduino,
https://doi.org/10.1007/978-1-4842-6891-9_1
Chapter 1 Introduction to Robotics

Robotics Basics
I like to tell people who are new to robotics, or are just robotics curious,
that a robot consists of three elements:

• The ability to gather data

• The ability to process or do something with the


gathered data

• The ability to interact with the environment

In the following chapters, we apply this principle to build a small


mobile robot. We will use ultrasonic rangefinders and infrared sensors
to gather data about the environment. Specifically, we will identify when
there is an object to be avoided, when we are about to drive off the edge of
a table, and the contrast between the table and the line that we will follow.
Once we have this data, we will apply logic to determine the appropriate
response.
We will use Python in a Linux environment to process the information
and send commands to our motors. I chose Python as the programming
language because it is easy to learn and you don’t have to have a complex
development environment to build some pretty complex applications.
Our interaction with the environment will be simply to control the
speed and direction of motors. This will allow our robot to move about
freely on the table or floor. There really isn’t much to driving a motor.
We will look at two ways of doing it: with a motor driver made for the
Raspberry Pi and with a common motor controller.
This book is intended to be challenging. I cover some pretty complex
material and I do it quickly. There is no way that I can provide detailed
coverage on any of these topics, but I hope to get you to a functional robot
by the end of the book. In each chapter, I try to provide you with more
resources to follow up on the topics discussed. You will struggle at times;
I did and I frequently still do.

2
Chapter 1 Introduction to Robotics

Not everyone will be interested in all the subjects. The expectation is


that you will expand on the areas that interest you the most outside of this
book. Persistence pays off.
At the end of the book, I add a little more challenge. In Chapter 9, we
begin leveraging the real power of the Raspberry Pi. We look at computer
vision. Specifically, we look at an open source package called OpenCV
(CV stands for computer vision). It is a common and very powerful
collection of utilities that make working with images and video streams
very easy. It’s also a six-hour build on the most recent version of the
Raspberry Pi. To make things a little easier and a lot less time-consuming,
I have available for download a version of the operating system with
OpenCV already installed. I discuss this more in Chapter 2.

L inux and Robotics


Linux is a Unix-based operating system. It is very popular with
programmers and computer scientists because it’s simple and
straightforward. They seem to enjoy the text-based interface of the
terminal. Yet, for many others, including me, Linux can be very
challenging. So why in the world would I choose this environment for an
introduction-to-robotics book? The answer to that question is threefold.
First, when you work with robotics, you eventually have to confront
Linux. That’s just a fact. You can do a lot without ever typing a single sudo
command, but you will have limited capabilities. The sudo command
stands for super user do in Linux. This tells the operating system that you
are about to perform a protected function that requires more than general
user access. You will learn more about this when we begin working with
the Raspberry Pi.
Second, Linux is challenging. As I stated before, this book will
challenge you. If you have worked in Linux before, then this reason
doesn’t apply to you. However, if you are new to Linux, the Raspberry Pi,

3
Chapter 1 Introduction to Robotics

or working in a command line, then some of the things that we do will be


challenging. And that’s good. You’re learning something new and it should
be a challenge.
Third, and this is by far the most important, the Raspberry Pi uses
Linux. Yes, you can install other operating systems on the Pi, but it was
designed and intended to use Linux. In fact, the Raspberry Pi has its
own flavor of Linux called Raspbian. This is the recommended operating
system, so it is what we’ll use. One of the nice things about using a prebuilt
operating system, besides its ease of use, is many of the tools are already
installed and ready to go.
Since we are using Linux, we will use command-line instructions
extensively. This is where most new users have problems. Command-line
code is entered via a terminal. Raspbian has a Windows-style interface
that we will use, but much of it uses the terminal. A terminal window
is available in the graphical user interface (GUI), so we will use that.
However, when we set up the Pi, we will set it up to boot into terminal
mode by default. Getting to the GUI is only a simple startx command.
All of this is covered in Chapter 2.

S
 ensors and GPIO
GPIO stands for general-purpose input/output. It represents all the various
connections to devices. The Raspberry Pi has a lot of GPIO options: HDMI,
USB, audio, and so forth. However, when I talk about GPIO in this book, I’m
generally referring to the 40-pin GPIO header. This header provides direct
access to most of the board’s functionality. I discuss this in Chapter 2.
Arduino also has GPIO. In fact, one could argue that Arduino is all
GPIO and nothing else. This isn’t far from the truth given that all the other
connections are there to allow you to communicate with and power the
AVR chip at the heart of the Arduino.

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

All of these headers and GPIO connections are there so we can access
sensors outside the boards themselves. A sensor is a device that gathers
data. There are many different types of sensors, and all serve a purpose.
Sensors can be used for detecting light levels, the range to an object,
temperature, speed, and so forth. In particular, we will use GPIO headers
with an ultrasonic rangefinder and an IR detector.

M
 otion and Control
One thing that most definitions of a robot have in common is that it needs
to be able to move. Sure, you can have a robot that doesn’t actually move,
but this type of device generally falls under the moniker of IoT, the Internet
of Things.
There are many ways to add motion to your project. The most common
is the use of motors. But you can also use solenoids, air, or water pressure.
I discuss motors more in Chapter 6.
Although it is possible to drive a motor directly off a Raspberry Pi
or an Arduino board, it is strongly discouraged. Motors tend to draw
more current than the processors on the boards can handle. Instead,
it is recommended that you use a motor controller. Like motors, motor
controllers come in many forms. The motor control board that we will use
is accessed through the Raspberry Pi’s header. I also discuss how to drive
motors with an L298N dual motor controller.

Raspberry Pi and Arduino


We will use a Raspberry Pi (see Figure 1-1) in conjunction with an Arduino
(see Figure 1-2) as our robot’s processing platform.

5
Chapter 1 Introduction to Robotics

Figure 1-1. Raspberry Pi 3 B+

Figure 1-2. Arduino Uno

The Raspberry Pi is a single-board computer that is about the size of


a credit card. Despite its small size, it is a very capable device. The Pi runs
a version of Linux that was customized to work on the ARM processor
that drives it. This puts a lot of functionality into a small device that is
easy to embed into things like robots. But, although it is a great computer,

6
Chapter 1 Introduction to Robotics

there are a few places where it does not excel. One area is interfacing with
external devices. It can work with sensors and external devices, but the
Arduino does this much better.
Arduino is another small processing device that is readily available and
easy to use. Unlike a Raspberry Pi, however, it does not have the capacity
for a full operating system. Rather than running a microprocessor like the
ARM, it uses a different type of chip called a microcontroller. The difference
is that a microcontroller is specifically designed to interact with sensors,
motors, lights, and all kinds of devices. It directly interacts with these
external devices. The Pi works through many layers of processing before it
ever reaches the pins that a device is connected to.
By combining the Raspberry Pi and the Arduino, we are able to
leverage what each does best. The Raspberry Pi offers the high-level
processing power of a full computer. Arduino provides the raw control over
external devices. The Pi allows us to process a video stream from a simple
USB camera, whereas the Arduino allows us to gather the information
from the various sensors and apply logic to make sense of all that data and
then return concise findings to the Pi.
You will learn more about the Raspberry Pi in Chapter 2. Later on, you
will connect an Arduino to the Pi and learn about programming it, as well
as how to pass information back and forth between the Arduino and the Pi.

P
 roject Overview
In this book, we will build a small mobile robot. The robot is designed to
demonstrate the lessons that you learn in each chapter. However, before
we can actually build the robot, we need to cover a lot of material and lay
the foundation for future lessons.

7
Chapter 1 Introduction to Robotics

T he Robot
The robot that we will build is a small two- or four-wheeled autonomous
rover. It will be able to detect obstacles and the edge of a table and to
follow a line. The chassis that I selected is a four-wheeled robot, but there
are other designs suitable for this project (see Figures 1-3 and 1-4).

Figure 1-3. The front of our robot shows the ultrasonic sensors and Pi
T-Cobbler on a breadboard

Figure 1-4. The back of our robot shows the Raspberry Pi and motor
control board
8
Chapter 1 Introduction to Robotics

Although I provide a list of the parts that I used for the project, you are
welcome to use whatever parts you wish. The important thing is that they
behave in a similar manner as those I have listed.

Bill of Materials (BOM)


For the most part, I tried to keep the list of materials as generic as possible.
There are a couple of items that are vendor specific. I chose them because
they provide a lot of functionality and convenience. The DC & Stepper
motor controller and the Pi T-Cobbler are from an online retailer called
Adafruit, which is a great resource for parts, tutorials, and inspiration.
The chassis kit is from an online retailer called ServoCity, which produces
many mechanical parts for robotics.
The following are the specialty parts (shown in Figure 1-5) that we use
in this book:

• Junior Runt Rover robot chassis from ServoCity.com

• Adafruit DC & Stepper Motor HAT for Raspberry


Pi – Mini Kit, PID 2348

• GPIO Stacking Header for Pi A+/B+, Pi 2, Pi 3 – Extra-­


long 2 × 20 pins, PID 2223 (allows the use of additional
plates and the Cobbler to attach to the breadboard)

• Assembled Pi T-Cobbler Plus (GPIO Breakout) – Pi A+/B+,


Pi 2, Pi 3, Pi Zero; PID 2028

9
Random documents with unrelated
content Scribd suggests to you:
Ven estampes y joguines
y llibrets de la passió.

Arrivant dona el bon dia


part enfora del cancell.
Els infants de la masia
formiguegen vora d'ell.

Ja'ls hi mostra la capella,


recolzant-la en el llindar.
D'una cambra surt la vella.
De la cuina surt el ca.

Compareix la masovera
ab el seu menut a bras.
Ell se fa una mica enrera.
Ella avensa un altre pas.

Com un buf de tramontana


agarbulla enjogassat
les rondalles de la plana
ab les verbes de ciutat.

Ja li ven escapularis
y dos ciris benehits,
confegint-li dos rosaris
que tenia mitg-partits.

Pregunta ella ab galania


si li lleu de descansar.
Ell se n'entra a la masia
com un pare capellà.

Ja li allarguen l'ampla tassa


fins a dalt plena de ví.
Ells els conta lo que passa
per l'aplec de Sant Martí.

Ja arreplega la capella
y'ls hi dona l'adeussiau.
Del portal se'l guaiten ella
y el menut cara-babau.

Y ell s'allunya ab cortesies


aturades d'hermità
pensant noves galanies
per si un dia pot tornar.

Mossa d'hostal

Roja de sol y de luxúria,


brega ab les tasques y'ls aimants
y multiplica ab cega fúria
ses renoueres mans.

Tot son cabell s'aplaca enrera,


en trena vil recargolat,
com una insòlita crinera
de poltre domenyat.
Sota la roba desinvolta
com dos cadells salten els pits.
Del front convex sota la volta,
pengen dos ulls petits.

Com una indòcil vaca brava


obra els badius de bat a bat,
y, de tants palps, com una esclava
ne porta el cos macat.

De la secreta forma nua


n'ix homenívola bavor
qui dels vestits, quan ne traspua,
arrenca un tremolor.

Roja de sol per la boscúria,


roja de feina pel veinat,
com un gran àpat de luxúria
pròdigament parat,

deixa, quan passa carregada


ab el cabàs obert, curull,
com un halè de mitgdiada
o de paller remull.

El bort

En la planura grisa d'un cel inanimat


la còrpora's destaca d'un home estintolat.
La barretina esquàlida, com una flor vermella
li tomba colltorsada tapant-li mitja cella.
La cara es tota roja com xerigot, del ví.
Les venes s'hi cargolen com cuques de verí.
El blanc dels ulls es vitri com testos de rejola.
La boca sembla una ansa lluhenta de cassola.
Y son recargolades y fines com un tel
les grans orelles qui retallen l'ample cel.
Com una escarbotada panotxa el nas s'inclina.
S'obra el gambeto com l'escorsa d'una alzina
y ab rigidesa enquadra la llenca del tricot
y un goll inverossímil qui gairebé no pot
balandrejar-se. Freguen sobre els tormells les grenyes
d'acartronades calses. D'inútils espardenyes
embotornats sobrixen feixugament els peus.
Es el pastor qui arrenca els brassos de les creus
y les canals de fusta de cada font que troba.
Es el pastor maligne qui, ple d'astúcia, roba
sols per fer mal. Y viu d'aglans a tot estrop.
Y garroteja son mastí qui sembla un llop.
Quan veu passâ una mossa, tremola embadocat.
Quan palpa les ovelles ab l'incentiu doblat
de la carnal fretura y de la miopia,
d'un baballut rogall ab la monotonia,
retreu les delectances de son compare el bóc.
Y les ovelles entren sumisament a joc.
Quan d'un bon tret de fona cama-trencada deixa
qualque primala, el riure sa fesomia esqueixa.
Quan bromejant el criden altres pastors, fa'l sort
per amagar l'estigma original: es bort.

Dinar de festa major

A N'Esteve Monegal, Pintor

La sala gran es plena de flaires y rialles.


Ab blau de la bugada, les blanques estovalles
fan ressaltar les cares vermelles y lluents
de les alegres noies, dels baladrers parents.
De les soperes puja la boira de la sopa
y tèrbola s'aplana quan ab el sostre topa.
Y dos porrons circulen, eternament curulls,
qui fan espurnejar de joia tots els ulls.
Y l'escarola brilla com d'una cornucòpia
les fragmentades corves. De la cullita pròpia
es el farcit de peres qui neden en la salsa.
L'innúmera quitxalla cinicament trasbalsa
les coses endressades fins que no'n queda un tros
sencer. Sota la taula grinyolen per un os
l'esquàlida canica y un foraster basset
y una ferotge gata, de nines ab verdet.
Y una forsuda mossa de colzes cantelluts,
rigidament cossada y de badius peluts,
bleixant d'angúnia porta la monstruosa plata
ab una llebra, com un dia la safata
ab l'ensagnada testa, la bella Salomè.
Se fon el pa de fleca a llesques sense fre.
Y encara després venen els ànecs y capons
replens de prunes seques y en abundor, segons
la tradició prescriu. Y encara ve un cabrit
esquarterat y al forn barbarament rostit.
La dringadera aumenta de gots y de coberts.
Els ulls qui no s'adormen, fulguren massa oberts.
Les galtes son lluentes del riure y del menjar.
Un pit de dona salta del giravolt que fa
quan un compare irònic de falsa rialleta,
pessiga la vehina ab la subtil palleta
d'una cadira. Xisclen les noies bojament
sota les manotades calmoses del jovent.
A un cap de taula, sòpit, el vell ubriagat
solemnement sacseja el goll embotornat.
A l'altre cap, serena, vigila la padrina.
A fora, la quitxalla molesta la pollina
o s'embutxaca fruita. Aumenta el rebombori
qui degenera prompte en bacanal desori,
quan se destapa la garrafa d'aiguardent.
El vell, desensonyant-se, reclama enteniment.

Oda a la noucentista propietaria


del Montseny, madamisel·la
Pietat Renom

A vos, Senyora, qui teniu dominical


poder gairebé sobre tota la gran montanya
(car vostra hisenda com horitzontal peanya,
de Rocs-Cremats s'allarga fins sota Sant Marsal)
les serres montsenyenques us fan acatament
y son per vos obertes com el Passeig de Gràcia.
Heu dit a les carenes, dominadora: –Plàcia
a mes gentils sirventes amplificar l'ambent.–

Y encara per la selva, com àgil amassona,


en un corcer trescavau, fogós, a tot galop,
ab vostre groom darrera qui, d'esma ja, esperona
com en imaginària persecució d'un llop.

Com diminuta olímpica plena d'enuig letal,


calladament rodant sobre una pols aurífica,
talment atravessaveu en un landeau, magnífica,
entre la polsaguera d'un mal cami-veinal.

Mes ara, en automòvil de rutilants metalls,


les costes embesteix la vostra perspicàcia.
Sobre el sedós coixí, darrera dels crestalls,
la vostra fas saluda com al Passeig de Gràcia.

Y passegeu el tedi subtil de l'existència,


ab una tremolor d'aristocràtic fret
y cavileu, frenètica de vostre omnipotència,
per traspassar l'obstacle darrer qui s'alsa dret.

Y en vostre esprit revolen mefistofèlics balls.


Hi dansa el nou progecte d'una ample carretera
qui, el bosc esmicolant de la montanya entera,
ab corves impossibles, us porti a Matagalls.
Llavors haurà assolida la vostra ambició
la joia faraònica de domenyar la cima
y, en vostra caretel·la d'avans airosa y prima,
podreu escalâ els núvols per veure l'horitzó.

El vell

Es el padrí renyaire, corcó de la galvana,


qui duu una catracòlica pagesa y ciutadana,
qui ja la barretina per rústica ha deixat
y dels senyors odia, per tradició, l'emprat
capell, y duu una gorra d'un trist color de cendra.
Es el padrí, la soca baumada: mes engendra
indefectiblement cada any un nou rebrot
qui esponerós li puja fins a abrassar-lo tot.
Es el padrí qui té les dobles a la gerra
y sab de la montanya fins l'últim palm de terra.
Es el padrí xaruc quan el mal temps l'abat:
mes quan el deixa en pau, torna entenimentat.
Es y serà rebec mentres no acluqui l'ull,
l'amo qui dirà això jo vull y això no vull.

Mitgdiada eterna

El sol canicular, de tropical crinera


com una serp de foc qui, sibilant, s'enarca
fa trontollâ al compàs que la cigala marca,
l'estèril solc polsós de l'ampla carretera.
A l'ombra insuficient d'esquàlida figuera
s'hi aclofa l'hostal vell ont, embrutit, descansa
el traginer colrat qui cerca delectansa
en la frescor propícia d'anònima hostalera.
Esclaten les panotxes de blat-de-moro al hort.
Pululen les alades ab musical acort.
De flaires de celler s'inonden els afores.
Les jàceres fumades se contorsionen brusques.
Y, dins l'antic rellotge monumental, les busques
fatídiques senyalen eternament dotze-hores.

Vora el sumort vilatge, la carretera dura


en corva rapidíssima soptadament se pert.
La pols, com una cendra de malvestats, el vert
dels plàtans oficials cobreix de floridura.
Sovint passen feixugues carretes grinyolant
ab un pagès darrera qui, catxassut, ostiga
els bous ab un renec. Corvada en sa fatiga,
porta una mossa un feix de llenya, murmurant.
Y quan ha sonat l'hora d'abandonar l'estudi,
inesperada esclata, com infernal preludi,
la cínica gatzara dels mal-criats bailets.
La creu de terme s'obra de rocs caixalejada.
Y el Crist escarbotat, aparta la mirada
d'aquella mena d'homes tan bestials y frets.

Com una boira passa l'enterro del albat.


Les filles de Maria porten la caixa blanca
guarnida ab campanetes cullides al veinat.
El dol, escàs y rígit, el llarc seguici tanca.
Devant, el capellà qui resa dignament.
Après, de les companyes la pàlida corrua.
Dels invisibles ciris la llumaneta nua
retalla com una ombra l'asserenat ambent.
Y encara una boirina de pols darrera el dol.
La creu de la parròquia duu penjarells de sol.
Y guaiten les poncelles obrint-se com un ull
de llàgrimes nocturnes calladament remull.
Saltironant minúscula, tritlleja la campana
soptada pel refrec de l'ànima germana.

Tragedia lluminosa

Sota una mitja volta ont s'hi rebat el sol,


hi ha el saferetx. Y l'aigua s'estén com un llensol
d'ondulacions molt lentes. No més qualques estones
com una pell tremola, sentint d'aquelles dones
qui renten, la caricia del foll pessigolletg.
Y tèrbola s'agita pel càlit saferetx.
Les dones son vermelles de colzes y de cara.
Tenen els ulls plorosos del vi de la gatzara,
mes implacables forguen dins l'aigua y ab enuig;
sembla, talment, que lluiten ab el llensol qui'ls fuig.
L'aigua s'ageu retuda de nou pel saferetx.
Enlleminida guaita, però, el carnal pantetg
dels pits qui sovint salten per sobre dels gipons
com d'opulent resclosa els màgics borbollons.
De sopte un bou s'acosta, atret pel remolí.
Esporuguides fugen les dones. Resta allí
el brau indòmit: guaita la gran escampadissa,
y, ab desconhort magnífic de mascle, gira al cel
els ulls de foc y exhala un perllongat bruel
qui ofega l'argentina, llunyana cridadissa.
Desprès la testa abaixa, s'acosta al rentador
y beu una glopada ab gran delectació
com si de l'aigua tèrbola cerqués en la virtut
la flamarada interna d'aquell botí perdut.

II.

A la masia

Oh masia xacrosa y endolada!


si un dia fores diferent de tu,
per obra de natura transformada
tens la dolcesa de lo qu'es madur.
Ja la negror t'ha esdevingut daurada.
L'eura mitiga de ton caire el nu.
Floreixen les canals y la teulada.
A sota el ràfec l'aureneta hi duu
cavalls-de-serp y cuques argentines.
Comodament terregen les gallines
vora ta llar, profètic esperit
qui traspua de llum per tes esquerdes.
Demunt tes grogues feixes y les verdes
clapes de bosc, com elles t'ets vestit.

Posta arbitraria
Demunt la llar pairal
hi llengoteja el foc
qui ressegueix d'un soc
l'escorsa desigual.
A fora, esclata el xoc
suprem del temporal.
Sona confós el toc
de l'hora capvespral.
Quan les vaixelles tosques
reflexen a les fosques
el llengotetg qui mor,
la cuina llu clapada
com entre la brancada
llunyana posta d'or.

Rebost

Emblanquinat per dins, entrenyinat de fora,


com un convent exhala benèvola frescor.
En un recó la gerra que tapa un tovalló,
un àpat suculent fa somniâ avans d'hora.
Del embigat sospesos, graviten els pernils,
mostrant un d'ells la sana rojor d'una ferida.
Una fragància puja fins arrivâ a l'eixida,
d'un enfilall esplèndit irradiant de fils.
Una renglera innúmera de pans abonyegats
s'allarga vora el sostre. Reposen, admirats,
en un prestatge, els pots d'espessa confitura,
qui alternen ab formatges ullats, alabastrins.
Y, respirant la pols qui a flor de terra sura,
secretament dialòguen dos plàcits ratolins.

Cambra

Es tota emblanquinada com una cel·la y té


una finestra plena d'aufàbregues rodones.
Les aurenetes hi entren com unes papellones.
A un raig de sol fulgura un aigua-beneiter.
El llit pairal ostenta pletòric respatller
qui's dressa en la penombra discreta de l'arcova.
Y d'un armari de paret vessa la roba
una fragància antiga de boles d'aromer.
L'empostissat es net y llis. La calaixera
d'incrustacions d'ivori y d'eban ramejat,
com un altar major de poble reverbera;
guardant la palmatòria del combregar. Penjat
un vell trabuc s'empolsa. Y afinen de grogor
uns tristos goigs de Sant Isidro Llaurador.

Porxo

Es el raser mes dols de tota la masia.


De part de fora vistes, semblen cataus de fosca
les dues grans arcades fetes de pedra tosca.
En la pilastra una eura manyaga s'hi congria.
Esbatanat, contempla la mitgdiada augusta.
En la foscor ressalta, ja grisa, la barana
de castanyê: hi reposa l'immòvil sargantana
com una esberla fina de la meteixa fusta.
Les aurenetes volen entorn del embigat
ont tenen, de petites curull, el niu penjat.
Del ràfec qui, al devant, aeri's precipita,
despleguen les aranyes un prodigiós filat.
Y en un recó bucòlic, de testos enquadrat,
les mans sobre el gaiato, l'avi cap-blanc dormita.

Els pallers

Com una professó de genis tutelars


sobrixen, corpulents, de la pairal teulada
qui vora d'ells s'aplana humil y consagrada
per la fumera dels calius familiars.

Jugant a fet s'hi encalsa l'innúmera mainada.


N'arrenca un brí llarguíssim un indolent pastor
y rosegant-lo hi troba recòndita dolsor.
Per entre el boll dispersa, terreja la llocada.

Y son ventruts y guarden mitja cullita anyal.


Y una fragància deixen de palla, massa intensa.
Quan el mal temps arriva o quan l'hivern comensa,

fulguren més aurifics al mitg del temporal.


Y'l masovê'ls acata com un esclau sumís
car son per ell les torres dels murs del paradís.

A la parella de les vaques

Oh parella pacífica, feinera!


la vostra testa s'ofereix al jou
qui recull la penjanta barballera.
La vostra qua displicent se mou.
El vostre front triangular es dur.
Brilla l'espai, de vostres ulls endins.
Vostres badius son molt oberts y fins.
En vostres banyes una corda lluu.
El vostre llom acarenat s'adressa.
De tant llaurar, desconeixeu la pressa.
Vostres mamelles un encuny de mà
serven, ja buides. Vostra pell es neta
y gastada pel tronc de la carreta.
Sou lentes y constants en trevallar.

Al fidelíssim ca

Oh fidelíssim ca
qui pagues les marfugues
del amo! cinc verrugues
t'enjoien. Al lladrar,
lladres tant fort y clar
y ab tanta bonhomia,
que'l teu lladruc desnia
un sentiment humà.
Soportes la mainada,
respectes la llocada,
dormites vora el foc,
convius ab tos col·legues,
els plats de cuina fregues
y no fas nosa enlloc.
El reial paó

Bell paó
radiant!
ets l'encant
del pastor.
Mostra, aurífic,
ton ventall,
geroglífic
devassall.
Per ta rara
petulància,
tens encara
l'elegància
que no sent
nostra gent.

L'horta

Ab la bellesa d'una mare forta


qui somrient alleta sa fillada,
ubèrrima, senzilla, dilatada,
sota el camí veinal reposa l'horta.
De presseguers dolcíssims clapejada,
exhala una frescor qui reconforta
y de sos camps la gradació variada
omplena el marc de la caiguda porta.
Els corriols l'esgaien fonedissos,
els reguerols, simètrics, l'atravessen,
les verdures hi ostenten un vert sà,
els margens ben cuidats formen pedrissos,
d'ocultes deus els regalims hi vessen
y s'hi rabeja un aire casolà.

El veinat
I.

Oh les petites cases del minuciós veinat


quiscuna ab un paller y un forn y la cisterna
ab una corriola y un canti abonyegat
y l'era qui de boll aurífic enlluerna!
Un corriol ondula per assolir-vos totes.
Els vostres cans el pas senyalen de la gent.
Teniu panotxes y rodells sobrers de botes.
Y l'aviram pastura desvergonyidament.
Les vostres feixes son minúscules, secanes.
Demunt dels enllosats hi dormen sargantanes.
Us enjoieu alhora de malves y llorer,
de romaní, de sàlvia y d'herba caixalera.
Y alguna de vosaltres es sota la noguera
com una aucella tímida qui fuig del esparver.

II.

Mes quan l'hivern impera, sou totes arraulides.


Els vostres cans no saben lladrar sino ab udols.
Quan es de nit dialoguen xibeques y mussols.
Filagarsades pengen les parres consumides.
Escaina per etzar la prematura lloca.
L'antic aroma d'herbes tè flaira d'estantís.
Es groc de les juntures l'humitejat pedrís.
D'un xiprer vert no mes l'ombra fatal us toca.
Quan d'una aubada freda l'intemperansa lluu,
us enrogiu de fret lleugerament galanes.
De vostres cuines ixen flairades casolanes.
De la finestra oberta ne penja un forc madur
qui branda ab les secretes cantúries de Nadal
y ab la forana audàcia del tràngol hivernal.
Pastorals
El pastor

El pastor vell sordeja del torb qui, udolador,


regolfa en les cingleres y pels cimals s'aplana.
Ab un encorvament de xacres y galvana
devalla pels dissaptes a provehî'l sarró.
El seu remat pastura tot sol per la carena,
y ell porta en la mirada la perennal visió.
Com un selvatge tímit s'amaga en un recó.
Y, endormiscant-se, aclama la vaca de llet plena.
Enfonsa la mà seca per l'àrit costellam
del gos d'atura. Parla no mes qu'ab la mainada
qui del sarró li pren, en rotllo vora el flam,
el floviol de boix, la fona ben trenada.
Y l'endemà, diumenge, se'n torna a la montanya
ab el sarró feixuc y una alegria estranya.

Entorn del òbit

Entorn del òbit de pollada alzina


trampelejant grinyolen els garrins
d'una rosada tremolô infantina,
blans y minúsculs com petits coixins.
Obstinats forguen, sens motiu, endins
l'humida terra qui els unglots els taca.
Llur borrissol té caires argentins.
Y quan els veu la corpulenta vaca,
maravellada, l'ample testa inclina,
y ells, aterrats, galopen bosc enllà.
La porcairola invàlida els domina
tractant-los com una ignocent joguina,
y mira els lloms flexibles llustrejar
sota l'escata de la pell albina.

A'l bany

Vora el bassal assoleiat


l'ànega passa atrafegada,
potes y bec d'un to daurat,
nèta com roba de bugada.
Gronxa feixuga, estarrufada,
sobre el tupit encatifat,
pomposament endiumenjada
ab son abric tornassolat.
Y les minúcies de sa prole,
sardanejant entorn la mole,
àvides forguen dins el llot.
Y, al invadir l'estany d'argent,
se deixen dur per la corrent
com unes bolves d'escardot.

Visió tardoral
En un decliu suavíssim, la prada, encara verda,
l'exuberància mostra de suculent pastura.
Les vaques s'hi rabegen ab l'herba a la cintura,
fregant ab les mamelles l'exuberància gerda.
Una pomera ostenta la soca ab una esquerda
del llamp, y dues branques socarrimades, mortes.
Mes son de tantes pomes les altres tres colltortes,
que besen ab les fulles els trèbols y l'userda.
Els penjarells qui branden, acurullats de pomes,
entre el fullatge brillen com ponentines bromes.
La copa's balandreja com femení ventall.
Y algunes pomes cauen com un aucell morent
qui, rodolant per l'herba, s'obra cami, talment.
Y tomben dins de l'aigua, perdent-se rec avall.

La càndida badella

Oh càndida badella!
com un segell sagrat
de ta nobilitat,
al front dus una estrella.
Ta vista s'esparpella
ab diafanitat.
Tremoles de novella
y saltes de bondat.
Y tens el morro encara
de llet materna moll,
que ja una dona rara
te penja arràn de coll
una feixuga esquella
¡oh càndida badella!

Quaresma

Pregona la naixenta primavera


un gradual allargament del dia.
Del més intim recó de l'establia
tèbia s'enlaira una remor lleugera.
El fret agònic enutjat impera
trucant a les parets de la masia.
Al voltant de la llar, tota alegria,
somriu la joia en la mirada austera.
Penja d'un mur la vella de quaresma.
El jaio, qui'l rosari mena d'esma,
s'endormisca sovint. Una vegada
se redressa no més, y, ab veu cansada,
comensa el Pare-Nostre a Sant Martí
per que les cabres puguen ben bocquir.

El pla de la Calma

L'àrida calma ondula com un immens desert.


El sol, a frec de terra, com borralló s'hi pert.
El cel fulgura plàcit: s'estén per l'infinit
com nítida llacuna de cignes blancs. La nit
assotja avidament darrera les Agudes.
La lluna plena surt d'afraus inconegudes
y gesticula immòvil, sanguinolenta d'ira.
D'uns carboners apunta, cingles avall, la pira.
En la monotonia dels rasos hi pasturen
les solitàries vaques: de tant en tant s'aturen
y exhalen un bruel de cara a l'establia
llunyana. D'una boira minúscula's desnia
la tremolor. De cabres, ovelles y crestats
alhora s'acorruen per entre els espadats
pacífiques remades. La polsaguera immonda
ab sa farum de llana la comarcada inonda.
Y, en mitg del remolí, brassegen els pastors,
y xiulen de les fones els rocs udoladors
qui a voltes cama-trenquen o escapsen qualque banya
ja consentida. Aborden ab alegria estranya
de subaltern els cans d'atura mal-carats.
Mes per demunt l'insòlita negror dels espadats
y de la vasta calma de serenor divina,
la Creu de Matagalls perdura gegantina.
Y les remades salten, rostos avall, de dret.
De Coll-Pregón arriven soptadament al net.
El sol ja s'ha perdut. La llum s'ha fos. La lluna
s'ha tota esblanquehit y perfilat com una
donzella a qui l'edat torna gentil, prudent.
Y la corona tot l'estol del firmament.
Ja envolten el corral de sinuós teulat.
Ja'l remat es a dins. La porta s'ha tencat
y pel llindar balder traspua el color groc
que escampen els tions des de la llar de foc.

Cinegètiques
Contemplant el cider
Oh placidesa de romandre
en la barraca, ab l'escopeta
disposta sempre en la mà dreta,
y en l'altra mà, caient de mandra
qualque volum d'André Chenier!
Sempre a l'aguait, quatre o cinch hores,
la vista erranta per les vores
y per les branques del cider,
l'aurella atenta a la cridòria
dels gaigs! La flauta d'una merla,
de tan propera, fa estremir.
Un espetec canta victòria…
Tomba una griba qui s'esberla
de caure, ubèrrima, al camí.

Guatlla captiva

Canta la guatlla blat-segat


per entre el ségal. Y peona
balandrejant-se. No s'adona
de que al demunt hi té'l filat
com un subtil entrenyinat
qui refregant per les espigues
fa temoregues les formigues.
Sona un botet precipitat.
De sopte una ombra li sorgeig
manotejant amenassanta.
Arrenca el vol y, ja captiva,
sent qu'una grapa l'oprimeix…
Una altra guatlla encara canta
y una altra vola fugitiva.

Fallida

En un mitgdia gris de tòrrida bavor,


per entre el blat-de-moro d'envidriades fulles,
ab una gran pallola comprada a un segador,
ab les ulleres fosques y ornat ab les despulles
d'una sotana esquàlida, passa el Sr. Rector,
vers els rostolls qui marquen la ratlla dels amprius.
Ja dins l'amagatall, aclama les perdius
ab les polifonies d'un escotxinador.
Ja un perdigot respòn, de zel adalerat.
D'una volada 's llensa al mitj del blat segat
y, al cim d'un còdol, guaita escotxinant rebent.
El bon Rector somriu de goig infantilment
y quan repara qu'es propicia l'ocasió,
el perdigot ja vola vers un parany millor.

Els serradors

Les rabassudes aixes, l'escardalenca serra


y les destrals de mànec d'alzina esbelt y llís
en escampall de fi de festa son per terra.
Y sura un grat perfum de llenya voladís.
Y l'herba de la prada grogueja del aixut
clapada arreu ab cercles d'una foguera estinta.
Del xarracar monòton afina l'atrahut.
Entre les vores passa el riu com una cinta.
Els serradors aixequen rectangulars pilons
de llates y quadrats, de posts y de taulons.
La gràcia de les corves qui omplien la boscúria,
les saves ab l'empenta del vi d'una centúria,
tot dorm en els anònims pilons acurullats,
de geomètrics caires y sostres alternats.

El molí

I.

Tot el molí trontolla del aigua qui, brunzenta,


fa rodolâ'l ciclopi rodet de cor d'alzina.
Pel carcabar xocant ab esplosió argentina,
s'escorra per les negres llambordes opulenta.
Y roda al seu impuls l'oculta ferramenta
ab infernal estrèpit. La filoseta dansa.
Brunz el feixuc volant qui, ben collat, descansa
en l'arbre incommovible qui tot l'impuls regenta.
De la sotana immòvil broten esquitxs de foc.
El molinê, ab ulleres, d'una altra mola pica
els reguerols simètrics, més obstinat que'l roc.
Al marc d'un finestrò un vidre fès repica.
Y en un prestatge salten, ab folla tremolor,
sis plats, una sopera, dos cantis y'l porró.

II.
Y'l moliner, deixant la tasca pacienta,
aboca altra quartera de blat a la tramuja,
de blat lluent y fresc com un varal de pluja
qui's fon al xuclador del canalot. Rebenta,
la mola se'l ne du y, ab una giravolta,
l'escampa sota seu, frenètica el tritura
y raja el blat d'avans, tornat farina pura,
entre el xerricament d'una eternal absolta.
El moliner linfàtic, per escalfar la sang,
enfonsa arràn d'aixella el bras a la farina
y'n treu una grapada y escampa la polsina
y, emblanquinat, sorgeix com un atleta. Blanc
té'l borrissol dels brassos, les celles y la testa…
Per tot sembla que hi hagi passat una congesta.

III.

Y semblen les trenyines subtils carmells de glas.


Tots els relleus son blancs. Nevades son les tanques.
Els sacs traspuen pols. Y les parets son blanques
demunt la sutzetat del fum qu'hei ha romàs.
La molinera té nevat el prim del nas.
Y duu'ls cabells albins com una cortesana.
Y té una flor de neu en cada galta blana.
Y aixeca boires pàlides ab l'aire de son pas.
La resignada cara, de perfecció, palpita.
Ressalta l'azebetge dels concirosos ulls
qui del espai anyoren la compassió infinita
y d'una vaga pena d'amor semblen remulls.
Y en les convexitats del ventre maternal
fulgura la nevada polsina d'un cimal.

IV.

A fora hi ha la calma, la clara transparència


ont floten els murmuris y les boirines d'or.
Dins un bassal s'esplaia, marmòria, l'opulència
dels ànecs y les oques ab monorrítmic chor.
Les sommogudes gleves qui envolten l'ampla soca
qui dels pigots fou víctima y ara ageguda cruix,
pletòrica esgarrapa la previsora lloca.
Quan troba la becada color de rosa, cluix,
y en boira escampadissa hi acuden els petits
qui trampelegen, àvits de pellucar quelcom.
Al seu entorn pululen marietes y mosquits,
cavalls-de-serp vinguts d'un amagat tocom.
Y aflotonats cimbregen, ab corpulències balbes,
els rengles de pollancres, els freixes y les albes.

Els carboners

Els carboners son negres com infernals titans


y en la negror dels rostres fulgura el blanc dels ulls
y una filera indòmita de dents com uns esculls.
Son mal-carats y guaiten la gent com uns infants.
En rotllo vora el plàcit remor de la foguera,
conversen del ofici tant profitós avans,
y mentres fan deu-hores calents de peus y mans,
ompla el bailet dos cantis ab aigua de riera.
Al arrivar la nit, se'n van a la barraca
y, aflotonats demunt el jas de la fullaca,
furtivament contemplen el poble llunyedà,
y quiscún d'ells hi troba sa dèbil llumaneta.
Y pensen en la dona qui'ls té la roba neta
y'ls hi ofereix les dolses primícies del quintar.
Poema
Ed ecco un lustro subito trascorse da tutte parti per la gran foresta.

Dante.

Preludi

(Parla el poeta:)
Mirant el bosc ab persistència
m'esdevé'l temps eternitat
y se'm transforma l'existència
en un llarc somni improvisat.
Y tot jo quedo obsessionat:
el bosc se'm torna pròpia essència
y de mon jo la conciència
se fon dins l'ampla immensitat.
Y veig els arbres per dins meu,
y les arrels veig dins la terra,
veig les entranyes de la serra,
veig els cimals sota la neu.
Y al fons de tot m'hi veig a mi
guaitant dins meu el bosc lluhir.

Génessi

You might also like