Haptic Motor Driver Hook Up Guide

Haptic Motor Driver Hook Up Guide a learn.sparkfun.com tutorial

Available online at: http://sfe.io/t595

Introducing the Haptic Motor Driver

Ready to add some good vibes to your project? Look no further than the Haptic Motor Driver. This board breaks out Texas Instruments’ DRV2605L haptic motor driver, which has some seriously cool features. Add meaningful feedback from your devices using the Haptic Motor Driver and an Arduino compatible device. This tutorial will get you up and running, or vibing, in no time with the I2C library for Arduino and example projects that give you the hardware setup and the code for various modes of operation.


SparkFun Haptic Motor Driver - DRV2605L

Added to your cart!


SparkFun Haptic Motor Driver – DRV2605L

In stock


ROB-14031

Ready to add some good vibes to your project? Look no further than the SparkFun Haptic Motor Driver. This board breaks out Te…


6.95

Features

  • Flexible Haptic and Vibration Driver for both ERM and LRA type motors
  • I2C Controlled Digital Playback Engine
  • Audio to Vibe
  • PWM input with 0% to 100% Duty-Cycle Control Range
  • Hardware Trigger Input
  • Built-in Waveform Sequencer and Trigger

And that is just to name a few. See the DRV2605L data sheet for a complete list.

Required Materials

You’ll need a handful of extra parts to get the Haptic Motor Driver up-and-running. Below are the basic components used in this tutorial, if you want to follow along.


SparkFun RedBoard - Programmed with Arduino

Added to your cart!


SparkFun RedBoard – Programmed with Arduino

In stock


DEV-12757

At SparkFun we use many Arduinos and we’re always looking for the simplest, most stable one. Each board is a bit different an…


19.95







124


Vibration Motor

Added to your cart!


Vibration Motor

In stock


ROB-08449

A vibration motor! This itty-bitty, shaftless vibratory motor is perfect for non-audible indicators. Use in any number of app…


4.95







7


Jumper Wires Premium 4" M/M - 20 AWG (30 Pack)

Added to your cart!


Jumper Wires Premium 4" M/M – 20 AWG (30 Pack)

In stock


PRT-13870

These are 101mm long 20AWG jumpers with male connectors on both ends. Use these to jumper from any female header on any board…


1.95


SparkFun Cerberus USB Cable - 6ft

Added to your cart!


SparkFun Cerberus USB Cable – 6ft

In stock


CAB-12016

You’ve got the wrong USB cable. It doesn’t matter which one you have, it’s the wrong one. But what if you could have the righ…


6.97







11

A microcontroller that supports I2C is required to communicate with the DRV2605L and relay the data to the user by means of vibration. The SparkFun RedBoard or Arduino Uno are popular options for this role, but just about any microcontroller development board should work. (The firmware examples use an Arduino library, if that serves as any extra motivation to use an Arduino.)


Arduino Pro Mini 328 - 5V/16MHz

Added to your cart!


Arduino Pro Mini 328 – 5V/16MHz

Out of stock


DEV-11113

It’s blue! It’s thin! It’s the Arduino Pro Mini! SparkFun’s minimal design approach to Arduino. This is a 5V Arduino running …


9.95







102


SparkFun RedBoard - Programmed with Arduino

Added to your cart!


SparkFun RedBoard – Programmed with Arduino

In stock


DEV-12757

At SparkFun we use many Arduinos and we’re always looking for the simplest, most stable one. Each board is a bit different an…


19.95







124


Arduino Uno - R3

Added to your cart!


Arduino Uno – R3

In stock


DEV-11021

This is the new Arduino Uno R3. In addition to all the features of the previous board, the Uno now uses an ATmega16U2 instead…


24.95







88


SparkFun SAMD21 Mini Breakout

Added to your cart!


SparkFun SAMD21 Mini Breakout

16 available


DEV-13664

If you’re ready to step your Arduino game up from older 8-bit/16MHz microcontrollers, the SparkFun SAMD21 Mini Breakout is …


19.95







9

Suggested Reading

The DRV2605L is designed for a handful of uses. The Technical Documents provided by Texas Instruments includes application notes, user guides, literature and blogs. The DRV2605L communicates over I2C. We’ve got a great library to make it easy to use. We’re going to be using a breadboard to connect the breakout board to the RedBoard. If these subjects sound foreign to you consider browsing through these tutorials before continuing on.

How to Solder – Through-hole Soldering

This tutorial covers everything you need to know about through-hole soldering.

Installing an Arduino Library

How do I install a custom Arduino library? It’s easy!

How to Use a Breadboard

Welcome to the wonderful world of breadboards. Here we will learn what a breadboard is and how to use one to build your very first circuit.

I2C

An introduction to I2C, one of the main embedded communications protocols in use today.

Hardware Overview

alt text

Parametrics

