I am a new Arduino IDE user and have a simple question below

For I2C transmission speed setting, there are serial begin() and wire.setClock(). Some sample codes just use Serial.begin() without Wire.seClock(), some use both as shown below. What is the real differences between them? When to use just serial and when to use both of them? Thanks.

void setup() {
  Serial.begin(9600);          // start serial communication at 9600bps

  Wire.begin();                // join i2c bus (address optional for master)

  Wire.setClock(400000); //Increase  I2C clock rate to 400 kHz

Serial has nothing to do with Wire/I2C communication. The examples only have this, because mostly they use Serial out- and input for interaction in the example codes (like showing the data of an I2C sensor on the Serial Monitor).

If you don't want to use the Serial Montior/Serial communication, then you can leave all the calls to Serial out.


Serial.begin starts the communication on USB or RX/TX pins. It has nothing to do with Wire library and I2C communication.

I2C clock speed determines the speed of communication on the I2C bus. Wire.begin() among other settings, sets the I2C clock speed to some default value.

Wire.setClock() allows to set a different clock speed. This should be supported by all devices on the I2C bus or clock speed can be changed before communicating with a specific device on the bus.

Wire.setClock should be called after Wire.begin because Wire.begin sets the clock speed to some default.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.