Quantcast
Viewing all articles
Browse latest Browse all 1123

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.

ROB-14031
$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.

DEV-12757
$19.95
117

ROB-08449
$4.95
7

PRT-13870
$1.95

CAB-12016
$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.)

DEV-11113
$9.95
102

DEV-12757
$19.95
117

DEV-11021
$24.95
85

DEV-13664
$19.95
8

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

Image may be NSFW.
Clik here to view.
alt text

Parametrics

ParameterDescription
Min-Max Source Voltage2V - 5.2V.
Special FeaturesIntegrated Haptic Effects & Smart Loop Architecture.
Input SignalPWM, Analog, I2C.
Maximum Output Voltage10.4V.
Haptic Actuator Type ERM & LRA type motors only.
Shut Down Current4uA.
Quiescent Current0.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.

Image may be NSFW.
Clik here to view.
alt text

Pin LabelDescription
GNDConnect to ground.
VCCUsed to power the DRV2605L Haptic Motor Driver. Must be between 2.0 - 5.2V
SDAI2C data
SCLI2C clock
INAnalog 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.

Image may be NSFW.
Clik here to view.
alt text

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

Image may be NSFW.
Clik here to view.
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.

Image may be NSFW.
Clik here to view.
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

Image may be NSFW.
Clik here to view.
alt text

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.

Image may be NSFW.
Clik here to view.
alt text

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

Image may be NSFW.
Clik here to view.
alt text

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

Image may be NSFW.
Clik here to view.
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:

Image may be NSFW.
Clik here to view.
alt text

Wires gathered at toes

Image may be NSFW.
Clik here to view.
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.

Image may be NSFW.
Clik here to view.
alt text

Switch on the side.

Image may be NSFW.
Clik here to view.
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.

Image may be NSFW.
Clik here to view.
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:

DEV-12757
$19.95
117

SEN-09088
$1.5
7

ROB-08449
$4.95
7

COM-08374
$0.25

The Circuit

Image may be NSFW.
Clik here to view.
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:

DEV-12757
$19.95
117

ROB-08449
$4.95
7

BOB-11570
$3.95
5

COM-08375
$0.25
1

Hardware Hook-Up

Image may be NSFW.
Clik here to view.
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:

Easy Driver Hook-up Guide

Get started using the SparkFun Easy Driver for those project that need a little motion.

Getting Started with the AutoDriver - v13

SparkFun's AutoDriver is a powerful tool for controlling stepper motors. Here's how to use it.

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


Viewing all articles
Browse latest Browse all 1123

Trending Articles