From 9fb7120b721f6b2c6f6e503d31054b4d3a9356b7 Mon Sep 17 00:00:00 2001 From: Kattni Rembor Date: Fri, 11 Nov 2022 15:16:26 -0500 Subject: [PATCH] Adding Arduino I2C scan code for PiCowbell Proto. --- .../arduino_i2c_scan/.pico_rp2040.test.only | 0 .../arduino_i2c_scan/arduino_i2c_scan.ino | 65 +++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 PiCowbell_Proto/arduino_i2c_scan/.pico_rp2040.test.only create mode 100644 PiCowbell_Proto/arduino_i2c_scan/arduino_i2c_scan.ino diff --git a/PiCowbell_Proto/arduino_i2c_scan/.pico_rp2040.test.only b/PiCowbell_Proto/arduino_i2c_scan/.pico_rp2040.test.only new file mode 100644 index 000000000..e69de29bb diff --git a/PiCowbell_Proto/arduino_i2c_scan/arduino_i2c_scan.ino b/PiCowbell_Proto/arduino_i2c_scan/arduino_i2c_scan.ino new file mode 100644 index 000000000..6563c5593 --- /dev/null +++ b/PiCowbell_Proto/arduino_i2c_scan/arduino_i2c_scan.ino @@ -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 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 +} \ No newline at end of file