I2C Ping/Check connected devices

Hi I am using the Ports and PortsSHT21 Libraries to use SHT21 sensors on a project as well as the standard "hard" I2C with SHT2x Library. I need to be able to check if the sensors are actually connected. Is there any way to do this?
I am hoping for a relatively simple way to do something like ping the sensors to see if they are present.

Here are the libraries I am using.

Thanks

The SHT21 sensor has a fixed address of 0x40, so you can simply send a command to the sensor and if it replies it's connected. I'd use the "Read User Register" command (0xE7) for that, by default you should get at least a 1 in bit 1.

Thanks, That works for the one on the 'hard' i2c but what about the 7 others I have running on soft ports?

way over my head but i see a lot of SHT21 going on!

Why should there be any difference on the soft ports? If the soft ports work, you can send commands to the device and get a response if the device is there, no response if the device is absent.

I don't know how well the Ports library works, I found at least some strange code:

    delayMicroseconds(2);
    digiWrite2(x);
    delayMicroseconds(5);

delayMicroseconds() has a minimal value of 4 because the call and the initialization of the variables need about 4 microseconds at least. It probably works but it's a sign that other problems may exist too.

Hi,
I do realise that this library is not perfect, however in practice it works and quite reliably, I don't have the programming skills to actually fix it. I haven't quite worked out how to just send commands and receive replies over the soft i2c channels yet.

Many thanks

Nick Gamon (one of the moderators) has written an I2C scanner on his site at http://www.gammon.com.au/forum/?id=10896

he says "If you have a device you aren't sure of the slave address of, you can run the sketch below. It tries every possible address (from 1 to 119) and if a device responds, prints that address."

// I2C Scanner
// Written by Nick Gammon
// Date: 20th April 2011

#include <Wire.h>

void setup() {
  Serial.begin (115200);
  Serial.println ();
  Serial.println ("I2C scanner. Scanning ...");
  byte count = 0;
  
  Wire.begin();
  for (byte i = 1; i < 120; i++)
  {
    Wire.beginTransmission (i);
    if (Wire.endTransmission () == 0)
      {
      Serial.print ("Found address: ");
      Serial.print (i, DEC);
      Serial.print (" (0x");
      Serial.print (i, HEX);
      Serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of good response
  } // end of for loop
  Serial.println ("Done.");
  Serial.print ("Found ");
  Serial.print (count, DEC);
  Serial.println (" device(s).");
}  // end of setup

void loop() {}

Thanks Lemming good find.
My only question now is ow to implement that on all 7 soft ports.

Beyond me but maybe you should ping Nick as he is the moderator for this forum.

Hi, thanks
I have PM'd him, hopefully he should reply soon.

Ok so I ran the code and the scan picks up 9 devices,

I2C scanner. Scanning ...
Found address: 64 (0x40)
Found address: 80 (0x50)
Found address: 81 (0x51)
Found address: 82 (0x52)
Found address: 83 (0x53)
Found address: 84 (0x54)
Found address: 85 (0x55)
Found address: 86 (0x56)
Found address: 87 (0x57)
Done.
Found 9 device(s).

The first one is the hard I2C channel SHT21 and then the second one is an I2C EEPROM chip, then I am guessing the other 7 detected are my soft channels. but only 3 of the channels have devices connected.