Skip to content

Unable to communicate with LIS3DH on MagTag via I2C. #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
BeldrothTheGold opened this issue Aug 12, 2021 · 2 comments
Closed

Unable to communicate with LIS3DH on MagTag via I2C. #60

BeldrothTheGold opened this issue Aug 12, 2021 · 2 comments

Comments

@BeldrothTheGold
Copy link

BeldrothTheGold commented Aug 12, 2021

  • Arduino board: Adafruit MagTag 2.9"

  • Arduino IDE version (found in Arduino -> About Arduino menu): 1.8.15

  • arduino-esp32 2.0.0 RC-1 installed via the boards manager

  • List the steps to reproduce the problem below (if possible attach a sketch or
    copy the sketch code in too): LIST REPRO STEPS BELOW

Upload sketch, reboot and open Serial Monitor.

I believe the issue is being caused by the esp32 implementation of the TwoWire::endTransmission() function expecting the user to call Wire.write() prior to calling Wire.endTransmission()

uint8_t TwoWire::endTransmission(bool sendStop) // Assumes Wire.beginTransaction(), Wire.write()
https://github.com/espressif/arduino-esp32/blob/2af8cc34850c445b1b0694653f086b9f9b1f52f9/libraries/Wire/src/Wire.cpp#L171

Minimum Sketch to reproduce issue:

#include <Adafruit_LIS3DH.h>

Adafruit_LIS3DH lis = Adafruit_LIS3DH();

void setup() {  
  Serial.begin(115200);
  while (!Serial);
  
  if (! lis.begin(0x19)) {   // change this to 0x19 for alternative i2c address
    Serial.println("Couldnt start LIS3DH");
    while (1) yield();
  }

  Serial.print("Range = "); Serial.print(2 << lis.getRange());
  Serial.println("G");
}

void loop() {
  // put your main code here, to run repeatedly:

}

image

This seems like an OK workaround:

Adding the following lines to the detected() function in Adafruit_I2CDevice.cpp

bool Adafruit_I2CDevice::detected(void) {
  // Init I2C if not done yet
  if (!_begun && !begin()) {
    return false;
  }

  // A basic scanner, see if it ACK's
  _wire->beginTransmission(_addr);

#ifdef ESP32 
  // ESP32 implementation of wire expects write before endTransmission
  _wire->write(0);
#endif

  if (_wire->endTransmission() == 0) {

image

@BeldrothTheGold BeldrothTheGold changed the title Unable to communicate with LIS3DH on MagTag via Arduino. Unable to communicate with LIS3DH on MagTag via I2C. Aug 12, 2021
@caternuson
Copy link
Contributor

It could be this known issue with the ESP32-S2 RC1 BSP:
espressif/arduino-esp32#5470

@BeldrothTheGold
Copy link
Author

BeldrothTheGold commented Aug 12, 2021

It could be this known issue with the ESP32-S2 RC1 BSP:
espressif/arduino-esp32#5470

Indeed the PR does fix this issue as well. OK. I will close my issue. Thanks!
espressif/arduino-esp32@e5bd18d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants