You are using staging server - a separate instance of the ESP Component Registry that allows you to try distribution tools and processes without affecting the real registry.
(See the README.md file in the upper level 'examples' directory for more information about examples.)
This example demonstrates usage of C++ exceptions in ESP-IDF. It is the C++ equivalent to the I2C Simple Example which is written in C.
In this example, the sdkconfig.defaults
file sets the CONFIG_COMPILER_CXX_EXCEPTIONS
option. This enables both compile time support (-fexceptions
compiler flag) and run-time support for C++ exception handling. This is necessary for the C++ I2C API.
To run this example, you should have one ESP32, ESP32-S series or ESP32-C series based development board as well as an MPU9250. MPU9250 is an inertial measurement unit, which contains an accelerometer, gyroscope as well as a magnetometer, for more information about it, you can read the datasheet of the MPU9250 sensor.
Note: The following pin assignments are used by default, you can change these in the menuconfig
.
SDA | SCL | |
---|---|---|
ESP I2C Master | I2C_MASTER_SDA | I2C_MASTER_SCL |
MPU9250 Sensor | SDA | SCL |
For the actual default value of I2C_MASTER_SDA
and I2C_MASTER_SCL
, see Example Configuration
in menuconfig
.
Note: There's no need to add external pull-up resistors for SDA/SCL pins, because the driver will enable the internal pull-up resistors.
Plaintext
idf.py menuconfig
Plaintext
idf.py -p <PORT> flash monitor
Replace with the name of the serial port. To exit the serial monitor, type Ctrl-]
.
See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.
If the sensor is read correctly:
Bash
I (328) i2c-simple-example: I2C initialized successfully
I (338) i2c-simple-example: WHO_AM_I = 71
I (338) i2c-simple-example: I2C de-initialized successfully
If something went wrong:
Plaintext
I2C Exception with error: ESP_FAIL (-1)
Couldn't read sensor!
To create a project from this example, run:
idf.py create-project-from-example "0xjakob/esp-idf-cxx=1.0.0:simple_i2c_rw_example"