The 5 Minute Guide to Setup a Raspberry Pi for Bluetooth Development
Pre-requisites
The pre-requisite for this guide is to have a stock Raspberry Pi 3 running the latest version of Raspbian. To do this simply:1) Download the official latest image here.
2) Follow the official instructions to transfer the image to an SD card.
Raspberry Pi Development Setup
There are three ways to setup your development environment. One option is to hook up an HDMI monitor, keyboard and mouse and develop directly on the Raspberry Pi. The other two options are to use a laptop and remotely connect to the Raspberry Pi either using Ethernet (or WiFi) or serial to USB connection.
I strongly recommend purchasing a Raspberry Pi Serial to USB cable and setting up a serial to USB connection because it allows you to develop offline, allowing you the freedom to develop in a coffee shop or anywhere because you don't need to have the Raspberry Pi connected to a network.
Raspberry Pi Environment Setup
Once you have setup your physical development environment here are some key packages to install using the command line.
VI Improved (VIM)
sudo apt-get install vim
There are people that wear it as a Badge of Honor that they know VI the Unix text editor inside and out. I am not one of those people and for me, VIM is the defacto.
Bluetooth Development Header Files
sudo apt-get install libbluetooth
This package contains the necessary headers used to compile Bluetooth related packages. Install this package will fix the situation when you see the following error: fatal error: bluetooth/bluetooth.h: No such file or directory
Python Development Header Files
sudo apt-get install python-dev
This package contains the necessary headers to compile Python related packages. Install this package will fix the situation where you see the following error: fatal error: Python.h: No such file or directory
Python Wrapper for BlueZ
sudo pip install PyBluez
BlueZ is the official Bluetooth stack for Linux. BlueZ utilizes the C programming language. PyBluez is a wrapper around the BlueZ to allow the use of Python to interface with the Bluetooth stack.
Albert Huang wrote a great introduction to Bluetooth programming that provides a good high level overview. What I found particular helpful was his PyBlueZ examples.
I had to use sudo apt-get install libbluetooth-dev then I could install the Wrapper
ReplyDeleteThe BLuetooth Development headers gave me a problem until I went here.
ReplyDeletehttps://www.raspberrypi.org/forums/viewtopic.php?f=32&t=187871&p=1184190&hilit=libbluetooth#p1184190
E: Unable to locate package libbluetooth
ReplyDeleteShould it be libbluetooth3?
libbluetooth-dev worked for me...
Delete