Controlling the robot with Bluetooth LE
Bluetooth LE is a two-way medium. In this section, we’ll see how to receive data from the UART and, better yet, how to decode that data into control signals. By the end of this section, you’ll be able to drive your robot with a smartphone!
Printing what we got
Before we try to decode control packets, let’s just make a simple app to echo whatever shows on the Bluefruit UART out onto the Raspberry Pi Pico console.
Put the following code in bluetooth-print-incoming/code.py
. We start by importing and setting up the UART port:
import board import busio uart = busio.UART(board.GP12,board.GP13,baudrate=9600, timeout=0.01) print("Waiting for bytes on UART...")
The one difference here is that I’ve added a short timeout. Without the short timeout, the port will wait a full second for the number of bytes read. You might have noticed with the Hello world example that it took a second before you got the...