Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
RobTillaart committed Jan 20, 2023
2 parents a8e40f8 + cc442e4 commit fccf04d
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 37 deletions.
16 changes: 16 additions & 0 deletions .arduino-ci.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
platforms:
rpipico:
board: rp2040:rp2040:rpipico
package: rp2040:rp2040
gcc:
features:
defines:
- ARDUINO_ARCH_RP2040
warnings:
flags:

packages:
rp2040:rp2040:
url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json

compile:
# Choosing to run compilation tests on 2 different Arduino platforms
platforms:
Expand All @@ -9,3 +24,4 @@ compile:
- esp32
- esp8266
- mega2560
- rpipico
83 changes: 66 additions & 17 deletions MultiSpeedI2CScanner.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// FILE: MultiSpeedI2CScanner.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.15
// VERSION: 0.1.16
// PURPOSE: I2C scanner at different speeds
// DATE: 2013-11-05
// URL: https://github.com/RobTillaart/MultiSpeedI2CScanner
Expand All @@ -12,63 +12,69 @@
#include <Arduino.h>
#include <Wire.h>

// FOR INTERNAL I2C BUS NANO 33 BLE
// #define WIRE_IMPLEMENT_WIRE1 1
// extern TwoWire Wire1;

TwoWire *wire;

const char version[] = "0.1.15";
const char version[] = "0.1.16";


// INTERFACE COUNT (TESTED TEENSY 3.5 AND ARDUINO DUE ONLY)
// INTERFACE COUNT (TESTED TEENSY 3.5 AND ARDUINO DUE ONLY)
int wirePortCount = 1;
int selectedWirePort = 0;


// scans devices from 50 to 800 KHz I2C speeds.
// speed lower than 50 and above 400 can cause problems
// scans devices from 50 to 800 KHz I2C speeds.
// speed lower than 50 and above 400 can cause problems
long speed[10] = { 100, 200, 300, 400 };
int speeds;

int addressStart = 8;
int addressEnd = 119;


// DELAY BETWEEN TESTS
// DELAY BETWEEN TESTS
// for delay between tests of found devices.
#ifndef RESTORE_LATENCY
#define RESTORE_LATENCY 5 // for delay between tests of found devices.
#define RESTORE_LATENCY 5
#endif

bool delayFlag = false;


// MINIMIZE OUTPUT
// MINIMIZE OUTPUT
bool printAll = true;
bool header = true;
bool disableIRQ = false;


// STATE MACHINE
// STATE MACHINE
enum states {
STOP, ONCE, CONT, HELP
};
states state = STOP;


// TIMING
// TIMING
uint32_t startScan;
uint32_t stopScan;


///////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
//
// MAIN CODE
//
void setup()
{
Serial.begin(115200);
while (!Serial);

#if defined (ESP8266) || defined(ESP32)
uint8_t sda = 14; // 21
uint8_t scl = 15; // 22
Wire.begin(sda, scl, 100000); // ESP32 - change config pins if needed.
uint8_t sda = 14; // 21
uint8_t scl = 15; // 22
Wire.begin(sda, scl, 100000); // ESP32 - change config pins if needed.
#else
Wire.begin();
#endif
Expand Down Expand Up @@ -97,8 +103,7 @@ void setup()
wire = &Wire;

Serial.println();
setSpeed('9');
displayHelp();
reset();
}


Expand Down Expand Up @@ -191,6 +196,10 @@ void loop()
setSpeed(command);
break;

case 'r':
reset();
break;

case 'a':
setAddress();
break;
Expand Down Expand Up @@ -224,6 +233,25 @@ void loop()
}
}

//////////////////////////////////////////////////////////////////////

void reset()
{
setSpeed('9');
selectedWirePort = 0;
addressStart = 8;
addressEnd = 119;

delayFlag = false;
printAll = true;
header = true;
disableIRQ = false;

state = STOP;

displayHelp();
}


void setAddress()
{
Expand Down Expand Up @@ -354,7 +382,8 @@ void displayHelp()
Serial.println(F("\tN = 3400 KHz"));
Serial.println(F("\tO = 5000 KHz"));
Serial.println(F("\tP = 100 400 1000 3400 5000 KHz (standards)"));
Serial.println(F("\n\t? = help - this page"));
Serial.println(F("\n\tr = reset to startup defaults."));
Serial.println(F("\t? = help - this page"));
Serial.println();
}

Expand Down Expand Up @@ -434,6 +463,26 @@ void I2Cscan()
}
}

/*
// FOOTER
if (header)
{
for (uint8_t s = 0; s < speeds + 5; s++)
{
Serial.print(F("--------"));
}
Serial.println();
Serial.print(F("TIME\tDEC\tHEX\t"));
for (uint8_t s = 0; s < speeds; s++)
{
Serial.print(F("\t"));
Serial.print(speed[s]);
}
Serial.println(F("\t[KHz]"));
}
*/

stopScan = millis();
if (header)
{
Expand Down
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ The scanner provides an overview of which addresses can be found
at which speed. This allows one to optimize the I2C performance of
many devices above the standard 100KHz speed.

#### Related

build your own I2C scanner with:
- https://github.com/RobTillaart/I2C_SCANNER


## Menu dialog

Expand Down Expand Up @@ -108,8 +113,14 @@ Check your datasheet to see which speeds are applicable for the processor in use

## Future

#### Must

#### Should

#### Could

- add watchdog reset (at least AVR - 8 seconds 0.2.0 )
- create an I2CScanner class
- r = reset (defaults)
- non-AVR command behind a ```#ifdef``` ?
- rename releaseNotes.md to changelog.md (in line with libraries)
- I2C GENERIC RESET address 0x00 CMD 0x06

Loading

0 comments on commit fccf04d

Please sign in to comment.