Skip to content

Adding Arduino I2C scan code for PiCowbell Proto. #2332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
65 changes: 65 additions & 0 deletions PiCowbell_Proto/arduino_i2c_scan/arduino_i2c_scan.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
// SPDX-FileCopyrightText: 2021 Carter Nelson for Adafruit Industries
// SPDX-FileCopyrightText: 2022 Kattni Rembor for Adafruit Industries
//
// SPDX-License-Identifier: MIT
// --------------------------------------
// PiCowbell Proto and Pico I2C scan code.
//
// Modified from https://playground.arduino.cc/Main/I2cScanner/
// --------------------------------------

#include <Wire.h>

// Wire uses GPIO4 (SDA) and GPIO5 (SCL) automatically.
#define WIRE Wire

void setup() {
WIRE.begin();

Serial.begin(9600);
while (!Serial)
delay(10);
Serial.println("\nPiCowbell Proto Pico I2C Scanner");
}


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.endTransmission to see if
// a device did acknowledge 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("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
}