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...