I'm struggling to control the DRV2605 via the I2C. I'm using the evaluation board and I'm interfacing with an arduino.
I have been following the steps very closely but I can't get the device to playback anything. I have initialized, calibrated (generated activity on the actuator), saved the calibrations, loaded a waveform into 0x04 set 0x0C but nothing. On the evaluation board I have followed the instructions to set external I2c input mode.
I wondered if anyone was able to look at my arduino sketch to see where I'm going wrong:
#include <Wire.h>
#define drv_address 0x5A
void setup(){
Wire.begin();
Serial.begin(9600);
delay(1000);
autoCalibrate();
delay(1000);
getDeviceInfo();
delay(1000);
test();
}
void loop(){}
void autoCalibrate(){
// calibtarion mode
setRegister(0x01, 0x07);
//select Actuator
//setRegister(0x1a, 0xA4); //LRA
setRegister(0x1a, 0x24); //ERM
//set voltage
setRegister(0x16, 160);
//clamp voltage
setRegister(0x17, 200);
//start calibration
byte go = 1;
setRegister(0x0C, go);
// wait for calibration
while(go > 0){
Wire.requestFrom(drv_address, 1);
go = Wire.read(); // wait until this reset to 0
}
// save calibration
setRegister(0x1E, 0x01);
// wait for settings to be saved
byte OPT = 0;
Wire.beginTransmission(drv_address);
Wire.write(0x20);
Wire.endTransmission();
while(OPT < 1){
Wire.requestFrom(drv_address, 1);
byte reg = Wire.read();
OPT = reg & B00000100; // check Bit2 - OPT_Status
}
}
void test(){
// deselect STABDBY
setRegister(0x01, 0x00);
// select library
setRegister(0x03, 0x02);
// set waveform
setRegister(0x04, 0x01); // Strong Click - 100%
Serial.println("Playback waveform");
byte go = 0;
//go
setRegister(0x0C, go); // Strong Click - 100%
while(go < 1){
Wire.requestFrom(drv_address, 1);
go = Wire.read();
Serial.print("Status: ");
Serial.println(go, BIN);
}
Serial.println("Done");
}
void checkRegister(byte reg, char name[]){
Wire.beginTransmission(drv_address);
Wire.write(reg);
Wire.endTransmission();
Wire.requestFrom(drv_address, 1);
Serial.print(name);
Serial.print(" (");
Serial.print(reg, HEX);
Serial.print(") : ");
Serial.println(Wire.read(), BIN);
}
void setRegister(byte reg, byte val){
Wire.beginTransmission(drv_address);
Wire.write(reg);
Wire.write(val);
Wire.endTransmission();
}
void getDeviceInfo(){
Serial.println("------- Device Info -------");
checkRegister(0x00, "Device Info");
checkRegister(0x16, "Rated Voltage");
checkRegister(0x17, "Overdrive Clamp Voltage");
checkRegister(0x18, "Auto Calibration Compensation");
checkRegister(0x19, "Auto Calibration Back-EMF");
checkRegister(0x1A, "Feedback Control");
checkRegister(0x1B, "Control 1");
checkRegister(0x1C, "Control 2");
checkRegister(0x1D, "Control 3");
checkRegister(0x01, "STANDBY");
checkRegister(0x04, "WAVEFORM");
Serial.println("----------------------------");
}