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