MultiSpeed I2C Scanner - 50,100,200,400 KHz.

The problem might be that the interrupts of printing interfere with the bits of the I2C bus.
You need a logic analyser for that I guess.

I think that my I2C bus is crumbling down at 670kHz. The sketch for the webpage is the resulting sketch with the client.prints. I tested it with your sketch with and without Serial.prints, with and without delay and so on. I even did Serial.flush() everywhere to be sure that the Serial library was not longer busy. The result was still the same.

I was assuming that my I2C could be best at 100kHz, because of wires and Arduino Slaves, but now I feel confident to use 200kHz :grin:

Well, I didn't buy an oscilloscope (yet) : budget USB oscilloscope - General Electronics - Arduino Forum

Hi,

for using Arduino Due you need at least Arduino IDE 1.5.8. The guys have changed some parts including wire. So you can use this tool if you replace this line from the code:

      TWBR = (F_CPU/(speed[s]*1000) - 16)/2;

with this part

#if ARDUINO >= 158
      Wire.setClock(speed[s]*1000);
#else
      TWBR = (F_CPU/(speed[s]*1000) - 16)/2;
#endif

I tried this with the Arduino nightly build of 1.6.0 and it works fine on my Due.

Best regards
Nils

added this to the scanner 0.1.06 version

derniwi:
Hi,

for using Arduino Due you need at least Arduino IDE 1.5.8. The guys have changed some parts including wire. So you can use this tool if you replace this line from the code:

      TWBR = (F_CPU/(speed[s]*1000) - 16)/2;

with this part

#if ARDUINO >= 158

Wire.setClock(speed[s]*1000);
#else
      TWBR = (F_CPU/(speed[s]*1000) - 16)/2;
#endif



I tried this with the Arduino nightly build of 1.6.0 and it works fine on my Due.

Best regards
Nils

I did it but ID.exe crashes while compiling !

Serial port Monitor returns this line : .."›ْ5گ.ضè,_ذPbڑMڑسح

any idea?

I'm using Mega2560 with RAMPS 1.4 and LCD is connected on "ReprapsDiscount Smart controller"

My problem is that lcd dos not start working !

do you have links to the RAMPS1.4 - LCD datasheets?
what is a ReprapsDiscount Smart controller?
how are these connected?

the I2C pins for a MEGA are different than on an UNO (did you use the right ones?)

For I2C you also need GND connected, and 4K7 pull up resistors are needed.

How do you power the device?

It looks like your PC uses an Arabic font? is that possible?

Started beta coding (0.1.07 beta) on support for scanning Wire and Wire1 if supported e.g. DUE.

If some other functionality is missing, please let me know. I might add it :slight_smile:

robtillaart:
do you have links to the RAMPS1.4 - LCD datasheets?
what is a ReprapsDiscount Smart controller?
how are these connected?

the I2C pins for a MEGA are different than on an UNO (did you use the right ones?)

For I2C you also need GND connected, and 4K7 pull up resistors are needed.

How do you power the device?

It looks like your PC uses an Arabic font? is that possible?

The red board at right is "ReprapsDiscount Smart controller"

باتشکر از یو آپلود برای میزبانی رایگان عکس

I did not do any pin or use any data sheets because all the boards are pre-installed !

The board uses the usb power and an externall adaptor for stepmotors !

It is not "Arabic", It is "Farsi"

I found the problem, The baud rate in port scanner was wrong !

now the problem is "0 devices found in 346 milliseconds"

anw tnx for yr attention and yr codes !

It is not "Arabic", It is "Farsi"
You are right, sorry

do you have some datasheet of that board?
I'm not familiar with it

Np, u r welcome

In RepRap Wiki it is as below
LCD Connect Schematics
RepRapDiscount Controller Final Schematics

It seems that VDD pin power is 4.3v , is it the reason that no lcd is found by scanner codes even lcd's ledes turn on ?

how is the system powered?

ATX 12 V , 20 A and USB

robtillaart:
There are several good I2C scanners available for the Arduino.
However I missed the feature to scan if a device is reachable at different speeds.

So time to roll my own ...

(I2C EEPROM 24LC256 attached to I2C bus)

when
#define PRINTALL false
the output looks like

Multispeed - I2C Scanner - V0.1 - 

ADDR ADDR 10 50 100 200 400 [KHz]

80 0x50 V V V V V

done...




when 
**#define PRINTALL true**
the output looks like


Multispeed - I2C Scanner - V0.1 -

ADDR ADDR 10 50 100 200 400 [KHz]

