Skip to content

(not issue; addition) faster esp32 arduino IDE implementation #558

@thijses

Description

@thijses

the files you made for the ESP_IDF can be turned into an arduino library with 1 change (which might be cleaner to do in general?):
the I2Cdev::initialize() function for the esp32 implementation is currently empty, it does nothing.
but if you just fill in the driver/i2c init functions from the example.c file:
i2c_param_config and i2c_driver_install
into the ::initialize() function, something like this:
void I2Cdev::initialize(uint8_t PIN_SDA, uint8_t PIN_CLK, uint32_t clk_speed) { i2c_config_t conf; conf.mode = I2C_MODE_MASTER; conf.sda_io_num = (gpio_num_t)PIN_SDA; conf.scl_io_num = (gpio_num_t)PIN_CLK; conf.sda_pullup_en = GPIO_PULLUP_ENABLE; conf.scl_pullup_en = GPIO_PULLUP_ENABLE; conf.master.clk_speed = clk_speed; ESP_ERROR_CHECK(i2c_param_config(I2C_NUM, &conf)); ESP_ERROR_CHECK(i2c_driver_install(I2C_NUM, I2C_MODE_MASTER, 0, 0, 0)); }
(readable?:
void I2Cdev::initialize(uint8_t PIN_SDA, uint8_t PIN_CLK, uint32_t clk_speed) {
i2c_config_t conf;
conf.mode = I2C_MODE_MASTER;
conf.sda_io_num = (gpio_num_t)PIN_SDA;
conf.scl_io_num = (gpio_num_t)PIN_CLK;
conf.sda_pullup_en = GPIO_PULLUP_ENABLE;
conf.scl_pullup_en = GPIO_PULLUP_ENABLE;
conf.master.clk_speed = clk_speed;
ESP_ERROR_CHECK(i2c_param_config(I2C_NUM, &conf));
ESP_ERROR_CHECK(i2c_driver_install(I2C_NUM, I2C_MODE_MASTER, 0, 0, 0));
}
)

with default parameters like 21,22,400000 in the header file,
then you can use it like a regular arduino library and init the I2C bus with I2Cdev::initialize() instead of Wire.begin()
i've never made (real) library.properties files before, so you'll have to forgive the crap i put in the linked zip file.
I2Cdev.zip

i do also need to include "Arduino.h" in MPU6050.h and <pgmspace.h> in motionApps to make it work
I am trying to read some DMP data, which took 1100-1200 micros before, but with the esp32 library it takes about 1000 micros (at 600Khz input freq, which is like 490Khz real due to ESP's weird clock)

edit:
i downloaded a newer version of the MPU6050 library (from this repository's Arduino folder), which needs readWords and writeWords, so i added those:
I2Cdev.zip
it just splits/merges words and sends/receives them using readBytes/writeBytes, super simple

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions