-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Simple I2C bus scanner with port guessing, not yet working on the NINA
- Loading branch information
Showing
4 changed files
with
141 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
firmware/examples/I2CScannerWithPortGuess/.vscode/arduino.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"sketch": "I2CScannerWithPortGuess.ino", | ||
"output": "build", | ||
"board": "espressif:esp32:nina_w10", | ||
"configuration": "UploadSpeed=921600", | ||
"port": "/dev/ttyUSB0" | ||
} |
18 changes: 18 additions & 0 deletions
18
firmware/examples/I2CScannerWithPortGuess/.vscode/c_cpp_properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"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" | ||
} | ||
], | ||
"version": 4 | ||
} |
42 changes: 42 additions & 0 deletions
42
firmware/examples/I2CScannerWithPortGuess/.vscode/launch.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Arduino", | ||
"type": "arduino", | ||
"request": "launch", | ||
"program": "${file}", | ||
"cwd": "${workspaceFolder}", | ||
"MIMode": "gdb", | ||
"targetArchitecture": "arm", | ||
"miDebuggerPath": "", | ||
"debugServerPath": "", | ||
"debugServerArgs": "", | ||
"customLaunchSetupCommands": [ | ||
{ | ||
"text": "target remote localhost:3333" | ||
}, | ||
{ | ||
"text": "file \"${file}\"" | ||
}, | ||
{ | ||
"text": "load" | ||
}, | ||
{ | ||
"text": "monitor reset halt" | ||
}, | ||
{ | ||
"text": "monitor reset init" | ||
} | ||
], | ||
"stopAtEntry": true, | ||
"serverStarted": "Info\\ :\\ [\\w\\d\\.]*:\\ hardware", | ||
"launchCompleteCommand": "exec-continue", | ||
"filterStderr": true, | ||
"args": [] | ||
} | ||
] | ||
} |
74 changes: 74 additions & 0 deletions
74
firmware/examples/I2CScannerWithPortGuess/I2CScannerWithPortGuess.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/** | ||
* This is an I2C scanner for the MakeZurich badge, customized for the NINA Breakout. | ||
* based on the original code | ||
* available on Arduino.cc and later improved by user Krodal and Nick Gammon (www.gammon.com.au/forum/?id=10896) | ||
* and probably others adjusted to serve as test code and example for the badge. | ||
* @author Michel Racic | ||
**/ | ||
|
||
#include <Wire.h> | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
while (!Serial); // Leonardo: wait for serial monitor | ||
Serial.println("\n\nI2C Scanner to scan for devices on each GPIO port pair"); | ||
} | ||
|
||
// This is a list of all GPIOs, I excluded GPIs as they are not suitable for I2C AFAIK | ||
// Those are the actual ESP32 pins | ||
//uint8_t portArray[] = {23, 32, 33, 21, 25, 26, 27, 22, 19, 1, 3, 4, 2, 0, 5, 18, 14, 15, 13, 12}; | ||
// This array is just needed to display the friendly name from the NINA-W102 pinout | ||
//String portMap[] = {"IO1", "IO5", "IO7", "IO8", "IO16", "IO17", "IO18", "IO20", "IO21", "IO22" "IO23", "IO24", "IO25", "IO27", "IO28", "IO29", "IO31", "IO32", "IO35", "IO36" }; | ||
// Disbled ports as there where strange characters... | ||
uint8_t portArray[] = {/**23, **//**32, 33, 21, 25, 26,**/ /**27, **//**22,**/ /**19, **//**1, 3, 4, 2,**/ 0, /**5, 18, 14, 15,**/ 13/**, 12 **/}; | ||
String portMap[] = {/**"IO1",**/ /**"IO5", "IO7", "IO8", "IO16", "IO17",**/ /**"IO18",**/ /**"IO20",**/ /**"IO21",**/ /**"IO22" "IO23", "IO24", "IO25", **/"IO27", /**"IO28", "IO29", "IO31", "IO32",**/ "IO35"/**, "IO36" **/ }; | ||
|
||
void scanPorts() { | ||
for (uint8_t i = 0; i < sizeof(portArray); i++) { | ||
for (uint8_t j = 0; j < sizeof(portArray); j++) { | ||
if (i != j){ | ||
Serial.printf("Scanning (SDA : SCL) - %i : %i\n", portMap[i], portMap[j]); | ||
//TODO maybe add speed evaluation? | ||
Wire.begin(portArray[i], portArray[j], 100000 /** bus speed in Hz **/); | ||
check_if_exist_I2C(); | ||
|
||
} | ||
} | ||
} | ||
} | ||
|
||
void check_if_exist_I2C() { | ||
byte error, address; | ||
int nDevices; | ||
nDevices = 0; | ||
for (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. | ||
Wire.beginTransmission(address); | ||
error = Wire.endTransmission(); | ||
|
||
if (error == 0){ | ||
Serial.print("I2C device found at address 0x"); | ||
if (address < 16) | ||
Serial.print("0"); | ||
Serial.print(address, HEX); | ||
Serial.println(" !"); | ||
nDevices++; | ||
} else if (error == 4) { | ||
Serial.print("Unknow error at address 0x"); | ||
if (address < 16) | ||
Serial.print("0"); | ||
Serial.println(address, HEX); | ||
} | ||
} //for loop | ||
if (nDevices == 0) | ||
Serial.println("No I2C devices found"); | ||
else | ||
Serial.println("**********************************\n"); | ||
} | ||
|
||
void loop() { | ||
scanPorts(); | ||
delay(3000); | ||
} |