0 0x0 . . . . .
1 0x1 . . . . .
2 0x2 . . . . .
3 0x3 . . . . .
4 0x4 . . . . .
5 0x5 . . . . .
6 0x6 . . . . .
7 0x7 . . . . .
8 0x8 . . . . .
9 0x9 . . . . .
10 0xA . . . . .
11 0xB . . . . .
12 0xC . . . . .
13 0xD . . . . .
14 0xE . . . . .
15 0xF . . . . .
16 0x10 . . . . .
17 0x11 . . . . .
18 0x12 . . . . .
19 0x13 . . . . .
20 0x14 . . . . .
21 0x15 . . . . .
22 0x16 . . . . .
23 0x17 . . . . .
24 0x18 . . . . .
25 0x19 . . . . .
26 0x1A . . . . .
27 0x1B . . . . .
28 0x1C . . . . .
29 0x1D . . . . .
30 0x1E . . . . .
31 0x1F . . . . .
32 0x20 . . . . .
33 0x21 . . . . .
34 0x22 . . . . .
35 0x23 . . . . .
36 0x24 . . . . .
37 0x25 . . . . .
38 0x26 . . . . .
39 0x27 . . . . .
40 0x28 . . . . .
41 0x29 . . . . .
42 0x2A . . . . .
43 0x2B . . . . .
44 0x2C . . . . .
45 0x2D . . . . .
46 0x2E . . . . .
47 0x2F . . . . .
48 0x30 . . . . .
49 0x31 . . . . .
50 0x32 . . . . .
51 0x33 . . . . .
52 0x34 . . . . .
53 0x35 . . . . .
54 0x36 . . . . .
55 0x37 . . . . .
56 0x38 . . . . .
57 0x39 . . . . .
58 0x3A . . . . .
59 0x3B . . . . .
60 0x3C . . . . .
61 0x3D . . . . .
62 0x3E . . . . .
63 0x3F . . . . .
64 0x40 . . . . .
65 0x41 . . . . .
66 0x42 . . . . .
67 0x43 . . . . .
68 0x44 . . . . .
69 0x45 . . . . .
70 0x46 . . . . .
71 0x47 . . . . .
72 0x48 . . . . .
73 0x49 . . . . .
74 0x4A . . . . .
75 0x4B . . . . .
76 0x4C . . . . .
77 0x4D . . . . .
78 0x4E . . . . .
79 0x4F . . . . .
80 0x50 V V V V V
81 0x51 . . . . .
82 0x52 . . . . .
83 0x53 . . . . .
84 0x54 . . . . .
85 0x55 . . . . .
86 0x56 . . . . .
87 0x57 . . . . .
88 0x58 . . . . .
89 0x59 . . . . .
90 0x5A . . . . .
91 0x5B . . . . .
92 0x5C . . . . .
93 0x5D . . . . .
94 0x5E . . . . .
95 0x5F . . . . .
96 0x60 . . . . .
97 0x61 . . . . .
98 0x62 . . . . .
99 0x63 . . . . .
100 0x64 . . . . .
101 0x65 . . . . .
102 0x66 . . . . .
103 0x67 . . . . .
104 0x68 . . . . .
105 0x69 . . . . .
106 0x6A . . . . .
107 0x6B . . . . .
108 0x6C . . . . .
109 0x6D . . . . .
110 0x6E . . . . .
111 0x6F . . . . .
112 0x70 . . . . .
113 0x71 . . . . .
114 0x72 . . . . .
115 0x73 . . . . .
116 0x74 . . . . .
117 0x75 . . . . .
118 0x76 . . . . .
119 0x77 . . . . .
120 0x78 . . . . .
121 0x79 . . . . .
122 0x7A . . . . .
123 0x7B . . . . .
124 0x7C . . . . .
125 0x7D . . . . .
126 0x7E . . . . .
127 0x7F . . . . .

done...




I'm thinking about adding a few more features and make it menu driven , so one can do different tests without reloading.

as always, remarks and comments are welcome

latest code - https://github.com/RobTillaart/Arduino/tree/master/sketches/MultiSpeedI2CScanner - 


//
//    FILE: MultiSpeedI2CScanner.ino
//  AUTHOR: Rob Tillaart
// VERSION: 0.1.04
// PURPOSE: I2C scanner @different speeds
//    DATE: 2013-11-05
//     URL: MultiSpeed I2C Scanner - 50,100,200,400 KHz. - Libraries - Arduino Forum
//
// Released to the public domain
//

#include <Wire.h>
#include <Arduino.h>