Parameter Description
Min-Max Source Voltage 2V – 5.2V.
Special Features Integrated Haptic Effects & Smart Loop Architecture.
Input Signal PWM, Analog, I2C.
Maximum Output Voltage 10.4V.
Haptic Actuator Type ERM & LRA type motors only.
Shut Down Current 4uA.
Quiescent Current 0.5mA – Important for your battery powered projects.

Pin Descriptions

The SparkFun Haptic Motor Driver – DRV2605L breakout board provides 6 pins to provide power to the sensor and I2C bus.

alt text

Pin Label Description
GND Connect to ground.
VCC Used to power the DRV2605L Haptic Motor Driver. Must be between 2.0 – 5.2V
SDA I2C data
SCL I2C clock
IN Analog and PWM signal input
EN Enable pin. Connect to VCC for most applications.
O- Negative motor terminal.
O+ Positive motor terminal.

Setting the Jumpers

On the front of the breakout board is a solder jumper:

  • I2C PU – This is a 3-way solder jumper that is used to connect and disconnect the I2C pullup resistors. By default, this jumper is closed, which means that both SDA and SCL lines have connected pullup resistors on the breakout board. Use some solder wick to open the jumper if you do not need the pullup resistors (e.g. you have pullup resistors that are located on the I2C bus somewhere else).

ERM and LRA Motors

The DRV2605L is capable to driving two different types of motors. So what are they? How do they work? How are they different?

Precision Microdrives published application notes on using both Eccentric Rotating Mass, ERM and Linear Resonant Actuator, LRA type motors. The default firmware for the DRV2605L is set for use with ERM type motors. There are six effects libraries for the ERM type and only one for LRA. If you want to get up and running quickly, I recommend our ERM type motor, otherwise you’ll be updating several registers in the device and spending much more time with the data sheet.

alt text

Photo courtesy of https://www.precisionmicrodrives.com/

alt text

Photo courtesy of https://www.precisionmicrodrives.com/

The difference between the two motors is how the movement of a mass is displaced. LRA vibration motors require an AC signal, driving a sine waveform that is modulated to get multiple effects. ERM vibration motors use a DC motor with a counter weight attached. The DC voltage controls the speed of the motor.

The ERM has an off-centre load, when it rotates the centripetal force causes the motor to move. The rotation is created by applying a current to the armature windings attached to the motor shaft. As these are inside a magnetic field created by the permanent magnets on the inside of the motor’s body, a force is created causing the shaft to rotate. To ensure the rotation continues in the same direction, the current in the windings is reversed. This is achieved by using static metal brushes at the motor terminals, which connect to a commutator that rotates with the shaft and windings. The different segments of the commutator connect to the brushes during rotation and the current is reversed, maintaining the direction of rotation.

In a similar method, LRAs use magnetic fields and electrical currents to create a force. One major difference is the voice coil (equivalent of the armature windings) remains stationary and the magnetic mass moves instead. The mass is also attached to a spring, which helps it return to the centre. Driving the magnetic mass up and down causes the displacement of the LRA and thereby the vibration force.1

More Suggested Reading

1: “AB-020 : UNDERSTANDING LINEAR RESONANT ACTUATOR CHARACTERISTICS.” Application Note. Https://www.precisionmicrodrives.com. N.p., n.d. Web. 29 Nov. 2016.

Using the SparFun DRV2605L Library

To use the SparkFun Haptic Motor Driver, you will need some supporting software. If you use Arduino, then you are in luck! We created an Arduino Library that makes the DRV2605L easy to use. Click the button below to download the latest version of the Haptic Motor Driver project files, which includes the Arduino library.

DOWNLOAD THE PROJECT FILES

The SparkFun DRV2605L library has every register defined, and simple functions can be called to create a custom haptic experience. Every register must be set (or use the default if that works for you). Use the data sheet to help you with the values that need to be written to the registers.

Going through the library header file, you’ll see just about every register has a comment with its function and corresponding page number in the data sheet. This board is capable of operating in seven modes and can use either an LRA or ERM type motors. There are three example sketches in the download folder using Internal Trigger mode, PWM mode and Audio-to-Vibe mode. From here it shouldn’t take much to get the device working in other modes.

Let’s explore each example in detail.

Internal Trigger Mode Example: Heated Foot Massager

This project was perfect for the season. What’s a better way to spend the day than in a recliner playing Ark: Survival Evolved riding a Stego with toasty toes and a foot massage? These are my heated house slippers.

alt text

These house slippers have a haptic motor and a heating pad in each foot giving me a gentle massage and keeping my feet warm.

Parts Needed

You will also need:

  • Pair of fuzzy slippers
  • Sewing needle
  • Thread
  • A handful of sew-on snaps
  • A pair of scissors

Hardware Hook-up

alt text

