Reader small image

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

Product typeBook
Published inMar 2023
Reading LevelBeginner
PublisherPackt
ISBN-139781803246079
Edition1st Edition
Languages
Concepts
Right arrow
Author (1)
Danny Staple
Danny Staple
author image
Danny Staple

Danny Staple builds robots and gadgets as a hobbyist, makes videos about his work with robots, and attends community events such as PiWars and Arduino Day. He has been a professional Python programmer, later moving into DevOps, since 2009, and a software engineer since 2000. He has worked with embedded systems, including embedded Linux systems, throughout the majority of his career. He has been a mentor at a local CoderDojo, where he taught how to code with Python. He has run Lego Robotics clubs with Mindstorms. He has also developed Bounce!, a visual programming language targeted at teaching code using the NodeMCU IoT platform. The robots he has built with his children include TankBot, SkittleBot (now the Pi Wars robot), ArmBot, and SpiderBot.
Read more about Danny Staple

Right arrow

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

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Robotics at Home with Raspberry Pi Pico
Published in: Mar 2023Publisher: PacktISBN-13: 9781803246079

Author (1)

author image
Danny Staple

Danny Staple builds robots and gadgets as a hobbyist, makes videos about his work with robots, and attends community events such as PiWars and Arduino Day. He has been a professional Python programmer, later moving into DevOps, since 2009, and a software engineer since 2000. He has worked with embedded systems, including embedded Linux systems, throughout the majority of his career. He has been a mentor at a local CoderDojo, where he taught how to code with Python. He has run Lego Robotics clubs with Mindstorms. He has also developed Bounce!, a visual programming language targeted at teaching code using the NodeMCU IoT platform. The robots he has built with his children include TankBot, SkittleBot (now the Pi Wars robot), ArmBot, and SpiderBot.
Read more about Danny Staple