Introduction

Documentation Status Discord Build Status

CircuitPython module for the DRV2605 haptic feedback motor driver.

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.

Installing from PyPI

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:

pip3 install adafruit-circuitpython-drv2605

To install system-wide (this may be required in some cases):

sudo pip3 install adafruit-circuitpython-drv2605

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .env
source .env/bin/activate
pip3 install adafruit-circuitpython-drv2605

Usage Example

See examples/drv2605_simpletest.py for a demo of the usage.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

Documentation

For information on building library documentation, please check out this guide.

Table of Contents

Simple test

Ensure your device works with this simple test.

examples/drv2605_simpletest.py
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# Simple demo of the DRV2605 haptic feedback motor driver.
# Will play all 123 effects in order for about a half second each.
# Author: Tony DiCola
import time

import board
import busio

import adafruit_drv2605


# Initialize I2C bus and DRV2605 module.
i2c = busio.I2C(board.SCL, board.SDA)
drv = adafruit_drv2605.DRV2605(i2c)

# Main loop runs forever trying each effect (1-123).
# See table 11.2 in the datasheet for a list of all the effect names and IDs.
#   http://www.ti.com/lit/ds/symlink/drv2605.pdf
effect_id = 1
while True:
    print("Playing effect #{0}".format(effect_id))
    drv.sequence[0] = adafruit_drv2605.Effect(effect_id)  # Set the effect on slot 0.
    # You can assign effects to up to 7 different slots to combine
    # them in interesting ways. Index the sequence property with a
    # slot number 0 to 6.
    # Optionally, you can assign a pause to a slot. E.g.
    # drv.sequence[1] = adafruit_drv2605.Pause(0.5)  # Pause for half a second
    drv.play()  # play the effect
    time.sleep(0.5)  # for 0.5 seconds
    drv.stop()  # and then stop (if it's still running)
    # Increment effect ID and wrap back around to 1.
    effect_id += 1
    if effect_id > 123:
        effect_id = 1

adafruit_drv2605

CircuitPython module for the DRV2605 haptic feedback motor driver. See examples/simpletest.py for a demo of the usage.

  • Author(s): Tony DiCola
class adafruit_drv2605.DRV2605(i2c, address=90)[source]

TI DRV2605 haptic feedback motor driver module.

library

The library selected for waveform playback. Should be a value of:

  • LIBRARY_EMPTY: Empty
  • LIBRARY_TS2200A: TS2200 library A (the default)
  • LIBRARY_TS2200B: TS2200 library B
  • LIBRARY_TS2200C: TS2200 library C
  • LIBRARY_TS2200D: TS2200 library D
  • LIBRARY_TS2200E: TS2200 library E
  • LIBRARY_LRA: LRA library

See the datasheet for the meaning and description of effects in each library.

mode

The mode of the chip. Should be a value of:

  • MODE_INTTRIG: Internal triggering, vibrates as soon as you call play(). Default mode.
  • MODE_EXTTRIGEDGE: External triggering, edge mode.
  • MODE_EXTTRIGLVL: External triggering, level mode.
  • MODE_PWMANALOG: PWM/analog input mode.
  • MODE_AUDIOVIBE: Audio-to-vibration mode.
  • MODE_REALTIME: Real-time playback mode.
  • MODE_DIAGNOS: Diagnostics mode.
  • MODE_AUTOCAL: Auto-calibration mode.

See the datasheet for the meaning of modes beyond MODE_INTTRIG.

play()[source]

Play back the select effect(s) on the motor.

sequence

List-like sequence of waveform effects. Get or set an effect waveform for slot 0-6 by indexing the sequence property with the slot number. A slot must be set to either an Effect() or Pause() class. See the datasheet for a complete table of effect ID values and the associated waveform / effect.

E.g. ‘slot_0_effect = drv.sequence[0]’, ‘drv.sequence[0] = Effect(88)’

set_waveform(effect_id, slot=0)[source]

Select an effect waveform for the specified slot (default is slot 0, but up to 7 effects can be combined with slot values 0 to 6). See the datasheet for a complete table of effect ID values and the associated waveform / effect.

stop()[source]

Stop vibrating the motor.

use_ERM()[source]

Use an eccentric rotating mass motor (the default).

use_LRM()[source]

Use a linear resonance actuator motor.

class adafruit_drv2605.Effect(effect_id)[source]

DRV2605 waveform sequence effect.

id

Effect ID.

raw_value

Raw effect ID.

class adafruit_drv2605.Pause(duration)[source]

DRV2605 waveform sequence timed delay.

duration

Pause duration in seconds.

raw_value

Raw pause duration.

Indices and tables