https://github.com/unidentifieddeveloper/esp-mcp9808
MCP9808 driver for ESP32 (ESP-IDF)
https://github.com/unidentifieddeveloper/esp-mcp9808
embedded-systems esp-idf esp32 espressif i2c-driver mcp9808
Last synced: 4 months ago
JSON representation
MCP9808 driver for ESP32 (ESP-IDF)
- Host: GitHub
- URL: https://github.com/unidentifieddeveloper/esp-mcp9808
- Owner: unidentifieddeveloper
- Created: 2019-09-03T19:59:10.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-09-03T21:18:38.000Z (over 6 years ago)
- Last Synced: 2025-01-03T11:46:30.923Z (about 1 year ago)
- Topics: embedded-systems, esp-idf, esp32, espressif, i2c-driver, mcp9808
- Language: C
- Size: 1.95 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# MCP9808 driver for ESP32 (ESP-IDF)
An MCP9808 digital temperature sensor driver for the Espressif Systems' ESP32.
## Overview
This is a simple driver which builds upon the ESP-IDF I2C driver and adds a few
functions to make it easy to read ambient temperature, etc.
*It does not configure or install the I2C driver - this must be done by the user.*
## Example usage
Add the repository as a submodule (or clone it) into your `components/` directory.
```sh
$ git submodule add https://github.com/unidentifieddeveloper/esp-mcp9808 components/mcp9808
```
Next, setup I2C and then init the MCP9808 driver and read ambient temperature.
```c
#include "mcp9808.h"
void app_main()
{
// TODO: Setup I2C as you see fit
// - i2c_param_config
// - i2c_driver_install
mcp9808_config_t mcp_config;
mcp_config.address = 0x18;
mcp_config.i2c_num = I2C_NUM_1;
mcp9808_handle_t mcp;
uint16_t mcp_manuf_id;
uint16_t mcp_device_id;
if (mcp9808_init(&mcp_config, &mcp, &mcp_manuf_id, &mcp_device_id) != ESP_OK)
{
return;
}
float temperature;
if (mcp9808_ambient_temp(mcp, &temperature) != ESP_OK)
{
return;
}
ESP_LOGI(TAG, "Temperature: %f", temperature);
mcp9808_delete(mcp);
}
```