12

I have a few useful I2C components, such as a 16-bit port expander (MCP23017), which I'd like to use in various projects.

What do I need to do to make these work with Arduino? Will it work with any Arduino, or do I need a specific board or shield?

3 Answers 3

9

Arduino have the Wire Library that communicate with I2C.

This library allows you to communicate with I2C / TWI devices. On the Arduino boards with the R3 layout (1.0 pinout), the SDA (data line) and SCL (clock line) are on the pin headers close to the AREF pin. The Arduino Due has two I2C / TWI interfaces SDA1 and SCL1 are near to the AREF pin and the additional one is on pins 20 and 21. As a reference the table below shows where TWI pins are located on various Arduino boards.

Board I2C / TWI pins

  • Uno, Ethernet A4 (SDA), A5 (SCL)
  • Mega2560 20 (SDA), 21 (SCL)
  • Leonardo 2 (SDA), 3 (SCL)
  • Due 20 (SDA), 21 (SCL), SDA1, SCL1

You can take a look at , this examples.

Like @TheDoctor said:

The I2C data lines both need resistors to 3.3V. This keeps them from drifting if they are disabled. Andy resistor value should work, but it is recommended to use one between 10k ohm and 47k ohm.

3
  • 1
    Don't forget pullup resistors on the I2C lines
    – TheDoctor
    Feb 13, 2014 at 13:42
  • 1
    To expand on that, the i2c data lines both need resistors to 5v. This keeps them from drifting if they are disabled. Andy resistor value should work, but it is recommended to use one between 10k ohm and 47k ohm
    – TheDoctor
    Feb 13, 2014 at 13:50
  • It should be said that if you use 5V pullups on the Arduino due (which was named in the answer) you have damaged the board. The Arduino Due uses 3.3V logic and it does NOT need 5V pullups, also SDA and SCL are already pulled up internally by the board.
    – John
    Jul 14, 2014 at 20:47
3

Additional shields are not needed.

You only need the Wire library and a couple of wires to connect the device to SDA and SCL.

The position of these pins is different on the various Arduinos, please have a look here.

3

For future readers: use the Adafruit_MCP23017 library.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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