Heads up! I was testing various motors while working on this project. The schematic above is for use with a 5V motor. To use with a 3.3V motor add a second switch to the 3.3V output in the POWER section of the RedBoard and connect the other side of the switch to the Haptic Motor Driver. The board is powered from a 9V battery into the barrel jack connector.

This is what the project looked like while it was being built. Start with a new pair of comfy slippers. Make the circuit on a breadboard, load the code and test it. I chose the haptic libraries that were the strongest and have it alternating between clicking, pulsing and alerting. You can customize your massage however you’d like. There are two switches included in this circuit, so you can use the Haptic Motor Driver independently of the heating element or both at one time. The LilyPad button switch controls the heat level on the heating pad. An LED will light up indicating a low, medium or high heat setting.

alt text

I chose these slippers because cats. And, also because the tops provided me with some room to store the electronics and battery.

alt text

Carefully cut the top off the slipper using a seam ripper and/or utility knife.

alt text

I laid out the parts so the vibration motor was in the center with the heating pad and the switch off to the side. I routed all the wires toward the toes and made a hole in the top so I could feed the wires into the cat’s head. Like this:

alt text

Wires gathered at toes

alt text

Here you can see the wires pulled through. You may need to remove some stuffing. I also sewed snaps along the opening for easy access to the electronics inside.

alt text

Switch on the side.

alt text

At this point test the circuit one more time to make sure wires weren’t disconnected when pulling them towards the front and through the top. Once you have verified the circuit works repeat the process for other slipper, sew it all back together and enjoy putting your feet up!

Arduino Sketch

To complete the project, upload the following code once your circuit is built.

language:c //DIY Heated Massage Slippers //Waveforms 16, 17 and 52 cycled to give your feet some TLC //Use with ERM type Motors //Try out other libraries (1-5, 7) //and play around with the Loop Gain,  //BACKEMF gain, braking factor etc. in //Feedback register through MotorSelect function  //Hardware Hookup  //Photoresitor to analog pin 0 //  #include <Sparkfun_DRV2605L.h> #include <Wire.h>  SFE_HMD_DRV2605L HMD; const int analogInPin = A0;  // Analog input pin that the sensor is attached to const int analogOutPin = 9; // Analog output pin that the Haptic Motor Driver is attached to  int sensorValue = 0;        // value read from the sensor int outputValue = 0;        // value output to the PWM (analog out)   void setup()  {   HMD.begin();   Serial.begin(9600);   HMD.Mode(3); //PWM INPUT    HMD.MotorSelect(0x0A);   HMD.Library(7); //change to 6 for LRA motors   } void loop()  {   // read the analog in value:   sensorValue = analogRead(analogInPin);   // map it to the range of the analog out:   outputValue = map(sensorValue, 0, 1023, 0, 255);   // change the analog out value:   analogWrite(analogOutPin, outputValue);    // print the results to the serial monitor:   Serial.print("sensor = ");   Serial.print(sensorValue);   Serial.print("\t output = ");   Serial.println(outputValue);    // wait 2 milliseconds before the next loop   // for the analog-to-digital converter to settle   // after the last reading:   delay(2);  } 

PWM & Analog Input Mode Example: Light Vibes

In this example project, we are going to control an ERM motor based on analog input from a photocell that gets mapped to a range from 0-255 and uses that result to set the pulse width modulation of an output pin connected to the IN/TRIG pin on the Haptic Motor Driver. This project will give haptic effects based on the amount of ambient light in an area.

alt text

Waving your hand over the photoresistor turns off the motor, and, when you move your hand away, you can feel the ramping effects as the PWM signal increases with the amount of light detected.

Parts Needed

In addition to the basics like hook-up wire, you’ll also need the following parts:


SparkFun RedBoard - Programmed with Arduino

Added to your cart!


SparkFun RedBoard – Programmed with Arduino

In stock


DEV-12757

At SparkFun we use many Arduinos and we’re always looking for the simplest, most stable one. Each board is a bit different an…


19.95







124


Mini Photocell

Added to your cart!


Mini Photocell

In stock


SEN-09088

