Skip to content

Nano 33 Sense v2: I2c Scanner running for Wire only acting strangely #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
mjs513 opened this issue Jan 24, 2025 · 6 comments · Fixed by #50
Closed

Nano 33 Sense v2: I2c Scanner running for Wire only acting strangely #49

mjs513 opened this issue Jan 24, 2025 · 6 comments · Fixed by #50

Comments

@mjs513
Copy link

mjs513 commented Jan 24, 2025

The only device I have on wire is a MPU9250.

With the know issue that Wire1 is not defined yet ran the i2c scanner for Wire only and its returning all devices in the scan list as attached:

Scanning Wire...
Device found at address 0x02  (AS3935)
Device found at address 0x1D  (LSM303D,LSM9DS0,ADXL345,MMA7455L,LSM9DS1,LIS3DSH)
Device found at address 0x20  (MCP23017,MCP23008,PCF8574,FXAS21002,SoilMoisture)
Device found at address 0x22  (MCP23017,MCP23008,PCF8574)
Device found at address 0x24  (MCP23017,MCP23008,PCF8574,ADAU1966,HM01B0)
Device found at address 0x27  (MCP23017,MCP23008,PCF8574,LCD16x2,DigoleDisplay)
Device found at address 0x29  (TSL2561,VL6180,TSL2561,TSL2591,BNO055,CAP1188)
Device found at address 0x2C  (MCP44XX ePot)
Device found at address 0x2E  (MCP44XX ePot)
Device found at address 0x30  (Si7210)
Device found at address 0x32  (Si7210)
Device found at address 0x34  (MAX11612,MAX11613)
Device found at address 0x36  (unknown chip)
Device found at address 0x38  (RA8875,FT6206,MAX98390)
Device found at address 0x3A  (MLX90632)
Device found at address 0x3C  (SSD1306,DigisparkOLED)
Device found at address 0x3E  (unknown chip)
Device found at address 0x40  (PCA9685,Si7021,MS8607)
Device found at address 0x42  (PCA9685)
Device found at address 0x44  (PCA9685, SHT3X, ADAU1966)
Device found at address 0x47  (PCA9685)
Device found at address 0x4A  (ADS1115,Qwiic Keypad,CS42448)
Device found at address 0x4D  (unknown chip)
Device found at address 0x4F  (unknown chip)
Device found at address 0x51  (EEPROM)
Device found at address 0x53  (ADXL345,EEPROM)
Device found at address 0x55  (EEPROM)
Device found at address 0x57  (EEPROM)
Device found at address 0x59  (unknown chip)
Device found at address 0x5B  (unknown chip)
Device found at address 0x5D  (unknown chip)
Device found at address 0x5F  (unknown chip)
Device found at address 0x61  (MCP4725,AtlasEzoDO)
Device found at address 0x63  (MCP4725,AtlasEzoPH)
Device found at address 0x65  (unknown chip)
Device found at address 0x67  (unknown chip)
Device found at address 0x6A  (LSM9DS1)
Device found at address 0x6C  (unknown chip)
Device found at address 0x6E  (unknown chip)
Device found at address 0x70  (HT16K33,TCA9548A)
Device found at address 0x72  (HT16K33)
Device found at address 0x74  (unknown chip)
Device found at address 0x76  (MS5607,MS5611,MS5637,BMP280)
Device found at address 0x78  (unknown chip)
Device found at address 0x7A  (unknown chip)
Device found at address 0x7C  (FRAM_ID)
Device found at address 0x7E  (unknown chip)
done

sketch used:

// Wire Scanner - scans for I2C devices on all Wire ports
//
// This Wire library adapted is for Teensy boards
//
//   https://github.com/PaulStoffregen/Wire/
//
// Adapted from I2C Scanner originally published on Arduino Playground
// see comments below for link and credits for original authors.
#include <Arduino.h>
#include <Wire.h>

#define WIRE_INTERFACES_COUNT 1
void printKnownChips(byte address);
void scan(TwoWire &myport);

void setup() {
#if WIRE_INTERFACES_COUNT >= 1
  Wire.begin();
#endif
#if WIRE_INTERFACES_COUNT >= 2
  Wire1.begin();
#endif
#if WIRE_INTERFACES_COUNT >= 3
  Wire2.begin();
#endif
#if WIRE_INTERFACES_COUNT >= 4
  Wire3.begin();
#endif
  Serial.begin(9600);
  while (!Serial);   // Wait for Arduino Serial Monitor
  Serial.println(F("\nI2C Scanner"));
}


