Contributors

Overview

The DRV2605 from TI is a fancy little motor driver. Rather than controlling a stepper motor or DC motor, its designed specifically for controlling haptic motors - buzzers and vibration motors. Normally one would just turn those kinds of motors on and off, but this driver has the ability to have various effects when driving a vibe motor. For example, ramping the vibration level up and down, 'click' effects, different buzzer levels, or even having the vibration follow a musical/audio input.

This chip is controlled over I2C - after initialization, a 'string' of multiple effects can be strung together in the chips memory and then triggered to actuate in a row. The built in effects are much much nicer than just 'on' and 'off' and will make your haptic project way nicer feeling.

We put this nice chip onto a breakout board. it works with both 3V and 5V power/logic, we have code specifically for Arduino but porting it to any I2C-capable processor should be quite simple. Check it out and get buzzing!

Pinouts

Power Pins

The motor driver/controller on the breakout requires 3-5V power. You can use either, whichever logic level you use on your embedded processor

Vin - To power the board, give it the same power as the logic level of your microcontroller - e.g. for a 5V micro like Arduino, use 5V

GND - common ground for power and logic

I2C Pins

SCL - I2C clock pin, connect to your microcontrollers I2C clock line. This pin can be used with 3V or 5V logic, and there's a 10K pullup on this pin.

SDA - I2C data pin, connect to your microcontrollers I2C data line. This pin can be used with 3V or 5V logic, and there's a 10K pullup on this pin.

Other!

IN/TRIG - This is a general purpose pin that can be used for a couple different uses. One use is to read analog audio in to control the audio-to-haptic code. Another use is to 'trigger' the effects to go rather than sending a I2C command.

Attach Motor

Arduino Code

Wiring for Arduino

You can easily wire this breakout to any microcontroller, we'll be using an Arduino. For another kind of microcontroller, just make sure it has I2C capability, then port the code - its pretty simple stuff!

Connect Vin to the power supply, 3-5V is fine. Use the same voltage that the microcontroller logic is based off of. For most Arduinos, that is 5V

Connect GND to common power/data ground

Connect the SCL pin to the I2C clock SCL pin on your Arduino. On an UNO & '328 based Arduino, this is also known as A5, on a Mega it is also known as digital 21 and on a Leonardo/Micro, digital 3

Connect the SDA pin to the I2C data SDA pin on your Arduino. On an UNO & '328 based Arduino, this is also known as A4, on a Mega it is also known as digital 20 and on a Leonardo/Micro, digital 2

Install Adafruit_DRV2605 Library

To begin controling the motor chip, you will need to install the Adafruit_DRV2605 Library. You can do that by going to the Arduino library manager under Sketch -> Include Library -> Manage Libraries...

Then search for DRV2605 and find the Adafruit DRV2605 Library and click Install

Multiple Waveforms

You can also string together multiple effects in a row, up to 7. Check out the complex example sketch, and setWaveform for each slot. The last slot should be set to 0 to indicate its the end.

When you are ready to place the full waveform sequence, send the go() command!

Audio

You can also turn the DRV2605 into an audio-to-vibration driver. Use a 1uF capacitor in series to line level voltage audio into the IN pin, then load up the audio example sketch. If you don't feel anything, try boosting up the source audio volume, it has to be pretty loud!

Python & CircuitPython

It's easy to use the DRV2605 controller with Python or CircuitPython, and the Adafruit CircuitPython DRV2605 module. This module allows you to easily write Python code that controls the vibration of the motor.

If your default Python is version 3 you may need to run 'pip' instead. Just make sure you aren't trying to use CircuitPython on Python 2.x, it isn't supported!

CircuitPython & Python Usage

To demonstrate the usage of the board we'll initialize it and vibrate the motor using effects built-in to the DRV2605 chip. First run the following code to import the necessary modules and initialize the I2C connection with the controller:

Now you're ready to start vibrating the motor with different built-in effects. First you need to choose an effect to play based on its ID number. See table 11.2 in the datasheet for a list of all the effects:

Each effect needs to be loaded into one of eight slots in the Waveform Sequencer:

You access the Waveform Sequencer by using the sequence property and providing an index for the slot location. To specify the effect, use the special Effect class provided in the library, giving it the effect number.

For example, here is how to load Effect ID No. 1 "Strong Click - 100%" into slot 0 of the sequence:

Try other effects to see which ones are interesting and useful in your project!

You can combine multiple effects to play back at once and create interesting compound effects. When you call play, the sequence is played until it either reaches a 0 or plays through all the slots. There's also a special Pause class you can use to generate a pause. You specify the pause time in seconds and it has to occupy a slot.

Let's play the two effects from above, separated by a half second pause:

The call to play is non-blocking, that is, it returns immediately and the rest of the code after that keeps running. The DRV2605 is doing the work of playing back the loaded sequence. If you ever want to stop the current playback, use the stop function:

Changing Motor Types

Finally it's uncommon but you might want to switch between using a linear resonance actuator motor or eccentric rotating mass motor. The small flat pancake motors like sold in the Adafruit shop are ERM motors and the library defaults to their usage. However you can call the use_LRM function to switch to configure the chip to use a LRM style motor:

That's all there is to using the DRV2605 with CircuitPython! Happy motoring!

Full Example Code

Here's a complete example of using the board to play the 123 effects for a half second each. Save this as main.py on your board and watch the REPL output to see the effect ID printed as it plays on the motor.

# 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

# 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

OUT OF STOCK NOTIFICATION

YOUR NAME

YOUR EMAIL

You have been successfully subscribed to the Notification List for this product and will therefore receive an e-mail from us when it is back in stock!

For security reasons, an e-mail has been sent to you acknowledging your subscription. Please remember that this subscription will not result in you receiving any e-mail from us about anything other than the restocking of this item.

If, for any reason, you would like to unsubscribe from the Notification List for this product you will find details of how to do so in the e-mail that has just been sent to you!