Skip to content

featheresp32-s2 does not work properly #815

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
kuravih opened this issue May 25, 2022 · 8 comments
Closed

featheresp32-s2 does not work properly #815

kuravih opened this issue May 25, 2022 · 8 comments

Comments

@kuravih
Copy link

kuravih commented May 25, 2022

TLDR

Works on arduino IDE but not on platformio


I'm using a Adafruit ESP32-S2 Feather with BME280 Sensor. I'm trying to access the sensor using the i2c scanner

#include "Arduino.h"
#include <Wire.h>

void setup() {
  Wire.begin();

  Serial.begin(9600);
  while (!Serial);
  Serial.println("\nI2C Scanner");
}


void loop() {
  byte error, address;
  int nDevices;

  Serial.println("Scanning...");

  nDevices = 0;
  for(address = 1; address < 127; address++ ) {
    // The i2c_scanner uses the return value of the Write.endTransmisstion to see if a device did acknowledge to the address.
    Wire.beginTransmission(address);
    error = Wire.endTransmission();

    if (error == 0) {
      Serial.print("I2C device found at address 0x");
      Serial.print(address, HEX);
      Serial.println("  !");
      nDevices++;
    } else if (error==4) {
      Serial.print("Unknown error at address 0x");
      Serial.println(address,HEX);
    }
    Serial.print("testing address ");
    Serial.println(address,HEX);
  }
  
  if (nDevices == 0)
    Serial.println("No I2C devices found\n");
  else
    Serial.println("done\n");

  delay(5000);  // wait 5 seconds for next scan
}

The platformio.ini:

[env:featheresp32-s2]
platform = espressif32
board = featheresp32-s2
framework = arduino

The board programs fine but the program does not find any of the sensors.

However using the Arduino IDE, and the board definition (Tools > Board > ESP32 Arduino > Adafruit Feather ESP32-S2) the program finds the two i2c sensors on the board as expected.

Another observation:

When programed through the Arduino IDE the programs prints the testing address xx lines all in one quick burst, (finds the two connected devices), then holds 5 seconds before doing another loop iteration. (ie. works as expected)

However when programmed using platformio the testing address xx lines print one by one in slow succession and does not find any of the connected devices.

@kuravih
Copy link
Author

kuravih commented May 25, 2022

BTW, Other sketches such as the blink and neopixel and serial port works fine using both programs.

@brentru
Copy link

brentru commented May 25, 2022

@valeros Noting that this is not an issue with PlatformIO.

@kuravih The Playground I2C scan example needs to be modified for the Feather ESP32-S2 because..

The Feather ESP32-S2 also has a power 'switch' on the I2C port. You need to activate the power port by setting the control pin (GPIO 7) to an OUTPUT and the opposite of the 'rest state' before accessing the I2C port.

Please try the modified i2c scan test on this page:
https://learn.adafruit.com/adafruit-esp32-s2-feather/i2c-scan-test

@kuravih
Copy link
Author

kuravih commented May 26, 2022

@brentru Thank you so much. I did not spot that section, Curiously it worked out of the box with the arduino ide, and not platfromio, so I just assumed it was a platfromio issue.

Marking as resolved,

@kuravih kuravih closed this as completed May 26, 2022
@maxgerhardt
Copy link
Contributor

The Arduino core has the I2C power up code built into an initialization function that is called by the core before setup() in adafruit_feather_esp32s2/variant.cpp, there should be no different code than in the Arduino IDE needed. It seems PlatformIO has problems linking this weak function and setting lib_archive = no in the platformio.ini might "fix" it

@maxgerhardt
Copy link
Contributor

maxgerhardt commented May 26, 2022

It seems the Arduino-ESP32 builder script has a bug in regards to linking in the variant.cpp object file in a way that makes the usage of the _weak initVariant function work.

Exchanging this with

    env.BuildSources(
        join("$BUILD_DIR", "FrameworkArduinoVariant"),
        join(variants_dir, env.BoardConfig().get("build.variant"))
    )

so that a .o file is linked and not a .a file makes the initVariant() function execute correctly (checked by Serial.println(digitalRead(NEOPIXEL_I2C_POWER)); now being 1 instead of 0).

The builder script for ESP32S2 is locally at <user home folder>/.platformio/packages/framework-arduinoespressif32/tools/platformio-build-esp32s2.py where the same type of modification can be done here. @kuravih can you test that and see if now the saem code as in the Arduino IDE works in PlatformIO?

CC @valeros

@maxgerhardt
Copy link
Contributor

maxgerhardt commented May 26, 2022

I've opened a pull request that fixes this as linked above.

@kuravih you can use the platformio.ini

[env:featheresp32-s2]
platform = espressif32
board = featheresp32-s2
framework = arduino
platform_packages =
   framework-arduinoespressif32@https://github.com/maxgerhardt/arduino-esp32.git#patch-3

to test this change.

@brentru
Copy link

brentru commented May 26, 2022

Thanks for supporting this, Max.

@kuravih
Copy link
Author

kuravih commented May 27, 2022

I tested the fix on hardware and verified it to be working. @maxgerhardt and @brentru Thank you very much for your time.

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

3 participants