Skip to content

Instantly share code, notes, and snippets.

@Zerg00s Zerg00s/I2C scanner
Created Jan 20, 2018

Embed
What would you like to do?
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(9600);
while (!Serial);
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 120; 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(" !");
DisplayGreeting();
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);
}
void DisplayGreeting(){
Serial.println("Showing stuff...");
Adafruit_SSD1306 display(4);
display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(10,0);
display.clearDisplay();
display.println("Greetings");
display.display();
delay(1);
display.startscrollright(0x00, 0x0F);
delay(500);
display.stopscroll();
delay(500);
display.startscrollleft(0x00, 0x0F);
delay(500);
display.stopscroll();
display.clearDisplay();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.