Adding Arduino I2C scan code for PiCowbell Proto.
This commit is contained in:
parent
2c74a5dfe5
commit
9fb7120b72
2 changed files with 65 additions and 0 deletions
0
PiCowbell_Proto/arduino_i2c_scan/.pico_rp2040.test.only
Normal file
0
PiCowbell_Proto/arduino_i2c_scan/.pico_rp2040.test.only
Normal file
65
PiCowbell_Proto/arduino_i2c_scan/arduino_i2c_scan.ino
Normal file
65
PiCowbell_Proto/arduino_i2c_scan/arduino_i2c_scan.ino
Normal file
|
|
@ -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
|
||||
}
|
||||
Loading…
Reference in a new issue