void loop() {
  Serial.println();
#if WIRE_INTERFACES_COUNT >= 1
  Serial.println(F("Scanning Wire..."));
  scan(Wire);
  delay(500);
#endif
#if WIRE_INTERFACES_COUNT >= 2
  Serial.println(F("Scanning Wire1..."));
  scan(Wire1);
  delay(500);
#endif
#if WIRE_INTERFACES_COUNT >= 3
  Serial.println(F("Scanning Wire2..."));
  scan(Wire2);
  delay(500);
#endif
#if WIRE_INTERFACES_COUNT >= 4
  Serial.println(F("Scanning Wire3..."));
  scan(Wire3);
  delay(500);
#endif
  delay(5000);           // wait 5 seconds for next scan
}


void scan(TwoWire &myport) {
  int nDevices = 0;
  for (int 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.
    myport.beginTransmission(address);
    int error = myport.endTransmission();
   
    if (error == 0) {
      Serial.print(F("Device found at address 0x"));
      if (address < 16) {
        Serial.print("0");
      }
      Serial.print(address,HEX);
      Serial.print("  (");
      printKnownChips(address);
      Serial.println(")");
      nDevices++;
    } else if (error==4) {
      Serial.print(F("Unknown error at address 0x"));
      if (address < 16) {
        Serial.print("0");
      }
      Serial.println(address,HEX);
    }
  }
  if (nDevices == 0) {
    Serial.println(F("No I2C devices found"));
  } else {
    Serial.println(F("done"));
  }
  Serial.println();
}


