I2C scanner

Files at this revision

API Documentation at this revision

Comitter:
JohnnyK
Date:
Tue Aug 02 10:05:33 2022 +0000
Commit message:
First

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Aug 02 10:05:33 2022 +0000
@@ -0,0 +1,30 @@
+#include "mbed.h"
+
+I2C i2c(ARDUINO_UNO_I2C_SDA, ARDUINO_UNO_I2C_SCL); 
+
+int main(){
+    printf("\nI2C Scanner running...\n");
+    printf("Mbed OS version %d.%d.%d\n\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);
+    //i2c.frequency(400000);
+    int error, address, nDevices;
+    nDevices = 0;
+
+    for(address = 0; address < 128; address++ ){
+        thread_sleep_for(10);
+        /*i2c.start();
+        error = i2c.write(address  << 1);
+        i2c.stop();*/
+        error = i2c.write(address  << 1, "1", 1);
+        //pc.printf("Erorr %d\n", error);
+        if (error == 0){ //need to be change according to what version of overloaded write method is used
+            printf("I2C device found at address 8bit: 0x%X 7bit: 0x%X\n", address, address << 1);
+            nDevices++;
+        }
+    }
+        
+    if (nDevices == 0){
+        printf("No I2C devices found\n");
+    }else{
+        printf("\ndone\n");
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Tue Aug 02 10:05:33 2022 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#b1796dedeb8accde1cbaecf136fab96895e23d81
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed_app.json	Tue Aug 02 10:05:33 2022 +0000
@@ -0,0 +1,1 @@
+{"requires": ["bare-metal"]}