|
| 1 | +# MetaWear SDK for Python by MBIENTLAB |
| 2 | + |
| 3 | +[](https://github.com/mbientlab/MetaWear-SDK-Python) |
| 4 | +[](https://mbientlab.com/license) |
| 5 | +[](https://github.com/mbientlab/MetaWear-SDK-Python) |
| 6 | + |
| 7 | + |
| 8 | + |
| 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. |
| 10 | + |
| 11 | +Also, check out the scripts in the [examples](https://github.com/mbientlab/MetaWear-SDK-Python/tree/master/examples) folder for sample code. |
| 12 | + |
| 13 | +> ADDITIONAL NOTES |
| 14 | +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). |
| 15 | + |
| 16 | +### Overview |
| 17 | + |
| 18 | +[MetaWear](https://mbientlab.com) is a complete development and production platform for wearable and connected device applications. |
| 19 | + |
| 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! |
| 21 | + |
| 22 | +The MetaWear hardware comes pre-loaded with a wirelessly upgradeable firmware, so it keeps getting more powerful over time. |
| 23 | + |
| 24 | +### Requirements |
| 25 | +- [MetaWear board](https://mbientlab.com/store/) |
| 26 | +- A linux or Windows 10+ machine with Bluetooth 4.0 |
| 27 | + |
| 28 | +### License |
| 29 | +See the [License](https://github.com/mbientlab/MetaWear-SDK-Python/blob/master/LICENSE). |
| 30 | + |
| 31 | +### Support |
| 32 | +Reach out to the [community](https://mbientlab.com/community/) if you encounter any problems, or just want to chat :) |
| 33 | + |
| 34 | +## Getting Started |
| 35 | + |
| 36 | +### Installation |
| 37 | + |
| 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. |
| 39 | + |
| 40 | +```ruby |
| 41 | +pip install metawear |
| 42 | +``` |
| 43 | + |
| 44 | +### Usage |
| 45 | + |
| 46 | +Import the MetaWear class and libmetawear variable from the metawear module and everything from the cbindings module. |
| 47 | +```python |
| 48 | +from mbientlab.metawear import MetaWear, libmetawear |
| 49 | +from mbientlab.metawear.cbindings import * |
| 50 | +``` |
| 51 | + |
| 52 | +If you do not know the MAC address of your device, use ``PyWarble`` to scan for nearby devices. |
| 53 | +```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 | + |
| 67 | +BleScanner.set_handler(device_discover_task) |
| 68 | +BleScanner.start() |
| 69 | +e.wait() |
| 70 | + |
| 71 | +BleScanner.stop() |
| 72 | +``` |
| 73 | + |
| 74 | +Once you have the device's MAC address, create a MetaWear object with the MAC address and connect to the device. |
| 75 | +```python |
| 76 | +device = MetaWear(address) |
| 77 | +device.connect() |
| 78 | +``` |
| 79 | + |
| 80 | +Upon a successful connection, you can begin calling any of the functions from the C++ SDK, for example, blinking the LED green. |
| 81 | +```python |
| 82 | +pattern= LedPattern(repeat_count= Const.LED_REPEAT_INDEFINITELY) |
| 83 | +libmetawear.mbl_mw_led_load_preset_pattern(byref(pattern), LedPreset.BLINK) |
| 84 | +libmetawear.mbl_mw_led_write_pattern(device.board, byref(pattern), LedColor.GREEN) |
| 85 | +libmetawear.mbl_mw_led_play(device.board) |
| 86 | +``` |
| 87 | + |
| 88 | +### Tutorials |
| 89 | + |
| 90 | +Tutorials can be found [here](https://mbientlab.com/tutorials/). |
0 commit comments