void printKnownChips(byte address)
{
  // Is this list missing part numbers for chips you use?
  // Please suggest additions here:
  // https://github.com/PaulStoffregen/Wire/issues/new
  switch (address) {
    case 0x00: Serial.print(F("AS3935")); break;
    case 0x01: Serial.print(F("AS3935")); break;
    case 0x02: Serial.print(F("AS3935")); break;
    case 0x03: Serial.print(F("AS3935")); break;
    case 0x04: Serial.print(F("ADAU1966")); break;
    case 0x0A: Serial.print(F("SGTL5000")); break; // MCLK required
    case 0x0B: Serial.print(F("SMBusBattery?")); break;
    case 0x0C: Serial.print(F("AK8963")); break;
    case 0x10: Serial.print(F("CS4272")); break;
    case 0x11: Serial.print(F("Si4713")); break;
    case 0x13: Serial.print(F("VCNL4000,AK4558")); break;
    case 0x18: Serial.print(F("LIS331DLH")); break;
    case 0x19: Serial.print(F("LSM303,LIS331DLH")); break;
    case 0x1A: Serial.print(F("WM8731")); break;
    case 0x1C: Serial.print(F("LIS3MDL")); break;
    case 0x1D: Serial.print(F("LSM303D,LSM9DS0,ADXL345,MMA7455L,LSM9DS1,LIS3DSH")); break;
    case 0x1E: Serial.print(F("LSM303D,HMC5883L,FXOS8700,LIS3DSH")); break;
    case 0x20: Serial.print(F("MCP23017,MCP23008,PCF8574,FXAS21002,SoilMoisture")); break;
    case 0x21: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x22: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x23: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x24: Serial.print(F("MCP23017,MCP23008,PCF8574,ADAU1966,HM01B0")); break;
    case 0x25: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x26: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x27: Serial.print(F("MCP23017,MCP23008,PCF8574,LCD16x2,DigoleDisplay")); break;
    case 0x28: Serial.print(F("BNO055,EM7180,CAP1188")); break;
    case 0x29: Serial.print(F("TSL2561,VL6180,TSL2561,TSL2591,BNO055,CAP1188")); break;
    case 0x2A: Serial.print(F("SGTL5000,CAP1188")); break;
    case 0x2B: Serial.print(F("CAP1188")); break;
    case 0x2C: Serial.print(F("MCP44XX ePot")); break;
    case 0x2D: Serial.print(F("MCP44XX ePot")); break;
    case 0x2E: Serial.print(F("MCP44XX ePot")); break;
    case 0x2F: Serial.print(F("MCP44XX ePot")); break;
    case 0x30: Serial.print(F("Si7210")); break;
    case 0x31: Serial.print(F("Si7210")); break;
    case 0x32: Serial.print(F("Si7210")); break;
    case 0x33: Serial.print(F("MAX11614,MAX11615,Si7210,MLX90640,MLX90641")); break;
    case 0x34: Serial.print(F("MAX11612,MAX11613")); break;
    case 0x35: Serial.print(F("MAX11616,MAX11617")); break;
    case 0x38: Serial.print(F("RA8875,FT6206,MAX98390")); break;
    case 0x39: Serial.print(F("TSL2561, APDS9960")); break;
    case 0x3A: Serial.print(F("MLX90632")); break;
    case 0x3C: Serial.print(F("SSD1306,DigisparkOLED")); break;
    case 0x3D: Serial.print(F("SSD1306")); break;
    case 0x40: Serial.print(F("PCA9685,Si7021,MS8607")); break;
    case 0x41: Serial.print(F("STMPE610,PCA9685")); break;
    case 0x42: Serial.print(F("PCA9685")); break;
    case 0x43: Serial.print(F("PCA9685")); break;
    case 0x44: Serial.print(F("PCA9685, SHT3X, ADAU1966")); break;
    case 0x45: Serial.print(F("PCA9685, SHT3X")); break;
    case 0x46: Serial.print(F("PCA9685")); break;
    case 0x47: Serial.print(F("PCA9685")); break;
    case 0x48: Serial.print(F("ADS1115,PN532,TMP102,LM75,PCF8591,CS42448")); break;
    case 0x49: Serial.print(F("ADS1115,TSL2561,PCF8591,CS42448,TC74A1")); break;
    case 0x4A: Serial.print(F("ADS1115,Qwiic Keypad,CS42448")); break;
    case 0x4B: Serial.print(F("ADS1115,TMP102,BNO080,Qwiic Keypad,CS42448")); break;
    case 0x50: Serial.print(F("EEPROM,FRAM")); break;
    case 0x51: Serial.print(F("EEPROM")); break;
    case 0x52: Serial.print(F("Nunchuk,EEPROM")); break;
    case 0x53: Serial.print(F("ADXL345,EEPROM")); break;
    case 0x54: Serial.print(F("EEPROM")); break;
    case 0x55: Serial.print(F("EEPROM")); break;
    case 0x56: Serial.print(F("EEPROM")); break;
    case 0x57: Serial.print(F("EEPROM")); break;
    case 0x58: Serial.print(F("TPA2016,MAX21100")); break;
    case 0x5A: Serial.print(F("MPR121,MLX90614")); break;
    case 0x60: Serial.print(F("MPL3115,MCP4725,MCP4728,TEA5767,Si5351, BMI150")); break;
    case 0x61: Serial.print(F("MCP4725,AtlasEzoDO")); break;
    case 0x62: Serial.print(F("LidarLite,MCP4725,AtlasEzoORP")); break;
    case 0x63: Serial.print(F("MCP4725,AtlasEzoPH")); break;
    case 0x64: Serial.print(F("AtlasEzoEC, ADAU1966")); break;
    case 0x66: Serial.print(F("AtlasEzoRTD")); break;
    case 0x68: Serial.print(F("DS1307,DS3231,MPU6050,MPU9050,BMI270,ITG3200,ITG3701,LSM9DS0,L3G4200D")); break;
    case 0x69: Serial.print(F("MPU6050,MPU9050,MPU9250,ITG3701,L3G4200D")); break;
    case 0x6A: Serial.print(F("LSM9DS1")); break;
    case 0x6B: Serial.print(F("LSM9DS0")); break;
    case 0x6F: Serial.print(F("Qwiic Button")); break;
    case 0x70: Serial.print(F("HT16K33,TCA9548A")); break;
    case 0x71: Serial.print(F("SFE7SEG,HT16K33")); break;
    case 0x72: Serial.print(F("HT16K33")); break;
    case 0x73: Serial.print(F("HT16K33")); break;
    case 0x76: Serial.print(F("MS5607,MS5611,MS5637,BMP280")); break;
    case 0x77: Serial.print(F("BMP085,BMA180,BMP280,MS5611")); break;
    case 0x7C: Serial.print(F("FRAM_ID")); break;
    default: Serial.print(F("unknown chip"));
  }
}


// --------------------------------------
// i2c_scanner
// https://playground.arduino.cc/Main/I2cScanner/
//
// 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
//    http://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.
//
@mjs513
Copy link
Author

mjs513 commented Jan 24, 2025

Out of curiosity I loaded up a MPU9250 sensor sketch using the bolderflight library and seems to still work. But don't understand the scanner. Wonder what would happen if I put a second device on wire. Ok later - need coffee.

@KurtE
Copy link

KurtE commented Jan 24, 2025

I tried to copy in the i2c0 and i2c1 configuration stuff nothing helped.

I then looked at the Wire library, and noticed that the begin method does not do anything but initialize the right buffer.
Any real init appears to be done on setting the clock:

So I changed your (@mjs513) sketch like:

// Wire Scanner - scans for I2C devices on all Wire ports
//
// This Wire library adapted is for Teensy boards
//
//   https://github.com/PaulStoffregen/Wire/
//
// Adapted from I2C Scanner originally published on Arduino Playground
// see comments below for link and credits for original authors.
#include <Arduino.h>
#include <Wire.h>

