HaaS EDU Scenario Application Learning-Thermometer and Hygrometer

1. Introduction to the experiment

This experiment mainly introduces the realization of thermometer and hygrometer. This product has the temperature and humidity sensor SI7006 onboard. The sensor can not only measure temperature, but also relative humidity.

This experiment will show you how to use the haas1000 to read the SI7006 digital temperature and humidity sensor to obtain information such as ambient temperature and relative humidity, and display the temperature and humidity values ​​on the OLED module.

Before starting to learn, let's take a look at the display effect, as shown in the following figure:

 

 

2. Involving knowledge points

  • I2C communication principle
  • SI7006 illumination and proximity sensor principle
  • OLED drawing
     

2.1, I2C communication principle

The IIC bus is a two-wire serial bus originally developed by PHILIPS, used to connect microcontrollers and their peripheral devices. It is a serial bus composed of data line SDA and clock SCL, which can send and receive data. Two-way transmission is carried out between the CPU and the controlled IC, and between the IC and the IC. The high-speed IIC bus can generally reach more than 400kbps.

There are three types of signals in the I2C bus in the process of transmitting data. They are: start signal, end signal and response signal.

Start signal: When SCL is high, SDA jumps from high to low and starts to transmit data.

End signal: When SCL is high level, SDA jumps from low level to high level, ending the data transmission.

Response signal: After receiving the 8bit data, the data-receiving IC sends a specific low-level pulse to the data-transmitting IC to indicate that the data has been received. After the CPU sends a signal to the controlled unit, it waits for the controlled unit to send a response signal. After the CPU receives the response signal, it determines whether to continue to transmit the signal according to the actual situation. If the response signal is not received, it is determined that the controlled unit is faulty.

The waveform is as follows:

 

2.2 Introduction to SI7006 sensor

  SI7006 is a relative humidity and temperature sensor launched by Silicon Lab. It combines factory-calibrated humidity and temperature sensor elements, analog-digital converters, signal processing and an I2C host interface. The use of industry standard low-K dielectric polymers provides excellent accuracy and long-term stability with low drift and low hysteresis. At the same time, its innovative CMOS design also enables it to have very low power consumption.

feature:

  • Relative humidity sensor:
  • ±5%RH (maximum) @ 0-80%RH
  • Temperature Sensor:
  • ±1.0°C accuracy (maximum) @ -10 to +85°C
  • 0 to 100% RH working range
  • Up to -40 to +125°C working range
  • Wide operating voltage range (1.9~3.6V)
  • Low power consumption: 2.2μW average power is 3.3V and 1 sample per second
  • I2C host interface
  • On-chip integrated heater
  • Available in 3mm x 3mm QFN package
  • Excellent long-term stability
  • Support factory calibration
  • Protection during backflow and operating life
  • Prevent contaminated dust, dirt, household chemicals and other liquids

 

application:

  • Asset and cargo tracking
  • Automotive climate control and defogging
  • Baby monitor
  • Continuous Positive Airway Pressure (CPAP) machine
  • Flood and water detection
  • Gas, fire and smoke detectors
  • Mobile phone/smart phone
  • Industrial HVAC/R
  • Laptop/tablet
  • laser printer
  • Microenvironment/Data Center
  • PLC and IO modules
  • Remote telemetry device
  • tablet
  • Test and measure
  • Constant temperature/constant humidity
  • Ventilation and air conditioning system
  • Weather station
  • Wind power inverter
  • Windshield and rearview mirror system
  • Wireless base station
  • wireless sensor network

 

2.3, OLED drawing

Refer to the previous experiment.

 

3. Preparation of software and hardware environment

3.1, hardware

  • One development computer
  • One HaaS EDU K1 development board (the development board has a built-in SI7006 sensor)
  • One USB Type-C data cable

 

3.2 Software

The " thermometer" function has been included in the edu_demo application and included in the release version. You can see information such as temperature and relative humidity every time you restart the system and switch the screen.

3.2.1, firmware version

Version number: VER 1.0.0

 

3.2.2, code path

Download code

git clone https://github.com/alibaba/AliOS-Things.git -b dev_3.1.0_haas

For domestic users, in order to avoid slow downloading from github, you can download from gitee.

git clone https://gitee.com/alios-things/AliOS-Things.git -b dev_3.1.0_haas

 

Compile

Enter the top-level directory of the code such as AliOS-Things to compile it. You can directly compile the demo app in the application/example/ directory, or the app developed by yourself. Take compiling helloworld_demo as an example below.

aos make edu_demo@haaseduk1 -c config

aos make

 

The relative paths of the files needed on the home screen are as follows:

application/example/edu_demo/k1_apps/homepage/homepage.c

application/example/edu_demo/k1_apps/homepage/homepage.h

application/example/edu_demo/app_entry.c

 

Burning method

See the development environment chapter

 

3.2.3, get started

The experimental results are as follows:

