Skip to main content

PyMetaWear

https://travis-ci.org/hbldh/pymetawear.svg?branch=master https://coveralls.io/repos/github/hbldh/pymetawear/badge.svg?branch=master

Python package for connecting to and using MbientLab’s MetaWear boards.

PyMetawear is meant to be a thin wrapper around the MetaWear C++ API, providing a more Pythonic interface. It has support for several different Python packages for Bluetooth Low Energy communication:

PyMetaWear can be run with Python 2 or 3 with both backends, but only with the pygatt backend for Python 3.5. It builds and runs on Linux systems, and can be built on Windows, given that Visual Studio Community 2015 has been installed first, but there is no working backend for Windows BLE yet.

Installation

$ pip install pymetawear

Currently, only the pygatt communication backend is installed by default. The other backends can be installed as extras:

$ pip install pymetawear[pybluez]

or

$ pip install pymetawear[bluepy]

Debian requirements for pymetawear

  • build-essential

  • python-dev

Additional requirements for pybluez

  • libglib2.0-dev

  • bluetooth

  • libbluetooth-dev

  • libboost-python-dev

  • libboost-thread-dev

Additional requirements for bluepy

  • libglib2.0-dev

Development

Clone this repository and run

$ python setup.py build

to pull in the MetaWear C++ API submodule, build it and copy the Python wrappers from it to the PyMetaWear folder. This can also be achieved by running

$ pip install -e .

in the cloned repository’s root folder.

Documentation

Available in the Github pages of this repository.

Basic Usage

The MetaWear client can be used in two ways: either as Pythonic convenience class for handling a MetaWear board or as a simple communication client governed by the libmetawear C++ library.

Creating a client, and thus also setting up a Bluetooth connection to the MetaWear board, is equal for both the two usage profiles:

from pymetawear.client import MetaWearClient
backend = 'pygatt'  # Or 'pybluez' or 'bluepy'
c = MetaWearClient('DD:3A:7D:4D:56:F0', backend)

An example: blinking with the LED lights can be done like this with the convenience methods:

pattern = c.led.load_preset_pattern('blink', repeat_count=10)
c.led.write_pattern(pattern, 'g')
c.led.play()

or like this using the raw libmetawear shared library:

from ctypes import byref
from pymetawear import libmetawear
from pymetawear.mbientlab.metawear.peripheral import Led

pattern = Led.Pattern(repeat_count=10)
libmetawear.mbl_mw_led_load_preset_pattern(byref(pattern), Led.PRESET_BLINK)
libmetawear.mbl_mw_led_write_pattern(c.board, byref(pattern), Led.COLOR_GREEN)
libmetawear.mbl_mw_led_play(c.board)

Actual addresses to your MetaWear board can be found by scanning, either directly with hcitool lescan or with the included discover_devices method:

from pymetawear.client import discover_devices
out = discover_devices()
print out
[(u'DD:3A:7D:4D:56:F0', u'MetaWear'), (u'FF:50:35:82:3B:5A', u'MetaWear')]

See the examples folder for more examples on how to use the libmetawear library with this client.

Modules

All functionality of the MetaWear C++ API is able to be used using the PyMetaWear client, and some of the modules have had convenience methods added to simplify the use of them. Below are two list, one of modules which have had their convenience methods written and one of modules that are awaiting such focus.

Completed Modules

Partial Modules

Unimplemented Modules

Accelerometer

Settings

Temperature

Gyroscope

Color Detector

Haptic

Humidity

Switch

GPIO

LED

I2C

Barometer

iBeacon

Magnetometer

NeoPixel Proximity

v0.5.2 (2016-10-13)

  • Temperature Module

  • Using Pygatt 3.0.0 (including PR from PyMetaWear contributors)

  • Builds on Windows

v0.5.1 (2016-09-15)

  • Corrections to make it distributable via PyPI.

v0.5.0 (2016-09-15)

  • Using MetaWear-CppAPI version 0.5.22

  • Changed building procedure to handle ARM processors

  • Updated requirements to make pygatt default, all others extras

  • Bluepy backend implemented and partially working

  • BL interface selection for all backends

  • Magnetometer module

  • Barometer module

  • Ambient Light module

  • Modifying notification wrappers to accommodate Epoch value in the data.

  • High speed sampling for accelerometer and gyroscope

v0.4.4 (2016-04-28)

  • Updated MetaWear-CppAPI submodule version.

  • Removed temporary build workaround.

v0.4.3 (2016-04-27)

  • Critical fix for switch notifications.

  • Updated MetaWear-CppAPI submodule version.

  • Now using the new setup_metawear method.

  • Restructured the IS_64_BIT usage which is still needed.

v0.4.2 (2016-04-27)

  • Critical fix for timeout in pybluez/gattlib backend.

  • Added Gyroscope module.

  • Added soft reset method to client.

  • Updated examples.

  • Updated documentation.

v0.4.1 (2016-04-20)

  • Cleanup of new modules sensor data parsing.

  • Bug fix related to accelerometer module.

  • Timeout parameter for client and backends.

v0.4.0 (2016-04-17)

  • Major refactorisation into new module layout.

  • New examples using the new module handling.

  • Accelerometer convenience methods shows strange lag still.

v0.3.1 (2016-04-10)

  • Critical fix for data signal subscription method.

  • Setup.py handling of building made better,

  • Documentation improved.

v0.3.0 (2016-04-09)

  • Major refactoring: all BLE comm code practically moved to backends.

  • Backend pybluez with gattlib now works well.

  • Travis CI problems with Python 2.7 encoding led to that we are now building on 2.7.11

v0.2.3 (2016-04-07)

  • Changed from using gattlib on its own to using pybluez with gattlib

  • Travis CI and Coveralls

  • Travis CI deploys documentation to gh-pages.

  • Some documentation written.

v0.2.2 (2016-04-06)

  • Convenience method for switch.

  • Sphinx documentation added.

  • Docstring updates.

v0.2.1 (2016-04-04)

  • Refactoring in moving functionality back to client from backends.

  • Enable BlueZ 4.X use with pygatt.

  • Disconnect methods added.

  • Example with switch button notification.

v0.2.0 (2016-04-02)

  • Two backends: pygatt and gattlib

  • pygatt backend can be fully initialize, i.e. handles notifications.

  • gattlib backend cannot fully initialize, i.e. does not handles notifications.

v0.1.1 (2016-03-30)

  • Fix to support Python 3

v0.1.0 (2016-03-30)

  • Initial release

  • Working communication, tested with very few API options.

Release files for pymetawear 0.5.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pymetawear 0.5.2
File Size Uploaded
pymetawear-0.5.2.tar.gz 206.3 kB Details

Release files / pymetawear-0.5.2.tar.gz

Download URL pymetawear-0.5.2.tar.gz
Size 206.3 kB
Tags Source
SHA-256 checksum
How to use checksums
81607b3c0c0956173c3584d0adbb3cd222870c6eafbca899cd894b5d2d8523d1
BLAKE2b-256 checksum
How to use checksums
ad28ac953c4ea8cf67366cddbb1f05f20a3b992f614152df5cfabd7885e06f8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

0.10.0

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.7.2

1 release file

0.7.1

1 release file

0.7.0

1 release file

0.6.0

1 release file

This release

0.5.2 This release

1 release file

0.5.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page