#define WIRE_INTERFACES_COUNT 2
void printKnownChips(byte address);
void scan(TwoWire &myport);

void setup() {
#if WIRE_INTERFACES_COUNT >= 1
  Wire.begin();
  Wire.setClock(I2C_SPEED_FAST);
#endif
#if WIRE_INTERFACES_COUNT >= 2
  Wire1.begin();
  Wire1.setClock(I2C_SPEED_FAST);
#endif
#if WIRE_INTERFACES_COUNT >= 3
  Wire2.begin();
#endif
#if WIRE_INTERFACES_COUNT >= 4
  Wire3.begin();
#endif
  Serial.begin(9600);
  while (!Serial);   // Wait for Arduino Serial Monitor
  Serial.println(F("\nI2C Scanner"));
}


void loop() {
  Serial.println();
#if WIRE_INTERFACES_COUNT >= 1
  Serial.println(F("Scanning Wire..."));
  scan(Wire);
  delay(500);
#endif
#if WIRE_INTERFACES_COUNT >= 2
  Serial.println(F("Scanning Wire1..."));
  scan(Wire1);
  delay(500);
#endif
#if WIRE_INTERFACES_COUNT >= 3
  Serial.println(F("Scanning Wire2..."));
  scan(Wire2);
  delay(500);
#endif
#if WIRE_INTERFACES_COUNT >= 4
  Serial.println(F("Scanning Wire3..."));
  scan(Wire3);
  delay(500);
#endif
  delay(5000);           // wait 5 seconds for next scan
}


void scan(TwoWire &myport) {
  int nDevices = 0;
  for (int 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.
    myport.beginTransmission(address);
    int error = myport.endTransmission();
   
    if (error == 0) {
      Serial.print(F("Device found at address 0x"));
      if (address < 16) {
        Serial.print("0");
      }
      Serial.print(address,HEX);
      Serial.print("  (");
      printKnownChips(address);
      Serial.println(")");
      nDevices++;
    } else if (error==4) {
      Serial.print(F("Unknown error at address 0x"));
      if (address < 16) {
        Serial.print("0");
      }
      Serial.println(address,HEX);
    }
  }
  if (nDevices == 0) {
    Serial.println(F("No I2C devices found"));
  } else {
    Serial.println(F("done"));
  }
  Serial.println();
}


