DRV2605 impossile to generate software i2c on two different bus

Hi to everyone,

it’s been days that i’m trying to generate a secondary i2c bus to drive my DRV2605 with non hardware default i2c bus on ESP32. What i need to do is :

1- to keep going with a first i2c bus driving a MPU9250 (so using pins 21 SDA1 and 22 SCL1, let’s name it Wire1

2- having a second i2c bus on pins 4 SDA2 and 17 SCL2. let’s name this Wire2

it looks like impossible using the library to have this

what i’m able to do is to move the original hardware i2c from 21-22 to 4-17 but this means that the original one it disappear and can’t be used

this does not work for a normal single core loop, nor using two different tasks using Core1 and Core2 (and this is what i’m going to do to run two instances of Wire and use simultaneously Wire1 and Wire2 and keep using MPU and DRV at the same time).

i’m stuck… :roll:

with a friend we understood that the library is using inside Wire.begin and it does not allow the call to change pins

any ideas :?:

thanks

Richie

On an ESP32 you can have 2 I2C channel: Wire and Wire1. The names are fixed and defined in Wire.h. For instructions to use see : https://randomnerdtutorials.com/esp32-i … ino-ide/#7

Hi Paul,

Many thanks for your reply

but i tried the last solution in your link several days ago and it does not work

in particular, with the library you provided, i can’t do &Wire1 in the begin assignment, it does not recognize it as correct

any thoughts?

Richie

Hey paul,

just to let you see what i did, here is the code

https://pastebin.com/mtGrWjsk

let me know what you think. You’ll find commented what it does not work and gives me an error compiling

in this way it compiles but does not work

thanks for your kind support

Richie

Hi Richie,

The issue with your sample code is that the usage of Wire is hard coded in the DRV2605 library. You will have to make adjustments to the library to allow for Wire1 usage.

The MPU9250 allows for Wire1 to use : (based on an example)

#define I2Cport Wire1
#define MPU9250_ADDRESS MPU9250_ADDRESS_AD1
MPU9250 myIMU(MPU9250_ADDRESS, I2Cport, I2Cclock);

As part of the creating that instance ‘myIPU’, it will perform a .begin() call. This will fail as there are NO default pins for Wire1 but the return code is neglected by the driver. In the sketch, as part of setup(), you have set Wire1.begin(SDA_2, SCL_2) BEFORE doing any call to myIMU (eg. myIMU.readByte()). I have tested this by adjusting my BM280 library and that worked.

Still this leads to another question… why would you use 2 different I2C channels. The I2C addresses are different so you could put both on the same channel.

Hi Paul,

thanks for you comment

at the end of the story, since the library does not allow to place the new pins, i had to leave wire1 for DRV and place the wire1 for IMU where i could place differet pins

my invite is to write a modification on the library to force different pins

thans a lot