Art_ PI study note 8: using aht10 temperature and humidity module

Time:2021-10-27

Development environment:
rt-thread studio

Development board:
Art-Pi

Reference link:
Introduction to RT thread studio (6) – collect temperature and humidity data_ Willliam_ William’s blog – CSDN blog
https://blog.csdn.net/qq_3811…

Based on Pandora’s development, use RT thread studio to develop and use the software package aht10 to encounter… – RT thread Q & a community
https://club.rt-thread.org/as…

Aht10 – Lichuang EDA open source hardware platform
https://oshwhub.com/chenzhy/A…

There is no temperature and humidity monitoring sensor on art PI, so you need to add it yourself. So recently, you bought aht10 temperature and humidity module from a treasure, so you almost received it from art PI for experience, but there are still some twists and turns in the middle. After groping, it was finally able to drive successfully, and then this record was pasted for the convenience of small partners.

In terms of hardware connection, the touch interface i2c2 of multimedia extended version is borrowed. Why use this I2C interface? On the one hand, since the RGB screen is available, the multimedia expansion screen has been in a gray state, and this interface does not need to be used for the time being; On the other hand, this interface has been used in debugging the multimedia expansion screen before, and I know the root. After all, it’s laziness.
Art_ PI study note 8: using aht10 temperature and humidity module

Art_ PI study note 8: using aht10 temperature and humidity module

Because the aht10 module is used instead of the chip, and the 3.3V LDO is integrated on the module, the power supply is pulled from 5V instead of 3.3V. If there is no LDO, it must be powered from 3.3V, because the maximum supply voltage of aht10 is 3.6V.

After the hardware connection is completed, the software configuration is completed. After referring to the above article, I made some exploration. The configuration is as follows:
The first is to add aht10 software package to simulate I2C components.
Art_ PI study note 8: using aht10 temperature and humidity module

The detailed configuration is as follows:
For the aht10 configuration here, I choose the latest version of the software package, and there is no software filtering function enabled.
Art_ PI study note 8: using aht10 temperature and humidity module

I2c2 is enabled in hardware, and the configuration pin is configured. Here, the default configuration remains unchanged
Art_ PI study note 8: using aht10 temperature and humidity module

Enable I2C device driver on assembly
Art_ PI study note 8: using aht10 temperature and humidity module

Save the configuration, exit settings, and then compile and download.
List in debugging terminal_ Device command, you can see that i2c1 and i2c2 have been registered successfully.
Art_ PI study note 8: using aht10 temperature and humidity module

Next, refer to the boss’s post to add the use code of aht10 to the program.
The first is port initialization
Art_ PI study note 8: using aht10 temperature and humidity module

Then the temperature acquisition thread entry function
Art_ PI study note 8: using aht10 temperature and humidity module

The next step is to create a thread
Art_ PI study note 8: using aht10 temperature and humidity module

After completion, compile and burn it to art PI, but it doesn’t work!
Art_ PI study note 8: using aht10 temperature and humidity module

It has been initialized successfully. Why can’t you read the data? Use list again_ Device check the device. It’s true that there are registered devices. I can’t figure it out.
Art_ PI study note 8: using aht10 temperature and humidity module

Through careful inspection, it turns out that SDA and SCL pins are connected incorrectly. Adjust the line, power on again, done, go!
Art_ PI study note 8: using aht10 temperature and humidity module

Then display the data on lvgl, perfect!
Art_ PI study note 8: using aht10 temperature and humidity module

Art_ PI study note 8: using aht10 temperature and humidity module

The following is the code, which is posted in the post for the first time.

//Example of using aht10
#include "sensor_asair_aht10.h"
#define AHT10_I2C_BUS  "i2c2"

//Aht10 port initialization
int rt_hw_aht10_port(void)
{
    struct rt_sensor_config cfg;
    cfg.intf.dev_name  = AHT10_I2C_BUS;
    cfg.intf.user_data = (void *)AHT10_I2C_ADDR;
    rt_hw_aht10_init("aht10", &cfg);
    return RT_EOK;
}

//Aht10 temperature and humidity acquisition
#include "aht10.h"

/*Define a temperature and humidity collection thread handle structure pointer*/
static rt_thread_t aht10_thread = RT_NULL;

float humidity, temperature;

/*Temperature and humidity acquisition thread entry function*/
static void aht10_thread_entry(void *parameter)
{
    rt_err_t res;
    aht10_device_t dev;

    rt_hw_aht10_port();
    dev = aht10_init(AHT10_I2C_BUS);
    if (dev == RT_NULL)
    {
        rt_kprintf(" The sensor initializes failure");
        return 0;
    }
    else
    {
        rt_kprintf(" The sensor initializes ok!");
    }

    while (1)
    {
        /*Read humidity*/
        humidity = aht10_read_humidity(dev);
        rt_kprintf("humidity   : %d.%d %%\n", (int)humidity, (int)      (humidity * 10) % 10); /* former is integer and behind is decimal */

        /*Read temperature*/
        temperature = aht10_read_temperature(dev);
        rt_kprintf("temperature: %d.%d \n", (int)temperature, (int)(temperature * 10) % 10); /* former is integer and behind is decimal */

        rt_thread_mdelay(60000);
    }

}


static int app_aht10_init(void)
{
    rt_err_t rt_err;
    /*Create temperature and humidity collection thread*/
    aht10_ thread = rt_ thread_ Create ("aht10 thread"), / * the name of the thread*/
                                aht10_ thread_ Entry, / * thread entry function*/
                                RT_ Null, / * parameter of thread entry function*/
                                1024, / * thread stack size, in bytes*/
                                25, / * thread priority. The smaller the value, the higher the priority*/
                                10);                /*  The time slice size of the thread*/
    /*If you get a thread control block, start the thread*/
    if (aht10_thread != RT_NULL)
        rt_err = rt_thread_startup(aht10_thread);
    else
        rt_kprintf("aht10 thread create failure !!! \n");

    /*Determine whether the thread is created successfully*/
    if( rt_err != RT_EOK)
        rt_kprintf("aht10 thread startup err. \n");

    return RT_EOK;
}

INIT_APP_EXPORT(app_aht10_init);