void printKnownChips(byte address)
{
  // Is this list missing part numbers for chips you use?
  // Please suggest additions here:
  // https://github.com/PaulStoffregen/Wire/issues/new
  switch (address) {
    case 0x00: Serial.print(F("AS3935")); break;
    case 0x01: Serial.print(F("AS3935")); break;
    case 0x02: Serial.print(F("AS3935")); break;
    case 0x03: Serial.print(F("AS3935")); break;
    case 0x04: Serial.print(F("ADAU1966")); break;
    case 0x0A: Serial.print(F("SGTL5000")); break; // MCLK required
    case 0x0B: Serial.print(F("SMBusBattery?")); break;
    case 0x0C: Serial.print(F("AK8963")); break;
    case 0x10: Serial.print(F("CS4272")); break;
    case 0x11: Serial.print(F("Si4713")); break;
    case 0x13: Serial.print(F("VCNL4000,AK4558")); break;
    case 0x18: Serial.print(F("LIS331DLH")); break;
    case 0x19: Serial.print(F("LSM303,LIS331DLH")); break;
    case 0x1A: Serial.print(F("WM8731")); break;
    case 0x1C: Serial.print(F("LIS3MDL")); break;
    case 0x1D: Serial.print(F("LSM303D,LSM9DS0,ADXL345,MMA7455L,LSM9DS1,LIS3DSH")); break;
    case 0x1E: Serial.print(F("LSM303D,HMC5883L,FXOS8700,LIS3DSH")); break;
    case 0x20: Serial.print(F("MCP23017,MCP23008,PCF8574,FXAS21002,SoilMoisture")); break;
    case 0x21: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x22: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x23: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x24: Serial.print(F("MCP23017,MCP23008,PCF8574,ADAU1966,HM01B0")); break;
    case 0x25: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x26: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x27: Serial.print(F("MCP23017,MCP23008,PCF8574,LCD16x2,DigoleDisplay")); break;
    case 0x28: Serial.print(F("BNO055,EM7180,CAP1188")); break;
    case 0x29: Serial.print(F("TSL2561,VL6180,TSL2561,TSL2591,BNO055,CAP1188")); break;
    case 0x2A: Serial.print(F("SGTL5000,CAP1188")); break;
    case 0x2B: Serial.print(F("CAP1188")); break;
    case 0x2C: Serial.print(F("MCP44XX ePot")); break;
    case 0x2D: Serial.print(F("MCP44XX ePot")); break;
    case 0x2E: Serial.print(F("MCP44XX ePot")); break;
    case 0x2F: Serial.print(F("MCP44XX ePot")); break;
    case 0x30: Serial.print(F("Si7210")); break;
    case 0x31: Serial.print(F("Si7210")); break;
    case 0x32: Serial.print(F("Si7210")); break;
    case 0x33: Serial.print(F("MAX11614,MAX11615,Si7210,MLX90640,MLX90641")); break;
    case 0x34: Serial.print(F("MAX11612,MAX11613")); break;
    case 0x35: Serial.print(F("MAX11616,MAX11617")); break;
    case 0x38: Serial.print(F("RA8875,FT6206,MAX98390")); break;
    case 0x39: Serial.print(F("TSL2561, APDS9960")); break;
    case 0x3A: Serial.print(F("MLX90632")); break;
    case 0x3C: Serial.print(F("SSD1306,DigisparkOLED")); break;
    case 0x3D: Serial.print(F("SSD1306")); break;
    case 0x40: Serial.print(F("PCA9685,Si7021,MS8607")); break;
    case 0x41: Serial.print(F("STMPE610,PCA9685")); break;
    case 0x42: Serial.print(F("PCA9685")); break;
    case 0x43: Serial.print(F("PCA9685")); break;
    case 0x44: Serial.print(F("PCA9685, SHT3X, ADAU1966")); break;
    case 0x45: Serial.print(F("PCA9685, SHT3X")); break;
    case 0x46: Serial.print(F("PCA9685")); break;
    case 0x47: Serial.print(F("PCA9685")); break;
    case 0x48: Serial.print(F("ADS1115,PN532,TMP102,LM75,PCF8591,CS42448")); break;
    case 0x49: Serial.print(F("ADS1115,TSL2561,PCF8591,CS42448,TC74A1")); break;
    case 0x4A: Serial.print(F("ADS1115,Qwiic Keypad,CS42448")); break;
    case 0x4B: Serial.print(F("ADS1115,TMP102,BNO080,Qwiic Keypad,CS42448")); break;
    case 0x50: Serial.print(F("EEPROM,FRAM")); break;
    case 0x51: Serial.print(F("EEPROM")); break;
    case 0x52: Serial.print(F("Nunchuk,EEPROM")); break;
    case 0x53: Serial.print(F("ADXL345,EEPROM")); break;
    case 0x54: Serial.print(F("EEPROM")); break;
    case 0x55: Serial.print(F("EEPROM")); break;
    case 0x56: Serial.print(F("EEPROM")); break;
    case 0x57: Serial.print(F("EEPROM")); break;
    case 0x58: Serial.print(F("TPA2016,MAX21100")); break;
    case 0x5A: Serial.print(F("MPR121,MLX90614")); break;
    case 0x60: Serial.print(F("MPL3115,MCP4725,MCP4728,TEA5767,Si5351, BMI150")); break;
    case 0x61: Serial.print(F("MCP4725,AtlasEzoDO")); break;
    case 0x62: Serial.print(F("LidarLite,MCP4725,AtlasEzoORP")); break;
    case 0x63: Serial.print(F("MCP4725,AtlasEzoPH")); break;
    case 0x64: Serial.print(F("AtlasEzoEC, ADAU1966")); break;
    case 0x66: Serial.print(F("AtlasEzoRTD")); break;
    case 0x68: Serial.print(F("DS1307,DS3231,MPU6050,MPU9050,BMI270,ITG3200,ITG3701,LSM9DS0,L3G4200D")); break;
    case 0x69: Serial.print(F("MPU6050,MPU9050,MPU9250,ITG3701,L3G4200D")); break;
    case 0x6A: Serial.print(F("LSM9DS1")); break;
    case 0x6B: Serial.print(F("LSM9DS0")); break;
    case 0x6F: Serial.print(F("Qwiic Button")); break;
    case 0x70: Serial.print(F("HT16K33,TCA9548A")); break;
    case 0x71: Serial.print(F("SFE7SEG,HT16K33")); break;
    case 0x72: Serial.print(F("HT16K33")); break;
    case 0x73: Serial.print(F("HT16K33")); break;
    case 0x76: Serial.print(F("MS5607,MS5611,MS5637,BMP280")); break;
    case 0x77: Serial.print(F("BMP085,BMA180,BMP280,MS5611")); break;
    case 0x7C: Serial.print(F("FRAM_ID")); break;
    default: Serial.print(F("unknown chip"));
  }
}


// --------------------------------------
// i2c_scanner
// https://playground.arduino.cc/Main/I2cScanner/
//
// 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
//    http://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.
//

