# NXP Semiconductors PCT2075 Sensor
[](https://github.com/K0I05)
[](/LICENSE)
[](https://en.wikipedia.org/wiki/C_(programming_language))
[](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/index.html)
[](https://code.visualstudio.com/)
[](https://platformio.org/)
[](https://registry.platformio.org/libraries/k0i05/esp_pct2075)
[](https://components.espressif.com/components/k0i05/esp_pct2075)
This ESP32 espressif IoT development framework (esp-idf) i2c peripheral driver was developed for the NXP Semiconductors PCT2075 temperature sensor. Information on features and functionality are documented and can be found in the `pct2075.h` header file and in the `documentation` folder.
## Repository
The component is hosted on github and is located here: <https://github.com/K0I05/ESP32-S3_ESP-IDF_COMPONENTS/tree/main/components/peripherals/i2c/esp_pct2075>
## General Usage
To get started, simply copy the component to your project's `components` folder and reference the `pct2075.h` header file as an include. The component includes documentation for the peripheral such as the datasheet, application notes, and/or user manual where applicable.
```text
components
└── esp_pct2075
├── CMakeLists.txt
├── README.md
├── LICENSE
├── idf_component.yml
├── library.json
├── documentation
│ └── datasheets, etc.
├── include
│ └── pct2075_version.h
│ └── pct2075.h
└── pct2075.c
```
## Basic Example
Once a driver instance is instantiated the sensor is ready for usage as shown in the below example. This basic implementation of the driver utilizes default configuration settings and makes a measurement request from the sensor at user defined interval and prints the results.
```c
#include "pct2075.h"
void i2c0_pct2075_task( void *pvParameters ) {
// initialize the xLastWakeTime variable with the current time.
TickType_t last_wake_time = xTaskGetTickCount ();
//
// initialize i2c device configuration
pct2075_config_t dev_cfg = I2C_PCT2075_CONFIG_DEFAULT;
pct2075_handle_t dev_hdl;
//
// init device
pct2075_init(i2c0_bus_hdl, &dev_cfg, &dev_hdl);
if (dev_hdl == NULL) {
ESP_LOGE(APP_TAG, "pct2075 handle init failed");
assert(dev_hdl);
}
//
esp_err_t result;
// set overtemperature shutdown temperature
float ots_temperature;
result = pct2075_set_ots_temperature(dev_hdl, 85.6f);
if (result != ESP_OK) {
ESP_LOGE(APP_TAG, "pct2075 set overtemperature shutdown temperature failed (%s)", esp_err_to_name(result));
assert(result == ESP_OK);
}
result = pct2075_get_ots_temperature(dev_hdl, &ots_temperature);
if (result != ESP_OK) {
ESP_LOGE(APP_TAG, "pct2075 get overtemperature shutdown temperature failed (%s)", esp_err_to_name(result));
assert(result == ESP_OK);
} else {
ESP_LOGI(APP_TAG, "overtemperature shutdown temperature: %.2f °C", ots_temperature);
}
//
// set hysteresis temperature
float hys_temperature;
result = pct2075_set_hys_temperature(dev_hdl, 70.7f);
if (result != ESP_OK) {
ESP_LOGE(APP_TAG, "pct2075 set hysteresis temperature failed (%s)", esp_err_to_name(result));
assert(result == ESP_OK);
}
result = pct2075_get_hys_temperature(dev_hdl, &hys_temperature);
if (result != ESP_OK) {
ESP_LOGE(APP_TAG, "pct2075 get hysteresis temperature failed (%s)", esp_err_to_name(result));
assert(result == ESP_OK);
} else {
ESP_LOGI(APP_TAG, "hysteresis temperature: %.2f °C", hys_temperature);
}
//
// set sampling period
//
// task loop entry point
for ( ;; ) {
ESP_LOGI(APP_TAG, "######################## PCT2075 - START #########################");
//
// handle sensor
float temperature;
esp_err_t result = pct2075_get_temperature(dev_hdl, &temperature);
if(result != ESP_OK) {
ESP_LOGE(APP_TAG, "pct2075 device read failed (%s)", esp_err_to_name(result));
} else {
ESP_LOGI(APP_TAG, "air temperature: %.2f °C", temperature);
}
//
ESP_LOGI(APP_TAG, "######################## PCT2075 - END ###########################");
//
//
// pause the task per defined wait period
vTaskDelaySecUntil( &last_wake_time, I2C0_TASK_SAMPLING_RATE );
}
//
// free resources
pct2075_delete( dev_hdl );
vTaskDelete( NULL );
}
```
Copyright (c) 2024 Eric Gionet (<gionet.c.eric@gmail.com>)
idf.py add-dependency "k0i05/esp_pct2075^1.2.7"