This is a very small light sensor. A photocell changes (also called a [photodetector](http://en.wikipedia.org/wiki/Photodetec…


1.5







7


Vibration Motor

Added to your cart!


Vibration Motor

In stock


ROB-08449

A vibration motor! This itty-bitty, shaftless vibratory motor is perfect for non-audible indicators. Use in any number of app…


4.95







7


Resistor 10k Ohm 1/6th Watt PTH

Added to your cart!


Resistor 10k Ohm 1/6th Watt PTH

In stock


COM-08374

1/6th Watt, +/- 5% tolerance PTH resistors. Commonly used in breadboards and perf boards, these 10K resistors make excellent …


0.25

The Circuit

alt text

Arduino Sketch

language:c // Control the vibration of an ERM motor // using PWM and a photoresistor.   #include <Sparkfun_DRV2605L.h> #include <Wire.h>  SFE_HMD_DRV2605L HMD; const int analogInPin = A0;  // Analog input pin that the sensor is attached to const int analogOutPin = 9; // Analog output pin that the Haptic Motor Driver is attached to  int sensorValue = 0;        // value read from the sensor int outputValue = 0;        // value output to the PWM (analog out)   void setup()  {   HMD.begin();   Serial.begin(9600);   HMD.Mode(0x03); //PWM INPUT    HMD.MotorSelect(0x0A);   HMD.Library(7); //change to 6 for LRA motors   } void loop()  {   // read the analog in value:   sensorValue = analogRead(analogInPin);   // map it to the range of the analog out:   outputValue = map(sensorValue, 0, 1023, 0, 255);   // change the analog out value:   analogWrite(analogOutPin, outputValue);    // print the results to the serial monitor:   Serial.print("sensor = ");   Serial.print(sensorValue);   Serial.print("\t output = ");   Serial.println(outputValue);    // wait 2 milliseconds before the next loop   // for the analog-to-digital converter to settle   // after the last reading:   delay(2);  } 

Audio to Vibe Mode Example: Really Feel the Music

For this project, I wanted to create something inspired by the movie, Mr. Holland’s Opus. At the end of this movie, Mr. Holland puts on a show for his son who is deaf. Theatrical lights went off along with the music that was played. The movie made it seem like it was a great visual, but, if you muted the TV, it wasn’t anything special. I set out to create an immersive experience based on what you can feel alone. The motors would be aligned to the body in a way to feel low to high frequencies. Bass at the bottom near the ankles, and treble up top near the shoulders. Each motor is linked to a specific instrument in the Orchestra, and the vibration motor should mimic the signal going in. Can you feel a symphony? This is what I set to find out.

Unfortunately, obtaining isolated tracks of specific instruments in an orchestral piece has proven to be difficult. This experiemtn leaves room for improvement. Here’s the Audio-to-vibe example.

Parts Needed

In addition to the basics like hook-up wire, you’ll also need the following parts:


SparkFun RedBoard - Programmed with Arduino

Added to your cart!


SparkFun RedBoard – Programmed with Arduino

In stock


DEV-12757

At SparkFun we use many Arduinos and we’re always looking for the simplest, most stable one. Each board is a bit different an…


19.95







124


Vibration Motor

Added to your cart!


Vibration Motor

In stock


ROB-08449

A vibration motor! This itty-bitty, shaftless vibratory motor is perfect for non-audible indicators. Use in any number of app…


4.95







7


SparkFun TRRS 3.5mm Jack Breakout

Added to your cart!


SparkFun TRRS 3.5mm Jack Breakout

In stock


BOB-11570

TRRS connectors are the audio-style connectors that you see on some phones, MP3 players and development boards. TRRS stands f…


3.95







5


Capacitor Ceramic 0.1uF

Added to your cart!


Capacitor Ceramic 0.1uF

In stock


COM-08375

This is a very common 0.1uF capacitor. Used on all sorts of applications to decouple ICs from power supplies. 0.1″ spaced lea…


0.25







1

Hardware Hook-Up

alt text

Arduino Sketch

language:c // Control the vibration of an ERM motor // using an AC Coupled Audio Signal into the IN/TRIG pin   #include <Sparkfun_DRV2605L.h> #include <Wire.h>  SFE_HMD_DRV2605L HMD;  void setup()  {   HMD.begin();   Serial.begin(9600);   Serial.print("Audio to Vibe");   HMD.Mode(0x04); //Audio INPUT    HMD.cntrl1(0xB3); // Set the AC Couple bit in Control 1   HMD.cntrl3(0x62); // Set the Analog bit in Control 3   HMD.MotorSelect(0x0A);   HMD.Library(7); //change to 6 for LRA motors   } void loop()  { } 

Resources and Going Further

Now that you have been through three of modes of operation, try out the other four and use an LRA motor! How will you add haptics to your next project?

Here are are the numerous resources and documents mentioned through out this tutorial.

For more motor-related fun, check out these other great SparkFun tutorials:

Hacker in Residence: The Harmonic Skew Zoetrope

Check out Hacker in Residence, Jesse’s awesome Harmonic Skew Zoetrope in this project tutorial.

Experiment Guide for RedBot with Shadow Chassis

This Experiment Guide offers nine experiments to get you started with the SparkFun RedBot. This guide is designed for those familiar with our SparkFun Inventors Kit and want to take their robotics knowledge to the next level.

Serial Controlled Motor Driver Hookup Guide

Hookup guide for the Serial Controlled Motor Driver

learn.sparkfun.com |
CC BY-SA 3.0
| SparkFun Electronics | Niwot, Colorado

You may also like...