Where I called the setting of the clock on Wire and Wire1 and now I see:

I2C Scanner

Scanning Wire...
No I2C devices found

Scanning Wire1...
Device found at address 0x10  (CS4272)
Device found at address 0x23  (MCP23017,MCP23008,PCF8574)
Device found at address 0x33  (MAX11614,MAX11615,Si7210,MLX90640,MLX90641)
Device found at address 0x39  (TSL2561, APDS9960)
Device found at address 0x4E  (unknown chip)
Device found at address 0x5C  (unknown chip)
Device found at address 0x68  (DS1307,DS3231,MPU6050,MPU9050,BMI270,ITG3200,ITG3701,LSM9DS0,L3G4200D)
Device found at address 0x7D  (unknown chip)
done


Scanning Wire...
No I2C devices found

@facchinm and ...
Wonder if maybe the begin should set the clock?

Secondary note: I tried setting clock to STANDARD and sort of random stuff returned, like groups of every possible ID.
I will hook up LA to the Wire pins and see what speeds are being used

@KurtE
Copy link

KurtE commented Jan 24, 2025

Quick update on it, I ran the MBED version and runs a lot quicker.
results:

Scanning Wire...
No I2C devices found

Scanning Wire1...
Device found at address 0x10  (CS4272)
Device found at address 0x39  (TSL2561, APDS9960)
Device found at address 0x44  (PCA9685, SHT3X, ADAU1966)
Device found at address 0x5C  (unknown chip)
Device found at address 0x68  (DS1307,DS3231,MPU6050,MPU9050,BMI270,ITG3200,ITG3701,LSM9DS0,L3G4200D)
done

More experimenting to do.
Edit I plugged in an Sparkfun QWIIC button as well as an LED strip and found by GIGA version:

Scanning Wire...
Device found at address 0x23  (MCP23017,MCP23008,PCF8574)
Device found at address 0x6F  (Qwiic Button)
done

Scanning Wire1...
Device found at address 0x10  (CS4272)
Device found at address 0x39  (TSL2561, APDS9960)
Device found at address 0x44  (PCA9685, SHT3X, ADAU1966)
Device found at address 0x5C  (unknown chip)
Device found at address 0x68  (DS1307,DS3231,MPU6050,MPU9050,BMI270,ITG3200,ITG3701,LSM9DS0,L3G4200D)
done


Scanning Wire...
Device found at address 0x23  (MCP23017,MCP23008,PCF8574)
Device found at address 0x6F  (Qwiic Button)
done

Image

@mjs513
Copy link
Author

mjs513 commented Jan 24, 2025

NIce @KurtE.

Looking at it now and going to try getting wire1 to work.

As to your question on setting clock - just looked and agree with you probably should setClock to standard in wire begin as a default.

Think I know the reason we have to setclock for sense - for the giga we have a default speed set up in the overlay but for the sense don't believe they do that.

Not sure why standard is not working.

@mjs513
Copy link
Author

mjs513 commented Jan 25, 2025

@KurtE - @facchinm

For some reason Wire1 always returned no i2c devices fournd after using changes @KurtE made to the overlay to add the additional pins and i2c1.

This morning for the heck of it I added

pinMode(31, OUTPUT);  //SCL1

and it started working using 400k:

Scanning Wire...
Device found at address 0x68  (DS1307,DS3231,MPU6050,MPU9050,BMI270,ITG3200,ITG3701,LSM9DS0,L3G4200D)
done

Scanning Wire1...
Device found at address 0x10  (CS4272, BMM150)
Device found at address 0x39  (TSL2561, APDS9960)
Device found at address 0x44  (PCA9685, SHT3X, ADAU1966, HS300x)
Device found at address 0x5C  (LPS22HB)
Device found at address 0x68  (DS1307,DS3231,MPU6050,MPU9050,BMI270,ITG3200,ITG3701,LSM9DS0,L3G4200D)
done

not sure where the 0x68 is coming from on wire1.

As Kurt mentioned 100k does not seem to work for Wire or Wire1 with the scanner.

@mjs513
Copy link
Author

mjs513 commented Jan 25, 2025

Just updated the device list in the sketch along with pinmode on wire1:

// Wire Scanner - scans for I2C devices on all Wire ports
//
// This Wire library adapted is for Teensy boards
//
//   https://github.com/PaulStoffregen/Wire/
//
// Adapted from I2C Scanner originally published on Arduino Playground
// see comments below for link and credits for original authors.
#include <Arduino.h>
#include <Wire.h>

#define WIRE_INTERFACES_COUNT 2
void printKnownChips(byte address);
void scan(TwoWire &myport);

