Skip to content

Commit

Permalink
Extended example to work with the 2 defined I2C buses on the badge
Browse files Browse the repository at this point in the history
  • Loading branch information
rac2030 committed Jun 16, 2018
1 parent 3f2f271 commit 2657c6b
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 9 deletions.
6 changes: 6 additions & 0 deletions firmware/examples/i2c_scanner/.vscode/arduino.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"board": "espressif:esp32:nina_w10",
"configuration": "UploadSpeed=115200",
"port": "/dev/ttyUSB0",
"sketch": "i2c_scanner.ino"
}
21 changes: 21 additions & 0 deletions firmware/examples/i2c_scanner/.vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"/home/rac/Arduino/hardware/espressif/esp32/cores/esp32"
],
"browse": {
"limitSymbolsToIncludedHeaders": false,
"path": [
"/home/rac/Arduino/hardware/espressif/esp32/cores/esp32"
]
},
"intelliSenseMode": "clang-x64",
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 4
}
34 changes: 25 additions & 9 deletions firmware/examples/i2c_scanner/i2c_scanner.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,40 @@

#include <Wire.h>

// Internal I2C bus where the sensor module is connected to
#define SDA1 13 // GPIO35
#define SCL1 0 // GPIO27

// User I2C bus which is exposed in the 2 breakouts at the bottom of the badge
// Note that those have the pullups not populated,
// depending on the module you connect you might need to populate them
#define SDA2 2 // GPIO25
#define SCL2 12 // GPIO36

void setup()
{
Wire.begin();

Serial.begin(115200);
delay(1000); // let serial console settle
Serial.println("\nI2C Scanner");
}


void loop()
{
scan("Internal I2C bus", SDA1, SCL1);
scan("User I2C bus", SDA2, SCL2);
delay(5000); // wait 5 seconds for next scan
}

void scan(String busDescription, int sda, int scl)
{
byte error, address;
int nDevices;

Serial.println("Scanning...");
Wire.begin(sda, scl);
Serial.print("Scanning ");
Serial.print(busDescription);
Serial.println("...");

nDevices = 0;
for(address = 1; address < 127; address++ )
Expand All @@ -38,7 +55,7 @@ void loop()

if (error == 0)
{
Serial.print("I2C device found at address 0x");
Serial.print(">> I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Expand All @@ -48,16 +65,15 @@ void loop()
}
else if (error==4)
{
Serial.print("Unknown error at address 0x");
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");
Serial.println(">> No I2C devices found\n");
else
Serial.println("done\n");

delay(5000); // wait 5 seconds for next scan
}
delay(1000);
}

0 comments on commit 2657c6b

Please sign in to comment.