// scans devices from 50 to 800KHz I2C speeds.
// lower than 50 is not possible
// DS3231 RTC works on 800 KHz. TWBR = 2; (?)
long speed[] = {
 50, 100, 200, 250, 400, 500, 800 };
const int speeds = sizeof(speed)/sizeof(speed[0]);

// DELAY BETWEEN TESTS
#define RESTORE_LATENCY  5    // for delay between tests of found devices.
bool delayFlag = false;

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

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

uint32_t startScan;
uint32_t stopScan;

void setup()
{
 Serial.begin(115200);
 Wire.begin();
 displayHelp();
}

void loop()
{
 switch (getCommand())
 {
 case 's':
   state = ONCE;
   break;
 case 'c':
   state = CONT;
   break;
 case 'd':
   delayFlag = !delayFlag;
   Serial.print(F("<delay="));
   Serial.println(delayFlag?F("5>"):F("0>"));
   break;
 case 'e':
   // eeprom test TODO
   break;
 case 'h':
   header = !header;
   Serial.print(F("<header="));
   Serial.println(header?F("yes>"):F("no>"));
   break;
 case '?':
   state = HELP;
   break;
 case 'p':
   printAll = !printAll;
   Serial.print(F("<print="));
   Serial.println(printAll?F("all>"):F("found>"));
   break;
 case 'q':
   state = HELP;
   break;
 default:
   break;
 }

switch(state)
 {
 case ONCE:
   I2Cscan();
   state = HELP;
   break;
 case CONT:
   I2Cscan();
   delay(1000);
   break;    
 case HELP:
   displayHelp();
   state = STOP;
   break;
 case STOP:
   break;
 default: // ignore all non commands
   break;
 }
}

char getCommand()
{
 char c = '\0';
 if (Serial.available())
 {
   c = Serial.read();
 }
 return c;
}

void displayHelp()
{
 Serial.println(F("\nArduino I2C Scanner - 0.1.03\n"));
 Serial.println(F("\ts = single scan"));
 Serial.println(F("\tc = continuous scan - 1 second delay"));
 Serial.println(F("\tq = quit continuous scan"));
 Serial.println(F("\td = toggle latency delay between successful tests."));
 Serial.println(F("\tp = toggle printAll - printFound."));
 Serial.println(F("\th = toggle header - noHeader."));
 Serial.println(F("\t? = help - this page"));
 Serial.println();
}

void I2Cscan()
{
 startScan = millis();
 uint8_t count = 0;

if (header)
 {
   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]"));
   for (uint8_t s = 0; s < speeds + 5; s++)
   {
     Serial.print(F("--------"));
   }
   Serial.println();
 }

// TEST
 // 0.1.04: tests only address range 8..120
 // --------------------------------------------
 // Address R/W Bit Description
 // 0000 000   0 General call address
 // 0000 000   1 START byte
 // 0000 001   X CBUS address
 // 0000 010   X reserved - different bus format
 // 0000 011   X reserved - future purposes
 // 0000 1XX   X High Speed master code
 // 1111 1XX   X reserved - future purposes
 // 1111 0XX   X 10-bit slave addressing
 for (uint8_t address = 8; address < 120; address++)
 {
   bool printLine = printAll;
   bool found[speeds];
   bool fnd = false;

for (uint8_t s = 0; s < speeds ; s++)
   {
     TWBR = (F_CPU/(speed[s]*1000) - 16)/2;
     Wire.beginTransmission (address);
     found[s] = (Wire.endTransmission () == 0);
     fnd |= found[s];
     // give device 5 millis
     if (fnd && delayFlag) delay(RESTORE_LATENCY);
   }

if (fnd) count++;
   printLine |= fnd;

if (printLine)
   {
     Serial.print(millis());
     Serial.print(F("\t"));
     Serial.print(address, DEC);
     Serial.print(F("\t0x"));
     Serial.print(address, HEX);
     Serial.print(F("\t"));

for (uint8_t s = 0; s < speeds ; s++)
     {
       Serial.print(F("\t"));
       Serial.print(found[s]? F("V"):F("."));
     }
     Serial.println();
   }
 }

stopScan = millis();
 if (header)
 {
   Serial.println();
   Serial.print(count);
   Serial.print(F(" devices found in "));
   Serial.print(stopScan - startScan);
   Serial.println(F(" milliseconds."));
 }
}

I'm having an issue with the I2C scanners both the multispeed and the regular one.

I am using the Nucleo L476RG (STM32L476RGT6U).