void setup() {
  pinMode(31, OUTPUT);
#if WIRE_INTERFACES_COUNT >= 1
  Wire.begin();
  Wire.setClock(400000);
#endif
#if WIRE_INTERFACES_COUNT >= 2
  Wire1.begin();
  Wire1.setClock(400000);
#endif
#if WIRE_INTERFACES_COUNT >= 3
  Wire2.begin();
#endif
#if WIRE_INTERFACES_COUNT >= 4
  Wire3.begin();
#endif
  Serial.begin(9600);
  while (!Serial);   // Wait for Arduino Serial Monitor
  Serial.println(F("\nI2C Scanner"));
}


void loop() {
  Serial.println();
#if WIRE_INTERFACES_COUNT >= 1
  Serial.println(F("Scanning Wire..."));
  scan(Wire);
  delay(500);
#endif
#if WIRE_INTERFACES_COUNT >= 2
  Serial.println(F("Scanning Wire1..."));
  scan(Wire1);
  delay(500);
#endif
#if WIRE_INTERFACES_COUNT >= 3
  Serial.println(F("Scanning Wire2..."));
  scan(Wire2);
  delay(500);
#endif
#if WIRE_INTERFACES_COUNT >= 4
  Serial.println(F("Scanning Wire3..."));
  scan(Wire3);
  delay(500);
#endif
  delay(5000);           // wait 5 seconds for next scan
}


void scan(TwoWire &myport) {
  int nDevices = 0;
  for (int 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.
    myport.beginTransmission(address);
    int error = myport.endTransmission();
   
    if (error == 0) {
      Serial.print(F("Device found at address 0x"));
      if (address < 16) {
        Serial.print("0");
      }
      Serial.print(address,HEX);
      Serial.print("  (");
      printKnownChips(address);
      Serial.println(")");
      nDevices++;
    } else if (error==4) {
      Serial.print(F("Unknown error at address 0x"));
      if (address < 16) {
        Serial.print("0");
      }
      Serial.println(address,HEX);
    }
  }
  if (nDevices == 0) {
    Serial.println(F("No I2C devices found"));
  } else {
    Serial.println(F("done"));
  }
  Serial.println();
}


