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

rodriguesluis:
hi there, it's possible the sensor can work with different speed I2C, but only send that data only in at one speed spec??
...

Good question, I don't know.
What I know is that an I2C EEPROM like the 24LC256, has an ~5 millisecond latency after a write. In this period the chip is not reachable (read or write). So different I2C devices can have artefacts, and when I extend this tool I hope to be able to handle them.
FYI my EEPROM lib can be found - Arduino Playground - LibraryForI2CEEPROM -

The scanner now only checks address reachability (sort of ping for I2C) as there are I2C devices that do not work on all speeds.
For specific devices I want to add additional tests (EEPROM, RTC, DISPLAY, PCF8574, ...)

Have added some (menu driven) features. When the application starts you get this menu

Arduino I2C Scanner - 0.1.02 

	s = single scan
	c = continuous scan - 1 second delay
	q = quit continuous scan
	d = toggle delay(5) between addresses.
	p = toggle printAll - printFound.
	h = toggle header - noHeader.
	? = help - this page

It can do just a single scan, and it gives output as shown in post above.
A continuous scan, gives the same output with a one second delay in between. This is useful to patch/change address lines to.
To stop the continuous scanning press q (quit).

Then there are three flags that modifies the behaviour.
d: adds 5 millisecond delay between addresses. This is because some devices have a latency and will not react immediately. I'm not happy with this behaviour and it will change in next version.

p: imho the most useful flag, print complete list of addresses or only the ones found. Reduces the output to something the eye can follow.
h: removes the header/footer from the output so only the lines of addresses responding will be shown. Works especially well in combination with p, and I have doubted for some time to combine the p and h flag.

The combination I use often is printFound, noHeader and continuous. It gives output like

Arduino I2C Scanner - 0.1.02

	s = single scan
	c = continuous scan - 1 second delay
	q = quit continuous scan
	d = toggle delay(5) between addresses.
	p = toggle printAll - printFound.
	h = toggle header - noHeader.
	? = help - this page

<print=found>
<header=no>
104	0x68		V	V	V	V	V	V	V
104	0x68		V	V	V	V	V	V	V
104	0x68		V	V	V	V	V	V	V
104	0x68		V	V	V	V	V	V	V
104	0x68		V	V	V	V	V	V	V
104	0x68		V	V	V	V	V	V	V
104	0x68		V	V	V	V	V	V	V
104	0x68		V	V	V	V	V	V	V

One can see the number of columns has changed as I added additional speeds for I2C: 250 and 500 KHz, 2 speeds at which my RTC and EEPROM work quite well. I also tested 1000 KHz and got mixed results. The RTC did not work reliably at that speed.
(I might try 800 KHz, also a perfect divider of 16 MHz.)

Although still work in progress, the tool already met some of its goals. First on my list is to get delay() behaviour right.

As always comments and remarks are welcome.

update: - code (0.1.02 version) removed.

update:

  • removed the 10 KHz test as TWBR is not valid for 10KHz as TWBR is a byte .. :blush:
  • updated title of thread.

new 0.1.03 version: (replaces all earlier versions)

  • removed 10 KHz
  • added 800 KHz (my RTC DS3231 seems to work reliably on this speed)
  • fixed TWBR math
  • d: delay toggle => now only waits for 5 millis if device is found.
  • added millis() time stamp in the output.

latest version of the code see first post

FYI: scan of the GY-80 10DOF module (with v. 0.1.03):