The results for both the I2C scanner and the multispeed end up comming with nothing.

Using the code by Rob Tillaart V 0.1.06

TIME	DEC	HEX		50	100	200	250	400	500	800	[KHz]
------------------------------------------------------------------------------------------------
55701	0	0x00		.	.	.	.	.	.	.
55703	1	0x01		.	.	.	.	.	.	.
55706	2	0x02		.	.	.	.	.	.	.
55709	3	0x03		.	.	.	.	.	.	.
55711	4	0x04		.	.	.	.	.	.	.
55714	5	0x05		.	.	.	.	.	.	.
55717	6	0x06		.	.	.	.	.	.	.
55719	7	0x07		.	.	.	.	.	.	.
55722	8	0x08		.	.	.	.	.	.	.
55725	9	0x09		.	.	.	.	.	.	.
55727	10	0x0A		.	.	.	.	.	.	.
55730	11	0x0B		.	.	.	.	.	.	.
55733	12	0x0C		.	.	.	.	.	.	.
55736	13	0x0D		.	.	.	.	.	.	.
55738	14	0x0E		.	.	.	.	.	.	.
55741	15	0x0F		.	.	.	.	.	.	.
55744	16	0x10		.	.	.	.	.	.	.
55747	17	0x11		.	.	.	.	.	.	.
55750	18	0x12		.	.	.	.	.	.	.
55752	19	0x13		.	.	.	.	.	.	.
55755	20	0x14		.	.	.	.	.	.	.
55758	21	0x15		.	.	.	.	.	.	.
55761	22	0x16		.	.	.	.	.	.	.
55763	23	0x17		.	.	.	.	.	.	.
55766	24	0x18		.	.	.	.	.	.	.
55769	25	0x19		.	.	.	.	.	.	.
55772	26	0x1A		.	.	.	.	.	.	.
55774	27	0x1B		.	.	.	.	.	.	.
55777	28	0x1C		.	.	.	.	.	.	.
55780	29	0x1D		.	.	.	.	.	.	.
55783	30	0x1E		.	.	.	.	.	.	.
55785	31	0x1F		.	.	.	.	.	.	.
55788	32	0x20		.	.	.	.	.	.	.
55791	33	0x21		.	.	.	.	.	.	.
55794	34	0x22		.	.	.	.	.	.	.
55796	35	0x23		.	.	.	.	.	.	.
55799	36	0x24		.	.	.	.	.	.	.
55802	37	0x25		.	.	.	.	.	.	.
55805	38	0x26		.	.	.	.	.	.	.
55807	39	0x27		.	.	.	.	.	.	.
55810	40	0x28		.	.	.	.	.	.	.
55813	41	0x29		.	.	.	.	.	.	.
55816	42	0x2A		.	.	.	.	.	.	.
55819	43	0x2B		.	.	.	.	.	.	.
55821	44	0x2C		.	.	.	.	.	.	.
55824	45	0x2D		.	.	.	.	.	.	.
55827	46	0x2E		.	.	.	.	.	.	.
55830	47	0x2F		.	.	.	.	.	.	.
55832	48	0x30		.	.	.	.	.	.	.
55835	49	0x31		.	.	.	.	.	.	.
55838	50	0x32		.	.	.	.	.	.	.
55841	51	0x33		.	.	.	.	.	.	.
55843	52	0x34		.	.	.	.	.	.	.
55846	53	0x35		.	.	.	.	.	.	.
55849	54	0x36		.	.	.	.	.	.	.
55852	55	0x37		.	.	.	.	.	.	.
55854	56	0x38		.	.	.	.	.	.	.
55857	57	0x39		.	.	.	.	.	.	.
55860	58	0x3A		.	.	.	.	.	.	.
55863	59	0x3B		.	.	.	.	.	.	.
55865	60	0x3C		.	.	.	.	.	.	.
55868	61	0x3D		.	.	.	.	.	.	.
55871	62	0x3E		.	.	.	.	.	.	.
55874	63	0x3F		.	.	.	.	.	.	.
55876	64	0x40		.	.	.	.	.	.	.
55879	65	0x41		.	.	.	.	.	.	.
55882	66	0x42		.	.	.	.	.	.	.
55885	67	0x43		.	.	.	.	.	.	.
55888	68	0x44		.	.	.	.	.	.	.
55890	69	0x45		.	.	.	.	.	.	.
55893	70	0x46		.	.	.	.	.	.	.
55896	71	0x47		.	.	.	.	.	.	.
55899	72	0x48		.	.	.	.	.	.	.
55901	73	0x49		.	.	.	.	.	.	.
55904	74	0x4A		.	.	.	.	.	.	.
55907	75	0x4B		.	.	.	.	.	.	.
55910	76	0x4C		.	.	.	.	.	.	.
55912	77	0x4D		.	.	.	.	.	.	.
55915	78	0x4E		.	.	.	.	.	.	.
55918	79	0x4F		.	.	.	.	.	.	.
55921	80	0x50		.	.	.	.	.	.	.
55923	81	0x51		.	.	.	.	.	.	.
55926	82	0x52		.	.	.	.	.	.	.
55929	83	0x53		.	.	.	.	.	.	.
55932	84	0x54		.	.	.	.	.	.	.
55934	85	0x55		.	.	.	.	.	.	.
55937	86	0x56		.	.	.	.	.	.	.
55940	87	0x57		.	.	.	.	.	.	.
55943	88	0x58		.	.	.	.	.	.	.
55945	89	0x59		.	.	.	.	.	.	.
55948	90	0x5A		.	.	.	.	.	.	.
55951	91	0x5B		.	.	.	.	.	.	.
55954	92	0x5C		.	.	.	.	.	.	.
55957	93	0x5D		.	.	.	.	.	.	.
55959	94	0x5E		.	.	.	.	.	.	.
55962	95	0x5F		.	.	.	.	.	.	.
55965	96	0x60		.	.	.	.	.	.	.
55968	97	0x61		.	.	.	.	.	.	.
55970	98	0x62		.	.	.	.	.	.	.
55973	99	0x63		.	.	.	.	.	.	.
55976	100	0x64		.	.	.	.	.	.	.
55979	101	0x65		.	.	.	.	.	.	.
55982	102	0x66		.	.	.	.	.	.	.
55984	103	0x67		.	.	.	.	.	.	.
55987	104	0x68		.	.	.	.	.	.	.
55990	105	0x69		.	.	.	.	.	.	.
55993	106	0x6A		.	.	.	.	.	.	.
55996	107	0x6B		.	.	.	.	.	.	.
55999	108	0x6C		.	.	.	.	.	.	.
56001	109	0x6D		.	.	.	.	.	.	.
56004	110	0x6E		.	.	.	.	.	.	.
56007	111	0x6F		.	.	.	.	.	.	.
56010	112	0x70		.	.	.	.	.	.	.
56013	113	0x71		.	.	.	.	.	.	.
56016	114	0x72		.	.	.	.	.	.	.
56019	115	0x73		.	.	.	.	.	.	.
56021	116	0x74		.	.	.	.	.	.	.
56024	117	0x75		.	.	.	.	.	.	.
56027	118	0x76		.	.	.	.	.	.	.
56030	119	0x77		.	.	.	.	.	.	.
56033	120	0x78		.	.	.	.	.	.	.
56036	121	0x79		.	.	.	.	.	.	.
56039	122	0x7A		.	.	.	.	.	.	.
56041	123	0x7B		.	.	.	.	.	.	.
56044	124	0x7C		.	.	.	.	.	.	.
56047	125	0x7D		.	.	.	.	.	.	.
56050	126	0x7E		.	.	.	.	.	.	.
56053	127	0x7F		.	.	.	.	.	.	.

