Book Image

Robotics at Home with Raspberry Pi Pico

By : Danny Staple
Book Image

Robotics at Home with Raspberry Pi Pico

By: Danny Staple

Overview of this book

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.
Table of Contents (20 chapters)
1
Part 1: The Basics – Preparing for Robotics with Raspberry Pi Pico
7
Part 2: Interfacing Raspberry Pi Pico with Simple Sensors and Outputs
12
Part 3: Adding More Robotic Behaviors to Raspberry Pi Pico

What is CircuitPython?

Many microcontrollers require C/C++ or Assembler to program—for example, the popular Arduino ecosystem. However, in robotics, Python is rapidly becoming a de facto language. It is used for AI and data science and is great for rapidly trying out new ideas. Let’s examine why it is handy and, specifically, why I’ve chosen CircuitPython for this book.

Python does not require a compile step. Getting you quick feedback on your code and Python’s read-eval-print loop (REPL) allow you to start typing and experimenting with code instantly. The REPL allows you to see what works before using ideas in code that you’ll keep. Here’s a REPL session with CircuitPython:

Adafruit CircuitPython 6.2.0 on 2021-04-05; Raspberry Pi Pico with rp2040
>>> print("Hello, world!")
Hello, world!

The preceding session shows a print running in a REPL on Raspberry Pi Pico. We’ll explore how to use the REPL for some Pico experiments. It even comes with built-in assistance; however, on Pico, not all of the help is left in, for size reasons.

Python has other things that help, such as being able to directly return multiple values from a function. Python has function calls and classes like C++, but functions can be used as data, and references to them can be stored in variables. Additionally, Python has functional programming elements that allow programmers to chain tools together for processing streams of data.

Python uses exceptions to handle errors, allowing you to choose how to respond to them or observe their output, leading you directly to a problem.

MicroPython is the original port of the Python language to run on small memory devices such as microcontrollers. It has a community working on it, and CircuitPython builds on it.

In CircuitPython, Raspberry Pi Pico mounts as a USB storage device, so you can copy your code and the libraries your code uses, directly onto the Pico. This makes composing code from multiple libraries or using third parties simple. Copying code over with the correct name is enough to run that code when Raspberry Pi Pico is powered up again.

CircuitPython has a huge library of device support for Neopixel LEDs, Bluetooth, many sensors, displays, and other devices. This library not only works with Pico but runs across many CircuitPython controllers, so familiarity with these library components will be useful when you are working with other controllers.

Now that we’ve chosen a language and the controller that we will build robots with in this book, it’s time to start planning a robot!