MCPcopy Create free account
hub / github.com/SmingHub/Sming / scanBus

Function scanBus

samples/Basic_ScannerI2C/app/application.cpp:37–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35}
36
37void scanBus()
38{
39 Serial.println("Scanning...");
40
41 unsigned nDevices{0};
42 for(uint8_t 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 auto error = Wire.endTransmission();
48
49 WDT.alive(); // Second option: notify Watch Dog what you are alive (feed it)
50
51 if(error == 0) {
52 Serial << _F("I2C device found at address 0x") << String(address, HEX, 2) << " !" << endl;
53 nDevices++;
54 } else if(error == 4) {
55 Serial << _F("Unknown error at address 0x") << String(address, HEX, 2) << endl;
56 }
57 }
58
59 Serial << nDevices << _F(" I2C devices found.") << endl << endl;
60}
61
62void init()
63{

Callers

nothing calls this directly

Calls 5

printlnMethod · 0.80
aliveMethod · 0.80
StringClass · 0.50
beginTransmissionMethod · 0.45
endTransmissionMethod · 0.45

Tested by

no test coverage detected