TIME    DEC     HEX             50      100     200     250     400     500     800     [KHz]
------------------------------------------------------------------------------------------------
1561    0       0x0             .       .       .       .       .       .       .
1563    1       0x1             .       .       .       .       .       .       V
1565    2       0x2             .       .       .       .       .       .       .
1568    3       0x3             .       .       .       .       .       .       V
1570    4       0x4             .       .       .       .       .       .       .
..
1618    24      0x18            .       .       .       .       .       .       .
1620    25      0x19            .       .       .       .       .       .       V
1623    26      0x1A            .       .       .       .       .       .       .
1626    27      0x1B            .       .       .       .       .       .       V
1628    28      0x1C            .       .       .       .       .       .       .
1631    29      0x1D            .       .       .       .       .       .       V
1633    30      0x1E            V       V       V       V       V       V       .
1635    31      0x1F            .       .       .       .       .       .       V
1638    32      0x20            .       .       .       .       .       .       .
1640    33      0x21            .       .       .       .       .       .       V
1643    34      0x22            .       .       .       .       .       .       .
1645    35      0x23            .       .       .       .       .       .       V
1647    36      0x24            .       .       .       .       .       .       .
1650    37      0x25            .       .       .       .       .       .       V
1652    38      0x26            .       .       .       .       .       .       .
1655    39      0x27            .       .       .       .       .       .       V
1657    40      0x28            .       .       .       .       .       .       .
1659    41      0x29            .       .       .       .       .       .       V
1662    42      0x2A            .       .       .       .       .       .       .
..
1756    80      0x50            .       .       .       .       .       .       .
1759    81      0x51            .       .       .       .       .       .       V
1761    82      0x52            .       .       .       .       .       .       .
1764    83      0x53            V       V       V       V       V       V       V
1766    84      0x54            .       .       .       .       .       .       .
1768    85      0x55            .       .       .       .       .       .       V
1771    86      0x56            .       .       .       .       .       .       .
1773    87      0x57            .       .       .       .       .       .       V
1776    88      0x58            .       .       .       .       .       .       .
1778    89      0x59            .       .       .       .       .       .       V
1780    90      0x5A            .       .       .       .       .       .       .
1783    91      0x5B            .       .       .       .       .       .       V
1785    92      0x5C            .       .       .       .       .       .       .
1788    93      0x5D            .       .       .       .       .       .       V
1790    94      0x5E            .       .       .       .       .       .       .
1793    95      0x5F            .       .       .       .       .       .       V
1796    96      0x60            .       .       .       .       .       .       .
1798    97      0x61            .       .       .       .       .       .       V
1801    98      0x62            .       .       .       .       .       .       .
1803    99      0x63            .       .       .       .       .       .       V
1805    100     0x64            .       .       .       .       .       .       .
1808    101     0x65            .       .       .       .       .       .       V
1810    102     0x66            .       .       .       .       .       .       .
1813    103     0x67            .       .       .       .       .       .       V
1815    104     0x68            .       .       .       .       .       .       .
1818    105     0x69            V       V       V       V       V       V       V
1820    106     0x6A            .       .       .       .       .       .       .
1823    107     0x6B            .       .       .       .       .       .       V
1825    108     0x6C            .       .       .       .       .       .       .
1828    109     0x6D            .       .       .       .       .       .       V
1830    110     0x6E            .       .       .       .       .       .       .
1833    111     0x6F            .       .       .       .       .       .       V
1836    112     0x70            .       .       .       .       .       .       .
1839    113     0x71            .       .       .       .       .       .       V
1841    114     0x72            .       .       .       .       .       .       .
1844    115     0x73            .       .       .       .       .       .       V
1846    116     0x74            .       .       .       .       .       .       .
1849    117     0x75            .       .       .       .       .       .       V
1851    118     0x76            .       .       .       .       .       .       .
1854    119     0x77            V       V       V       V       V       V       V
1856    120     0x78            .       .       .       .       .       .       .
1859    121     0x79            .       .       .       .       .       .       V
1861    122     0x7A            .       .       .       .       .       .       .
1864    123     0x7B            .       .       .       .       .       .       V
1866    124     0x7C            .       .       .       .       .       .       .
1869    125     0x7D            .       .       .       .       .       .       V
1871    126     0x7E            .       .       .       .       .       .       .
1874    127     0x7F            .       .       .       .       .       .       V

66 devices found in 322 milliseconds.

Hi Pito,
Very interesting results especially the 800 KHz results at every odd address. I have not seen it

What board are you using?
What is the value of the pull up resistors used? I assume at this speed the squareness of the signal is very important?

Solder-less breadboard, 1284p @16MHz, 3V3, maybe 10k pullups (I have to check).
I'll try with smaller pullups..
2k2 pullups:

