-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
50 lines (44 loc) · 1.29 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
void app_main(void)
{
int i2c_master_port = I2C_MASTER_NUM ;
i2c_config_t conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = I2C_SDA_GPIO,
.scl_io_num = I2C_SCL_GPIO,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = I2C_FREQUENCY,
};
i2c_param_config(i2c_master_port, &conf);
esp_err_t i2c_ret = i2c_driver_install(i2c_master_port, conf.mode, 0, 0, 0);
if(i2c_ret != ESP_OK)
{
printf("Failed to install I2C driver!\n");
return;
}
while (1)
{
int8_t status = _measurementReq();
float temp = readTemperature(CELSIUS);
if(temp != 0)
{
printf("Temperature %2f °C\n", temp);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
else
{
printf("Error reading temperature sensor! Status %d\n" , status);
vTaskDelay(2000 / portTICK_PERIOD_MS);
}
float humidity = readHumidity();
if(temp != 0)
{
printf("Humidity %2f\n", humidity);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
else
{
printf("Error reading humidity sensor! Status %d\n" , status);
vTaskDelay(2000 / portTICK_PERIOD_MS);
}
}