1# Example: C++ I2C sensor read for MCP9808 2 3(See the README.md file in the upper level 'examples' directory for more information about examples.) 4 5This example demonstrates usage of C++ exceptions in ESP-IDF. 6 7In this example, the `sdkconfig.defaults` file sets the `CONFIG_COMPILER_CXX_EXCEPTIONS` option. 8This enables both compile time support (`-fexceptions` compiler flag) and run-time support for C++ exception handling. 9This is necessary for the C++ I2C API. 10 11## How to use example 12 13### Hardware Required 14 15An MCP9808 sensor and any commonly available ESP32 development board. 16Pullups aren't necessary as the default pullups are enabled in the I2CMaster class. 17 18### Configure the project 19 20``` 21idf.py menuconfig 22``` 23 24### Build and Flash 25 26``` 27idf.py -p PORT flash monitor 28``` 29 30(Replace PORT with the name of the serial port.) 31 32(To exit the serial monitor, type ``Ctrl-]``.) 33 34See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects. 35 36## Example Output 37 38If the sensor is read correctly: 39 40``` 41Current temperature: 24.875 42``` 43 44If something went wrong: 45``` 46I2C Exception with error: ESP_FAIL (-1) 47Coulnd't read sensor! 48``` 49 50