ebe72ad95cff3adc03bb225fa80e4aff52b6ade3
Tech/Interface-dat/I2C-dat/I2C-dat.md
... | ... | @@ -33,4 +33,6 @@ the most easy to use library for ESP |
33 | 33 | - https://randomnerdtutorials.com/esp32-i2c-communication-arduino-ide/#1 |
34 | 34 | |
35 | 35 | |
36 | -- [[arduino-dat]] |
|
... | ... | \ No newline at end of file |
0 | +- [[arduino-dat]] |
|
1 | + |
|
2 | +- [[I2C-scan-dat.ino]] |
|
... | ... | \ No newline at end of file |
Tech/Interface-dat/I2C-dat/I2C-scan-dat.ino
... | ... | @@ -0,0 +1,52 @@ |
1 | + |
|
2 | +#include <Wire.h> |
|
3 | + |
|
4 | +void setup() |
|
5 | +{ |
|
6 | + Wire.begin(); |
|
7 | + |
|
8 | + Serial.begin(115200); |
|
9 | + Serial.println("\nI2C Scanner"); |
|
10 | +} |
|
11 | + |
|
12 | +void loop() |
|
13 | +{ |
|
14 | + byte error, address; |
|
15 | + int nDevices; |
|
16 | + |
|
17 | + Serial.println("Scanning..."); |
|
18 | + |
|
19 | + nDevices = 0; |
|
20 | + for (address = 1; address < 127; address++) |
|
21 | + { |
|
22 | + // The i2c_scanner uses the return value of |
|
23 | + // the Write.endTransmisstion to see if |
|
24 | + // a device did acknowledge to the address. |
|
25 | + Wire.beginTransmission(address); |
|
26 | + error = Wire.endTransmission(); |
|
27 | + |
|
28 | + if (error == 0) |
|
29 | + { |
|
30 | + Serial.print("I2C device found at address 0x"); |
|
31 | + if (address < 16) |
|
32 | + Serial.print("0"); |
|
33 | + Serial.print(address, HEX); |
|
34 | + Serial.println(" !"); |
|
35 | + |
|
36 | + nDevices++; |
|
37 | + } |
|
38 | + else if (error == 4) |
|
39 | + { |
|
40 | + Serial.print("Unknow error at address 0x"); |
|
41 | + if (address < 16) |
|
42 | + Serial.print("0"); |
|
43 | + Serial.println(address, HEX); |
|
44 | + } |
|
45 | + } |
|
46 | + if (nDevices == 0) |
|
47 | + Serial.println("No I2C devices found\n"); |
|
48 | + else |
|
49 | + Serial.println("done\n"); |
|
50 | + |
|
51 | + delay(2000); // wait 5 seconds for next scan |
|
52 | +} |
|
... | ... | \ No newline at end of file |
Tech/Interface-dat/I2C-dat/I2C-scan-dat.md
... | ... | @@ -1,5 +0,0 @@ |
1 | - |
|
2 | -# I2C-scan-dat |
|
3 | - |
|
4 | -scan I2C address |
|
5 | - |