Robotics at Home with Raspberry Pi Pico: Build autonomous robots with the versatile low-cost Raspberry Pi Pico controller and Python
By Danny Staple
()
About this ebook
The field of robotics is expanding, and this is the perfect time to learn how to create robots at home for different purposes. This book will help you take your first steps in planning, building, and programming a robot with Raspberry Pi Pico, an impressive controller bursting with I/O capabilities. After a quick tour of Pico, you’ll begin designing a robot chassis in 3D CAD. With easy-to-follow instructions, shopping lists, and plans, you’ll start building the robot. Further, you’ll add simple sensors and outputs to extend the robot, reinforce your design skills, and build your knowledge in programming with CircuitPython. You’ll also learn about interactions with electronics, standard robotics algorithms, and the discipline and process for building robots. Moving forward, you’ll learn how to add more complicated sensors and robotic behaviors, with increasing complexity levels, giving you hands-on experience. You’ll learn about Raspberry Pi Pico’s excellent features, such as PIO, adding capabilities such as avoiding walls, detecting movement, and compass headings. You’ll combine these with Bluetooth BLE for seeing sensor data and remotely controlling your robot with a smartphone. Finally, you’ll program the robot to find its location in an arena.
By the end of this book, you’ll have built a robot at home, and be well equipped to build more with different levels of complexity.
Read more from Danny Staple
Learn Robotics Programming: Build and control AI-enabled autonomous robots using the Raspberry Pi and Python Rating: 0 out of 5 stars0 ratingsLearn Robotics Programming: Build and control autonomous robots using Raspberry Pi 3 and Python Rating: 0 out of 5 stars0 ratings
Related to Robotics at Home with Raspberry Pi Pico
Related ebooks
The Official Raspberry Pi Projects Book Volume 5: 200 Pages of Ideas Rating: 0 out of 5 stars0 ratingsThe Official Raspberry Pi Handbook 2023: Astounding projects with Raspberry Pi computers Rating: 0 out of 5 stars0 ratingsRaspberry Pi 2 Server Essentials Rating: 0 out of 5 stars0 ratingsRaspberry Pi Robotic Projects - Third Edition Rating: 0 out of 5 stars0 ratingsRaspberry Pi Home Automation with Arduino - Second Edition Rating: 0 out of 5 stars0 ratingsRaspberry Pi 3 Model B for Beginners: Explore What Raspberry Pi 3 Model B Can Do Rating: 0 out of 5 stars0 ratingsMastering BeagleBone Robotics Rating: 5 out of 5 stars5/5Raspberry Pi 3 Project: Raspberry Pi 3 for Beginners Rating: 0 out of 5 stars0 ratingsProgramming the BeagleBone Black: Getting Started with JavaScript and BoneScript Rating: 0 out of 5 stars0 ratingsLearning Raspbian Rating: 5 out of 5 stars5/5Raspberry Pi: Amazing Projects from Scratch Rating: 0 out of 5 stars0 ratingsBeagleBone Home Automation Blueprints Rating: 0 out of 5 stars0 ratingsBeginning Robotics with Raspberry Pi and Arduino: Using Python and OpenCV Rating: 0 out of 5 stars0 ratingsRaspberry Pi Server Essentials Rating: 0 out of 5 stars0 ratingsProgramming Raspberry Pi in 30 Days: Learn how to build amazing Raspberry Pi projects using Python with ease (English Edition) Rating: 0 out of 5 stars0 ratingsRaspberry Pi IoT Projects: Prototyping Experiments for Makers Rating: 0 out of 5 stars0 ratingsLearning JavaScript Robotics Rating: 3 out of 5 stars3/5BeagleBone By Example Rating: 0 out of 5 stars0 ratingsLearning C for Arduino Rating: 0 out of 5 stars0 ratingsBeagleBone For Dummies Rating: 0 out of 5 stars0 ratingsRaspberry Pi Essentials Rating: 0 out of 5 stars0 ratingsRaspberry Pi :Raspberry Pi Guide On Python & Projects Programming In Easy Steps Rating: 3 out of 5 stars3/5Raspberry Pi: The complete guide to raspberry pi, including raspberry pi projects, tips, troubleshooting, and more! Rating: 0 out of 5 stars0 ratingsRaspberry Pi LED Blueprints Rating: 0 out of 5 stars0 ratingsInternet of Things with Arduino Blueprints Rating: 0 out of 5 stars0 ratingsRaspberry Pi Robotic Blueprints Rating: 2 out of 5 stars2/5Smart Internet of Things Projects Rating: 4 out of 5 stars4/5Raspberry Pi Mechatronics Projects HOTSHOT Rating: 5 out of 5 stars5/5
Hardware For You
Apple Watch For Dummies Rating: 0 out of 5 stars0 ratingsElectrical Engineering | Step by Step Rating: 0 out of 5 stars0 ratingsmacOS Sonoma For Dummies Rating: 0 out of 5 stars0 ratingsCompTIA A+ Complete Review Guide: Core 1 Exam 220-1101 and Core 2 Exam 220-1102 Rating: 5 out of 5 stars5/5CompTIA A+ Complete Review Guide: Exam Core 1 220-1001 and Exam Core 2 220-1002 Rating: 5 out of 5 stars5/5Chip War: The Fight for the World's Most Critical Technology Rating: 4 out of 5 stars4/5Raspberry Pi Electronics Projects for the Evil Genius Rating: 3 out of 5 stars3/5Chromebook For Dummies Rating: 5 out of 5 stars5/5Exploring Apple iPad: iPadOS 15 Edition: The Illustrated, Practical Guide to Using your iPad Rating: 0 out of 5 stars0 ratingsAfter Steve: How Apple Became a Trillion-Dollar Company and Lost Its Soul Rating: 4 out of 5 stars4/5Exploring Arduino: Tools and Techniques for Engineering Wizardry Rating: 4 out of 5 stars4/5iPhone For Dummies Rating: 0 out of 5 stars0 ratingsiPhone 16 Pro Max User Manual: The Complete Step-By-Step Guide to Maximize your New iPhone 16 Pro Max and iOS 18 Rating: 0 out of 5 stars0 ratingsAmazon Web Services (AWS) Interview Questions and Answers Rating: 5 out of 5 stars5/5Build Your Own PC Do-It-Yourself For Dummies Rating: 4 out of 5 stars4/5Programming Arduino: Getting Started with Sketches Rating: 4 out of 5 stars4/5Upgrading and Fixing Computers Do-it-Yourself For Dummies Rating: 4 out of 5 stars4/5iPhone 15 Pro Max User Guide for Beginners and Seniors Rating: 0 out of 5 stars0 ratingsTeach Yourself VISUALLY MacBook Pro and MacBook Air Rating: 4 out of 5 stars4/5How To Repair Your iPad - Quickly and Professionally!: Fix It Yourself, #5 Rating: 0 out of 5 stars0 ratingsBuilding Confidence Using Your iPhone: Book I — THE ULTIMATE GUIDE Rating: 0 out of 5 stars0 ratingsLaptops For Dummies Rating: 5 out of 5 stars5/5Arduino Electronics Blueprints Rating: 4 out of 5 stars4/5Arduino Essentials Rating: 5 out of 5 stars5/5CompTIA A+ Complete Study Guide: Core 1 Exam 220-1101 and Core 2 Exam 220-1102 Rating: 0 out of 5 stars0 ratingsmacOS Black Book: Mastering Shortcut Keys Rating: 0 out of 5 stars0 ratings
Reviews for Robotics at Home with Raspberry Pi Pico
0 ratings0 reviews
Book preview
Robotics at Home with Raspberry Pi Pico - Danny Staple
BIRMINGHAM—MUMBAI
Robotics at Home with Raspberry Pi Pico
Copyright © 2023 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.
Group Product Manager: Rahul Nair
Publishing Product Manager: Rahul Nair
Content Development Editor: Sujata Tripathi
Technical Editor: Rajat Sharma
Copy Editor: Safis Editing
Project Coordinator: Sean Lobo
Proofreader: Safis Editing
Indexer: Pratik Shirodkar
Production Designer: Nilesh Mohite
Senior Marketing Coordinator: Nimisha Dua
Marketing Coordinator: Gaurav Christian
First published: March 2023
Production reference: 1170223
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
ISBN 978-1-80324-607-9
www.packtpub.com
To my amazing wife, Carol, who has supported all my robotics experiments with love, inspiration, and tolerance of a living room filled with robots. To my children, Helena and Jonathan, for all their ideas and enthusiasm and for encouraging me to take a break and play with them sometimes!
– Danny Staple
Contributors
About the author
Danny Staple is a robot builder and programmer. He has been a professional software engineer since 2000, uses Python professionally, and regularly contributes to open source projects.
Danny has been building robots at home since 2004 and has a cupboard full of projects, including robots with wheels, cameras, tank tracks, legs, and arms, made from plastic, cardboard, metal, kits, lunchboxes, and modified toys.
Danny authored Learn Robotics Programming, published in 2021 by Packt Publishing, and has written magazine articles for The MagPi. He runs the robotics YouTube channel Orionrobots and brings his robots to events such as Pi Wars and Arduino Day. Danny also mentors at CoderDojo KU, where he shows kids how to program in Python and has run Lego robotics clubs.
I would like to thank the Pi Wars and Adafruit communities for answering my tricky questions, Mike Moncrieffe for checking diagrams for me, and my review team for the great feedback throughout this book.
About the reviewer
Leo White is a professional software engineer and a graduate of the University of Kent. His interests include electronics, 3D printing, and robotics. He first started programming on the Commodore 64 and later wrote several applications for the Acorn Archimedes. He currently programs set-top boxes for his day job. Utilizing the Raspberry Pi as a foundation, he has mechanized children’s toys and driven robot arms, blogging about his experiences and processes along the way. He has given presentations at Raspberry Jams and entered a variety of robots in the Pi Wars competition.
Table of Contents
Preface
Part 1: The Basics – Preparing for Robotics with Raspberry Pi Pico
1
Planning a Robot with Raspberry Pi Pico
Technical requirements
What is Raspberry Pi Pico, and why is it suitable for robotics?
A microcontroller that runs Python
Raspberry Pi Pico’s interfaces for sensors and devices
What is CircuitPython?
Planning a Raspberry Pi Pico robot
An overview of robot planning
A note on trade-offs
Choosing a robot chassis
Choosing the power systems
Pin usage
Test fitting a Raspberry Pi Pico robot
Creating your first test-fit part
Motors
Power systems
Creating a rough chassis
Arranging the test-fit parts
A recommended shopping list for robot basics
Robot parts and where to find them
The robot workshop and makerspaces
Summary
Exercises
Further reading
2
Preparing Raspberry Pi Pico
Technical requirements
Getting CircuitPython onto Raspberry Pi Pico
Preparing the CircuitPython library for Pico
Coding on Pico – first steps
Downloading the Mu editor
Lighting the Pico LED with CircuitPython
Blinking the LED with code
Soldering headers to Raspberry Pi Pico
Summary
Exercises
Further reading
3
Designing a Robot Chassis in FreeCAD
Technical requirements
Introducing FreeCAD
The FreeCAD screen
Selecting workbenches
FreeCAD settings
Making robot chassis sketches in FreeCAD
Preparing the document
Sketching the chassis outline
Creating the upper parts main sketch
Sketching the motor holes
Designing the caster placement
Modeling chassis parts from sketches
Modeling the chassis plate
Modeling the other parts
Troubleshooting the model
Modeling the caster in 3D
Making FreeCAD technical drawings
Setting up the page
Adding parts to the drawing
Preparing the drawing for print
Summary
Exercises
Further reading
4
Building a Robot around Pico
Technical requirements
Cutting styrene parts
Transferring CAD measurements to a plastic sheet
Cutting the plastic sheet
Finishing and sanding the chassis plate
Assembling a robot chassis
Attaching the caster and battery box
Attaching the motors and wheels
Wiring a Raspberry Pi Pico robot
Wiring Pico and the motor controller into the breadboard
Adding the batteries
Wiring in the motors and encoders
Powering the robot up
Summary
Exercises
Further reading
5
Driving Motors with Raspberry Pi Pico
Technical requirements
Driving forward and back
Testing each motor with CircuitPython
Driving wheels in a straight line
Steering with two motors
An introduction to pulse width modulation speed control
Driving fast and slow
Turning while moving
Driving along a planned path
Putting line and turn moves together
The flaw with driving this way
Summary
Exercises
Further reading
Part 2: Interfacing Raspberry Pi Pico with Simple Sensors and Outputs
6
Measuring Movement with Encoders on Raspberry Pi Pico
Technical requirements
About encoders and odometry
Absolute and relative sensing
Types of encoders
Encoder pulse data
Wiring in encoders on a Raspberry Pi Pico robot
Examining the motors
Examining the wiring
Programming Raspberry Pi Pico PIO
Introduction to PIO programming
Introducing PIOASM
Detecting input with PIO
PIO instructions and registers
Making a counter with PIO
Measuring encoder count for movement
Making a simple PIO change detection loop
Making a bidirectional counter with PIO
Making reusable encoder code
Measure counts for a known time
Summary
Exercises
Further reading
7
Planning and Shopping for More Devices
Technical requirements
Introducing sensors
Analog sensor types
Timed pulses
Data bus sensors
The robot block diagram
Choosing device types
Distance sensors
Inertial measurement unit
Bluetooth devices
Device pin usage summary
Planning what to add and where
Bluetooth and IMU mounting plan
Distance sensor mounting plan
Shopping list – parts and where to find them
Preparing the robot
Designing the shelf
Cutting the shelf
Designing the front sensor brackets
Cutting the sensor brackets
Preparing the chassis plate
Assembling the robot
Summary
Exercises
Further reading
8
Sensing Distances to Detect Objects with Pico
Technical requirements
How distance sensing works
Soldering headers and attaching them to the robot
Soldering headers
Mounting the sensors
Introduction to I2C communication
Communicating with a single distance sensor
Wiring the distance sensors
VL53LX theory of operation
Reading a single distance sensor in CircuitPython
Troubleshooting
Connecting two distance sensors
Troubleshooting
Building a wall avoider with Raspberry Pi Pico
Preparing the robot library
Wall-avoiding theory of operation
Distance sensor wall avoider code
Troubleshooting
Summary
Exercises
Additional reading
9
Teleoperating a Raspberry Pi Pico Robot with Bluetooth LE
Technical requirements
Wireless robot connection options
Connecting Bluetooth LE to Raspberry Pi Pico
Attaching the Bluetooth module to the robot
Wiring the Bluetooth breakout to Raspberry Pi Pico
Connecting to the Bluefruit LE device with UART
Connecting a smartphone
Troubleshooting the Bluefruit module
Getting sensor data over Bluetooth LE on Raspberry Pi Pico
Graphing the data
Controlling the robot with Bluetooth LE
Printing what we got
Button control mode
Decoding button control packets to drive the robot
Troubleshooting
Summary
Exercises
Further reading
Part 3: Adding More Robotic Behaviors to Raspberry Pi Pico
10
Using the PID Algorithm to Follow Walls
Technical requirements
Introducing the PID algorithm
Control and feedback
Bang-bang control
Distance sensing with proportional control
Troubleshooting
Using the integral to handle small distances
Dealing with oscillations using the derivative
Using PID to follow a wall
Changing the sensor’s placement
Wall-following code
Troubleshooting
PID tuning – using graphs to tune the PID
Controlling motor speed
The proportional component
Adjusting the derivative gain
Tuning the integral
Closing notes on tuning
Summary
Exercises
Further reading
11
Controlling Motion with Encoders on Raspberry Pi Pico
Technical requirements
Converting an encoder count into a speed
Loose bolts and nuts
Robot wheel geometry
Encoder geometry
Measuring the speed of each wheel
Fixing the encoder glitches
Using PID to maintain speed and a straight line
The speed control system
Speed control code
Speed controller PID tuning
Driving a known distance
Theory of operation
Code to control distance and speed
Summary
Exercises
Further reading
12
Detecting Orientation with an IMU on Raspberry Pi Pico
Technical requirements
What is an IMU and how to choose one
Components of an IMU
Choosing an IMU module
Connecting the IMU to the robot
Preparing the BNO055
Attaching the BNO055
Wiring the BNO055 to Raspberry Pi Pico
Setting up the software and connecting
Troubleshooting
Calibrating and getting readings
Calibration code
The calibration process
Always face North behavior
CircuitPython code for the face North behavior
Troubleshooting
Making a known turn behavior
Summary
Exercises
Further reading
13
Determining Position Using Monte Carlo Localization
Technical requirements
Creating a training area for our robot
What we will make
How we will make the arena
Tips for cutting
Modeling the space
Representing the arena and robot position as numbers
Serving the arena from the robot
The Bleak library
Creating a Bluetooth LE wrapper library
Showing the robot’s data on the computer screen
Using sensors to track relative pose
Setting up poses
Displaying poses
Moving with collision avoidance
Moving poses with the encoders
Pose movement probabilities
Monte Carlo localization
Generating pose weights from a position
Resampling the poses
Incorporating distance sensors
Tuning and improving the Monte Carlo model
Summary
Exercises
Further reading
14
Continuing Your Journey – Your Next Robot
Technical requirements
A summary of what you have learned in this book
Basic robotics with Raspberry Pi Pico
Extending a Raspberry Pi Pico robot with sensors
Writing CircuitPython behavior code for Raspberry Pi Pico
Planning to extend this robot
Sensors you could add
Interacting with the robot
Chassis and form enhancements
Electronics enhancements
Outputs you could add
Extending the code and behaviors
Planning your next robot
Form, shape, and chassis
Electronics and sensors
Code and behavior
Further suggested areas to learn about
Electronics
Design and manufacturing
Robotic competitions and communities
Robotics systems and code
Summary
Exercises
Further reading
Index
Other Books You May Enjoy
Preface
Robotics is an emerging field with applications in every walk of life. Robotics, and the associated technology, appear to be confined to the well-equipped laboratories of universities and high-tech companies. However, many of the aspects of robotics – building them and programming them – can be learned and practiced in your own home.
The main areas of robotics are as follows:
Structure – the design and building of a mechanical platform
Electronics – sensors, motors, and control circuits
Software – the code for libraries, sensor interactions, and behaviors
This book aims to cover a little of each area, looking at basic CAD design, part fabrication, and assembly of hardware. It introduces some starting digital electronics, such as connections and data buses. It aims to dig a little deeper into the sensors and the code needed to make interesting behaviors using them.
There are robotics books that offer a theoretical robotics introduction; however, the aim of this book is to take you on a journey of practice, fun, and experimentation. This book provides step-by-step applied explanations and images to aid understanding.
Building your own robots in your home is a great way to learn technology skills. This is an experience of technology that replaces impenetrable magic with real-world experience and confidence to build more – anyone with practice can become a robotics wizard too.
Who this book is for
The book is intended for those who would like a practical and step-by-step hands-on introduction to designing, building, and programming robots, using the popular Python programming language. It is also for those who would like to gain an introduction to 3D CAD, robotics sensors, robotics hardware, and robotics behaviors that make use of the sensors and hardware.
This book will be valuable to makers, learners, and developers who want to build robots in their homes or workshops. The book does not require a specialist workshop, and any skills and tools needed will be explained throughout the book.
Those who have written a little code before will find this book useful. You do not need to have any experience with electronics or making things, but you can expect to gain initial experiences while practicing the techniques in this book.
We expect you to have a keen interest in learning more and a little fearlessness in trying robotics experiments. Practical application of the examples within is essential. Getting the most out of this book means being willing to make a real robot and test it.
What this book covers
Chapter 1, Planning a Robot with Raspberry Pi Pico, introduces Raspberry Pi Pico in relation to other robotics main controllers. It shows the advantages of the CircuitPython programming environment and takes you through making an overview plan for a robot build built around Pico. The chapter provides a robot hardware shopping list for the first half of the book, discussing the parts and trade-offs in choosing them.
Chapter 2, Preparing Raspberry Pi Pico, takes you through getting CircuitPython onto Pico, then taking your first steps in writing code with it. It will also cover soldering headers onto Raspberry Pi Pico so it can connect to robot parts.
Chapter 3, Designing a Robot Chassis in FreeCAD, introduces FreeCAD while turning the overview plan into 3D CAD designs. It shows you how to make drawings from the design for building the robot parts.
Chapter 4, Building a Robot around Pico, shows how you can use CAD drawings with hand tools to craft robot parts by cutting and drilling sheet plastic. It guides you in assembling the parts then wiring and connecting the electronics. This chapter is where the robot is first powered on!
Chapter 5, Driving Motors with Raspberry Pi Pico, introduces you to controlling motors with CircuitPython and Raspberry Pi Pico, showing how motors can be used to make line motions and turns and how speed can be controlled. The chapter then shows you how to pull these together into programmed motion sequences.
Chapter 6, Measuring Movement with Encoders on Raspberry Pi Pico, introduces the first robotic sensor in the book with wheel encoders, showing you how to detect wheel movement in code. The chapter covers the Raspberry Pi Pico PIO peripheral as a powerful way to manage these sensors.
Chapter 7, Planning and Shopping for More Devices, prepares you for the next section of the book with distance sensors, Bluetooth LE, and an inertial measurement unit (IMU), with further advice on choosing the devices and how they will be attached. The chapter provides a shopping list for the latter part of the book. You will revisit FreeCAD part design to make sensor mounts, and then use tools to cut them.
Chapter 8, Sensing Distances to Detect Objects with Pico, takes you through attaching and wiring two distance sensors into the robot. The chapter provides information on I2C communication and then shows you how to program the robot to communicate with the sensors. You will then build code for the robot to autonomously avoid walls.
Chapter 9, Teleoperating Raspberry Pi Pico Robot with Bluetooth LE, makes a comparison of wireless connection options, showing why Bluetooth LE was a suitable design choice. You will connect a Bluetooth LE module to the robot, then extend existing code to output sensor data through this connection, and display the output on a smartphone. You will also see how to drive the robot from a smartphone.
Chapter 10, Using the PID Algorithm to Follow Walls, provides an introduction to the PID algorithm, a fundamental building block for sensor/output control behaviors in robotics. We build a wall-following demonstration using a distance sensor, then show you how to tune the PID with smartphone plots via Bluetooth LE.
Chapter 11, Controlling Motion with Encoders on Raspberry Pi Pico, revisits encoders, showing you how to convert their output into units understandable by humans. You will learn how to combine these sensors with the PID algorithm to control motor speeds and drive in a straight line. You will then program the robot to drive a specified distance in a straight line at a specified speed.
Chapter 12, Detecting Orientation with an IMU on Raspberry Pi Pico, introduces the IMU, a sensor that lets you determine the orientation of the robot. The chapter provides a guide on connecting the sensor and calibrating it. You will use the IMU with the PID algorithm for a behavior that makes a robot always face north. Finally, the chapter shows you how to program the robot to make a specified turn using the IMU.
Chapter 13, Determining Location with Monte Carlo, will show you how to program a robot to determine where it is likely to be in an arena. You’ll use plans in the chapter to build a foam board arena and model this arena in code. You are shown how to visualize this space on a computer using Bluetooth LE with Matplotlib. You will then learn about moving robot poses based on sensor input. The chapter shows how multiple robot behaviors can cooperate in the same application. You will be introduced to using probability algorithms in robot motion, making predictions, and refining them.
Chapter 14, Continuing Your Journey – Your Next Robot, provides a summary of the topics learned in the book, with information on digging deeper into each of them. The chapter provides ideas and research areas for you to extend all the aspects of the robot, and then further suggestions to build more ambitious robots and grow your skills. The chapter also recommends robotics communities you could participate in.
To get the most out of this book
You will need to have knowledge of a few Python basics, such as variables, looping, conditionals, and functions. A well-lit and ventilated desk space is recommended for the robot-building aspects of the book. Access to hand tools will help, although you will be shown which tools to shop for. The robot code examples have been tested on CircuitPython 7.2.0 on Raspberry Pi Pico but should work with later versions. The computer code examples were tested on Python 3.9.
Thonny comes with a built-in Python 3.x installation. The Tools | Open System shell menu can be used to install packages in Thonny’s Python.
If you are using the digital version of this book, we advise you to type the code yourself or access the code from the book’s GitHub repository (a link is available in the next section). Doing so will help you avoid any potential errors related to the copying and pasting of code.
Help for this book can be found by:
Raising a bug on the book’s GitHub repository at https://github.com/PacktPublishing/Robotics-at-Home-with-Raspberry-Pi-Pico
Asking via Discord at https://discord.gg/2VHYY3FkXV
Download the example code files
You can download the example code files for this book from GitHub at https://github.com/PacktPublishing/Robotics-at-Home-with-Raspberry-Pi-Pico. If there’s an update to the code, it will be updated in the GitHub repository.
We also have other code bundles from our rich catalog of books and videos available at https://github.com/PacktPublishing/. Check them out!
Download the color images
We also provide a PDF file that has color images of the screenshots and diagrams used in this book. You can download it here: https://packt.link/7x3ku.
Conventions used
There are a number of text conventions used throughout this book.
Code in text: Indicates code words in text, database table names, folder names, filenames, file extensions, pathnames, dummy URLs, user input, and Twitter handles. Here is an example: To run this code, be sure to send the pio_encoders.py library, the updated robot.py file, and then measure_fixed_time.py.
A block of code is set as follows:
import time
import board
import digitalio
led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT
while True:
led.value = True
time.sleep(0.5)
led.value = False
time.sleep(0.5)
When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:
>>>
print(Hello, world!
)
Hello, World!
>>>
Any command-line input or output is written as follows:
code.py output:
4443 4522
Bold: Indicates a new term, an important word, or words that you see onscreen. For instance, words in menus or dialog boxes appear in bold. Here is an example: Launch Mu Editor, and when it is running, click on the Mode button. From this, select CircuitPython.
Tips or important notes
Appear like this.
Get in touch
Feedback from our readers is always welcome.
General feedback: If you have questions about any aspect of this book, email us at [email protected] and mention the book title in the subject of your message.
Errata: Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you have found a mistake in this book, we would be grateful if you would report this to us. Please visit www.packtpub.com/support/errata and fill in the form.
Piracy: If you come across any illegal copies of our works in any form on the internet, we would be grateful if you would provide us with the location address or website name. Please contact us at [email protected] with a link to the material.
If you are interested in becoming an author: If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, please visit authors.packtpub.com.
Share Your Thoughts
Once you’ve read Robotics at Home with Raspberry Pi Pico, we’d love to hear your thoughts! Please click here to go straight to the Amazon review page for this book and share your feedback.
Your review is important to us and the tech community and will help us make sure we’re delivering excellent quality content.
Download a free PDF copy of this book
Thanks for purchasing this book!
Do you like to read on the go but are unable to carry your print books everywhere? Is your eBook purchase not compatible with the device of your choice?
Don’t worry, now with every Packt book you get a DRM-free PDF version of that book at no cost.
Read anywhere, any place, on any device. Search, copy, and paste code from your favorite technical books directly into your application.
The perks don’t stop there, you can get exclusive access to discounts, newsletters, and great free content in your inbox daily
Follow these simple steps to get the benefits:
Scan the QR code or visit the link below
https://packt.link/free-ebook/9781803246079
Submit your proof of purchase
That’s it! We’ll send your free PDF and other benefits to your email directly
Part 1: The Basics – Preparing for Robotics with Raspberry Pi Pico
In this part, you will take your first steps in learning about Raspberry Pi Pico, then plan and build a robot around it, and get the initial robot code to make the robot move.
This part contains the following chapters:
Chapter 1, Planning a Robot with Raspberry Pi Pico
Chapter 2, Preparing Raspberry Pi Pico
Chapter 3, Designing a Robot Chassis in FreeCAD
Chapter 4, Building a Robot around Pico
Chapter 5, Driving Motors with Raspberry Pi Pico
1
Planning a Robot with Raspberry Pi Pico
When you plan, you create the best chance for a mission’s success. We want to build robots in an achievable way. Let’s start with a plan in mind! We’ll use this plan to explore why Raspberry Pi Pico is a great fit for this and make a shopping list!
In this chapter, you’ll learn about Raspberry Pi Pico’s capabilities. You’ll discover CircuitPython and understand why it is a great language for Raspberry Pi Pico. Additionally, we’ll plan a robot design and understand the trade-offs to make choices about the robot early in the project. We’ll check that our robot fits together, working out the parts and tools you’ll need with suggestions on how to get them.
At the end of the chapter, you’ll have both a plan and parts arriving so that you are ready to build a robot. Additionally, you’ll have a starting process for making other robots and setting yourself up for success with them.
In this chapter, we’ll cover the following main topics:
What is Raspberry Pi Pico, and why is it suitable for robotics?
What is CircuitPython?
Planning a Raspberry Pi Pico robot
Test fitting a Raspberry Pi Pico robot
A recommended shopping list for robot basics
Technical requirements
We’ll go into the necessary hardware and shopping list as we progress further in this chapter. So, in this section, we’ll just focus on what you will need physically and on your computer to get started.
You will require the following:
Some thin cardboard
A ruler, pencil, and scissors
A good web browser with internet access
What is Raspberry Pi Pico, and why is it suitable for robotics?
At the heart of every robot is a controller. Usually, this is a computing device that is responsible for running the code for the robot to perform its tasks and behaviors. Choosing a controller is a key choice in robot design. You can either come from the I have this controller, what can I do with it? perspective or the which controllers have the capabilities I’ll want for a particular robot? perspective.
In this section, we’ll take a closer look at what Raspberry Pi Pico offers as a controller and the trade-offs it’s made. We’ll explore why it is good for robotics and why it could be part of a larger, more interesting system, too.
Additionally, we’ll delve into the details of its interfaces and how they’ll be useful to us.
A microcontroller that runs Python
Let’s start by taking a look at Raspberry Pi Pico, and discover what it has. The following photograph shows Raspberry Pi Pico:
Figure 1.1 – Raspberry Pi PicoFigure 1.1 – Raspberry Pi Pico
Raspberry Pi Pico, as shown in Figure 1.1, is an RP2040 microcontroller on a Raspberry Pi-designed board. This microcontroller is a small computing device that has been designed to interface closely with hardware. It has a USB connection on the right-hand side for power or programming on a computer. The LED is useful