Initial commit for dht11-lcd example.

This commit is contained in:
Shaun Reed 2025-11-01 13:36:07 -04:00
parent 555e2096b9
commit 7d87b35b1c
10 changed files with 2448 additions and 0 deletions

View File

@ -0,0 +1,18 @@
# For more information about build system see
# https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/build-system.html
# The following five lines of boilerplate have to be in your project's
# CMakeLists in this exact order for cmake to work correctly
cmake_minimum_required(VERSION 3.26)
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
project(
#[[NAME]] aht20
VERSION 0.1
DESCRIPTION "Using the AHT20 sensor with ESP-IDF over I2C"
LANGUAGES CXX
)
message(STATUS "[Klips] Configuring example: ${PROJECT_NAME}")
# For writing pure cmake components, see the documentation
# https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-guides/build-system.html#writing-pure-cmake-components
idf_build_set_property(COMPILE_OPTIONS "-Wno-error" APPEND)

View File

@ -0,0 +1,27 @@
# 08_dht11-lcd
Using the ESP IDF for reading data from a DHT11 sensor and displaying it on an LCD.
[ESP IDF - I2C](https://docs.espressif.com/projects/esp-idf/en/v5.3.2/esp32/api-reference/peripherals/i2c.html)
[ESP IDF - LCD](https://docs.espressif.com/projects/esp-idf/en/v5.3.2/esp32/api-reference/peripherals/lcd/index.html)
[ESP IDF - FreeRTOS](https://docs.espressif.com/projects/esp-idf/en/v5.3.2/esp32/api-reference/system/freertos.html)
![schematic](./schematic.png)
![example](./example.gif)
For instructions on setting up the ESP-IDF see [04_-esp-idf-arduino](./../04_esp-idf-arduino)
To build this example run the following commands.
```bash
source ~/path/to/esp-idf/export.sh
mkdir build
cd build
cmake ..
make -j $(nproc)
make flash
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 887 KiB

View File

@ -0,0 +1,7 @@
idf_component_register(
SRCS
main.cpp
main.h i2c.h
INCLUDE_DIRS .
REQUIRES driver
)

View File

@ -0,0 +1,3 @@
## IDF Component Manager Manifest File
dependencies:
idf: '>=5.3.0'

View File

@ -0,0 +1,22 @@
/*#############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2025 Shaun Reed, all rights reserved ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com ##
##############################################################################
*/
#include "i2c.h"
// Pin may vary based on your schematic.
#define PIN_SDA GPIO_NUM_21
#define PIN_SCL GPIO_NUM_22
#define PIN_RST (-1)
I2C i2c(PIN_SDA, PIN_SCL, PIN_RST);
extern "C" void app_main(void)
{
}

View File

@ -0,0 +1,39 @@
/*#############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2025 Shaun Reed, all rights reserved ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com ##
##############################################################################
*/
#include "display.h"
#include "ssd1306.h"
// Pin may vary based on your schematic.
#define PIN_SDA GPIO_NUM_21
#define PIN_SCL GPIO_NUM_22
#define PIN_RST (-1)
I2C i2c(PIN_SDA, PIN_SCL, PIN_RST);
extern "C" void app_main(void)
{
SSD1306 ssd1306(i2c);
Display d(ssd1306);
d.set_text("Test test 12345678910",
"test-text1",
LV_LABEL_LONG_SCROLL,
LV_ALIGN_CENTER);
d.set_text("Test test changing text",
"test-text1",
LV_LABEL_LONG_SCROLL,
LV_ALIGN_CENTER);
d.set_text("Hello hello hello hello hello hello hello hello!", "test-text2");
d.set_text("A random sentence with no meaning at all.",
"test-text3",
LV_LABEL_LONG_CLIP,
LV_ALIGN_BOTTOM_MID);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 227 KiB

File diff suppressed because it is too large Load Diff

92
esp/cpp/components/i2c.h Normal file
View File

@ -0,0 +1,92 @@
/*#############################################################################
## Author: Shaun Reed ##
## Legal: All Content (c) 2025 Shaun Reed, all rights reserved ##
## ##
## Contact: shaunrd0@gmail.com | URL: www.shaunreed.com ##
##############################################################################
*/
#ifndef I2C_H
#define I2C_H
#define I2C_BUS_PORT 0
#include <esp_log.h>
#include <driver/i2c_master.h>
/**
* Encapsulates ESP I2C creation and usage.
*/
struct I2C {
/**
* Construct and initialize an ESP I2C master bus.
* An I2C constructor may only be called one time in any application.
*
* @param sda GPIO pin number for SDA
* @param scl GPIO pin number for SCL
* @param rst GPIO pin number for RST
*/
I2C(gpio_num_t sda, gpio_num_t scl, int rst = -1) :
I2C((i2c_master_bus_config_t) {
.i2c_port = I2C_BUS_PORT,
.sda_io_num = sda,
.scl_io_num = scl,
.clk_source = I2C_CLK_SRC_DEFAULT,
.glitch_ignore_cnt = 7,
.flags {
.enable_internal_pullup = true,
},
},
rst
) { }
/**
* Construct an ESP I2C master bus given a specific ESP I2C configuration.
* An I2C constructor may only be called one time in any application.
*
* @param config ESP I2C master bus configuration.
* @param rst GPIO pin number for RST
*/
explicit I2C(i2c_master_bus_config_t config, int rst = -1) :
esp_bus_config_(config),
rst_num_(rst)
{
i2c_master_bus_handle_t i2c;
ESP_LOGI(TAG, "Initializing new master I2C bus");
ESP_ERROR_CHECK(i2c_new_master_bus(&esp_bus_config_, &i2c));
}
~I2C() = default;
//
// GETTERS
/**
* ESP I2C master bus handle getter.
* This will fail if an I2C instance was never constructed.
*/
static i2c_master_bus_handle_t get()
{
i2c_master_bus_handle_t i2c = nullptr;
ESP_ERROR_CHECK(i2c_master_get_bus_handle(0, &i2c));
return i2c;
}
//
// PUBLIC MEMBERS
/// ESP I2C master bus configuration used during initialization.
i2c_master_bus_config_t esp_bus_config_;
/// RST GPIO pin number.
int rst_num_;
private:
//
// PRIVATE MEMBERS
/// Tag used for ESP logging.
constexpr static const char *TAG = "I2C";
};
#endif //I2C_H