<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card>
<p><b>Enabling LRA mode on the Adafruit DRV2605L Haptic Motor Controller</b></p>
<p>
For a Project I wanted to use the LRA (Linear Resonance Actuator) that Nintendo uses in their Joycons with an Arduino.
</p>
<p>The </p><p><a href="https://www.adafruit.com/product/2305">Adafruit DRV2605L</a></p>
<p> is a breakout board for the </p><p><a href="https://www.ti.com/product/DRV2605L">Texas Instruments DRV2605L</a></p>
<p>. According to both the TI as well as the Adafruit datasheet, that controller supports LRAs.</p><p>
Because Adafruit doesn't sell any LRAs, their library expects an ERM. But they mention in their documentation that an LRA should theoretically work.
</p>
<p>Except that the only public documentation on how do do that is the TI datasheet and the only documentation of anyone doing that is a user called </p><p><a href="https://forums.adafruit.com/viewtopic.php?t=191296">dustyntobin on the Adafruit forums</a></p>
<p>.
About four hours after asking for help, they responded that they solved it without mentioning what they did.</p><p> </p><p>
 // dustyntobin //
</p>
<p>---<br /></p>
<p> in case you see this: </p><p>
 // I hope you step on a lego //
</p>
<p>---<br /></p>
<p>.</p><p>To solve it myself I went through the code for the Adafruit library as well as the TI Datasheet. Mainly </p><p>
 // 8.5.4.2 Programming for LRA Open-Loop Operation //
</p>
<p>---<br /></p>
<p>and </p><p>
 // 8.6 Register Map //
</p>
<p>---<br /></p>
<p> where helpful for me here.</p><p>
To save others from having to figure it out themselves, here's the code to make it work. It's heavily inspired by one of the Adafruit example sketches:
</p>
<p>
 // #include &lt;Wire.h&gt;
#include "Adafruit_DRV2605.h"

Adafruit_DRV2605 drv;

void setup() {
  Serial.begin(9600);

  if (! drv.begin()) {
    Serial.println("Could not find DRV2605");
    while (1) delay(10);
  }

//DRV2605_REG_FEEDBACK is 0x1A
//DRV2605_REG_CONTROL3 is 0x1D

  //Switch to LRA mode:
  //Set ERM_OPEN_LOOP in 0x1D to 0 (clears what happens automatically during begin())
  drv.writeRegister8(DRV2605_REG_CONTROL3, drv.readRegister8(DRV2605_REG_CONTROL3) &amp; 0x1F);
  //Set N_ERM_LRA in 0x1A to 1
  drv.writeRegister8(DRV2605_REG_FEEDBACK, drv.readRegister8(DRV2605_REG_FEEDBACK) | 0x80);
  //Set LRA_OPEN_LOOP in 0x1D to 1
  drv.writeRegister8(DRV2605_REG_CONTROL3, drv.readRegister8(DRV2605_REG_CONTROL3) | 0x01);

  drv.selectLibrary(1);
  drv.setMode(DRV2605_MODE_INTTRIG); 
}

void loop() {
  drv.setWaveform(0, 1);
  drv.setWaveform(1, 0);
  drv.go();

  delay(500);
}
 //
</p>
<p>---<br /></p>
<p>
If you're using "HD Rumble" LRA from a Nintendo controller, the Positive lead on the DRV2605L breakout goes to the contact on the end of the ribbon, the negative lead goes to the one thats closer to where the ribbons enters the metal case.
</p>
<p>
Since I'm basically only posting this to get it out there this is the end of the blog post.
</p>
<p>---<br /></p>
<p>
 // If you liked this post or found it helpful, let me know at @dekkia@dekkia.com in the fediverse. You can also follow me there or subscribe to the RRS-feed of this blog if you want to keep up to date with what I'm doing. //
</p>
<p>---<br /></p>
<p> </p><p>~ </p><p><a href="https://dekkia.com/@dekkia">Dekkia</a></p>
<p align="center">
<a href="/blog">post index</a>
</p>
</card>
</wml>
