I2C use 2 libraries on the same I2C bus ?

Am building a big robot, 80% done. Eight Arduinos on the same I2C bus, one master, 7 slaves - works perfectly. Now I would like to add a PCA9685 (Adafruit) to the same I2C network, however the Adafruit library for it, assumes (I think) complete control of the I2C bus. I tried a few variations and conclude that the wire and adafruit libraries cannot coexist on the same bus. I know I can use a serial connection to a new Arduino which can then drive the PCA9685 with it's I2C bus. I would like to avoid that if possible.

I have seen the softi2c library but cannot find that it will run two buses concurrently.

Does anyone know of an alternative approach? Not looking for complete solutions, just ideas about things I may not have seen in perusing the net. Thanks

There shouldn't be a problem using both. Did you get an error when compiling? Can u post your code.

Here’s the code. No compile errors. Serial.prints indicate am sending the right values to the pwm.setPWM command. Getting nothing at the servos.

Had to remove several sections in order to get under 9500 word limit. Didn’t remove anything relevant to the problem.

#include <Wire.h>
#include <EEPROM.h>
#include <MatrixOrbitali2c.h>
#include <stdlib.h> 
#include <Adafruit_PWMServoDriver.h>
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x40);
MatrixOrbitali2c lcd(0x28);
 
 

//***********  new sweep structure  **************
struct ServoMgr{
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Variables for each instance of ServoMgr (e.g. fl, fr, etc.)
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    int top;
    int bottom;
    int period;
	int servoValue; 
    int servoRange;
	int pwmvalue;
	int corFact;
    long startTime; 
    long time;
    String name; // Just so we know which one we are for debugging.
    int pwmpin;
    	    
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    // Instance functions to act on the variables above and any parameters
    // passed in.  We start with a Setup() function here, but you can 
    // use any names you want.
    //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    
    void Setup(int servoPin, String servoName){
        pwmpin = servoPin; 
        name = servoName;
        
        /* The following is not necessary, but this would be a good place to 
           initialize anything at startup. */
        top = 0;
        bottom = 0;
        servoRange=top-bottom;
        startTime=0;
        time=0;
    }
    void Move(int newBottom, int newTop, int newPeriod) {
		if(bottom != newBottom || top != newTop || period != newPeriod*100)
		{
            Initialize(newBottom, newTop, newPeriod);
          //  Serial.println(name + " sweep after Initialize");
        }
		
		time = millis() - startTime;
		if(top>bottom && servoValue>=top){
        	Serial.println(servoValue);
			return;
			};
		if(top<bottom && servoValue <=top){
			Serial.println(servoValue);
			return;
			};
		servoValue=map(time,0, period,bottom,top);
		pwmvalue=map(servoValue,0,180,150,600);
		pwm.setPWM(pwmpin,0,pwmvalue);
		Serial.print("servovalue  ");
		Serial.print(servoValue);
		Serial.print("     pwmvalue  ");
		Serial.println(pwmvalue);	
		
	}
    void Sweep(long newBottom, long newTop, long newPeriod){
		  //  Serial.println(String(bottom)+"  "+String(newBottom)+"  "
		  //  +String(top)+"  "+String(newTop)+"  "+String(period)+"  "
		  //  +String(newPeriod*100));
        if(bottom != newBottom || top != newTop || period != newPeriod*100)
		{
            Initialize(newBottom, newTop, newPeriod);
          //  Serial.println(name + " sweep after Initialize");
        }
        
        time = millis() - startTime; 
        if(time >= period)
            InitTime();
        
        /* Little Trick: The absolute value function, abs(), makes a nice up/down when spread accross 0 (-10 to 10).
           I'm screwing it up right now, but you might consider it :) 
           
           servoValue = map(servoRange*abs(period/2 - time),0,servoRange*(period),bottom,top); 
        */
        
        
        if(time >=0 && time <= period/2){
	//		Serial.println(String(servoRange)+"  "+String(time)+"  0  "+String(servoRange)
	//		+"  "+String(period/2)+"  "+String(bottom)+"  "+String(top));
            servoValue=map(servoRange*time,0, servoRange*(period/2),bottom,top)+corFact;
		}
        if(time > period/2 && time <= period){		
            servoValue=map(-servoRange*(time-period),0,servoRange*(period/2),bottom,top)+corFact;
		}        
        /*  Serial.print (time,DEC);
		  Serial.print("  ");
		  Serial.print(name);
		  Serial.print("  value =  ");
		  Serial.println(servoValue+corFact,DEC);
		 */ 
         //Serial.println(name + ": bottom = " + String(bottom) + " top = " + String(top) + " servoValue = " + String(servoValue+corFact,DEC));

       // myServo.write(servoValue);//DEBUG-UNCOMMENT THIS LINE IN REAL LIFE
    }
    
