ztrayl3 / PyPav2

Pavlok 2 Python API
25 stars 2 forks source link

PyPav2

A simple python module for the Pavlok 2 habit breaking device. The product was released with an API that utilizes a web service, but this module directly connects to the device via Bluetooth Low Energy (BLE). While the module is essentially a wrapper around the linux gatttool, the code allows for very simple usage of the Pavlok 2 device.

Specifically, this project began as a way to implement the Pavlok 2 as a viable and cost effective alternative fear conditioning tool in behavioral psychology. An easy python interface, convenient attachment to the subject, and effective shock elliciting allow it to potentially serve a purpose in psychology research as well as consumer use.

As of January 2020, the Pavlok 2 device and this code are in use for a psychological study at Louisiana State University testing the efficacy of the device in fear conditioning studies.

For more information on this project and the Pavlok device's inner workings, please check out:

the project's wiki page,

Becky Stern's wonderfully useful Pavlok Teardown,

and of course the Pavlok official website

Requirements:

Stimulus Arguments:

* duration_on and gap only apply to the beep and vibrate functions, shock does not allow for repetition beyond one shock natively. Shock repetition can be performed outside of the function, though there is a 700ms delay between each shock.

Usage

from PyPav2 import Pavlok
device = Pavlok(mac="mac:address:of:your:device")

device.beep(5)
device.shock(2, count=2)
device.beep(10, count=1, duration_on=1.5)
device.vibrate(10, count=2, duration_on=1, gap=.5)

device.button_assign("vibrate", 7, count=2, duration_on=.5, gap=.5)

Clock Arguments:

Usage

device.clock()  # return time from Pavlok 2 on-board clock
device.clock(sync=True)  # synchronize clock to UTC time on computer
device.clock(sync=True, utcd=-5, dst=False)  # synchronize clock to local time, denoted by UTC difference and daylight savings time

Miscellaneous Functions:

device.battery()  # returns integer battery percentage
device.vibe_count()  # returns integer tally of vibrate calls
device.beep_count()  # returns integer tally of beep calls
device.shock_count()  # returns integer tally of shock calls

On the way (hopefully):