Closed shivapower1985 closed 2 years ago
There is no use of esp-idf-lib in your code. It has nothing to do with esp-idf-lib. This repository is not a beginner support forum. To successfully work with aht10, use the appropriate component (aht) from esp-idf-lib.
The issue
Hi UncleRus, I altered the library to read temperature and humidity data from AHT10. Please see the Mail code file and output below. Please help me to solve the problem
################Here is my code below############### // MAIN FILE
include "esp_event.h"
include "esp_log.h"
include "esp_spi_flash.h"
include "esp_system.h"
include "freertos/FreeRTOS.h"
include "freertos/event_groups.h"
include "freertos/task.h"
include "nvs_flash.h"
include "sdkconfig.h"
include "driver/gpio.h"
include "esp_log.h"
include "driver/i2c.h"
include
include "esp_err.h"
define I2C_MASTER_NUM 0
define ESP_ERR_AHT10_BASE 0x30000
define ESP_ERR_TOO_SLOW_TICK_RATE (ESP_ERR_AHT10_BASE + 1)
define ESP_ERR_AHT10_NOT_DETECTED (ESP_ERR_AHT10_BASE + 2)
define ESP_ERR_AHT10_CALIBRATION_FAILURE (ESP_ERR_AHT10_BASE + 3)
// Tag for logging from this file static const char TAG = "user"; static const char AHT10_I2C_LOG_TAG = "AHT10 I2C Read";
// slave address of aht10 uint8_t fd_AHT = 0x39;
uint8_t pl_i2c_read(uint8_t slave_addr) { // hold payload data to read uint8_t byte = 0;
}
esp_err_t pl_i2c_init(gpio_num_t sda_pin, gpio_num_t scl_pin, uint32_t clock_speed) { // configuration object for i2c driver esp_err_t err; i2c_config_t i2c_conf; int i2c_master_port = I2C_MASTER_NUM; memset(&i2c_conf, 0, sizeof(i2c_config_t)); // set parameters a master i2c_conf.mode = I2C_MODE_MASTER; i2c_conf.sda_io_num = sda_pin; i2c_conf.sda_pullup_en = GPIO_PULLUP_ENABLE; i2c_conf.scl_io_num = scl_pin; i2c_conf.scl_pullup_en = GPIO_PULLUP_ENABLE; i2c_conf.master.clk_speed = clock_speed;
} //end
//Description // Write 0x2E into reg 0xF4, wait 4.5ms and then read // registers 0xF6 (MSB), 0xF7 (LSB). Log the value to the // console. //*/ // Get the temperature int32_t al_aht10_get_ut(uint8_t slave_addr) { int32_t ut = 0;
}
int32_t al_aht10_get_temperature() { float t = al_aht10_get_ut(fd_AHT); // algorithm for the temperature
}
// application entry point void app_main() { // Initialize NVS esp_err_t ret = nvs_flash_init(); if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) { ESP_ERROR_CHECK(nvs_flash_erase()); ret = nvs_flash_init(); } ESP_ERROR_CHECK(ret);
}
##############End of the CODE #############
OUTPUT: W (350) user: Hello world! I (350) user: finished init I (350) AHT10 I2C Read: I2C successfully initialized I (410) user: byte= 7 I (410) user: temperature in degree celsius: 7.000000 I (410) user: temperature= 7.0 I (5470) user: byte= 7 I (5470) user: temperature in degree celsius: 7.000000 I (5470) user: temperature= 7.0
The answer shows only 7 .............please help me to solve this problem
Which SDK are you using?
esp-idf
Which version of SDK are you using?
ESP-IDF V4.4
Which build target have you used?
Component causing the issue
aht
Anything in the logs that might be useful for us?
No response
Additional information or context
No response
Confirmation