No, Arduino Core does not install any drivers unless you ask it to do so. So yes, in your Arduino sketch you can use ESP-IDF API freely. Just choose what to use: either ESP-IDF or Arduino COre. No conflicts.
the code of post 15 is not complete and is for ESP32 core V 2.x.x.
this works with ESP32 core 3.3.11
// ESP32 I2C scanner using Espressif driver/i2c_master.h
// https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/peripherals/i2c.html
// https://github.com/espressif/esp-idf/blob/2067f3ae32b7e7b61a0f3a052df63d619cd7c61d/examples/peripherals/i2c/i2c_basic/main/i2c_basic_example_main.c
#include <Arduino.h>
#include "driver/i2c_master.h"
#define I2C_MASTER_SCL_IO (gpio_num_t)9 /*!< GPIO number used for I2C master clock */
#define I2C_MASTER_SDA_IO (gpio_num_t)8 /*!< GPIO number used for I2C master data */
#define I2C_MASTER_NUM I2C_NUM_0 /*!< I2C port number for master dev */
#define I2C_MASTER_FREQ_HZ 100000 //CONFIG_I2C_MASTER_FREQUENCY /*!< I2C master clock frequency */
#define I2C_MASTER_TX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
#define I2C_MASTER_RX_BUF_DISABLE 0 /*!< I2C master doesn't need buffer */
#define I2C_MASTER_TIMEOUT_MS 1000
i2c_master_bus_handle_t bus_handle;
esp_err_t err = ESP_OK;
void setup() {
Serial.begin(115200);
delay(2000);
Serial.println("\nESP32 I2C scanner using Espressif driver/i2c_master.h");
i2c_scan();
}
void loop() {}
void i2c_scan(void) {
Serial.println("Starting I2C bus scan...");
// configure the I2C master bus
i2c_master_bus_config_t bus_config = {
.i2c_port = I2C_MASTER_NUM,
.sda_io_num = I2C_MASTER_SDA_IO,
.scl_io_num = I2C_MASTER_SCL_IO,
.clk_source = I2C_CLK_SRC_DEFAULT,
.glitch_ignore_cnt = 7,
.flags{
.enable_internal_pullup = true,
}
};
if (err = i2c_new_master_bus(&bus_config, &bus_handle) != ESP_OK) {
Serial.printf("i2c_new_master_bus FAIL err = %d\n", err);
while (1) delay(100);
}
// scan I2C addresses
for (uint8_t addr = 1; addr < 127; addr++) {
// probe device addr to see if on bus - print sucess or fail message
if (err = i2c_master_probe(bus_handle, addr, -1) != ESP_OK) {
Serial.printf("i2c_master_probe address 0x%02x FAIL err = %d\n", addr, err);
} else
Serial.printf("i2c_master_probe address 0x%02X OK \n", addr);
}
i2c_del_master_bus(bus_handle);
Serial.println("I2C scan finished.");
}
running on an ESP32S3 with a BME280 connected to the I2C bus (address 0x76)
serial monitor output only showing start and end of scan
ESP32 I2C scanner using Espressif driver/i2c_master.h
Starting I2C bus scan...
i2c_master_probe address 0x01 FAIL err = 1
i2c_master_probe address 0x02 FAIL err = 1
i2c_master_probe address 0x03 FAIL err = 1
i2c_master_probe address 0x04 FAIL err = 1
i2c_master_probe address 0x05 FAIL err = 1
i2c_master_probe address 0x06 FAIL err = 1
i2c_master_probe address 0x07 FAIL err = 1
i2c_master_probe address 0x08 FAIL err = 1
....
i2c_master_probe address 0x73 FAIL err = 1
i2c_master_probe address 0x74 FAIL err = 1
i2c_master_probe address 0x75 FAIL err = 1
i2c_master_probe address 0x76 OK
i2c_master_probe address 0x77 FAIL err = 1
i2c_master_probe address 0x78 FAIL err = 1
i2c_master_probe address 0x79 FAIL err = 1
i2c_master_probe address 0x7a FAIL err = 1
i2c_master_probe address 0x7b FAIL err = 1
i2c_master_probe address 0x7c FAIL err = 1
i2c_master_probe address 0x7d FAIL err = 1
i2c_master_probe address 0x7e FAIL err = 1
I2C scan finished.
ESP32-0C6 slave does not appear
EDIT: if I run the above I2C scanner code on the ESP32-C6 and have the ESP32-S3 running WireSlave (I2C address 0x55) the scanner displays (note BME280 I2C address 0x76 also connected to I2C bus)
ESP32 I2C scanner using Espressif driver/i2c_master.h
Starting I2C bus scan...
i2c_master_probe address 0x01 FAIL err = 1
i2c_master_probe address 0x02 FAIL err = 1
i2c_master_probe address 0x03 FAIL err = 1
i2c_master_probe address 0x04 FAIL err = 1
i2c_master_probe address 0x05 FAIL err = 1
i2c_master_probe address 0x06 FAIL err = 1
...
i2c_master_probe address 0x53 FAIL err = 1
i2c_master_probe address 0x54 FAIL err = 1
i2c_master_probe address 0x55 OK
i2c_master_probe address 0x56 FAIL err = 1
i2c_master_probe address 0x57 FAIL err = 1
...
i2c_master_probe address 0x73 FAIL err = 1
i2c_master_probe address 0x74 FAIL err = 1
i2c_master_probe address 0x75 FAIL err = 1
i2c_master_probe address 0x76 OK
i2c_master_probe address 0x77 FAIL err = 1
i2c_master_probe address 0x78 FAIL err = 1
i2c_master_probe address 0x79 FAIL err = 1
i2c_master_probe address 0x7a FAIL err = 1
i2c_master_probe address 0x7b FAIL err = 1
i2c_master_probe address 0x7c FAIL err = 1
i2c_master_probe address 0x7d FAIL err = 1
i2c_master_probe address 0x7e FAIL err = 1
I2C scan finished.
type or paste code here
displays the ESP32-S3 WireSlave address 0x55 and the BME280 address 0x76
raised problem on ESP32 Arduino Forum - see ESP32-C6 I2C slave not working
reply summary
This is a known limitation of the ESP32-C6 in the Arduino core: I2C slave mode is not implemented for the C6 (and C5) in the current arduino-esp32 framework