Issues with Arduino Wire Library

Hi all,

I’m experiencing a hard-to-trace issue with the Arduino Wire library (essentially, the I2C support functions) on the ATmega328P. I would just use the avr-libc IO routines, but want to leverage Jeff Rowberg’s I2CDev libraries which require use of the Arduino Wire API.

Essentially, whenever I build a project using Wire with PlatformIO, the Wire libraries fail to function as expected - after some debug, I’ve found the PlatformIO-built version to hang consistently on the endTransmission() function. However, the exact same code built with the Arduino IDE works just fine.

I’m not sure that this is PlatformIO’s fault, so I’d like to hear if anyone can reproduce the issue; can you use the Wire libraries (from Arduino 1.6.7, the latest) with PlatformIO successfully on an 8-bit AVR (ATmega328P or equivalent)?

Potentially related - other “standard” Arduino functions also seem to have issues when used from PlatformIO - notably, the Serial library is also non-functional on my end, but again works fine when built from the Arduino IDE. In general, have others seen issues in using PlatformIO with the Arduino standard libraries?


Hi @automagical
I’ve just tried BMP180 library (based on Wire), Uno board (ATmega328P) and latest PlatformIO (2.8.5) - everything works fine.
Could you provide your project to reproduce this issue?

This may or may not be helpful, but I’ve noticed Arduino Wire libraries will hang on i2c when the terminating resistors are not arranged correctly.

EDIT: And for the record, I have successfully used PIO + I2CDev libs, but it was over a month ago and can’t be sure it was the same version

Thanks for the responses - I did doubt that it was a software issue, so it’s good to hear that you have working implementations. Still, the same project built with the Arduino IDE seems to work; I’ll investigate some more and report back.

The code I’m using to test this behavior is actually even simpler than any sensor interface - I’m just trying to scan the I2C bus over a fixed range, like this:

void scani2c() {
    byte error, address;
    int nDevices;


    nDevices = 0;
    for(address = 0x65; address < 0x72; address++ )
      // The i2c_scanner uses the return value of
      // the Write.endTransmisstion to see if
      // a device did acknowledge to the address.
      usart_pstr("sent bits");
      error = Wire.endTransmission();
      usart_pstr("read bits");

      if (error == 0)
        usart_pstr("I2C device found at address 0x");
      else if (error==4)
      usart_pstr("Unknown error at address 0x");
        if (address<16)
    if (nDevices == 0)
      usart_pstr("No I2C devices found\n");

(is there any way to fold the above into a code block?)

Note that usart_pstr() is basically Serial.print.
I never see the string “read bits”, implying that the program enters Wire.endTransmission() but never returns.

Please use 4 spaces before each line