Wire library (#include utility/twi.h) not working?

I keep getting this error when I try to use the wire library:

In file included from ../Mag_wrapper.cpp:23:0: 
C:/Users/slb0494/Desktop/LCD/Wire.cpp:26:27: fatal error: utility/twi.h: No such file or directory 
   #include <utility/twi.h>

This particular error is in Matlab, but I got the same error when I tried to execute the below code using the Arduino IDE. It is interesting to note that the below code only gave me the error when I used the Due, but the Uno worked fine. Any idea what the problem is here?

/**
 * TCA9548 I2CScanner.pde -- I2C bus scanner for Arduino
 *
 * Based on code c. 2009, Tod E. Kurt, http://todbot.com/blog/
 *
 */
 
#include "Wire.h"
extern "C" { 
#include "utility/twi.h"  // from Wire library, so we can do bus scanning
}
 
#define TCAADDR 0x70
 
void tcaselect(uint8_t i) {
  if (i > 7) return;
 
  Wire.beginTransmission(TCAADDR);
  Wire.write(1 << i);
  Wire.endTransmission();  
}
 
 
// standard Arduino setup()
void setup()
{
    while (!Serial);
    delay(1000);
 
    Wire.begin();
    
    Serial.begin(115200);
    Serial.println("\nTCAScanner ready!");
    
    for (uint8_t t=0; t<8; t++) {
      tcaselect(t);
      Serial.print("TCA Port #"); Serial.println(t);
 
      for (uint8_t addr = 0; addr<=127; addr++) {
        if (addr == TCAADDR) continue;
      
        uint8_t data;
        if (! twi_writeTo(addr, &data, 0, 1, 1)) {
           Serial.print("Found I2C 0x");  Serial.println(addr,HEX);
        }
      }
    }
    Serial.println("\ndone");
}
 
void loop() 
{
}

The Arduino SAM Boards hardware package, which is used for the Due, has a Wire library but it does not contain the file utility/twi.h. Thus the error.

That makes sense, thanks! Any idea how I could go about resolving this issue? I can't seem to find the other wire library

Here's the easiest way to find the location of the Arduino SAM Boards Wire library:

  • Tools > Board > Arduino Due
  • File > Examples > Wire > digital_potentiometer
  • Sketch > Show sketch folder
  • Navigate up two folder levels to the Wire folder.
  • Open the src subfolder. There you will fine the source files of the Wire library.

Thank you! I replaced the other wire library I was using with this one and ran it in Matlab, resulting in the same error. Upon checking the Wire.h file, I noticed this one still has the #include <include/twi.h> (shown below).

// Include Atmel CMSIS driver
#include <include/twi.h>

#include "Stream.h"
#include "variant.h"

#define BUFFER_LENGTH 32

 // WIRE_HAS_END means Wire has end()
#define WIRE_HAS_END 1

Just to see if this was a simple error, I commented that part out and ran the code again. This time I got the same error but regarding the #include “variant.h”. I also tried to simply comment that out just to see what would happen, which not surprisingly resulted in a lot more errors. Any idea what the deal is with this?

Ever find a fix to this problem??