How to Connect to a Bluetooth Device with a MacBook and Python
Connect to smart watches, smart light bulbs, and Bluetooth LE sensors with Python and Bleak on your Mac OS computer.
This is a beginner tutorial on Python and Bluetooth LE (Low Energy). If you know Python and Bluetooth already, check out the short TL;DR version of this article.
We’ll be connecting to an Xsens DOT wearable movement sensor as an example device, though you can connect to any device you have.
Requirements
- A Mac OS computer (12.x+)
- Python 3
- Bleak (a Python Bluetooth LE library)
- A smart watch, smart lightbulb, or similar Bluetooth LE device
What This Tutorial Covers
We will connect to one Bluetooth LE device with Python 3 by writing code from scratch. This code will be a building block for adding Bluetooth functionality to your projects and can be used to make dashboards, tools, and data analysis pipelines for Bluetooth LE devices.
NOTE: This tutorial is for Bluetooth LE devices, not regular Bluetooth. Though they’re similar, Bluetooth LE and Bluetooth are not the same under the hood. The code that we write here cannot be used to connect to a regular Bluetooth (“Bluetooth…