void printKnownChips(byte address)
{
  // Is this list missing part numbers for chips you use?
  // Please suggest additions here:
  // https://github.com/PaulStoffregen/Wire/issues/new
  switch (address) {
    case 0x00: Serial.print(F("AS3935")); break;
    case 0x01: Serial.print(F("AS3935")); break;
    case 0x02: Serial.print(F("AS3935")); break;
    case 0x03: Serial.print(F("AS3935")); break;
    case 0x04: Serial.print(F("ADAU1966")); break;
    case 0x0A: Serial.print(F("SGTL5000")); break; // MCLK required
    case 0x0B: Serial.print(F("SMBusBattery?")); break;
    case 0x0C: Serial.print(F("AK8963")); break;
    case 0x10: Serial.print(F("CS4272, BMM150")); break;
    case 0x11: Serial.print(F("Si4713")); break;
    case 0x13: Serial.print(F("VCNL4000,AK4558")); break;
    case 0x18: Serial.print(F("LIS331DLH")); break;
    case 0x19: Serial.print(F("LSM303,LIS331DLH")); break;
    case 0x1A: Serial.print(F("WM8731")); break;
    case 0x1C: Serial.print(F("LIS3MDL")); break;
    case 0x1D: Serial.print(F("LSM303D,LSM9DS0,ADXL345,MMA7455L,LSM9DS1,LIS3DSH")); break;
    case 0x1E: Serial.print(F("LSM303D,HMC5883L,FXOS8700,LIS3DSH")); break;
    case 0x20: Serial.print(F("MCP23017,MCP23008,PCF8574,FXAS21002,SoilMoisture")); break;
    case 0x21: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x22: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x23: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x24: Serial.print(F("MCP23017,MCP23008,PCF8574,ADAU1966,HM01B0")); break;
    case 0x25: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x26: Serial.print(F("MCP23017,MCP23008,PCF8574")); break;
    case 0x27: Serial.print(F("MCP23017,MCP23008,PCF8574,LCD16x2,DigoleDisplay")); break;
    case 0x28: Serial.print(F("BNO055,EM7180,CAP1188")); break;
    case 0x29: Serial.print(F("TSL2561,VL6180,TSL2561,TSL2591,BNO055,CAP1188")); break;
    case 0x2A: Serial.print(F("SGTL5000,CAP1188")); break;
    case 0x2B: Serial.print(F("CAP1188")); break;
    case 0x2C: Serial.print(F("MCP44XX ePot")); break;
    case 0x2D: Serial.print(F("MCP44XX ePot")); break;
    case 0x2E: Serial.print(F("MCP44XX ePot")); break;
    case 0x2F: Serial.print(F("MCP44XX ePot")); break;
    case 0x30: Serial.print(F("Si7210")); break;
    case 0x31: Serial.print(F("Si7210")); break;
    case 0x32: Serial.print(F("Si7210")); break;
    case 0x33: Serial.print(F("MAX11614,MAX11615,Si7210,MLX90640,MLX90641")); break;
    case 0x34: Serial.print(F("MAX11612,MAX11613")); break;
    case 0x35: Serial.print(F("MAX11616,MAX11617")); break;
    case 0x38: Serial.print(F("RA8875,FT6206,MAX98390")); break;
    case 0x39: Serial.print(F("TSL2561, APDS9960")); break;
    case 0x3A: Serial.print(F("MLX90632")); break;
    case 0x3C: Serial.print(F("SSD1306,DigisparkOLED")); break;
    case 0x3D: Serial.print(F("SSD1306")); break;
    case 0x40: Serial.print(F("PCA9685,Si7021,MS8607")); break;
    case 0x41: Serial.print(F("STMPE610,PCA9685")); break;
    case 0x42: Serial.print(F("PCA9685")); break;
    case 0x43: Serial.print(F("PCA9685")); break;
    case 0x44: Serial.print(F("PCA9685, SHT3X, ADAU1966, HS300x")); break;
    case 0x45: Serial.print(F("PCA9685, SHT3X")); break;
    case 0x46: Serial.print(F("PCA9685")); break;
    case 0x47: Serial.print(F("PCA9685")); break;
    case 0x48: Serial.print(F("ADS1115,PN532,TMP102,LM75,PCF8591,CS42448")); break;
    case 0x49: Serial.print(F("ADS1115,TSL2561,PCF8591,CS42448,TC74A1")); break;
    case 0x4A: Serial.print(F("ADS1115,Qwiic Keypad,CS42448")); break;
    case 0x4B: Serial.print(F("ADS1115,TMP102,BNO080,Qwiic Keypad,CS42448")); break;
    case 0x50: Serial.print(F("EEPROM,FRAM")); break;
    case 0x51: Serial.print(F("EEPROM")); break;
    case 0x52: Serial.print(F("Nunchuk,EEPROM")); break;
    case 0x53: Serial.print(F("ADXL345,EEPROM")); break;
    case 0x54: Serial.print(F("EEPROM")); break;
    case 0x55: Serial.print(F("EEPROM")); break;
    case 0x56: Serial.print(F("EEPROM")); break;
    case 0x57: Serial.print(F("EEPROM")); break;
    case 0x58: Serial.print(F("TPA2016,MAX21100")); break;
    case 0x5A: Serial.print(F("MPR121,MLX90614")); break;
    case 0x5C: Serial.print(F("LPS22HB")); break;
    case 0x60: Serial.print(F("MPL3115,MCP4725,MCP4728,TEA5767,Si5351, BMI150")); break;
    case 0x61: Serial.print(F("MCP4725,AtlasEzoDO")); break;
    case 0x62: Serial.print(F("LidarLite,MCP4725,AtlasEzoORP")); break;
    case 0x63: Serial.print(F("MCP4725,AtlasEzoPH")); break;
    case 0x64: Serial.print(F("AtlasEzoEC, ADAU1966")); break;
    case 0x66: Serial.print(F("AtlasEzoRTD")); break;
    case 0x68: Serial.print(F("ATECC608A, DS1307,DS3231,MPU6050,MPU9050,BMI270,ITG3200,ITG3701,LSM9DS0,L3G4200D")); break;
    case 0x69: Serial.print(F("MPU6050,MPU9050,MPU9250,ITG3701,L3G4200D")); break;
    case 0x6A: Serial.print(F("LSM9DS1")); break;
    case 0x6B: Serial.print(F("LSM9DS0")); break;
    case 0x6F: Serial.print(F("Qwiic Button")); break;
    case 0x70: Serial.print(F("HT16K33,TCA9548A")); break;
    case 0x71: Serial.print(F("SFE7SEG,HT16K33")); break;
    case 0x72: Serial.print(F("HT16K33")); break;
    case 0x73: Serial.print(F("HT16K33")); break;
    case 0x76: Serial.print(F("MS5607,MS5611,MS5637,BMP280")); break;
    case 0x77: Serial.print(F("BMP085,BMA180,BMP280,MS5611")); break;
    case 0x7C: Serial.print(F("FRAM_ID")); break;
    default: Serial.print(F("unknown chip"));
  }
}


// --------------------------------------
// i2c_scanner
// https://playground.arduino.cc/Main/I2cScanner/
//
// 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
//    http://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.
//

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants