Wire.Endtransmission: How can I test if I2C device available

Hello

How can I test if an I2C cable is installed before trying to start it with the Wire command code? The I2C cable would be use to drive an LCD for a diagnostic only. Don't need to have it installed permanently

Problem, code stall after Wire.endTransmission();

Wire.beginTransmission(0x20);
Wire.write(0xff); // put a high level on pins
Wire.endTransmission();

Martin

When the Wire.endTransmission() halts the sketch, then SDA is shortcut to GND or SCL is shortcut to GND or SDA is shortcut to SCL. Instead of a real "shortcut" it is also possible that a I2C device on the bus is not powered, or that there are no pullup resistors.

To check if something is on the bus. Use its address with Wire.beginTransmission(), then a Wire.endTransmission() and check the error returned by Wire.endTransmission().
That is how the I2C Scanner works: Arduino Playground - I2cScanner.

The I2C bus was not designed to let it go through a cable. How long is that cable ? What kind of cable ?
Can you tell which Arduino board you use and which display ?

you could do a check like suggested by sparkfun "isConnected" How to Write A Great Arduino Library - News - SparkFun Electronics

noiasca:
you could do a check like suggested by sparkfun "isConnected" How to Write A Great Arduino Library - News - SparkFun Electronics

Thank you Noissca. Great info, Will go trough it tonight.

Stay safe

Martin