    void Initialize(int newBottom, int newTop, int newPeriod){
        bottom = newBottom;
        top = newTop;
        period = newPeriod * 100;
        servoRange=top-bottom;
        InitTime();        
      //  Serial.println(name + ": - New Values Initialized.");
      //  Serial.println("  " + name + ": bottom = " + String(bottom) + " top = " + String(top) + " period = " + String(period));
    }
    
    void InitTime(){
        time=0;
        startTime=millis();
    }
};
ServoMgr lc,rc;



//************************  Master Variables   *******************************
int rled = A0;
int tled = A1;
byte inByte;
byte stringPos;
byte cb[1200];  // for maximum of one master and 12 slaves
byte cbb[25];
byte cbsend[25];
int swt=0;
int swr=0;

												
//********************** end Master Variables  ********************************

// *******************    begin setup   **************************************
void setup() {
Serial.begin(57600);
Serial1.begin(57600);
Wire.begin();  
lcd.begin(4,20); 
pwm.begin();
pwm.setPWMFreq(1600); 
uint8_t twbrbackup = TWBR;
TWBR = 12;
pinMode(tled,OUTPUT);
pinMode(rled,OUTPUT);
lc.Setup(lcircles,"left ciccles");
rc.Setup(rcircles,"right circles");


//  *********************  end of setup  ***************************************

//****************  loop    loop    loop   *****************************
void loop(){
 //if(schedule(3))cbout();
// if(schedule(3))cbin();
cbout();
delay(30);
cbin();
delay(30);
//if(schedule(0)) printcb();   // {2000,0},{50,0},{1000,0},{50,0}
if(schedule(1)) lcdprint();	  //          
if(schedule(2)) slave10(); 
if(schedule(1)) mfa();
mfa();

updatebuffer();	

}

//**************** end loop     end loop    end loop  *****************
//******************  mode function action  **************************
void mfa(){
//Serial.println("mfa");
	switch(mode){  // 2-8 only here, 0-2 and 9 are in teh R2Base
		case 2:
			switch(function){
				case 1:  // misc testing here 
					switch(action){
						case 1:  // circles folded back
						Serial.println("2 1 1");
							lc.Move(175,85,60);
							rc.Move(175,85,60);
							
						break;
						case 2:  // circles folded out
						Serial.println("2 1 2");
							lc.Move(85,175,60);
							rc.Move(85,175,60);
						break;
					}
				break;
			}
		break;
	}
}
//***************  end mode function action  *****************************






//*************** OUT***********out***********************
void cbout()
{
 if(swt==0) digitalWrite(tled,HIGH);
 for(int i=1;i<=2;i++) {
     for(int j=2; j<=numslave;j++) { // set to cover all slaves
     for(int jj=0;jj<=24;jj++) cbsend[jj]=cb[((j-2)*50)+((i-1)*25)+jj];
 Wire.beginTransmission(j);
 Wire.write(cbsend, 25);
 Wire.endTransmission();
     }
 }
if(swt==5) digitalWrite(tled,LOW);
if(swt==8) swt=-1;
swt++;
} 
//*******************  end of OUT  ****************************
//*****************IN************IN********************
void cbin() {
  if(swr==0) digitalWrite(rled,HIGH);
  for(int i=1;i<=2;i++) {
  for(int j=2;j<=numslave;j++) {
Wire.requestFrom(j,25);
for (int kk=0;kk<=24;kk++) cbb[kk]=Wire.read();
for(int jj=0;jj<=24;jj++) cb[(cbb[24]-24)+(j-2)*50+600+jj]= cbb[jj]; 
  }
  }
if(swr==5) digitalWrite(rled,LOW);
if(swr==8) swr=-1;
swr++;

}
//  ********************** end of IN  *****************************
void printcb () {
	for(int i=400;i<=419;i++) {
		Serial.print(cb[i]);
		Serial.print("  ");
	}
	Serial.println();
	for(int i=1000;i<=1019;i++) {
		Serial.print(cb[i]);
		Serial.print("  ");
	}
	Serial.println();
}
//*****************   4x20 LCD  Print  ****************************************
void lcdprint(){  
  // Serial.print("mode = ");
  // Serial.print(mode);
  // Serial.print("    function =  ");
  // Serial.print(function);
  // Serial.print("      index = ");
  // Serial.println(cb[603]);
  lcd.clear();
  lcd.print("m");
  lcd.print(mode);
  lcd.print("  f");
  lcd.print(function);
  lcd.print("  a");
  lcd.print(action);
  
  
}
//****************   end 4x20 LCD  Print  *************************
boolean schedule(int id){
	unsigned long currentMillis = millis()%1000000;
	if(currentMillis - schedules[id][1] > schedules[id][0]){
		schedules[id][1] = currentMillis;
		return true;
	}
	else 
		return false;
}

wayneft Thanks for solving my problem !!

Your suggestion that it should work prompted me to load the servo example from the adafruit library. Lo and behold it works. I have a bug I'll have to work on.

Thanks for correcting my bad assumption.