Skip to content

Commit

Permalink
add i2c scan example
Browse files Browse the repository at this point in the history
  • Loading branch information
Gitshaoxiang committed Nov 1, 2024
1 parent e4baa54 commit 8c5dd9d
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions examples/Advanced/i2c_tester/i2c_tester.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
*
* SPDX-License-Identifier: MIT
*/

#include <M5CoreS3.h>

void setup()
{
CoreS3.begin();
CoreS3.Display.setTextColor(YELLOW); // Set the font color to yellow.
CoreS3.Display.setTextSize(2); // Set the font size to 2.
CoreS3.Display.println("M5CoreS3 I2C Tester"); // Print a string on the screen.
CoreS3.Ex_I2C.begin();
CoreS3.In_I2C.begin();
}

int textColor = YELLOW;

void runScan(m5::I2C_Class &i2c)
{
int address;
for (address = 8; address < 0x78; address++) {
if (i2c.start(address, false, 400000) && i2c.stop()) {
CoreS3.Display.print(address, HEX);
CoreS3.Display.print(" ");
Serial.print(address, HEX);
Serial.print(" ");
} else {
CoreS3.Display.print(".");
Serial.print(".");
}

delay(10);
}
if (textColor == YELLOW) {
textColor = CYAN;
} else {
textColor = YELLOW;
}
CoreS3.Display.setTextColor(textColor, BLACK);
}

void loop()
{
int count = 5;
CoreS3.Display.clear();
while (count--) {
CoreS3.Display.setCursor(0, 0);
CoreS3.Display.println("Ex I2C Address [HEX]");
runScan(CoreS3.Ex_I2C);
}
count = 5;
CoreS3.Display.clear();

while (count--) {
CoreS3.Display.setCursor(0, 0);
CoreS3.Display.println("In I2C Address [HEX]");
runScan(CoreS3.In_I2C);
}
}

0 comments on commit 8c5dd9d

Please sign in to comment.