Welcome to ADI Study Watch SDK documentation!

Install the whl file

pip install adi_study_watch

Firmware Setup

Follow the link (pdf) to setup firmware for the study watch.

Working with hexadecimal values in python

>>> val = 13
>>> '0x%X' % val # convert int value to hexadecimal
# '0xD'
>>> hex_val = '0xD'
>>> int(hex_val, 16) # convert hexadecimal value to int
# 13

Basic Example using USB:

import time
from datetime import datetime
from adi_study_watch import SDK

# callback function to receive adxl data
def callback_data(data):
    sequence_number = data["payload"]["sequence_number"]
    for stream_data in data["payload"]["stream_data"]:
        dt_object = datetime.fromtimestamp(stream_data['timestamp'] / 1000)  # convert timestamp from ms to sec.
        print(f"seq :{sequence_number} timestamp: {dt_object} x,y,z :: ({stream_data['x']}, "
              f"{stream_data['y']}, {stream_data['z']})")


if __name__ == "__main__":
    sdk = SDK("COM4")
    application = sdk.get_adxl_application()
    application.set_callback(callback_data)

    # quickstart adxl stream
    application.start_sensor()
    application.enable_csv_logging("adxl.csv") # logging adxl data to csv file
    application.subscribe_stream()
    time.sleep(10)
    application.unsubscribe_stream()
    application.disable_csv_logging()
    application.stop_sensor()

Example using Ble:

import time
from datetime import datetime
from adi_study_watch import SDK

# callback function to receive adxl data
def callback_data(data):
    sequence_number = data["payload"]["sequence_number"]
    for stream_data in data["payload"]["stream_data"]:
        dt_object = datetime.fromtimestamp(stream_data['timestamp'] / 1000)  # convert timestamp from ms to sec.
        print(f"seq :{sequence_number} timestamp: {dt_object} x,y,z :: ({stream_data['x']}, "
              f"{stream_data['y']}, {stream_data['z']})")


if __name__ == "__main__":
    sdk = SDK("COM6", mac_address="C5-05-CA-F1-67-D5") # watch MAC address.
    application = sdk.get_adxl_application()
    application.set_callback(callback_data)

    # quickstart adxl stream
    application.start_sensor()
    application.enable_csv_logging("adxl.csv") # logging adxl data to csv file
    application.subscribe_stream()
    time.sleep(10)
    application.unsubscribe_stream()
    application.disable_csv_logging()
    application.stop_sensor()

How to log and download adxl stream data.

from adi_study_watch import SDK
import time

# SDK setup
sdk = SDK("COM4")
adxl_application = sdk.get_adxl_application()
fs_application = sdk.get_fs_application()


# START LOGGING
adxl_application.start_sensor()
fs_application.subscribe_stream(fs_application.STREAM_ADXL)
fs_application.start_logging()
print(fs_application.get_status()["payload"]["status"])

print("logging...")
time.sleep(20)

# STOP LOGGING
adxl_application.stop_sensor()
fs_application.unsubscribe_stream(fs_application.STREAM_ADXL)
fs_application.stop_logging()
print(fs_application.get_status()["payload"]["status"])

# List all the files available to download.
files = fs_application.ls()
for x in files:
    print(x["payload"]["filename"])

# download data from the watch and save it to a file.
fs_application.download_file(files[0]["payload"]["filename"], download_to_file=True, display_progress=True)

How to plot adxl data with Matplotlib.

from adi_study_watch import SDK
from matplotlib import pyplot
from matplotlib.animation import FuncAnimation

# callback to store adxl data in array, we are only storing 200 values.
def callback_data(data, adxl_time, adxl_x, adxl_y, adxl_z):
    if len(adxl_time) > 200:
        del adxl_time[:5]
        del adxl_x[:5]
        del adxl_y[:5]
        del adxl_z[:5]

    for value in data["payload"]["stream_data"]:
        adxl_time.append(value["timestamp"])
        adxl_x.append(value["x"])
        adxl_y.append(value["y"])
        adxl_z.append(value["z"])

x_data, y_data, z_data, time = [], [], [], []

# figure and x,y,z line initiated.
figure = pyplot.figure()
x_line, = pyplot.plot(time, x_data, '-')
y_line, = pyplot.plot(time, y_data, '-')
z_line, = pyplot.plot(time, z_data, '-')

# plot update function
def update(frame, plot_time, plot_x_data, plot_y_data, plot_z_data):
    x_line.set_data(plot_time, plot_x_data)
    y_line.set_data(plot_time, plot_y_data)
    z_line.set_data(plot_time, plot_z_data)
    figure.gca().relim()
    figure.gca().autoscale_view()
    return x_line, y_line, z_line

# SDK setup and sensor start
sdk = SDK("COM4")
application = sdk.get_adxl_application()
# setting callback with some reference list to plot from
application.set_callback(callback_data, args=(time, x_data, y_data, z_data))

# start sensor
application.start_sensor()
application.subscribe_stream()

# plot started
animation = FuncAnimation(figure, update, interval=10, fargs=(time, x_data, y_data, z_data))
pyplot.show()
_images/plot.png

For more detail on FuncAnimation visit matplotlib animation api.

All API modules:

Module Index

Indices and tables