Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Robotics at Home with Raspberry Pi Pico

You're reading from  Robotics at Home with Raspberry Pi Pico

Product type Book
Published in Mar 2023
Publisher Packt
ISBN-13 9781803246079
Pages 400 pages
Edition 1st Edition
Languages
Concepts
Author (1):
Danny Staple Danny Staple
Profile icon Danny Staple

Table of Contents (20) Chapters

Preface Part 1: The Basics – Preparing for Robotics with Raspberry Pi Pico
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 Part 2: Interfacing Raspberry Pi Pico with Simple Sensors and Outputs
Chapter 6: Measuring Movement with Encoders on Raspberry Pi Pico Chapter 7: Planning and Shopping for More Devices Chapter 8: Sensing Distances to Detect Objects with Pico Chapter 9: Teleoperating a Raspberry Pi Pico Robot with Bluetooth LE Part 3: Adding More Robotic Behaviors to Raspberry Pi Pico
Chapter 10: Using the PID Algorithm to Follow Walls Chapter 11: Controlling Motion with Encoders on Raspberry Pi Pico Chapter 12: Detecting Orientation with an IMU on Raspberry Pi Pico Chapter 13: Determining Position Using Monte Carlo Localization Chapter 14: Continuing Your Journey – Your Next Robot Index Other Books You May Enjoy

Building a wall avoider with Raspberry Pi Pico

Two distance sensors and independent motor control with some code are the ingredients needed to avoid obstacles. Let’s start by putting the distance sensors in the shared robot library.

Preparing the robot library

Like we have with other aspects of the robot, we’ll start by building the distance sensors set up in the robot.py file. At the top of this file, the imports now include busio and adafruit_vl53l1x libraries:

import board
import pwmio
import pio_encoder
import busio
import adafruit_vl53l1x

We can then set up our left and right distance sensors. Insert the following below the encoder setup and above the stop function:

i2c0 = busio.I2C(sda=board.GP0, scl=board.GP1)
i2c1 = busio.I2C(sda=board.GP2, scl=board.GP3)
left_distance = adafruit_vl53l1x.VL53L1X(i2c0)
right_distance = adafruit_vl53l1x.VL53L1X(i2c1)

Save this file and be sure to upload it to the CIRCUITPY volume.

We will use robot.py in the...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime}