Skip to content

Commit

Permalink
Cleaning .ino
Browse files Browse the repository at this point in the history
  • Loading branch information
SauviaTron committed Nov 16, 2023
1 parent 036636d commit 5358d7f
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 55 deletions.
55 changes: 0 additions & 55 deletions 2_Firmware/0_I2C_Scanning/0_I2C_Scanning.ino

This file was deleted.

86 changes: 86 additions & 0 deletions 2_Firmware/1_I2C_Scanning/1_I2C_Scanning.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Created on: 16/11/2023
* Author: Andrea Sauviat
* E-mail: [email protected]
*
* Description: Blinks LEDs on the Mini RAK-Tracker
*
* GitHub : https://github.com/SauviaTron/Mini_RAK-Tracker
*
*/


// > The libraries you need :
#include <Wire.h> // For I2C


// —————————————————————————————————————————————————————————————————————————————————————————————— //
// GLOBAL VARIABLES //
// —————————————————————————————————————————————————————————————————————————————————————————————— //

byte I2C_Error ; // I2C error
byte I2C_deviceAddress ; // Get I2C address of the component
int I2C_howManyDevices ; // Counts the number of components detected


// —————————————————————————————————————————————————————————————————————————————————————————————— //
// SETUP() //
// —————————————————————————————————————————————————————————————————————————————————————————————— //

void setup() {

// > Configure the baud rate
Serial.begin( 115200 ) ;
while ( !Serial ) {} ; // Wait for the serial to be available
delay(2500) ; // Add a custom delay for user to 'see' the setup function


// > Welcome Msg
Serial.println("\nWelcome to the I2C Scanner program !") ;


// > Configure the I2C
Wire.begin();

}


// —————————————————————————————————————————————————————————————————————————————————————————————— //
// LOOP() //
// —————————————————————————————————————————————————————————————————————————————————————————————— //

void loop() {

// > New loop
Serial.println("\n> I2C - Scanning...");

I2C_howManyDevices = 0 ; // Initializes the counter

// Check all the I2C address to see if there is a device wired on it
for(I2C_deviceAddress = 1; I2C_deviceAddress < 127; I2C_deviceAddress++ ) {

Wire.beginTransmission( I2C_deviceAddress ) ; // Try to communicate with the component
I2C_Error = Wire.endTransmission() ; // Get error


if( I2C_Error == 0 ) { // If no error detected
Serial.print(" Device found at address 0x") ; // Display a msg
if( I2C_deviceAddress<16 ){ Serial.print("0"); } // Display address
Serial.println(I2C_deviceAddress,HEX) ; // ...
I2C_howManyDevices = I2C_howManyDevices + 1 ; // +1 to the number of devices detected
}
else if( I2C_Error==4 ) { // If a weird device is detected
Serial.print(" Unknown error at address 0x"); // Display a msg
if( I2C_deviceAddress<16 ){ Serial.print("0"); } // Display address
Serial.println(I2C_deviceAddress,HEX) ; // ...
}

}

if( I2C_deviceAddress == 0 ){ Serial.println(" No I2C devices found"); }
else { Serial.println(" I2C Scanning done"); }

delay(5000); // wait 5 seconds for next scan

}

0 comments on commit 5358d7f

Please sign in to comment.