Skip to content

Changing the Arduino's I2C speed to 9600Hz

FROGbots-4634 edited this page Jun 9, 2019 · 1 revision

The HiTechnic controllers use an unusually slow I2C speed of 9600Hz. By default, the Arduino runs I2C at 100KHz, which results in corrupted communications with the controllers. This issue can be rectified by setting the Arduino's I2C speed to 9600Hz.

Unfortunately, I only have an Arduino Uno, so I can only guarantee that these instructions will work for that specific board.

  1. Close the Arduino IDE if you have it open
  2. Navigate to arduinoInstallDir/hardware/arduino/avr/libraries/Wire/src/utility
  3. Open twi.c in a text editor of your choice
  4. Find this line // initialize twi prescaler and bit rate
  5. Change the line directly below from cbi(TWSR, TWPS0); to sbi(TWSR, TWPS0);
  6. Save and close the file.
  7. Make sure to put #define TWI_FREQ 37390L at the top of your sketch!