Created
October 11, 2025 01:58
-
-
Save AlexLynd/6337bc13851cc39c1eb02ccd583b581d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// SPDX-FileCopyrightText: 2023 Carter Nelson for Adafruit Industries | |
// | |
// SPDX-License-Identifier: MIT | |
// -------------------------------------- | |
// i2c_scanner | |
// | |
// Modified from https://playground.arduino.cc/Main/I2cScanner/ | |
// -------------------------------------- | |
#include <Wire.h> | |
// Set I2C bus to use: Wire, Wire1, etc. | |
#define WIRE Wire | |
void setup() { | |
pinMode(D8, OUTPUT); | |
delay(250); | |
digitalWrite(D8, HIGH); | |
WIRE.begin(); | |
digitalWrite(D8,LOW); | |
Serial.begin(9600); | |
while (!Serial) | |
delay(10); | |
Serial.println("\nI2C Scannerr"); | |
} | |
const int RST_PIN = D8; // change to your reset pin | |
const unsigned long RST_HOLD_MS = 20; // hold reset low this long | |
const unsigned long POST_RST_MS = 120; // wait after release | |
void manualResetDisplay() { | |
pinMode(RST_PIN, OUTPUT); | |
// assert reset (active low) | |
digitalWrite(RST_PIN, LOW); | |
delay(RST_HOLD_MS); | |
// release reset | |
digitalWrite(RST_PIN, HIGH); | |
// give the display time to initialize | |
delay(POST_RST_MS); | |
} | |
void loop() { | |
byte error, address; | |
int nDevices; | |
Serial.println("Scanning..."); | |
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. | |
manualResetDisplay(); | |
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("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"); | |
else | |
Serial.println("done\n"); | |
delay(5000); // wait 5 seconds for next scan | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment