Two I2C devices with same address

Hello,

I am using an ESP32 board and I have to use two DRV2605 motor controllers with the same address (0x5A). I have to run two LRA motors independently with different inputs.
The scan part in the code below is working perfectly and I am able to detect both the devices, but I am not able to run the LRA on both of devices. Only the device connected to SDA 1 and SCL1 is vibrating the LRA. I am wondering what is the mistake in the code. I know I have to end the transmission to one device before starting the transmission to the other, but I do it at the end of the loop.

I am using this code currently:

#include <Wire.h>
#include “Adafruit_DRV2605.h”

Adafruit_DRV2605 drv;

#define SDA1 21
#define SCL1 22

#define SDA2 17
#define SCL2 16

TwoWire I2Cone = TwoWire(0);
TwoWire I2Ctwo = TwoWire(1);
uint8_t effect = 1;

void scan1(){
Serial.println(“Scanning I2C Addresses Channel 1”);
uint8_t cnt=0;
for(uint8_t i=0;i<128;i++){
I2Cone.beginTransmission(i);
uint8_t ec=I2Cone.endTransmission(true);
if(ec==0){
if(i<16)Serial.print(‘0’);
Serial.print(i,HEX);
cnt++;
}
else Serial.print("…");
Serial.print(’ ');
if ((i&0x0f)==0x0f)Serial.println();
}
Serial.print(“Scan Completed, “);
Serial.print(cnt);
Serial.println(” I2C Devices found.”);

drv.setWaveform(0, effect); // play effect
drv.setWaveform(1, 0); // end waveform
drv.go();
I2Cone.endTransmission();
}

void scan2(){
Serial.println(“Scanning I2C Addresses Channel 2”);
uint8_t cnt=0;
for(uint8_t i=0;i<128;i++){
I2Ctwo.beginTransmission(i);
drv.setWaveform(0, effect); // play effect
drv.setWaveform(1, 0); // end waveform

drv.go();
uint8_t ec=I2Ctwo.endTransmission(true);
if(ec==0){
if(i<16)Serial.print(‘0’);
Serial.print(i,HEX);
cnt++;
}
else Serial.print("…");
Serial.print(’ ');
if ((i&0x0f)==0x0f)Serial.println();
}
Serial.print(“Scan Completed, “);
Serial.print(cnt);
Serial.println(” I2C Devices found.”);

drv.setWaveform(0, effect); // play effect
drv.setWaveform(1, 0); // end waveform
drv.go();
I2Ctwo.endTransmission();
}

void setup(){
Serial.begin(115200);
I2Cone.begin(SDA1,SCL1,400000); // SDA pin 21, SCL pin 22 TTGO TQ
I2Ctwo.begin(SDA2,SCL2,400000); // SDA2 pin 17, SCL2 pin 16
Serial.println(“DRV test”);
drv.begin();
drv.useLRA();
drv.selectLibrary(6);
drv.autoCalibration();
drv.setMode(DRV2605_MODE_INTTRIG);
}

void loop(){
scan1();
Serial.println();
delay(100);
scan2();
Serial.println();
delay(5000);
}

Please edit your post and insert code tags!

I am wondering what is the mistake in the code.

Yes, there is. You have only one Adafruit_DRV2605 object (drv) and that one uses the default bus (0). Create a second driver object and assign it to the second bus (in the begin() method).