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

Getting sensor data over Bluetooth LE on Raspberry Pi Pico

So far, you’ve tested the sensor-based examples, seeing their output in the console by connecting your laptop to it. However, building on our hello world example and the distance sensing in Chapter 8, Sensing Distances to Detect Objects with Pico, we can not only see the sensor output over UART as text but also plot in in a graph. So, let’s get into it.

We’ll put this code in a folder named bluetooth-distance-sensors. Copy in the robot.py and pio_encoder.py files. We will add code.py. Let’s start with the imports, combining the sensors and bus setup:

import board
import time
import busio
import robot
uart = busio.UART(board.GP12, board.GP13, baudrate=9600)

With the UART now prepared, we can prepare the sensors:

robot.left_distance.distance_mode = 1
robot.left_distance.start_ranging()
robot.right_distance.distance_mode = 1
robot.right_distance.start_ranging()

We’ve set both sensors...