### JavaScript Example: Blinking LED Source: https://mbientlab.com/tutorials/MetaHub Provides instructions to run a basic JavaScript example script that blinks an LED using the MetaWear SDK. It requires installing dependencies and using a specific Node.js version. ```bash nvm use 10 npm install sudo node led.js ``` -------------------------------- ### Setup and Stream Sensor Fusion Data Source: https://mbientlab.com/tutorials/JsLinux Example JavaScript code to configure sensor fusion mode, accelerometer and gyroscope ranges, write the configuration, subscribe to quaternion data, and start the sensor fusion process. ```JavaScript console.log('Setting up sensor fusion...'); // Setup gyro, acc, and sensor fusion settings MetaWear.mbl_mw_sensor_fusion_set_mode(device.board, 1); // SensorFusionMode.NDOF MetaWear.mbl_mw_sensor_fusion_set_acc_range(device.board, 2 ); // SensorFusionAccRange._8G MetaWear.mbl_mw_sensor_fusion_set_gyro_range(device.board, 0); // SensorFusionGyroRange._2000DPS MetaWear.mbl_mw_sensor_fusion_write_config(device.board); console.log('Getting quaternion signal.'); let signal = MetaWear.mbl_mw_sensor_fusion_get_data_signal(device.board, 3); // QUATERNION console.log('Setting up data stream subscription.'); MetaWear.mbl_mw_datasignal_subscribe(signal, ref.NULL, MetaWear.FnVoid_VoidP_DataP.toPointer((ctx, pointer) => { var data = pointer.deref(); var value = data.parseValue(); console.log('Epoch: ' + data.epoch + ' Quat: ' + value.x + ' ' + value.y + ' ' + value.z); })); console.log('Starting sensor fusion.'); MetaWear.mbl_mw_sensor_fusion_enable_data(device.board, 3); // QUATERNION MetaWear.mbl_mw_sensor_fusion_start(device.board); console.log('Sensor fusion started. Waiting for data...'); ``` -------------------------------- ### Install C++ Compiler (Example) Source: https://mbientlab.com/tutorials/PyLinux Provides an example command to install a specific version of GCC and G++ compilers, along with Clang. This is useful if your system's default compilers are outdated or incompatible. ```bash sudo apt-get install -y gcc-6 g++-6 clang-3.8 ``` -------------------------------- ### Install Git Version Control System Source: https://mbientlab.com/tutorials/JsLinux Installs Git, a distributed version control system essential for software development, including tracking changes and collaborating on code. Verifies the installation. ```bash sudo apt-get install git-core ``` ```bash git --version ``` -------------------------------- ### Setup RSS Data Processor (JavaScript) Source: https://mbientlab.com/tutorials/JsLinux Demonstrates setting up a Root Sum Square (RSS) data processor using the MetaWear JavaScript SDK. It shows how to get an acceleration data signal, create the RSS processor, and handle the asynchronous creation callback. This processor calculates the root mean square of input data. ```javascript // start to setup rms->avg->thresh->log chain console.log('Get acc signal'); var acc = MetaWear.mbl_mw_acc_get_acceleration_data_signal(device.board); // create RSS console.log('Create RSS'); let promise = new Promise((resolve, reject) => { var rms = MetaWear.mbl_mw_dataprocessor_rss_create(acc, ref.NULL, MetaWear.FnVoid_VoidP_DataProcessorP.toPointer(function onSignal(context, dataPtr) { console.log('RSS Created'); resolve(dataPtr); })); }); let rms = await promise; ``` -------------------------------- ### Install Project Dependencies Source: https://mbientlab.com/tutorials/JsLinux Command to install all project dependencies after cloning the repository or setting up a new project. This ensures all necessary libraries are available. ```bash >>> npm install ``` -------------------------------- ### Run Example Scripts Source: https://mbientlab.com/tutorials/JsLinux Command to execute JavaScript example files from the command line using Node.js. Requires 'sudo' if the Noble library is used, due to Bluetooth permissions. ```bash >>> node led.js ``` ```bash >>> sudo node led.js ``` -------------------------------- ### Python Example: Blinking LED Source: https://mbientlab.com/tutorials/MetaHub Provides instructions to run a basic Python example script that blinks an LED using the MetaWear SDK. It requires the Python 3 interpreter and the MAC address of the sensor. ```bash python3 led.py [mac address] # Example: python3 led.py E6:Fe:B6:B4:DB:E7 ``` -------------------------------- ### Create RSS Processor Example Source: https://mbientlab.com/tutorials/SwApple Demonstrates creating a Root Sum Square (RSS) data processor for acceleration data. It subscribes to the processed signal and starts acceleration sampling. Dependencies include the device's acceleration data signal and various MetaWear C++ API functions. ```swift let signal = mbl_mw_acc_bosch_get_acceleration_data_signal(device.board) // Create RSS signal!.rssCreate().continueOnSuccessWith { rss in self.streamingCleanup[signal!] = { mbl_mw_acc_stop(self.device.board) mbl_mw_acc_disable_acceleration_sampling(self.device.board) mbl_mw_datasignal_unsubscribe(rss) } mbl_mw_datasignal_subscribe(rss, bridge(obj: self)) { (context, obj) in let acceleration_rss: MblMwCartesianFloat = obj!.pointee.valueAs() print(acceleration_rss) } mbl_mw_acc_enable_acceleration_sampling(self.device.board) mbl_mw_acc_start(self.device.board) } ``` -------------------------------- ### Install Git using Homebrew Source: https://mbientlab.com/tutorials/SwApple Installs Git using the Homebrew package manager. This is a convenient method if Homebrew is already set up on your system. ```shell brew install git ``` -------------------------------- ### Install MetaWear Node.js Package Source: https://mbientlab.com/tutorials/JsLinux Installs the MetaWear library using npm, the Node Package Manager. This command fetches and installs the package and its dependencies from the npm registry. ```bash npm install metawear ``` -------------------------------- ### Install Alternative Development Dependencies Source: https://mbientlab.com/tutorials/JsLinux An alternative set of commands to install Bluetooth-related development libraries. This may be used if the previous set is not fully comprehensive or if specific components are preferred. ```bash sudo apt-get install bluetooth bluez libbluetooth-dev libudev-dev ``` -------------------------------- ### Check Git Installation Source: https://mbientlab.com/tutorials/SwApple Verifies if Git, a distributed version-control system, is installed on your system. If Git is not found, it suggests alternative installation methods. ```shell git --version ``` -------------------------------- ### Install Noble Bluetooth Library Source: https://mbientlab.com/tutorials/JsLinux Instructions to install the Noble Bluetooth library, which is a core dependency for the MetaWear JavaScript APIs. It's usually installed automatically but can be installed manually if needed. ```bash >>> npm install noble ``` -------------------------------- ### Install Node.js Build Tools and npm Source: https://mbientlab.com/tutorials/JsLinux Installs essential build tools and the Node Package Manager (npm) required for compiling native addons and managing Node.js packages. Includes system updates. ```bash sudo apt-get install -y build-essential ``` ```bash sudo apt-get install npm ``` ```bash sudo apt-get update ``` ```bash sudo apt-get upgrade ``` -------------------------------- ### Install and Verify Git Source: https://mbientlab.com/tutorials/PyLinux Installs the Git version control system using apt-get and verifies the installation by checking the Git version. Git is recommended for forking or creating repositories. ```shell sudo apt-get install git-core ``` ```shell git --version ``` -------------------------------- ### Install Homebrew Package Manager Source: https://mbientlab.com/tutorials/SwApple Installs the Homebrew package manager on macOS. Homebrew simplifies software installation and management. This command downloads and executes the official installation script. ```shell ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" ``` -------------------------------- ### Install Bluetooth Packages Source: https://mbientlab.com/tutorials/JsLinux Installs essential Bluetooth packages and dependencies required for Bluetooth functionality on Debian-based systems like Ubuntu and Raspberry Pi OS. ```bash sudo apt install bluetooth pi-bluetooth bluez blueman bluez-utils ``` -------------------------------- ### Install Development Dependencies Source: https://mbientlab.com/tutorials/JsLinux Installs core development tools and libraries, including build essentials, Bluetooth support, and Boost libraries, which are often required for compiling C++ projects or using specific hardware interfaces. ```bash sudo apt-get install build-essential ``` ```bash sudo apt-get install bluez ``` ```bash sudo apt-get install libboost-all-dev ``` ```bash sudo apt-get install libbluetooth-dev ``` -------------------------------- ### Install USB and Udev Development Libraries Source: https://mbientlab.com/tutorials/JsLinux Installs libraries necessary for interacting with USB devices and managing system device events (udev). These are often required for low-level hardware communication. ```bash sudo apt-get install libusb-dev ``` ```bash sudo apt-get install libudev-dev ``` -------------------------------- ### Install Node.js from Ubuntu Repository Source: https://mbientlab.com/tutorials/JsLinux Installs the Node.js runtime using the default Ubuntu package repository. This is a straightforward method for obtaining a stable version. ```bash sudo apt install nodejs ``` -------------------------------- ### JavaScript: Start and Download Sensor Logging Source: https://mbientlab.com/tutorials/JsLinux Demonstrates how to configure, start, and stop logging for accelerometer data on a MetaWear device, followed by downloading the logged data. It includes setting sensor parameters, creating a logger, subscribing to data, and handling download progress. ```javascript var acceLogger = null; function startLogging(device, callback) { // Set up the acc functionality MetaWear.mbl_mw_acc_set_odr(device.board, 50.0); MetaWear.mbl_mw_acc_set_range(device.board, 16.0); MetaWear.mbl_mw_acc_write_acceleration_config(device.board); // Create a logger var accSignal = MetaWear.mbl_mw_acc_get_acceleration_data_signal(device.board); MetaWear.mbl_mw_datasignal_log(accSignal, ref.NULL, MetaWear.FnVoid_VoidP_DataLoggerP.toPointer(function (context, logger) { accelLogger = logger; callback(logger.address() ? null : new Error('failed to start logging accel')); })); // Start logging and enable the acc MetaWear.mbl_mw_logging_start(device.board, 0); MetaWear.mbl_mw_acc_enable_acceleration_sampling(device.board); MetaWear.mbl_mw_acc_start(device.board); } function downloadLog(device, callback) { // Disable accel MetaWear.mbl_mw_acc_stop(device.board); MetaWear.mbl_mw_acc_disable_acceleration_sampling(device.board); // Stop logging MetaWear.mbl_mw_logging_stop(device.board); // Setup handler for accel data points and create callback to parse incoming logger data MetaWear.mbl_mw_logger_subscribe(accelLogger, ref.NULL, MetaWear.FnVoid_VoidP_DataP.toPointer(function onSignal(context, dataPtr) { var data = dataPtr.deref(); var pt = data.parseValue(); console.log(data.epoch + ' ' + pt.x + ',' + pt.y + ',' + pt.z); })); // Setup the handlers for events during the download var downloadHandler = new MetaWear.LogDownloadHandler(); // Logger progress callback downloadHandler.received_progress_update = MetaWear.FnVoid_VoidP_UInt_UInt.toPointer(function onSignal(context, entriesLeft, totalEntries) { console.log('received_progress_update entriesLeft:' + entriesLeft + ' totalEntries:' + totalEntries); }); // Logger unknown entry callback downloadHandler.received_unknown_entry = MetaWear.FnVoid_VoidP_UByte_Long_UByteP_UByte.toPointer(function onSignal(context, id, epoch, data, length) { // ... handle unknown entry ... }); // Start the download MetaWear.mbl_mw_logging_download(device.board, downloadHandler); callback(); } ``` -------------------------------- ### Verify Node.js and npm Installation Source: https://mbientlab.com/tutorials/JsLinux Checks the installed versions of Node.js and npm to confirm successful installation. Essential for ensuring the environment is correctly set up. ```bash node -v ``` ```bash npm -v ``` -------------------------------- ### Install MetaWear NPM Module Source: https://mbientlab.com/tutorials/JsLinux Command to install the MetaWear NPM module, which includes the JavaScript SDK. This process may compile C++ libraries and can take some time. ```bash >>> npm install metawear ``` -------------------------------- ### Install Node.js from NodeSource Repository (v10.x) Source: https://mbientlab.com/tutorials/JsLinux Installs Node.js version 10.x by adding the NodeSource repository. This method allows for installing specific, often newer, versions than the default Ubuntu repository. ```bash curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash - ``` ```bash sudo apt-get install nodejs ``` -------------------------------- ### JavaScript: Create, Record, and Start MetaWear Timer Source: https://mbientlab.com/tutorials/JsLinux Demonstrates creating an indefinite MetaWear timer, recording commands to read temperature data, and starting the timer. It uses Promises for asynchronous operations and MetaWear SDK functions for timer and event management. ```JavaScript async function startLogging(device, callback) { // Get temp signal console.log('Get temp signal'); var tempSignal = MetaWear.mbl_mw_multi_chnl_temp_get_temperature_data_signal(device.board, 1); // Create a timer console.log('Create timer'); var promise = new Promise((resolve, reject) => { var timer = MetaWear.mbl_mw_timer_create_indefinite(device.board, 1000, 0, ref.NULL, MetaWear.FnVoid_VoidP_TimerP.toPointer(function onSignal(context, timer) { console.log(context); console.log('Timer created'); console.log(timer); resolve(timer); })); }); tempTimer = await promise; console.log(tempTimer); // Create event based on timer and record as a command console.log('Record command'); MetaWear.mbl_mw_event_record_commands(tempTimer); console.log('Command to read temp signal'); MetaWear.mbl_mw_datasignal_read(tempSignal); console.log('End record command'); promise = new Promise((resolve, reject) => { var rec = MetaWear.mbl_mw_event_end_record(tempTimer, ref.NULL, MetaWear.FnVoid_VoidP_EventP_Int.toPointer(function onSignal(context, dataPtr, lstatus) { console.log('Command created'); resolve(lstatus); })); }); let rec = await promise; // Start timer MetaWear.mbl_mw_timer_start(tempTimer); // Create a logger MetaWear.mbl_mw_datasignal_log(tempSignal, ref.NULL, MetaWear.FnVoid_VoidP_DataLoggerP.toPointer(function (context, logger) { tempLogger = logger; callback(logger.address() ? null : new Error('failed to start logging temp')); })); // Start logger MetaWear.mbl_mw_logging_start(device.board, 0); } ``` -------------------------------- ### Create and Start MetaWear Timers Source: https://mbientlab.com/tutorials/SwApple Set up periodic or delayed tasks on the MetaWear board using timers. This involves creating a timer, programming it to execute commands (like reading data signals), and then starting the timer. Timer creation and starting are asynchronous operations. ```swift let signal = mbl_mw_multi_chnl_temp_get_temperature_data_signal(device.board, 1)! mbl_mw_datasignal_subscribe(signal, bridge(obj: self)) { (context, obj) in let temp: UInt32 = obj!.pointee.valueAs() print(format: "%d", temp) } // Create a timer to read every 700 ms device.timerCreate(period: 700).continueOnSuccessWith { timer in self.streamingCleanup[signal] = { mbl_mw_timer_remove(timer) mbl_mw_datasignal_unsubscribe(signal) } mbl_mw_event_record_commands(timer) mbl_mw_datasignal_read(signal) timer.eventEndRecord().continueOnSuccessWith { mbl_mw_timer_start(timer) } } ``` -------------------------------- ### Upgrade System Packages (Ubuntu/Debian) Source: https://mbientlab.com/tutorials/JsLinux Command to install newer versions of all installed packages. This process can take a significant amount of time and should not be interrupted. ```shell sudo apt upgrade ``` -------------------------------- ### Install Node.js from NodeSource Repository (v12.x) Source: https://mbientlab.com/tutorials/JsLinux Installs Node.js version 12.x by adding the NodeSource repository. This method is suitable for users requiring the features and performance of Node.js v12. ```bash curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - ``` ```bash sudo apt-get install -y nodejs ``` -------------------------------- ### Python MetaWear Accelerometer Streaming Example Source: https://mbientlab.com/tutorials/PyLinux Provides a complete example for streaming accelerometer data. It includes setting the output data rate (ODR) and range, writing the configuration, getting the data signal, subscribing with a callback, enabling sampling, and starting the sensor. It also shows the teardown process. ```python # Callback function pointer callback = FnVoid_VoidP_DataP(self.data_handler) # Callback function to process/parse the gyroscope data def data_handler(self, ctx, data): print("%s -> %s" % (self.device.address, parse_value(data))) # Setup the accelerometer sample frequency and range libmetawear.mbl_mw_acc_set_odr(device.board, 100.0) libmetawear.mbl_mw_acc_set_range(device.board, 16.0) libmetawear.mbl_mw_acc_write_acceleration_config(device.board) # Get the accelerometer data signal signal = libmetawear.mbl_mw_acc_get_acceleration_data_signal(device.board) # Subscribe to it libmetawear.mbl_mw_datasignal_subscribe(signal, None, callback) # Enable the accelerometer libmetawear.mbl_mw_acc_enable_acceleration_sampling(device.board) libmetawear.mbl_mw_acc_start(device.board) ... # Disable the accelerometer libmetawear.mbl_mw_acc_stop(device.board) libmetawear.mbl_mw_acc_disable_acceleration_sampling(device.board) # Unsubscribe to it signal = libmetawear.mbl_mw_acc_get_acceleration_data_signal(device.board) libmetawear.mbl_mw_datasignal_unsubscribe(signal) libmetawear.mbl_mw_debug_disconnect(device.board) ``` -------------------------------- ### Setup Timer for Periodic ADC Reading Source: https://mbientlab.com/tutorials/Cpp This example shows how to create and configure an indefinite timer to periodically trigger tasks. It records commands to read an analog input (ADC) signal every time the timer fires and starts the timer. ```cpp #include "metawear/core/event.h" #include "metawear/core/timer.h" #include "metawear/sensor/gpio.h" void timer_setup(MblMwMetaWearBoard* board) { static auto cmds_recorded = [](void* context, MblMwEvent* event, int32_t status) { printf("timer task setup\n"); }; static auto timer_created = [](void* context, MblMwTimer* timer) { auto owner = mbl_mw_event_get_owner((MblMwEvent*) timer); auto adc_signal= mbl_mw_gpio_get_analog_input_data_signal(board, 0, MBL_MW_GPIO_ANALOG_READ_MODE_ADC); // read gpio adc data every time the timer fires an event mbl_mw_event_record_commands((MblMwEvent*) timer); mbl_mw_datasignal_read(adc_signal); mbl_mw_event_end_record((MblMwEvent*) timer, context, cmds_recorded); mbl_mw_timer_start(timer); }; // create a timer that indefinitely fires events every 500ms mbl_mw_timer_create_indefinite(board, 500, 0, nullptr, timer_created); } ``` -------------------------------- ### Setup Accelerometer Data Stream and Event Listeners Source: https://mbientlab.com/tutorials/JaAndroid Configures button click listeners to manage the accelerometer data stream. The 'Start' button sets up a data route, subscribes to the stream, and starts the sensor, while the 'Stop' button halts the sensor and cleans up resources. ```java @Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); view.findViewById(R.id.acc_start).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { accelerometer.acceleration().addRouteAsync(new RouteBuilder() { @Override public void configure(RouteElement source) { source.stream(new Subscriber() { @Override public void apply(Data data, Object... env) { Log.i("MainActivity", data.value(Acceleration.class).toString()); } }); } }).continueWith(new Continuation() { @Override public Void then(Task task) throws Exception { accelerometer.acceleration().start(); accelerometer.start(); return null; } }); } }); view.findViewById(R.id.acc_stop).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { accelerometer.stop(); accelerometer.acceleration().stop(); metawear.tearDown(); } }); } ``` -------------------------------- ### MetaWear Swift Tutorials Source: https://mbientlab.com/tutorials/SwApple Step-by-step tutorials to guide developers in using the Swift libraries for MetaWear sensors, covering common use cases and integration patterns. ```URL https://mbientlab.com/iosdocs/latest ``` -------------------------------- ### Initial Route Setup with Streaming and Chaining Source: https://mbientlab.com/tutorials/JaAndroid Demonstrates setting up an initial data route using MetaWear's Android SDK. It includes streaming data from a source, applying a subscriber to process incoming data, and chaining another route using onSuccessTask for sequential execution. ```Java metawear.getModule(Switch.class).state().addRouteAsync(new RouteBuilder() { @Override public void configure(RouteComponent source) { source.stream(new Subscriber() { @Override public void apply(Data data, Object... env) { if (data.value(Boolean.class)) { led.editPattern(Led.Color.BLUE, Led.PatternPreset.SOLID).commit(); led.play(); } } }); } }).onSuccessTask(new Continuation>() { @Override public Task then(Task task) throws Exception { return accBosch.tap().addRouteAsync(new RouteBuilder() { @Override public void configure(RouteComponent source) { source.stream(new Subscriber() { @Override public void apply(Data data, Object... env) { led.stop(true); } }); } }); } }); ``` -------------------------------- ### MbientLab MetaWear Java Tutorials Source: https://mbientlab.com/tutorials/JaAndroid Guides and tutorials for developers looking to integrate MbientLab MetaWear devices into their Android applications using Java. These resources cover setup, common functionalities, and best practices. ```URL https://mbientlab.com/androiddocs/latest/ ``` -------------------------------- ### Handle Gyroscope Data (Python) Source: https://mbientlab.com/tutorials/PyLinux Demonstrates how to subscribe to and process gyroscope data using the Python API. It includes setting up a callback function, getting the gyroscope signal, enabling sampling, and starting the sensor, followed by disabling and stopping. ```Python # Callback function pointer callback = FnVoid_VoidP_DataP(self.data_handler) # Callback function to process/parse the gyroscope data def data_handler(self, ctx, data): print("%s -> %s" % (self.device.address, parse_value(data))) self.samples+= 1 # Get the gyroscope data signal signal = libmetawear.mbl_mw_gyro_bmi160_get_rotation_data_signal(device.board) // Subscribe to it libmetawear.mbl_mw_datasignal_subscribe(signal, None, callback) # Enable the gyroscope libmetawear.mbl_mw_gyro_bmi160_enable_rotation_sampling(device.board) libmetawear.mbl_mw_gyro_bmi160_start(device.board) sleep(30.0) # Disable the gyroscope libmetawear.mbl_mw_gyro_bmi160_stop(device.board) libmetawear.mbl_mw_gyro_bmi160_disable_rotation_sampling(device.board) ``` -------------------------------- ### MetaWear Sensor Fusion API Source: https://mbientlab.com/tutorials/JsLinux API functions for configuring, starting, and subscribing to sensor fusion data on MetaMotion boards. This includes setting fusion modes, sensor ranges, writing configurations, getting data signals, and subscribing to data streams. ```APIDOC MetaWear Sensor Fusion Configuration and Data Streaming: - mbl_mw_sensor_fusion_set_mode(board, mode) - Sets the sensor fusion mode. - Parameters: - board: Pointer to the MetaWear board. - mode: Integer representing the fusion mode (e.g., 1 for NDoF). - mbl_mw_sensor_fusion_set_acc_range(board, range) - Sets the accelerometer data range. - Parameters: - board: Pointer to the MetaWear board. - range: Integer representing the accelerometer range (e.g., 2 for 8G). - mbl_mw_sensor_fusion_set_gyro_range(board, range) - Sets the gyroscope data range. - Parameters: - board: Pointer to the MetaWear board. - range: Integer representing the gyroscope range (e.g., 0 for 2000 DPS). - mbl_mw_sensor_fusion_write_config(board) - Writes the configured sensor fusion settings to the board. - Parameters: - board: Pointer to the MetaWear board. - mbl_mw_sensor_fusion_get_data_signal(board, output_type) - Retrieves the data signal for a specific sensor fusion output type. - Parameters: - board: Pointer to the MetaWear board. - output_type: Integer representing the desired output type (e.g., 3 for QUATERNION). - Returns: Pointer to the data signal. - mbl_mw_datasignal_subscribe(signal, context, callback) - Subscribes to a data signal, providing a callback function to process incoming data. - Parameters: - signal: Pointer to the data signal. - context: User-defined context pointer (can be NULL). - callback: Function pointer to handle data reception. - mbl_mw_sensor_fusion_enable_data(board, output_type) - Enables the specified sensor fusion output data to be streamed. - Parameters: - board: Pointer to the MetaWear board. - output_type: Integer representing the output type to enable. - mbl_mw_sensor_fusion_start(board) - Starts the sensor fusion algorithm on the board. - Parameters: - board: Pointer to the MetaWear board. Related Functions: - mbl_mw_datasignal_unsubscribe: Unsubscribes from a data signal. - mbl_mw_sensor_fusion_stop: Stops the sensor fusion algorithm. ``` -------------------------------- ### Sensor Fusion Setup and Data Subscription Source: https://mbientlab.com/tutorials/PyLinux Configures the sensor fusion algorithm by setting the mode (e.g., NDOF), accelerometer range, and gyroscope range. It then subscribes to the Quaternion data signal and enables the sensor fusion output. This is a comprehensive example for integrating sensor fusion. ```python # Sensor fusion setup libmetawear.mbl_mw_sensor_fusion_set_mode(s.device.board, SensorFusionMode.NDOF) libmetawear.mbl_mw_sensor_fusion_set_acc_range(s.device.board, SensorFusionAccRange._8G) libmetawear.mbl_mw_sensor_fusion_set_gyro_range(s.device.board, SensorFusionGyroRange._2000DPS) libmetawear.mbl_mw_sensor_fusion_write_config(s.device.board) # Subscribe to the quaternion signal signal = libmetawear.mbl_mw_sensor_fusion_get_data_signal(s.device.board, SensorFusionData.QUATERNION) libmetawear.mbl_mw_datasignal_subscribe(signal, None, s.callback) # Start sensor fusion (acc + gyro + mag + on-board sensor fusion algo) libmetawear.mbl_mw_sensor_fusion_enable_data(s.device.board, SensorFusionData.QUATERNION) libmetawear.mbl_mw_sensor_fusion_start(s.device.board) sleep(10.0) # Stop sensor fusion libmetawear.mbl_mw_sensor_fusion_stop(s.device.board) # Unsubscribe signal = libmetawear.mbl_mw_sensor_fusion_get_data_signal(s.device.board, SensorFusionData.QUATERNION) libmetawear.mbl_mw_datasignal_unsubscribe(signal) ``` -------------------------------- ### MetaBase Configuration File Example Source: https://mbientlab.com/tutorials/MetaHub Shows a snippet from the `metabase-config.json` file, specifically how to define the MAC addresses of MetaWear devices to connect to. This file is used by the MetaBase Node application. ```json " devices": [ "E2:C3:6D:33:73:6F" ] ``` -------------------------------- ### Check Xcode Command Line Tools Installation Source: https://mbientlab.com/tutorials/SwApple Verifies if the Command Line Tools (CLT) for Xcode are installed on your macOS system. This is a prerequisite for installing Homebrew and other development tools. It returns the path to the developer directory if installed. ```shell xcode-select -p ``` -------------------------------- ### Check and Install Warble Source: https://mbientlab.com/tutorials/PyLinux Checks if the Warble package is installed and provides commands to install it if missing. Warble is a dependency for MetaWear, wrapping the libblepp library. ```shell pip3 list --user warble (local) ``` ```shell pip3 list warble (global / sudo) ``` ```shell pip3 install warble ``` ```shell sudo pip3 install warble ``` -------------------------------- ### Record and Play MetaWear Macro Source: https://mbientlab.com/tutorials/Cpp This snippet demonstrates how to record a sequence of MetaWear commands, such as setting an LED pattern and playing it, into a macro. It shows the steps to initiate recording, execute commands, and then end the recording, associating a callback for completion. ```cpp #include "metawear/core/macro.h" #include "metawear/peripheral/led.h" void setup_macro(MblMwMetaWearBoard* board) { static auto callback = [](void* context, MblMwMetaWearBoard* board, int32_t id) -> void { cout << "Macro ID = " << id << endl; }; MblMwLedPattern pattern = { 16, 16, 0, 500, 0, 1000, 0, 5 }; mbl_mw_macro_record(board, 1); mbl_mw_led_write_pattern(board, &pattern, MBL_MW_LED_COLOR_BLUE); mbl_mw_led_play(board); mbl_mw_macro_end_record(board, nullptr, callback); } ``` -------------------------------- ### Install Python 3.6 via deadsnakes PPA on Ubuntu Source: https://mbientlab.com/tutorials/PyLinux Installs Python 3.6 on Ubuntu by adding the deadsnakes PPA, which provides newer Python versions. It includes steps to install the necessary software-properties-common, add the PPA, update the package list, and then install Python 3.6. ```bash sudo apt-get install software-properties-common sudo add-apt-repository ppa:deadsnakes/ppa sudo apt-get update sudo apt-get install python3.6 ``` -------------------------------- ### Install MetaWear Python Package Source: https://mbientlab.com/tutorials/PyLinux Installs the MetaWear Python package using pip. It shows options for installing with or without sudo, and using 'pip3' or 'python3 -m pip'. ```shell pip3 install metawear ``` ```shell sudo pip3 install metawear ``` ```shell python3 -m pip install metawear ``` ```shell sudo python3 -m pip install metawear ``` -------------------------------- ### Clone MetaWear JavaScript SDK Repository Source: https://mbientlab.com/tutorials/JsLinux Command to clone the MetaWear JavaScript SDK repository from GitHub. This allows access to the source code and example scripts for development. ```bash >>> git clone --recursive https://github.com/mbientlab/MetaWear-SDK-JavaScript ``` -------------------------------- ### Install Mbientlab Package (User) Source: https://mbientlab.com/tutorials/PyLinux Installs the 'metawear' Python package for the current user only. This avoids requiring administrator privileges and installs packages into the user's local directory. ```bash python3 -m pip install metawear ``` -------------------------------- ### MetaWear JavaScript SDK API Source: https://mbientlab.com/tutorials/JsLinux Documentation for core MetaWear JavaScript SDK functions. This includes discovering devices, connecting, setting up, and controlling device features like LEDs. ```APIDOC MetaWear: discover(callback: function) - Discovers the first MetaWear device found. - Parameters: - callback: A function that receives the discovered device object. discoverByAddress(address: string, callback: function) - Discovers a MetaWear device by its MAC address. - Parameters: - address: The MAC address of the device (e.g., 'cb:7d:c5:b0:20:8f'). - callback: A function that receives the discovered device object. Device: connectAndSetUp(callback: function) - Connects to a discovered MetaWear device and performs initial setup. - Parameters: - callback: A function that receives an error object if connection fails. on(event: string, listener: function) - Attaches an event listener to the device. - Example: - device.on('disconnect', function() { ... }); MetaWear.LedPattern: - Constructor for creating LED patterns. - Methods: - ref(): Returns a reference to the pattern object. MetaWear.LedPreset: - Enum for predefined LED patterns. - Values: - BLINK MetaWear.LedColor: - Enum for LED colors. - Values: - GREEN MetaWear.mbl_mw_led_load_preset_pattern(pattern: MetaWear.LedPattern, preset: MetaWear.LedPreset) - Loads a predefined pattern into an LED pattern object. - Parameters: - pattern: The LED pattern object to load into. - preset: The predefined pattern to load (e.g., MetaWear.LedPreset.BLINK). MetaWear.mbl_mw_led_write_pattern(board: object, pattern: MetaWear.LedPattern, color: MetaWear.LedColor) - Writes a loaded LED pattern to the device's board. - Parameters: - board: The device board object. - pattern: The loaded LED pattern. - color: The color for the LED pattern. MetaWear.mbl_mw_led_play(board: object) - Plays the configured LED pattern on the device. - Parameters: - board: The device board object. MetaWear.mbl_mw_debug_reset(board: object) - Resets the MetaWear device. - Parameters: - board: The device board object. Complete Example: var MetaWear = require('metawear'); MetaWear.discover(function (device) { device.connectAndSetUp(function (error) { var pattern = new MetaWear.LedPattern(); MetaWear.mbl_mw_led_load_preset_pattern(pattern.ref(), MetaWear.LedPreset.BLINK); MetaWear.mbl_mw_led_write_pattern(device.board, pattern.ref(), MetaWear.LedColor.GREEN); MetaWear.mbl_mw_led_play(device.board); // After 5 seconds we reset the board to clear the LED, when we receive // a disconnect notice we know the reset is complete, so exit the program setTimeout(function () { device.on('disconnect', function () { process.exit(0); }); MetaWear.mbl_mw_debug_reset(device.board); }, 5000); }); }); ``` -------------------------------- ### CocoaPods Installation Source: https://mbientlab.com/tutorials/SwApple Demonstrates the command to install CocoaPods, a dependency manager for Swift and Objective-C Cocoa projects. It highlights the potential need for sudo privileges when using the default Ruby installation on macOS. ```shell sudo gem install cocoapods ``` -------------------------------- ### Record MetaWear Macro using JavaScript Source: https://mbientlab.com/tutorials/JsLinux This snippet demonstrates how to record a sequence of MetaWear commands into a macro. It involves starting the recording, executing desired commands (like LED patterns), and then ending the recording to create the macro object. The recorded macro can be executed later or set to run on boot. ```javascript console.log('Macro started'); MetaWear.mbl_mw_macro_record(device.board, 1); console.log('LED'); var pattern = new MetaWear.LedPattern(); MetaWear.mbl_mw_led_load_preset_pattern(pattern.ref(), MetaWear.LedPreset.BLINK); MetaWear.mbl_mw_led_write_pattern(device.board, pattern.ref(), MetaWear.LedColor.GREEN); MetaWear.mbl_mw_led_play(device.board); console.log('END'); var promise = new Promise((resolve, reject) => { var macro = MetaWear.mbl_mw_macro_end_record(device.board, ref.NULL, MetaWear.FnVoid_VoidP_Int.toPointer(function onSignal(context, rec) { console.log('Macro created'); console.log(rec); resolve(rec); })); }); var rec = await promise; ``` -------------------------------- ### Install Python 3.6 on Ubuntu Source: https://mbientlab.com/tutorials/PyLinux Installs Python 3.6 on Ubuntu systems using the apt-get package manager. This command first updates the package list and then installs the specified version. ```bash sudo apt-get update sudo apt-get install python3.6 ``` -------------------------------- ### Logging Download Handlers Source: https://mbientlab.com/tutorials/JsLinux Sets up callbacks for handling received log entries during a download process. It defines handlers for unknown and unhandled entries and initiates the download. ```javascript // Logger bad entry callback downloadHandler.received_unhandled_entry = MetaWear.FnVoid_VoidP_DataP.toPointer(function onSignal(context, dataPtr) { var data = dataPtr.deref(); var dataPoint = data.parseValue(); console.log('received_unhandled_entry: ' + dataPoint); }); // Actually start the log download, this will cause all the handlers we setup to be invoked MetaWear.mbl_mw_logging_download(device.board, 20, downloadHandler.ref()); ```