arduino-libraries / Arduino_LSM6DS3

LSM6DS3 Library for Arduino
GNU Lesser General Public License v2.1
30 stars 31 forks source link

For I2C, end() method calls for _wire->end() instead of _wire->endTransmission() #17

Open cjinn opened 3 years ago

cjinn commented 3 years ago

I noticed, when trying out this library for a ESP32 and I2C project, this library does not compile due to the following errors:

libraries\Arduino_LSM6DS3\src\LSM6DS3.cpp: In member function 'void LSM6DS3Class::end()':`
`libraries\Arduino_LSM6DS3\src\LSM6DS3.cpp:110:12: error: 'class TwoWire' has no member named 'end'_wire->end()';

This issue is only present when compiling for any ESP32 boards. When I switched the board to a Arduino board, it compiles.

Further investigate reveals, on both Arduino ESP32's Wire.h and the Arduino Standard Library use endTransmission(), not end().

A hotfix inside LSM6DS3.cpp that got my library to compile would be of the following:

void LSM6DS3Class::end()
{
  if (_spi != NULL) {
    _spi->end();
    digitalWrite(_csPin, LOW);
    pinMode(_csPin, INPUT);
  } else {
    writeRegister(LSM6DS3_CTRL2_G, 0x00);
    writeRegister(LSM6DS3_CTRL1_XL, 0x00);

    _wire->end(); // This does not compile for esp32. Somehow works for Arduino. Legacy code?
    // _wire->endTransmission();
  }
}

I'm wondering if the above code is all that is required to fix this issue.

cjinn commented 3 years ago

Forgot to mention my library/environment versions:

abrahmx commented 2 years ago

I noticed, when trying out this library for a ESP32 and I2C project, this library does not compile due to the following errors:

libraries\Arduino_LSM6DS3\src\LSM6DS3.cpp: In member function 'void LSM6DS3Class::end()':`
`libraries\Arduino_LSM6DS3\src\LSM6DS3.cpp:110:12: error: 'class TwoWire' has no member named 'end'_wire->end()';

This issue is only present when compiling for any ESP32 boards. When I switched the board to a Arduino board, it compiles.

Further investigate reveals, on both Arduino ESP32's Wire.h and the Arduino Standard Library use endTransmission(), not end().

A hotfix inside LSM6DS3.cpp that got my library to compile would be of the following:

void LSM6DS3Class::end()
{
  if (_spi != NULL) {
    _spi->end();
    digitalWrite(_csPin, LOW);
    pinMode(_csPin, INPUT);
  } else {
    writeRegister(LSM6DS3_CTRL2_G, 0x00);
    writeRegister(LSM6DS3_CTRL1_XL, 0x00);

    _wire->end(); // This does not compile for esp32. Somehow works for Arduino. Legacy code?
    // _wire->endTransmission();
  }
}

I'm wondering if the above code is all that is required to fix this issue.

Thank you for this, I'm using ESP8266 and I was getting this error as well. After changing this I could compile and upload. My settings are: Platformio(v2.5.1) on VS Code, Platform espressif8266, board = nodemcuv2, framework = Arduino.

Regards