Abstract: In this short howto we will install BluePy (an API to allow access to Bluetooth Low Energy devices from Python) on Raspberry Pi. We will use it in some python scripts which use BLE (Bluetooth Low Energy) devices.

1.) Setup a Raspberry Pi as explained here

2.) Login as pi user

3.) Install the required phyton software via

sudo apt-get install python-pip libglib2.0-dev

To find out which phyton software you are running you can use "python --version"

4.) We will now install BluePy directly from the Phyton Package Index via PIP:

sudo pip install bluepy

This might take some time but once installed we will find the needed files in:

Working dir is /tmp/pip-build-b_rUBd/bluepy
Installing blescan script to /usr/local/bin
Installing sensortag script to /usr/local/bin

The main package is installed in /usr/local/lib/pythonVERSION/dist-packages/. In the example here (default Debian Jessie) its: /usr/local/lib/python2.7/dist-packages/bluepy

5.) To check BluePy now, we need the MAC from our BLE device. If we know that (sometimes its written on the package from the BLE device or on the device itself). If not we can use lescan to scan for BLE devices. This can be done via:

sudo hcitool lescan

It will output somehing like:

7C:2F:80:AD:08:66 Gigaset G-tag
E0:00:69:19:08:66 SPEED_CELL

Which shows currently my Gigaset G-Tag and my Adidas Speed Cell. The numbers in front of the devices is the MAC address which we need. Once the device came up we can press ctrl + c to stop the scan, otherwiese it will run forever (keep noted that lescan is not part of BluePy).

6.) Once we have the MAC we can switch to "/usr/local/lib/python2.7/dist-packages/bluepy" and run:

python btle.py 7C:2F:80:AD:08:6

if working it will show us some useful info´s, here is a short abbreviation from the output (might take some time to show something):

Service <uuid=Battery Service handleStart=25 handleEnd=28> :
    Characteristic <Battery Level>, hnd=0x1a, supports NOTIFY READ
    -> 'd'
Service <uuid=Device Information handleStart=16 handleEnd=24> :
    Characteristic <Manufacturer Name String>, hnd=0x11, supports READ
    -> 'Gigaset'
    Characteristic <Model Number String>, hnd=0x13, supports READ
    -> 'G-tag'
    Characteristic <Firmware Revision String>, hnd=0x15, supports READ
    -> 'v_3.0.6.0'
    Characteristic <Software Revision String>, hnd=0x17, supports READ
    -> 'v_3.50.2.07'

If yours look similar then you can be sure its working. Keep noted that if you play with different BLE devices, the options you will see might be different.

7.) To run another test you could enter


which will then output something like

Python 2.7.9 (default, Mar  8 2015, 00:52:26)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

And then you can enter:

from bluepy.btle import UUID, Peripheral

Which should work without error

Keep noted that LE scan mußt run as root as mentioned here

P.S. Thanks to Ian Harvey and others who report issues and code for spending time in writing and improving BluePy which helps a lot to build scripts for BLE devices.

Comments (6)

  1. Peter

Thanks for that kind of information :-).

  Comment was last edited about 7 months ago by Author Team Author Team
  1. mike

You have posted very nice tutorial which i like reading. I suggest this post for students they can learn a lot from it.
services of ncr form

  1. Jhonny

I needed to thank you for this incredible read!! I reading the tutorial you have posted. I have you bookmarked your site to look at the new stuff you post.
Buy latest stickers printing at discount rate

  1. Jason

You have posted a nice tutorial about install BluePy, i must say you have posted very nice educational post which is not easy to find.
Cosmetic packaging boxes design

  1. Jade

Very well written article about BluePy , you have explained it in detail which makes it easy to understand. I just want to say that i like your work.
E Liquid Packaging Boxes

  1. Steven

This is a great tutorial, i like reading it. I have learn a lot from this article which will help me a lot in future.
discount painting services

There are no comments posted here yet

Leave your comments

Posting comment as a guest.
Attachments (0 / 3)
Share Your Location