Arduino 101 I2C servo driver issue. TWBR not declared

I am building a Quadruped walking robot using 8 9G servos and an Arduino 101. To drive the servos I have the “Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface - PCA9685”. After installing the library using the library manager and opening an example provided by Adafruit, the code compiles fine with any other boards but not with the Arduino 101 board.

The error is

pwmtest:38: error: ‘TWBR’ was not declared in this scope

uint8_t twbrbackup = TWBR;

I have tried including <arduino.h> and doing a Wire.begin();

I am assuming it has something to do with how the 101 does I2C, after searching the web I haven’t found a sollution.

Thanks in advance for any help!

Here is the simple example sketch provided by the library.

#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

// called this way, it uses the default address 0x40
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
// you can also call it with a different address you want
//Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver(0x41);

void setup() {
Serial.begin(9600);
Serial.println(“16 channel PWM test!”);

// if you want to really speed stuff up, you can go into ‘fast 400khz I2C’ mode
// some i2c devices dont like this so much so if you’re sharing the bus, watch
// out for this!

pwm.begin();
pwm.setPWMFreq(1600); // This is the maximum PWM frequency

// save I2C bitrate
uint8_t twbrbackup = TWBR;
// must be changed after calling Wire.begin() (inside pwm.begin())
TWBR = 12; // upgrade to 400KHz!

}

void loop() {
// Drive each PWM in a ‘wave’
for (uint16_t i=0; i<4096; i += 8) {
for (uint8_t pwmnum=0; pwmnum < 16; pwmnum++) {
pwm.setPWM(pwmnum, 0, (i + (4096/16)*pwmnum) % 4096 );
}
}
}

hi fileark

Delete your lines:

  // save I2C bitrate
  uint8_t twbrbackup = TWBR;
  // must be changed after calling Wire.begin() (inside pwm.begin())
  TWBR = 12; // upgrade to 400KHz!

and substitute

wire.begin();
wire.setClock(400000L);

The sketch is looking to set the I2C bus to 400khz. The only way I know to do that is using setClock.