trouble with a library needed for a Multiplexer

I'm running a MKR1010 with a multiplexer in order to run 3 sensors all with the same I2C address. I'm finding that is am getting the following error when I try to compile a multiplexer sketch;

"utility/twi.h no such library"

looking on the blogs and help sites the issue looks to be that the MKR1010 is a SAMD board. When i compile with a Uno selected (an AVR board) it works just fine. I tested by selecting other boards and the error holds true for the SAMD boards and works fine in the other AVR boards. So what is the issue with SAMD boards and what can be done to correct this issue?

EMTJIM

I’m pretty sure that’s not what the error message says. Please always post the full and exact error output, not some paraphrased snippet.

Please post your full sketch.

If possible, you should always post code directly in the forum thread as text using code tags:

  • Do an Auto Format (Tools > Auto Format in the Arduino IDE or Ctrl + B in the Arduino Web Editor) on your code. This will make it easier for you to spot bugs and make it easier for us to read.
  • In the Arduino IDE or Arduino Web Editor, click on the window that contains your sketch code.
  • Press “Ctrl + A”. This will select all the text.
  • Press “Ctrl + C”. This will copy the selected text to the clipboard.
  • In a forum reply here, click the “Reply” button.
  • click on the reply field.
  • Click the </> button on the forum toolbar. This will add the forum’s code tags markup to your reply.
  • Press “Ctrl + V”. This will paste the sketch between the code tags.
  • Move the cursor outside of the code tags before you add any additional text to your reply.
  • Repeat the above process if your sketch has multiple tabs.

This will make it easy for anyone to look at it, which will increase the likelihood of you getting help.

If the sketch is longer than the 9000 characters maximum allowed by the forum, then it’s OK to add it as an attachment. After clicking the “Reply” button, you will see an “Attachments and other settings” link.

When your code requires a library that’s not included with the Arduino IDE please post a link (using the chain links icon on the forum toolbar to make it clickable) to where you downloaded that library from or if you installed it using Library Manger (Sketch > Include Library > Manage Libraries in the Arduino IDE or Libraries > Library Manager in the Arduino Web Editor) then say so and state the full name of the library.


Please do this:

  • When you encounter an error, you’ll see a button on the right side of the orange bar “Copy error messages” in the Arduino IDE (or the icon that looks like two pieces of paper at the top right corner of the black console window in the Arduino Web Editor). Click that button…
  • In a forum reply here, click on the reply field.
  • Click the </> button on the forum toolbar. This will add the forum’s code tags markup to your reply.
  • Press “Ctrl + V”. This will paste the error between the code tags.
  • Move the cursor outside of the code tags before you add any additional text to your reply.

If the text exceeds the forum’s 9000 character limit, save it to a .txt file and post it as an attachment. If you click the “Reply” button here, you will see an “Attachments and other settings” link.

Arduino: 1.8.10 (Mac OS X), Board: “Arduino MKR WiFi 1010”

Multiple libraries were found for “Wire.h”
TCA9548_scanner:10:10: error: utility/twi.h: No such file or directory
Used: /Users/jimbaldauf/Library/Arduino15/packages/arduino/hardware/samd/1.8.4/libraries/Wire
#include “utility/twi.h” // from Wire library, so we can do bus scanning
^~~~~~~~~~~~~~~
compilation terminated.
exit status 1
utility/twi.h: No such file or directory

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

Well I was close… here is what it said. And the sketch

</**

  • 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()
{
}