TIME    DEC     HEX             50      100     200     250     400     500     800     [KHz]
------------------------------------------------------------------------------------------------
303     0       0x0             .       .       .       .       .       .       .
306     1       0x1             .       .       .       .       .       .       V
308     2       0x2             .       .       .       .       .       .       .
310     3       0x3             .       .       .       .       .       .       V
312     4       0x4             .       .       .       .       .       .       .
314     5       0x5             .       .       .       .       .       .       .
316     6       0x6             .       .       .       .       .       .       .
319     7       0x7             .       .       .       .       .       .       V
321     8       0x8             .       .       .       .       .       .       .
323     9       0x9             .       .       .       .       .       .       .
325     10      0xA             .       .       .       .       .       .       .
327     11      0xB             .       .       .       .       .       .       .
329     12      0xC             .       .       .       .       .       .       .
332     13      0xD             .       .       .       .       .       .       .
334     14      0xE             .       .       .       .       .       .       .
336     15      0xF             .       .       .       .       .       .       V
338     16      0x10            .       .       .       .       .       .       .
342     17      0x11            .       .       .       .       .       .       .
344     18      0x12            .       .       .       .       .       .       .
346     19      0x13            .       .       .       .       .       .       .
349     20      0x14            .       .       .       .       .       .       .
351     21      0x15            .       .       .       .       .       .       .
353     22      0x16            .       .       .       .       .       .       .
356     23      0x17            .       .       .       .       .       .       .
358     24      0x18            .       .       .       .       .       .       .
360     25      0x19            .       .       .       .       .       .       .
363     26      0x1A            .       .       .       .       .       .       .
365     27      0x1B            .       .       .       .       .       .       .
367     28      0x1C            .       .       .       .       .       .       .
370     29      0x1D            .       .       .       .       .       .       .
372     30      0x1E            V       V       V       V       V       V       .
374     31      0x1F            .       .       .       .       .       .       V
377     32      0x20            .       .       .       .       .       .       .
379     33      0x21            .       .       .       .       .       .       .
381     34      0x22            .       .       .       .       .       .       .
385     35      0x23            .       .       .       .       .       .       .
..
412     47      0x2F            .       .       .       .       .       .       .
415     48      0x30            .       .       .       .       .       .       .
417     49      0x31            .       .       .       .       .       .       .
419     50      0x32            .       .       .       .       .       .       .
422     51      0x33            .       .       .       .       .       .       .
424     52      0x34            .       .       .       .       .       .       .
427     53      0x35            .       .       .       .       .       .       .
430     54      0x36            .       .       .       .       .       .       .
432     55      0x37            .       .       .       .       .       .       .
434     56      0x38            .       .       .       .       .       .       .
437     57      0x39            .       .       .       .       .       .       .
439     58      0x3A            .       .       .       .       .       .       .
441     59      0x3B            .       .       .       .       .       .       .
444     60      0x3C            .       .       .       .       .       .       .
446     61      0x3D            .       .       .       .       .       .       .
448     62      0x3E            .       .       .       .       .       .       .
451     63      0x3F            .       .       .       .       .       .       V
453     64      0x40            .       .       .       .       .       .       .
455     65      0x41            .       .       .       .       .       .       .
..
482     76      0x4C            .       .       .       .       .       .       .
484     77      0x4D            .       .       .       .       .       .       .
487     78      0x4E            .       .       .       .       .       .       .
489     79      0x4F            .       .       .       .       .       .       .
491     80      0x50            .       .       .       .       .       .       .
494     81      0x51            .       .       .       .       .       .       .
496     82      0x52            .       .       .       .       .       .       .
498     83      0x53            .       V       V       V       V       V       .
500     84      0x54            .       .       .       .       .       .       .
503     85      0x55            .       .       .       .       .       .       .
505     86      0x56            .       .       .       .       .       .       .
..
541     101     0x65            .       .       .       .       .       .       .
543     102     0x66            .       .       .       .       .       .       .
546     103     0x67            .       .       .       .       .       .       .
548     104     0x68            .       .       .       .       .       .       .
551     105     0x69            V       V       V       V       V       V       .
553     106     0x6A            .       .       .       .       .       .       .
557     107     0x6B            .       .       .       .       .       .       .
559     108     0x6C            .       .       .       .       .       .       .
561     109     0x6D            .       .       .       .       .       .       .
564     110     0x6E            .       .       .       .       .       .       .
566     111     0x6F            .       .       .       .       .       .       .
569     112     0x70            .       .       .       .       .       .       .
571     113     0x71            .       .       .       .       .       .       .
573     114     0x72            .       .       .       .       .       .       .
576     115     0x73            .       .       .       .       .       .       .
578     116     0x74            .       .       .       .       .       .       .
581     117     0x75            .       .       .       .       .       .       .
583     118     0x76            .       .       .       .       .       .       .
585     119     0x77            V       V       V       V       V       V       .
588     120     0x78            .       .       .       .       .       .       .
590     121     0x79            .       .       .       .       .       .       .
593     122     0x7A            .       .       .       .       .       .       .
595     123     0x7B            .       .       .       .       .       .       .
598     124     0x7C            .       .       .       .       .       .       .
601     125     0x7D            .       .       .       .       .       .       .
603     126     0x7E            .       .       .       .       .       .       .
606     127     0x7F            .       .       .       .       .       .       V

