Simple test¶
Ensure your device works with this simple test.
1# SPDX-FileCopyrightText: 2017 Tony DiCola for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4# Simple demo of the DRV2605 haptic feedback motor driver.
5# Will play all 123 effects in order for about a half second each.
6import time
7
8import board
9import busio
10
11import adafruit_drv2605
12
13
14# Initialize I2C bus and DRV2605 module.
15i2c = busio.I2C(board.SCL, board.SDA)
16drv = adafruit_drv2605.DRV2605(i2c)
17
18# Main loop runs forever trying each effect (1-123).
19# See table 11.2 in the datasheet for a list of all the effect names and IDs.
20# http://www.ti.com/lit/ds/symlink/drv2605.pdf
21effect_id = 1
22while True:
23 print("Playing effect #{0}".format(effect_id))
24 drv.sequence[0] = adafruit_drv2605.Effect(effect_id) # Set the effect on slot 0.
25 # You can assign effects to up to 8 different slots to combine
26 # them in interesting ways. Index the sequence property with a
27 # slot number 0 to 7.
28 # Optionally, you can assign a pause to a slot. E.g.
29 # drv.sequence[1] = adafruit_drv2605.Pause(0.5) # Pause for half a second
30 drv.play() # play the effect
31 time.sleep(0.5) # for 0.5 seconds
32 drv.stop() # and then stop (if it's still running)
33 # Increment effect ID and wrap back around to 1.
34 effect_id += 1
35 if effect_id > 123:
36 effect_id = 1