How to command two I2Cs asynchronously in DUE

Hi, everyone.
I’m trying to command two LRAs (linear-resonant-actuator) with DRV2605, and I can control them synchronously via two I2Cs on DUE now. I connected two drivers to I2Cs respectively and sent the frequency to get the shake.

I want these two drivers can work in different frequencies, but I don’t know how to send commands independently. My thought is to set X and Y for two I2Cs, and send corresponding commands.

Can someone give me some suggestions about the code or example code to control 2 I2Cs on ARDUINO DUE?

Sorry for my poor English expression.

Adafruit_DRV2605.CPP file.txt (3.59 KB)

Basic(Drv2605 library.txt (678 Bytes)

The data sheet shows the devices use a fixed address, so the only way I can see is to use both I2C interfaces. Connect one to SDA and SCL, and the other to SDA1 and SCL1, then use Wire for one and Wire1 for the other.

Thank you for reply.

I have changed the code, and I can control them with Wire and Wire1. But I only achieved to control them with same commands, how can I do this individually? I don’t know how to set two effects for two I2C ports.

This is new code that I have changed:
/***************************************************
This is a library for the Adafruit DRV2605L Haptic Driver

----> http://www.adafruit.com/products/2306

Check out the links above for our tutorials and wiring diagrams
This motor/haptic driver uses I2C to communicate

Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!

Written by Limor Fried/Ladyada for Adafruit Industries.
MIT license, all text above must be included in any redistribution
****************************************************/

#if ARDUINO >= 100
#include “Arduino.h”
#else
#include “WProgram.h”
#endif #define Wire Wire#define Wire Wire1

#include <Wire.h>

#include <Adafruit_DRV2605.h>

//
/*!
@brief Instantiates a new DRV2605 class
*/
/
/
// I2C, no address adjustments or pins
Adafruit_DRV2605::Adafruit_DRV2605() {
}

//
/*!
@brief Setups the HW
*/
/
/
boolean Adafruit_DRV2605::begin() {
Wire.begin();
Wire1.begin(); uint8_t id = readRegister8(DRV2605_REG_STATUS);
//Serial.print(“Status 0x”); Serial.println(id, HEX);

writeRegister8(DRV2605_REG_MODE, 0x00); // out of standby

writeRegister8(DRV2605_REG_RTPIN, 0x00); // no real-time-playback

writeRegister8(DRV2605_REG_WAVESEQ1, 1); // strong click
writeRegister8(DRV2605_REG_WAVESEQ2, 0);

writeRegister8(DRV2605_REG_OVERDRIVE, 0); // no overdrive

writeRegister8(DRV2605_REG_SUSTAINPOS, 0);
writeRegister8(DRV2605_REG_SUSTAINNEG, 0);
writeRegister8(DRV2605_REG_BREAK, 0);
writeRegister8(DRV2605_REG_AUDIOMAX, 0x64);

// ERM open loop

// turn off N_ERM_LRA
writeRegister8(DRV2605_REG_FEEDBACK, readRegister8(DRV2605_REG_FEEDBACK) & 0x7F);
// turn on ERM_OPEN_LOOP
writeRegister8(DRV2605_REG_CONTROL3, readRegister8(DRV2605_REG_CONTROL3) | 0x20);

return true;
}

void Adafruit_DRV2605::setWaveform(uint8_t slot, uint8_t w) {
writeRegister8(DRV2605_REG_WAVESEQ1+slot, w);
}

void Adafruit_DRV2605::selectLibrary(uint8_t lib) {
writeRegister8(DRV2605_REG_LIBRARY, lib);
}

void Adafruit_DRV2605::go() {
writeRegister8(DRV2605_REG_GO, 1);
}

void Adafruit_DRV2605::setMode(uint8_t mode) {
writeRegister8(DRV2605_REG_MODE, mode);
}

/********************************************************************/

uint8_t Adafruit_DRV2605::readRegister8(uint8_t reg) {
uint8_t x ;
// use i2c
Wire.beginTransmission(DRV2605_ADDR);
Wire.write((byte)reg);
Wire.endTransmission();
Wire.requestFrom((byte)DRV2605_ADDR, (byte)1);
x = Wire.read();

// use i2c
Wire1.beginTransmission(DRV2605_ADDR);
Wire1.write((byte)reg);
Wire1.endTransmission();
Wire1.requestFrom((byte)DRV2605_ADDR, (byte)1);
x = Wire1.read();// Serial.print("$"); Serial.print(reg, HEX);
// Serial.print(": 0x"); Serial.println(x, HEX);

return x;
}

void Adafruit_DRV2605::writeRegister8(uint8_t reg, uint8_t val) {
// use i2c
Wire.beginTransmission(DRV2605_ADDR);
Wire.write((byte)reg);
Wire.write((byte)val);
Wire.endTransmission();
// use i2c
Wire1.beginTransmission(DRV2605_ADDR);
Wire1.write((byte)reg);
Wire1.write((byte)val);
Wire1.endTransmission();
}

/****************/

You will have to change the library to accept another parameter to each of those calls to denote which device you are commanding.

I have solved this problem, these two files are the new library, hope helpful for someone.

Adafruit_DRV2605.cpp (4.41 KB)

Adafruit_DRV2605.h (2.48 KB)