The same with 680ohm pullups. The GY-80 module includes a level translator afaik, so the pullups value may not have direct impact on the signal shape at the sensors..

I have pull ups of 3.2K (measured value), so my signal might be more "square"

I have added a link to your MultiSpeed I2C Scanner in Arduino Playground - I2cScanner
See the "Interesting Links" section.
But I don't like that link to reply 4.

robtillaart, could you give your Multispeed I2C Scanner it's own place and adjust that link in the i2c_scanner ?
You could add it to the i2c_scanner page, but perhaps that is confusing for new users, that page is very simple now, and that is better for new users.
Another option to edit your first post, and make that the main article and for your scanner.

good proposal,
will put the link in the first post.

@krodal

  • moved last code to first post
  • updated link in the 12csanner page
  • added a small header in i2c scanner page (you may remove it)

Short testrun on a MEGA r3 today => worked smooth.

Hi Rob,

I used your MultispeedScanner 0.1.03 for Test an I2C Circuit. It works fine with a Duemilanova, but if I use an Arduino Due (with levelshifter from 3.3V to 5V) I got no Answer from any I2C chip. The change for the Due I did is to comment out the "TWBR-Statement". I used IDE 1.5.6-R2.
In this Postings you can find als some scope and small pieces from the a logic analyzer.
http://forum.arduino.cc/index.php?topic=234999.msg1692208#msg1692208

Regards, Detlef

AFAIK, the DUE has problems with I2C but I never dived into the details.

Can you get meaningful results from other I2C scanners on the DUE?

Two modifications were necessary for MultiSpeed I2C Scanner to work with Due.

  1. TWBR must be emulated by adding the following code after the #include statements (cf. ARM support · Issue #48 · jrowberg/i2cdevlib · GitHub):
#if defined(__arm__)
class TWBRemulation
{
public:
    inline TWBRemulation & operator = (int val) __attribute__((always_inline)) {
    if (val == 12 || val == ((F_CPU / 400000) - 16) / 2) {
        #if F_BUS == 48000000
        I2C0_F = 0x1A; // 400 kHz
        #elif F_BUS == 24000000
        I2C0_F = 0x45; // 400 kHz
        #endif
    }
    return *this;
}
};
TWBRemulation TWBR;
#endif
  1. Due's pull-up resistors are unsuitable for most I2C devices (cf. Due I2C not working - Arduino Due - Arduino Forum). Thus I removed the onboard network resistor, and used external 4.7k pull-ups.

(Maybe using the Wire1 library instead of Wire and connecting an externally-pulluped I2C bus to SCL1/SDA1 pins will work, too, but I just checked the above mentioned workaround works.)

And please use a Nightly build version of Arduino IDE. Because the Wire library before 1.5.7 including the current 1.5.6r2 has a serious bug on the return values of TwoWire::endTransmission function. (cf. Fix for Due Wire library by bluesign2k · Pull Request #1994 · arduino/Arduino · GitHub )

Thanks for these additions (have no time to confirm, sorry )

Did you get meaningful results with the I2C scanner now?

Oh....
I'm sorry. This morning I found the addition 1 is meaningless and not working as multi speeds. It only scans at 100kHz.
So if you only need to scan at 100kHz, simply comment out the TWBR code and use the nightly ide 1.5.7.

(cf. MPU_DMP6 with Arduino DUE (TWBR not declared) - MPU-6050 6-axis accelerometer/gyroscope (InvenSense) - I2Cdevlib Forums)

updated to 0.1.04 (see first post)

main change is restricting the # addresses to be scanned as I2C address 0..7 and 120..127 have special meanings.

or download from here - Arduino/sketches/MultiSpeedI2CScanner at master · RobTillaart/Arduino · GitHub -

updated to version 0.1.05 on github

not tested enough imho, so not updated in the first post.

as always comments and remarks are welcome.

Hi,
I have added the Multi Speed I2C to my webserver, running on a Arduino Mega 2560.

But when I let it try 500kHz my webserver crashes.
Is it possible to detect a I2C error without causing a crash ?

In Arduino 1.5.8 the new Wire.setClock() can be used.

table-multispeedtest.png

Peter_n:
Is it possible to detect a I2C error without causing a crash ?

Really depends on the cause of the crash.
Does the I2C scanner work when used standalone (no webserver)?
Does the webserver crash if you just set the I2C clock to 500KHz?

You may post your code ....