描述
<h2>视频链接:</h2>
<p><a href="https://www.bilibili.com/video/BV1Ay411B7MF/?vd_source=a2cfa7ab4c27b82528b05c71931dcf02" target="_blank">B站视频--功能演示及介绍</a></p>
<h2>项目简介</h2>
<p>本项目是基于esp32c3单片机的温湿度检测仪,具有检测温湿度功能。</p>
<h2>项目功能</h2>
<p>本设计是基于esp32c3单片机设计的温湿度检测仪。能检测环境的温湿度。</p>
<h2>项目参数</h2>
<ul>
<li>本设计采用esp32c3单片机</li>
<li>本设计采用P169H002液晶显示,显示当前的温度和湿度。</li>
<li>选用盛思瑞温湿度传感器SHT40-AD1B,具有较宽的温度测量范围,可以满足一般需求;</li>
</ul>
<h2>原理解析(硬件说明)</h2>
<p>本项目由以下部分组成,主控、屏幕、传感器;主控采用esp32c3开发板、通过ESP-IDF完成编译和烧录,屏幕使用P169H002液晶,使用spi协议,通过lvgl绘制到屏幕上。传感器采用盛思瑞温湿度传感器模块,通过i2c协议读取数据。</p>
<p><img src="//image.lceda.cn/oshwhub/2e395dd370ac4f2ab4694d913cab39ad.png" alt="截图 2024-11-05 21-13-01.png"></p>
<p>示例图1--主控:
对于开发板,器件库中没有现成的,于是自己新建了元件、画了封装、绑了模型。</p>
<p><img src="//image.lceda.cn/oshwhub/c1d9d61c566e4cbebb04ca890ff4fd3b.png" alt="image.png"></p>
<p>示例图2--温湿度传感器电路:
平平无奇,比较简单。</p>
<p><img src="//image.lceda.cn/oshwhub/f11d3e18c6eb4b929ea4b77cd3ac3068.png" alt="image.png"></p>
<p>示例图3--屏幕电路:
抄的淘宝卖家给的资料里的</p>
<p>......</p>
<h2>软件代码</h2>
<p>初始化i2c</p>
<pre><code> int i2c_master_port = I2C_MASTER_NUM;
i2c_config_t i2c_conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = I2C_MASTER_SDA_IO,
.scl_io_num = I2C_MASTER_SCL_IO,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master.clk_speed = I2C_MASTER_FREQ_HZ,
};
i2c_param_config(i2c_master_port, &i2c_conf);
i2c_driver_install(i2c_master_port, i2c_conf.mode, 0, 0, 0);</code></pre>
<p>获取温湿度传感器数据</p>
<pre><code>
static void get_sensor_data_task(void *arg)
{
ESP_LOGI(TAG, "Starting get sensor data task");
uint8_t dev_addr = (uint8_t)0x44;
uint8_t writeData[1] = {0xFD};
uint8_t readData[6] = {0};
uint32_t tempData = 0;
i2c_cmd_handle_t cmd;
esp_err_t ret;
float temperature, humidity = 0.0;
char str_temperature[21],str_humidity[21];
while (1) {
memset(str_temperature,0,sizeof(str_temperature));
memset(str_humidity,0,sizeof(str_humidity));
cmd = i2c_cmd_link_create();
vTaskDelay(pdMS_TO_TICKS(40));
ret = i2c_master_start(cmd);
assert(ESP_OK == ret);
ret = i2c_master_write_byte(cmd, dev_addr </code></pre>
评论(0)