0 devices found in 368 milliseconds.

Arduino I2C Scanner - 0.1.06

Scanmode:
	s = single scan
	c = continuous scan - 1 second delay
	q = quit continuous scan
	d = toggle latency delay between successful tests. 0 - 5 ms
Output:
	p = toggle printAll - printFound.
	h = toggle header - noHeader.
	a = toggle address range, 0..127 - 8..120
Speeds:
	0 = 50 - 800 Khz
	1 = 100 KHz only
	2 = 200 KHz only
	4 = 400 KHz only
	8 = 800 KHz only

	? = help - this page

However if I address the device (BME280 0x76) on its own with no scanner I can RW to it without issues.
Any Ideas?

Finally got some time to add a new feature to the MultiSpeed I2C scanner, one I needed myself :slight_smile: .

TEENSY_3.5 support - tested Wire1 and Wire2. (TEENSY_3.6 uses the same libs, not tested)

The @ key is used to step though the available I2C ports.

You can find the latest 0.1.7 version on github @

As always remarks and comments are welcome,

Rob

1 Like

Really the sketch I needed. Very good written.

How can I use to Same I2C devices as Slaves?
I connect Three QMC5883L to Arduino uno and scanned with all I2C_Scanner codes but they just show me one address as 0*D and writes " one device found"
??????