AS3935 with i2c

Hi guys! I need your help!
I’m gonna use a sensor (https://www.embeddedadventures.com/datasheets/AS3935_Datasheet_EN_v2.pdf).
It works with i2c and spi interfaces. I need to use it with the i2c interface, but the library (AS3935 library ) uses the i2c.h (i2c.h library) instead of the wire.h .

The differences are 2:

the i2c.h library has two functions used in the sensor’s library

uint8_t I2C::read(uint8_t address, uint8_t registerAddress, uint8_t numberBytes)
{
  bytesAvailable = 0;
  bufferIndex = 0;
  if(numberBytes == 0){numberBytes++;}
  nack = numberBytes - 1;
  returnStatus = 0;
  returnStatus = start();
  if(returnStatus){return(returnStatus);}
  returnStatus = sendAddress(SLA_W(address));
  if(returnStatus)
  {
    if(returnStatus == 1){return(2);}
    return(returnStatus);
  }
  returnStatus = sendByte(registerAddress);
  if(returnStatus)
  {
    if(returnStatus == 1){return(3);}
    return(returnStatus);
  }
  returnStatus = start();
  if(returnStatus)
  {
    if(returnStatus == 1){return(4);}
    return(returnStatus);
  }
  returnStatus = sendAddress(SLA_R(address));
  if(returnStatus)
  {
    if(returnStatus == 1){return(5);}
    return(returnStatus);
  }
  for(uint8_t i = 0; i < numberBytes; i++)
  {
    if( i == nack )
    {
      returnStatus = receiveByte(0);
      if(returnStatus == 1){return(6);}
      if(returnStatus != MR_DATA_NACK){return(returnStatus);}
    }
    else
    {
      returnStatus = receiveByte(1);
      if(returnStatus == 1){return(6);}
      if(returnStatus != MR_DATA_ACK){return(returnStatus);}
    }
    data[i] = TWDR;
    bytesAvailable = i+1;
    totalBytes = i+1;
  }
  returnStatus = stop();
  if(returnStatus)
  {
    if(returnStatus == 1){return(7);}
    return(returnStatus);
  }
  return(returnStatus);
}

and

uint8_t I2C::write(uint8_t address, uint8_t registerAddress, uint8_t data)
{
  returnStatus = 0;
  returnStatus = start(); 
  if(returnStatus){return(returnStatus);}
  returnStatus = sendAddress(SLA_W(address));
  if(returnStatus)
  {
    if(returnStatus == 1){return(2);}
    return(returnStatus);
  }
  returnStatus = sendByte(registerAddress);
  if(returnStatus)
  {
    if(returnStatus == 1){return(3);}
    return(returnStatus);
  }
  returnStatus = sendByte(data);
  if(returnStatus)
  {
    if(returnStatus == 1){return(3);}
    return(returnStatus);
  }
  returnStatus = stop();
  if(returnStatus)
  {
    if(returnStatus == 1){return(7);}
    return(returnStatus);
  }
  return(returnStatus);
}

that are not present in the wire.h .
How can I solve this problem? Thank you in advance! :slight_smile:

How can I solve this problem?

What problem? Why is the fact that the library uses I2C.h instead of Wire.h a problem?

The Wire library HAS read() and write() methods.

Yes, but the sensor's library uses
these methods

I2c.read((uint8_t)_devadd, (uint8_t)RegAdd, (uint8_t)0x01);

and

I2c.write(_devadd, RegAdd, NewRegData);

that are not present in the wire.h library

From the wire.h library:

		void begin(uint8_t);
		void begin(int);
		void beginTransmission(uint8_t);
		void beginTransmission(int);
		uint8_t endTransmission(void);
		uint8_t endTransmission(uint8_t);
		uint8_t requestFrom(uint8_t, uint8_t);
		uint8_t requestFrom(int, int);
		void __attribute__((deprecated("Use write() instead"))) send(uint8_t);
		void __attribute__((deprecated("Use write() instead"))) send(uint8_t*, uint8_t);
		void __attribute__((deprecated("Use write() instead"))) send(int);
		void __attribute__((deprecated("Use write() instead"))) send(char*);
		int write(uint8_t);
		int write(uint8_t*, uint8_t);
		int write(int);
		int write(char*);
		uint8_t available(void);
		uint8_t __attribute__((deprecated("Use read() instead"))) receive(void);
		uint8_t read(void);
		void onReceive(void (*)(int));
		void onRequest(void (*)(void));

as you can see the arent't the same methods.