Arduino Technology
Hook up an Arduino to I2C

This project explains how the Arduino can interface with I2C. Pretty nice description with a detailed how-to included at the link below.

Arduino I2C Expansion I/O

10 thoughts on “Hook up an Arduino to I2C

  1. Way too much detail. In short :

    Connect Analog 4 to SDI and Analog 5 to SDA. No pull-ups needed.

    Then :

    // Request 6 bytes from slave device at address 0xA0 (always use 7 bits addresses) :
    Wire.requestFrom(0xA0, 6);
    while(Wire.available()) {
    byte b = Wire.receive();
    // Do stuff with b …

    // Transmit some data to device at address 0xA0 (7 bits address again) :
    Wire.send(“x is “); // sends five bytes
    Wire.send(25); // sends one byte
    Wire.send(byteArray, 3); // sends the first 3 bytes of byteArray

  2. Hi, vivi.

    Analog *4* is actually SDA, and analog 5 is SCL. I2C won’t work with the lines switched.

    Regarding your code snippets, I can copy and paste from the Wire library reference too. The problems were that the examples are outdated/inconsistent, and that they don’t tell the whole story. In particular, the simplistic examples of reading bytes from and writing bytes to the slave device don’t deal with the intricacies of register addressing on the slave — they would only work for a slave device that was some sort of transceiver.

    The challenges I encountered — besides my own mistakes while working — revolved around the mismatch between the underlying I2C operations and the way they’re encapsulated in the code, and thereby difficulties translating from the slave device’s datasheet into proper Wire code for things like selecting a register and then reading from it.

    I thought it would be helpful to describe how to get from a datasheet to actual working code, and based on the feedback I’ve been receiving, other people have indeed found it useful. If what I did was too much detail for you, then you’re probably not the audience I was writing for.

  3. Oi, Keith

    Though I am currently not working with the I2C buss I am planning to do so in the next 3 months. The documentation I have seen so far has not been as helpful as your article. I you have any other suggestions as far as material on I2C I would truly appreciate it.

    Thanks for the write up, you have probably saved me a day of reading and 2 days of sloppy code.

    Oh and keep on ignoring critiques about the volume of detail.

  4. Dang, I need to proofread a little more. should read “If you have any other suggestions as far as material on I2C I would truly appreciate it.”

  5. I appreciated your honesty in reporting the stupid mistakes you made along the way. Glad I’m not the only one.

    The clear english details you provided are much appreciated. The datasheets weren’t meant for human consumption.

    Now to take apart some old gear to salvage some I2C bits and have a play with it….

Comments are closed.