The first line shows the temperature in degrees Celsius, and the second line shows the humidity value in%

As shown below:

 

4. Hardware design

In this experiment, SI7006 is mounted on the motherboard, and the middle I2C communicates with the MCU. The schematic diagram is as follows:

EDU SI7006 partial schematic diagram

5. Software design

5.1, application code part

The file path is as follows:

application/example/edu_demo/k1_apps/humiture/humiture.c

application/example/edu_demo/k1_apps/humiture/humiture.h

        si7006_getTempHumidity(&hump, &temp);

        sprintf(temp_str, "T:%5.1fC", temp);

        sprintf(hump_str, "H:%5.1f%%", hump);



        OLED_Icon_Draw(14, 4, &icon_thermometer_24_24, 0);

        OLED_Icon_Draw(14, 36, &icon_hygrometer_24_24, 0);



        OLED_Icon_Draw(2, 24, &icon_skip_left, 0);

        OLED_Icon_Draw(122, 24, &icon_skip_right, 0);



        OLED_Show_String(42, 8, temp_str, 16, 1);

        OLED_Show_String(42, 40, hump_str, 16, 1);



        OLED_Refresh_GRAM();

        aos_msleep(500);

5.2, drive part

The file path is as follows:

components/peripherals/sensor/drv/drv_temp_humi_si_si7006.c

The overall driver code is divided into three parts:

  • Get product ID
  • Get temperature value
  • Get humidity value
void si7006_getID(uint8_t *id_buf)

{

    uint8_t reg[4]  = {Si7006_READ_ID_LOW_0,Si7006_READ_ID_LOW_1,Si7006_READ_ID_HIGH_0,Si7006_READ_ID_HIGH_1};



    hal_i2c_master_send(&i2c_dev, i2c_dev.config.dev_addr, reg, 2, 1000);

    aos_msleep(30);

    hal_i2c_master_recv(&i2c_dev, i2c_dev.config.dev_addr, id_buf, 4, 1000);



    hal_i2c_master_send(&i2c_dev, i2c_dev.config.dev_addr, &reg[2], 2, 1000);

    aos_msleep(30);

    hal_i2c_master_recv(&i2c_dev, i2c_dev.config.dev_addr, &id_buf[4], 4, 1000);



    return;

}



bool si7006_getTemperature(float *temperature)

{

    uint8_t reg  = Si7006_MEAS_TEMP_NO_MASTER_MODE;

    uint8_t read_data[2] = {0};

    unsigned int value;



    hal_i2c_master_send(&i2c_dev, i2c_dev.config.dev_addr, &reg, 1, 1000);

    aos_msleep(30);

    hal_i2c_master_recv(&i2c_dev, i2c_dev.config.dev_addr, read_data, 2, 1000);

    value = (read_data[0] << 8) | read_data[1];

    LOGI("APP", "%0x -- %0x -->0x%x\n", read_data[0],read_data[1],value);

    // A temperature measurement will always return XXXXXX00 in the LSB field.

    if (value & 0xFFFC)

    {

        *temperature = (175.72f * (float)value) / 65536.0f - 46.85f;

        LOGI("APP", "temperature: %2f \n", *temperature);

    }

    else

    {

        LOGI("APP", "Error on temp\n");

        return 1;

    }

    return 0;

}



/*

i2c – the i2c device

dev_addr – device address

mem_addr – mem address

mem_addr_size – mem address

data – i2c master send data

size – i2c master send data size

*/

bool si7006_getHumidity(float *humidity)

{

    uint8_t reg  = Si7006_MEAS_REL_HUMIDITY_NO_MASTER_MODE;

    uint8_t read_data[3] = {0};

    unsigned int value;



    hal_i2c_master_send(&i2c_dev, i2c_dev.config.dev_addr, &reg, 1, 1000);



    aos_msleep(30);



    hal_i2c_master_recv(&i2c_dev, i2c_dev.config.dev_addr, read_data, 2, 1000);

    value = (read_data[0] << 8) | read_data[1];

    LOGI("APP", "%0x -- %0x -->0x%x\n", read_data[0],read_data[1],value);

    if (value & 0xFFFE)

    {

        *humidity = ((125.0f * (float)value ) / 65535.0f) - 6.0f;

        LOGI("APP", "humidity: %f \n", *humidity);

    }

    else

    {

        LOGI("APP", "Error on humidity\n");

        return 1;

    }

    return 0;

}



//get temp and humidity

void si7006_getTempHumidity(float *humidity, float *temperature)

{

    si7006_getTemperature(temperature);

    si7006_getHumidity(humidity);

}

6. Developer technical support

If you need more technical support, you can join the DingTalk developer group or follow the WeChat public account

For more technology and solution introduction, please visit the Aliyun AIoT homepage https://iot.aliyun.com/

Guess you like

Origin blog.csdn.net/HaaSTech/article/details/114004725