Files

copied

There are no circuits or boards in this repository.

Last update 1 year 2 months by Darren Winter
FilesFirmware
..
.gitkeep
CMakeLists.txt
c_cpp_properties.json
launch.json
main.c
settings.json
shtc3.c
shtc3.h
tasks.json
main.c
#include "sdkconfig.h" #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "esp_log.h" #include "shtc3.h" #define SDA_GPIO 20 #define SCL_GPIO 21 #define TMP117_ADDRESS 0X48 #define SENSOR_ADDR 0x70 const char *TAG = "MAIN"; void ReadTMP117() //Communicating and reading from TMP117 { uint8_t raw[2]; i2c_cmd_handle_t cmd_handle = i2c_cmd_link_create(); i2c_master_start(cmd_handle); i2c_master_write_byte(cmd_handle, (TMP117_ADDRESS << 1) | I2C_MASTER_READ, true); i2c_master_read(cmd_handle, (uint8_t *)&raw, 2, I2C_MASTER_ACK); i2c_master_stop(cmd_handle); i2c_master_cmd_begin(I2C_NUM_0, cmd_handle, 1000 / portTICK_PERIOD_MS); i2c_cmd_link_delete(cmd_handle); int16_t data = (raw[0] << 8 | raw[1]); float temperature = (data * 0.0078125); printf("temperature from TMP117 is %f\n", temperature); vTaskDelay(1000/portTICK_PERIOD_MS); } void InitSensors() //Initiliazing I2C { i2c_config_t conf = { .mode = I2C_MODE_MASTER, .sda_io_num = SDA_GPIO, .scl_io_num = SCL_GPIO, .sda_pullup_en = GPIO_PULLUP_ENABLE, .scl_pullup_en = GPIO_PULLUP_ENABLE, .master.clk_speed = 100000}; i2c_param_config(I2C_NUM_0, &conf); i2c_driver_install(I2C_NUM_0, I2C_MODE_MASTER,0,0,0); } void ReadTHSHTC3() //Reading temperature and humidity from SHTC3 { //get_ID_sensor(SENSOR_ADDR); wakeup_sensor(SENSOR_ADDR); float temperature =0, humidity =0; read_out(SENSOR_ADDR, T_FIRST_N, &temperature, &humidity); sleep_sensor(SENSOR_ADDR); ESP_LOGI(TAG, "SHTC3: Temperature: %f, Humidade: %f", temperature, humidity); vTaskDelay(2000 / portTICK_PERIOD_MS); } void app_main(void) { InitSensors(); while (1) { ReadTHSHTC3(); ReadTMP117(); } }
Report a bug