You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 9 година
пре 9 година
пре 9 година
пре 9 година
пре 9 година
пре 9 година
пре 9 година
пре 9 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. // --------------------------------------
  2. // i2c_scanner
  3. // http://playground.arduino.cc/Main/I2cScanner
  4. //
  5. // Version 1
  6. // This program (or code that looks like it)
  7. // can be found in many places.
  8. // For example on the Arduino.cc forum.
  9. // The original author is not know.
  10. // Version 2, Juni 2012, Using Arduino 1.0.1
  11. // Adapted to be as simple as possible by Arduino.cc user Krodal
  12. // Version 3, Feb 26 2013
  13. // V3 by louarnold
  14. // Version 4, March 3, 2013, Using Arduino 1.0.3
  15. // by Arduino.cc user Krodal.
  16. // Changes by louarnold removed.
  17. // Scanning addresses changed from 0...127 to 1...119,
  18. // according to the i2c scanner by Nick Gammon
  19. // http://www.gammon.com.au/forum/?id=10896
  20. // Version 5, March 28, 2013
  21. // As version 4, but address scans now to 127.
  22. // A sensor seems to use address 120.
  23. // Version 6, November 27, 2015.
  24. // Added waiting for the Leonardo serial communication.
  25. //
  26. //
  27. // This sketch tests the standard 7-bit addresses
  28. // Devices with higher bit address might not be seen properly.
  29. //
  30. #include <Wire.h>
  31. void setup() {
  32. Wire.begin();
  33. Serial.begin(9600);
  34. while (!Serial); // Leonardo: wait for serial monitor
  35. Serial.println(F("\nI2C Scanner"));
  36. }
  37. void loop() {
  38. byte error, address;
  39. int nDevices;
  40. Serial.println(F("Scanning..."));
  41. nDevices = 0;
  42. for (address = 1; address < 127; address++) {
  43. // The i2c_scanner uses the return value of
  44. // the Write.endTransmisstion to see if
  45. // a device did acknowledge to the address.
  46. Wire.beginTransmission(address);
  47. error = Wire.endTransmission();
  48. if (error == 0) {
  49. Serial.print(F("Device found at address 0x"));
  50. if (address < 16) {
  51. Serial.print("0");
  52. }
  53. Serial.print(address,HEX);
  54. Serial.print(" (");
  55. printKnownChips(address);
  56. Serial.println(")");
  57. nDevices++;
  58. } else if (error==4) {
  59. Serial.print(F("Unknown error at address 0x"));
  60. if (address < 16) {
  61. Serial.print("0");
  62. }
  63. Serial.println(address,HEX);
  64. }
  65. }
  66. if (nDevices == 0) {
  67. Serial.println(F("No I2C devices found\n"));
  68. } else {
  69. Serial.println(F("done\n"));
  70. }
  71. delay(5000); // wait 5 seconds for next scan
  72. }
  73. void printKnownChips(byte address)
  74. {
  75. switch (address) {
  76. case 0x0A: Serial.print(F("SGTL5000")); break;
  77. case 0x0C: Serial.print(F("AK8963")); break;
  78. case 0x10: Serial.print(F("CS4272")); break;
  79. case 0x11: Serial.print(F("Si4713")); break;
  80. case 0x13: Serial.print(F("VCNL4000,AK4558")); break;
  81. case 0x19: Serial.print(F("LSM303")); break;
  82. case 0x1A: Serial.print(F("WM8731")); break;
  83. case 0x1D: Serial.print(F("LSM9DS0,ADXL345,MMA7455L")); break;
  84. case 0x1E: Serial.print(F("LSM303,HMC5883L,FXOS8700")); break;
  85. case 0x20: Serial.print(F("MCP23017,FXAS21002")); break;
  86. case 0x21: Serial.print(F("MCP23017")); break;
  87. case 0x22: Serial.print(F("MCP23017")); break;
  88. case 0x23: Serial.print(F("MCP23017")); break;
  89. case 0x24: Serial.print(F("MCP23017")); break;
  90. case 0x25: Serial.print(F("MCP23017")); break;
  91. case 0x26: Serial.print(F("MCP23017")); break;
  92. case 0x27: Serial.print(F("MCP23017")); break;
  93. case 0x28: Serial.print(F("BNO055")); break;
  94. case 0x29: Serial.print(F("TSL2561,VL6180")); break;
  95. case 0x2A: Serial.print(F("SGTL5000")); break;
  96. case 0x38: Serial.print(F("RA8875,FT6206")); break;
  97. case 0x3C: Serial.print(F("SSD1306")); break;
  98. case 0x3D: Serial.print(F("SSD1306")); break;
  99. case 0x40: Serial.print(F("PCA9685")); break;
  100. case 0x41: Serial.print(F("STMPE610,PCA9685")); break;
  101. case 0x42: Serial.print(F("PCA9685")); break;
  102. case 0x43: Serial.print(F("PCA9685")); break;
  103. case 0x44: Serial.print(F("PCA9685")); break;
  104. case 0x45: Serial.print(F("PCA9685")); break;
  105. case 0x46: Serial.print(F("PCA9685")); break;
  106. case 0x47: Serial.print(F("PCA9685")); break;
  107. case 0x48: Serial.print(F("ADS1115,PN532,TMP102")); break;
  108. case 0x49: Serial.print(F("ADS1115")); break;
  109. case 0x4A: Serial.print(F("ADS1115")); break;
  110. case 0x4B: Serial.print(F("ADS1115,TMP102")); break;
  111. case 0x50: Serial.print(F("EEPROM")); break;
  112. case 0x51: Serial.print(F("EEPROM")); break;
  113. case 0x52: Serial.print(F("Nunchuck,EEPROM")); break;
  114. case 0x53: Serial.print(F("ADXL345,EEPROM")); break;
  115. case 0x54: Serial.print(F("EEPROM")); break;
  116. case 0x55: Serial.print(F("EEPROM")); break;
  117. case 0x56: Serial.print(F("EEPROM")); break;
  118. case 0x57: Serial.print(F("EEPROM")); break;
  119. case 0x58: Serial.print(F("TPA2016")); break;
  120. case 0x5A: Serial.print(F("MPR121")); break;
  121. case 0x60: Serial.print(F("MPL3115,MCP4725,MCP4728,TEA5767,Si5351")); break;
  122. case 0x61: Serial.print(F("MCP4725")); break;
  123. case 0x62: Serial.print(F("LidarLite")); break;
  124. case 0x68: Serial.print(F("MPU9250,ITG3200,DS1307,DS3231")); break;
  125. case 0x6B: Serial.print(F("LSM9DS0")); break;
  126. case 0x76: Serial.print(F("MS5607,MS5611")); break;
  127. case 0x77: Serial.print(F("BMP085,BMA180")); break;
  128. default: Serial.print(F("unknown chip"));
  129. }
  130. }