Please file an issue in Issues · platformio/platform-espressif32 · GitHub to get help from the developers. If basic I2C sketches do not execute correctly although both should be using the Arduino Core 2.0.3 with the exact same board definition , so especially the same I2C SDA and SCL pins, the outcome should be the same. It not being the same hints at a bug.
How do I make sure that I’m using the same board definition as the arduino ide?
On arduino ide I do Tools > Board > ESP32 Arduino > Adafruit Feather ESP32-S2
,
On platformio I have platformio.ini
[env:featheresp32-s2]
platform = espressif32
board = featheresp32-s2
framework = arduino
Does that ensure I have the same board definition?
It should. Selecting Adafruit Feather ESP32-S2
in the Arduino IDE uses the definitions from here , most importantly the variant folder as adafruit_feather_esp32s2
.
Using board = featheresp32-s2
maps to featheresp32-s2.json which has that same adafruit_feather_esp32s2
variant set.
Not a platformio issue, Just a feather esp32-s2 quirk.
opened 12:29AM - 25 May 22 UTC
closed 01:06AM - 26 May 22 UTC
## TLDR
Works on arduino IDE but not on platformio
----
I'm using a [Adaf… ruit ESP32-S2 Feather with BME280 Sensor](https://www.adafruit.com/product/5303). I'm trying to access the sensor using the [i2c scanner](https://playground.arduino.cc/Main/I2cScanner/)
```
#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.
Needed to configure the i2c correctly (I2C Scan Test | Adafruit ESP32-S2 Feather | Adafruit Learning System )
pinMode(PIN_I2C_POWER, INPUT);
delay(1);
bool polarity = digitalRead(PIN_I2C_POWER);
pinMode(PIN_I2C_POWER, OUTPUT);
digitalWrite(PIN_I2C_POWER, !polarity);
But how come in PlatformIo you have to add this code when you said that
where that is not explicitly done? Same could should lead to same results.
This I2C power initialization is already done in the adafruit_feather_esp32s2/variant.cpp , which is called here .
Let me do some sanity checks on whether this function is called at all when using PlatformIO. These _weak
functions are quirky in PlatformIO where you usually have to set lib_archive = no
in the platformio.ini
to make them work.
EDIT : Builder sript is bugged, see comment in issue above.