XIAO problems with wire-library

Dear All

I just got some new XIAO’s and the blink examples works fine. I would like to use the I2C interface. Hence as a first step I downloaded the “standard” I2C-Scanner program. I was astonished, the XIAO tells me that he has a I2C decive on all addresses regardless whether nothing at all is connected or if there is a real device. I used the I2C scanner and the device on several other arduino alternatives and never had any problem. It seems as the Wire.endTransmission() is always returning 0. Normally this means that a device is found. But in this case this is not correct. Does anyone has an idea how I could solve this problem?

Regards, Juergl

Hi @JuergL ,can you attach screenshots, code and error log, I’ll try to replicate.

How pull-up resistors are managed?

Hi All

Yes I have included two 10 kOhm resistors. The code is the following:

// --------------------------------------
// i2c_scanner
//
// Version 1
//    This program (or code that looks like it)
//    can be found in many places.
//    For example on the Arduino.cc forum.
//    The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
//     Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26  2013
//    V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
//    by Arduino.cc user Krodal.
//    Changes by louarnold removed.
//    Scanning addresses changed from 0...127 to 1...119,
//    according to the i2c scanner by Nick Gammon
//    https://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
//    As version 4, but address scans now to 127.
//    A sensor seems to use address 120.
// Version 6, November 27, 2015.
//    Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//
 
#include <Wire.h>
 
 
void setup()
{
  Wire.begin();
 
  Serial.begin(9600);
  while (!Serial);             // Leonardo: wait for serial monitor
  Serial.println("\nI2C Scanner");
}
 
 
void loop()
{
  byte error, address;
  int nDevices;
 
  Serial.println("Scanning...");
 
  nDevices = 0;
  for(address = 1; address < 127; address++ )
  {
    // The i2c_scanner uses the return value of
    // the Write.endTransmisstion to see if
    // a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();
 
    if (error == 0)
    {
      Serial.print("I2C device found at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.print(address,HEX);
      Serial.println("  !");
 
      nDevices++;
    }
    else if (error==4)
    {
      Serial.print("Unknown error at address 0x");
      if (address<16)
        Serial.print("0");
      Serial.println(address,HEX);
    }    
  }
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");
 
  delay(5000);           // wait 5 seconds for next scan
}

In the output all addresses appear with a found device…

I have attached an Adafruit BME680 via I2C. After the commands

Wire.begin()
bme.begin()

I got an error: no sensor found. Same code, same pullups work fine with other arduinos. Why not with the XIAO. It is so small!

In the meantime I have tested the I2C scanner program with a different computer, with a different cable with a different XIAO and have even created a new breadboard setup (have setup the same I2C device several times before). But what ever I do, the I2C doesn’t work as expected. What is my mistake?

Hi, we have recognised this. This seems to be an error from the SAMD core as Arduino Zero face the same problem(also SAMD21 core). For simple reference, you may use this version of I2C scanner(modified for SAMD series.)

https://wiki.seeedstudio.com/Arduino_Software_I2C_user_guide/#i2c-scanner-for-arduino

1 Like

@ansonhe97 Oh thank you very much! I wasn’t aware of this problem. I have taken your library and modified the I2C scanner program provided above and it now tells me:

I2C device found at address 0x77 !

And this is the proper address of the attached BME680 sensor. I see there is some work necessary to modify the libraries used, but this is just a matter of time.
I’m pleased to see that there is a work around. If you put a link on the Wiki to this software library, it may make the peoples life easier from the beginning :slight_smile:
Thanks a lot, JuergL

I had a similar issue. It only worked if I used a 4.7k ohm pull-up in both sda and scl.

2 Likes

Hi @JuergL,

Will do thanks :smiley:

This has been a huge issue with avr arduino board for 10+ years. Earlier this year, the Arduino project finally addressed the issue with blocking loops in the Wire library. Please update the Wire implementation for Seeed boards! The hardware Wire library is tagged

  • Copyright © 2015 Arduino LLC. All rights reserved.

Here’s the proposed documentation for the update to the Wire library:

This problem is resolved via a new timeout method:

ok, noted for upcoming