Skip to content
This repository was archived by the owner on Jul 20, 2025. It is now read-only.

Commit f249403

Browse files
committed
update readme
1 parent 9968cb7 commit f249403

File tree

1 file changed

+227
-30
lines changed

1 file changed

+227
-30
lines changed

README.md

Lines changed: 227 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,32 @@
1-
# MetaWear SDK for Python by MBIENTLAB
1+
# MetaWear SDK for Python by MBIENTLAB
22

3-
[![Platforms](https://img.shields.io/badge/platform-linux--64%20%7C%20win--32%20%7C%20win--64-lightgrey?style=flat)](https://github.com/mbientlab/MetaWear-SDK-Python)
3+
[![Platforms](https://img.shields.io/badge/platform-linux-lightgrey?style=flat)](https://github.com/mbientlab/MetaWear-SDK-Python)
44
[![License](https://img.shields.io/cocoapods/l/MetaWear.svg?style=flat)](https://github.com/mbientlab/MetaWear-SDK-Python/blob/master/LICENSE.md)
55
[![Version](https://img.shields.io/badge/python-3.5%20%7C%203.6%20%7C%203.7-blue?style=flat)](https://github.com/mbientlab/MetaWear-SDK-Python)
66

77
![alt tag](https://raw.githubusercontent.com/mbientlab/MetaWear-SDK-iOS-macOS-tvOS/master/Images/Metawear.png)
88

9-
SDK for creating MetaWear apps on the Linux platform. This is a thin wrapper around the [MetaWear C++ API](https://github.com/mbientlab/MetaWear-SDK-Cpp) so you will find the C++ [documentation](https://mbientlab.com/cppdocs/latest/) and [API reference](https://mbientlab.com/docs/metawear/cpp/latest/globals.html) useful.
9+
SDK for creating MetaWear apps on the Linux platform. Supported for Linux only.
1010

11-
Also, check out the scripts in the [examples](https://github.com/mbientlab/MetaWear-SDK-Python/tree/master/examples) folder for sample code.
11+
This is a thin wrapper around the [MetaWear C++ API](https://github.com/mbientlab/MetaWear-SDK-Cpp) so you will find the C++ [documentation](https://mbientlab.com/cppdocs/latest/) and [API reference](https://mbientlab.com/docs/metawear/cpp/latest/globals.html) useful.
12+
13+
Also, check out the Python [examples](https://github.com/mbientlab/MetaWear-SDK-Python/tree/master/examples).
1214

1315
> ADDITIONAL NOTES
1416
This is not the pymetawear package. That is a community developed Python SDK which you can find over [here](https://github.com/mbientlab-projects/pymetawear).
17+
You can try to get our Python SDK running on OSX or Windows at your own risk. This requires that you get Warble to work under those OSs yourself. We do not provide examples or support for this; experts ONLY. Please see the Noble README.
1518

1619
### Overview
1720

1821
[MetaWear](https://mbientlab.com) is a complete development and production platform for wearable and connected device applications.
1922

20-
MetaWear features a number of sensors and peripherals all easily controllable over Bluetooth 4.0 Low Energy using this SDK, no firmware or hardware experience needed!
23+
MetaWear features a number of sensors and peripherals all easily controllable over Bluetooth 4.0/5.0 Low Energy using this SDK, no firmware or hardware experience needed!
2124

2225
The MetaWear hardware comes pre-loaded with a wirelessly upgradeable firmware, so it keeps getting more powerful over time.
2326

2427
### Requirements
2528
- [MetaWear board](https://mbientlab.com/store/)
26-
- A Linux or Windows 10+ machine with Bluetooth 4.0
29+
- A linux machine with Bluetooth 4.0/5.0
2730

2831
### License
2932
See the [License](https://github.com/mbientlab/MetaWear-SDK-Python/blob/master/LICENSE.md).
@@ -33,58 +36,252 @@ Reach out to the [community](https://mbientlab.com/community/) if you encounter
3336

3437
## Getting Started
3538

36-
### Installation
39+
### Pre-Installation
40+
41+
#### Python
42+
You need to make sure you have Python2 or Python3 installed as well as Pip. We don't cover this in this README, you can google-fu how to install Python and Pip.
43+
```
44+
python -V
45+
python3 -V
46+
```
47+
48+
You installation might look like this for Python3:
49+
```
50+
sudo apt update
51+
sudo apt-get install -y build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev
52+
sudo apt install python3
53+
```
54+
Or like this:
55+
```
56+
wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tar.xz
57+
tar xf Python-3.9.0.tar.xz
58+
cd Python-3.9.0
59+
./configure --prefix=/usr/local/opt/python-3.9.0
60+
make -j 4
61+
sudo make altinstall
62+
```
63+
It will be entirely up to you to figure out how you want to install Python and if you want to use Python 2 or 3.
64+
65+
You should also check where Python was installed:
66+
```
67+
which python
68+
which python3
69+
```
70+
71+
##### Pip
72+
You can install packages from the Python Package Index (PyPI). To do so, use the pip tool (google-fu how to install).
73+
74+
It will look something like this:
75+
```
76+
curl -O https://bootstrap.pypa.io/get-pip.py
77+
sudo python3 get-pip.py
78+
```
79+
80+
There are two versions of pip:
81+
82+
- pip for installing Python 2 modules
83+
- pip3 for Python 3 modules
84+
85+
Under normal circumstances, you should only be using Python 3 and therefore pip3.
86+
87+
You can install modules using the pip3 install command. For example, if you wanted to download the guizero module, you would type this into a terminal window:
88+
```
89+
sudo pip3 install guizero
90+
```
91+
You may or may not need to install with sudo:
92+
```
93+
pip3 install guizero
94+
```
95+
And you may or may want to install packages for the local user only:
96+
```
97+
pip3 install --user guizero
98+
```
99+
Again this is all up to you.
100+
101+
Here are a few useful commands:
102+
- Upgrade an already installed module:
103+
```
104+
sudo pip3 install --upgrade name_of_module
105+
```
106+
- Uninstall a module:
107+
```
108+
sudo pip3 uninstall name_of_module
109+
```
110+
- List all installed modules:
111+
```
112+
sudo pip3 list
113+
```
114+
115+
You will need to make sure when you install packages/libraries/dependencies using pip, that they are installed in the correct directory. Some can be installed in /usr/bin/, some in /usr/local/bin/ or /usr/.local/bin/. If you are having issues with modules not being found, a little google-fu will go a long way.
116+
117+
Using sudo python and non-sudo python might even change which Python is being used.
118+
119+
For example, this might work:
120+
```
121+
/usr/local/bin/python3 -m pip install cassandra-driver
122+
```
123+
But this might not work:
124+
```
125+
pip3 install cassandra-driver
126+
```
127+
But this might works also:
128+
```
129+
sudo pip3 install cassandra-driver
130+
```
131+
It entirely depends on your setup because a different location/version of Python may be called in each case such that cassandra-driver may be installed in `/usr/local/lib/python3/dist-packages` or
132+
133+
To make sure you're installing it for the version of python you're using:
134+
```
135+
/path/to/your/python -m pip install <package>
136+
```
137+
Or you will get the error:
138+
```
139+
ImportError: No module named <package_name>
140+
```
141+
You can also update your $PATH but the best way to avoid all this is to use Python virtual environments (google-fu this).
142+
143+
##### Using sudo - a Warning
144+
It is important to note that because our scripts use OS level Bluetooth libraries, it may be required to use sudo (or you will get a Bluetooth warning).
145+
```
146+
terminate called after throwing an instance of 'BLEPP::HCIScanner::IOError'
147+
what(): Setting scan parameters: Operation not permitted
148+
```
149+
150+
##### Using bluez, BLE Dongles, and Python
151+
At the time of this release, Python3.7 is supported. We are moving away from Python 2.7 (use the older 1.2.0 release for Python2).
152+
153+
Bluez 5.50 works but 5.54 might not work. Here's a good [tutorial](https://learn.adafruit.com/install-bluez-on-the-raspberry-pi/installation)
37154

38-
Use pip to install the metawear package. It depends on [PyWarble](https://github.com/mbientlab/PyWarble) so ensure your target environment has the necessary [dependencies](https://github.com/mbientlab/Warble#build) installed.
155+
If you are not using a BLE dongle, you need to make sure your system is working and supports Bluetooth 4.0 or later (Bluetooth low energy).
39156

40-
```ruby
157+
If you are using a BLE dongle, you need to make sure it's working. You can google-fu how to use tools such as `bluetoothctl`, `hciconfig`, `btmon` and more to confirm this.
158+
159+
#### Pre-Requisites
160+
MetaWear depends on [PyWarble](https://github.com/mbientlab/PyWarble) so ensure your target environment has the necessary [dependencies](https://github.com/mbientlab/Warble#build) installed.
161+
162+
### Installation
163+
You have two options for installation:
164+
165+
#### 1. Use PIP (recommended)
166+
You can simply install the MetaWear package lib with Pip using the command line:
167+
```
41168
pip install metawear
42169
```
170+
For Python 3:
171+
```
172+
pip3 install metawear
173+
```
174+
Or maybe (depends on your setup - see section above):
175+
```
176+
/usr/bin/python3 -m pip install metawear
177+
```
43178

44-
### Usage
179+
If you install metawear with Python2, you will get an older version (we are no longer supporting Python2 but the older libs work).
180+
We recommend using Python3 and our Pypi3 metawear package (this should automatically be resolved with pip).
181+
182+
#### 2. Clone our Repository (local deps - developers only)
183+
We packaged everything for you already in this repository.
184+
185+
Make sure that when you clone this repository, that you clone the submodule with it.
186+
```
187+
git clone --recurse-submodules https://github.com/mbientlab/MetaWear-SDK-Python.git
188+
```
189+
190+
Then you can simply install:
191+
```
192+
python3 setup.py build
193+
```
194+
This will compile the underlying cpp libraries and may take a few seconds.
195+
196+
#### Errors and Issues
197+
If you have any issues with the installation, make sure you have warble and all the dependencies installed correctly.
198+
199+
Make sure all python, and warble dependencies are installed:
200+
```
201+
sudo apt update
202+
sudo apt-get install -y build-essential tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libssl-dev libbz2-dev libexpat1-dev liblzma-dev zlib1g-dev libffi-dev
203+
sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev libboost-all-dev build-essential
204+
```
205+
206+
Make sure warble is installed and listed:
207+
```
208+
pip3 list
209+
pip3 freeze
210+
```
211+
212+
Make sure your bluetooth system and dongles are working usin `bluetoothctl`.
213+
214+
#### Running your first Script
215+
Once the install is successful, you can run our example scripts in the example folder (see the example folder in our repository):
216+
```
217+
sudo python3 scan_connect.py
218+
```
45219

46-
Import the MetaWear class and libmetawear variable from the metawear module and everything from the cbindings module.
220+
If you get the following error:
221+
```
222+
error 1609703819.483035: Setting scan parameters: Operation not permitted
223+
```
224+
Please ignore it, it is coming from a low level third party dependence (blecpp) and does not affect your script.
225+
226+
#### Notes
227+
You should familiarize yourself with this README and our tutorials since there a few limitiations and other gotchas spelled out, such as the maximum number of simultaneous Bluetooth connections.
228+
229+
### Usage
230+
Require the metawear package by importing the MetaWear class and libmetawear variable from the metawear module and everything from the cbindings module.
47231
```python
48232
from mbientlab.metawear import MetaWear, libmetawear
49233
from mbientlab.metawear.cbindings import *
50234
```
51235

52-
If you do not know the MAC address of your device, use ``PyWarble`` to scan for nearby devices.
236+
If you do not know the MAC address of your device, use `PyWarble` to scan for nearby devices.
53237
```python
54-
from mbientlab.warble import *
55-
from mbientlab.metawear import *
56-
from threading import Event
57-
58-
e = Event()
59-
address = None
60-
def device_discover_task(result):
61-
global address
62-
if (result.has_service_uuid(MetaWear.GATT_SERVICE)):
63-
# grab the first discovered metawear device
64-
address = result.mac
65-
e.set()
66-
67238
BleScanner.set_handler(device_discover_task)
68239
BleScanner.start()
69240
e.wait()
70-
71241
BleScanner.stop()
72242
```
73243

74-
Once you have the device's MAC address, create a MetaWear object with the MAC address and connect to the device.
244+
Or a specific MAC address
245+
```python
246+
address = C8:4B:AA:97:50:05
247+
```
248+
249+
After that, you must connect to the device
75250
```python
76251
device = MetaWear(address)
77252
device.connect()
78253
```
79254

80-
Upon a successful connection, you can begin calling any of the functions from the C++ SDK, for example, blinking the LED green.
255+
At this point you can call any of the MetaWear API's, for example, you can blink the LED green
81256
```python
82257
pattern= LedPattern(repeat_count= Const.LED_REPEAT_INDEFINITELY)
83-
libmetawear.mbl_mw_led_load_preset_pattern(byref(pattern), LedPreset.BLINK)
258+
libmetawear.mbl_mw_led_load_preset_pattern(byref(pattern), LedPreset.SOLID)
84259
libmetawear.mbl_mw_led_write_pattern(device.board, byref(pattern), LedColor.GREEN)
85260
libmetawear.mbl_mw_led_play(device.board)
86261
```
87262

88-
### Tutorials
263+
### Example
264+
```python
265+
# usage: python led.py [mac]
266+
from __future__ import print_function
267+
from mbientlab.metawear import MetaWear, libmetawear
268+
from mbientlab.metawear.cbindings import *
269+
from time import sleep
270+
from threading import Event
271+
import sys
272+
device = MetaWear(sys.argv[1])
273+
device.connect()
274+
print("Connected")
275+
pattern= LedPattern(repeat_count= Const.LED_REPEAT_INDEFINITELY)
276+
libmetawear.mbl_mw_led_load_preset_pattern(byref(pattern), LedPreset.SOLID)
277+
libmetawear.mbl_mw_led_write_pattern(device.board, byref(pattern), LedColor.GREEN)
278+
libmetawear.mbl_mw_led_play(device.board)
279+
sleep(5.0)
280+
libmetawear.mbl_mw_led_stop_and_clear(device.board)
281+
sleep(1.0)
282+
device.disconnect()
283+
```
89284

285+
### Tutorials
90286
Tutorials can be found [here](https://mbientlab.com/tutorials/).
287+

0 commit comments

Comments
 (0)