Skip to content

Instantly share code, notes, and snippets.

@tzechienchu
Forked from kamiyaowl/I2C_Tester.ino
Created March 22, 2022 14:07
Show Gist options
  • Save tzechienchu/6a9e272d57e8106de936eefd382aa089 to your computer and use it in GitHub Desktop.
Save tzechienchu/6a9e272d57e8106de936eefd382aa089 to your computer and use it in GitHub Desktop.
/************************************************************************
M5StackFire I2C Scanner
The M5StackFire has a connector for I2C devices.
This program scans the addresses 1-127 continuosly and shows
the devices found on the TFT.
The M5Stack fire has two internal I2C devices at address 0x68 and 0x75.
If they do not appear on the TFT it could mean you made a short cut on
the I2C bus.
October 2018, ChrisMicro
************************************************************************/
#include <TFT_eSPI.h> // Graphics and font library for ILI9341 driver chip
#include <SPI.h>
#include <Wire.h>
#define TFT_GREY 0x5AEB // New colour
TFT_eSPI tft = TFT_eSPI(); // Invoke library
void setup()
{
tft.init();
tft.setRotation(2);
Wire.begin();
delay(3000);
tft.fillScreen(TFT_BLACK);
}
int textColor = TFT_YELLOW;
void loop()
{
int address;
int error;
tft.setCursor(0, 0);
tft.println("scanning Address [HEX]");
for (address = 1; address < 127; address++)
{
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
tft.print(address, HEX);
tft.print(" ");
}
else
tft.print(".");
delay(10);
}
if (textColor == TFT_YELLOW)
textColor = TFT_GREEN;
else
textColor = TFT_YELLOW;
tft.setTextColor(textColor, TFT_BLACK);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment