Description
Board
ESP32 DEV Module
Device Description
Using generic ESP32 dev board
Hardware Configuration
non
Version
v2.0.3
IDE Name
Arduino IDE
Operating System
Windows 11
Flash frequency
80
PSRAM enabled
no
Upload speed
921600
Description
I am using a vl53l3cx TOF sensor with an ESP32 board.
I am using this library and its example for testing and it works perfectly but I need to change inside the ESP32 package to make it work. To be specific inside the Wire.h file of the ESP32 package.
Initially, the example was not working directly but I read somewhere in the form that it needs to increase the I2C buffer size as the received packet size from the sensor is big therefore default size will not work.
#define I2C_BUFFER_LENGTH 128
First I tested it by changing the I2C_BUFFER_LENGTH to 256 directly in the Wire.h file and the example code is working perfectly. This test was done in the old ESP32 package release V1.0.6
But In the latest releases that I can see after V2.0.3 in Wire.h file it's defined like this
#ifndef I2C_BUFFER_LENGTH
#define I2C_BUFFER_LENGTH 128
#endif
So I thought I can increase the size of the buffer externally directly from the Arduino .ino file itself like this before including the Wire.h
#define I2C_BUFFER_LENGTH 256
#include<Wire.h>
But on uploading in this way the sensor data is not read properly like previously, So I checked by printing the I2C_BUFFER_LENGTH in Arduino code as well as inside the Wire.begin(); library function.
And shockingly it printed 256 in the Arduino code and when begin to function is called it printed 128.
So it seems like it not making any change to the I2C_BUFFER_LENGTH even it's defined before calling the library.
Is there any way to change the I2C_BUFFER_LENGTH without making any modifications to the ESP32 package itself?
As I think the Arduino compile is somehow compiling all ESP32 packagess before even we include them. As I have done the same test with the blank sketch with only Wire.h library included and I2C_BUFFER_LENGTH same results were seen.
Thank you,
Dharmik Patel
Sketch
#define I2C_BUFFER_LENGTH 256
#include<Wire.h>
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
delay(2000);
Serial.println(I2C_BUFFER_LENGTH); // here it will print 256 that what we need
Wire.begin(); // but in actually its not changed here it will print 128
}
void loop() {
// put your main code here, to run repeatedly:
}
Debug Message
None
Other Steps to Reproduce
To debug properly add this line inside your Wire.cpp file function
bool TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency)
add this inside that
Serial.println(I2C_BUFFER_LENGTH);
Finally, it will look like this
// Master Begin
bool TwoWire::begin(int sdaPin, int sclPin, uint32_t frequency)
{
Serial.println(I2C_BUFFER_LENGTH);
I have checked existing issues, online documentation and the Troubleshooting Guide
- I confirm I have checked existing issues, online documentation and Troubleshooting guide.
Metadata
Metadata
Assignees
Type
Projects
Status