HYT humidity & temp sensor polling / showing received data at TFT with capacitive touchscreen

Dependencies:   FT800_2 HYT mbed

HYT humidity & temperature sensor: polling and showing data at TFT via graphical controller FT800/FT801.

Hardware

For documentation on the FT800 library, please refer to the library pages.

Connection

MCU-board to TFT-module

MCU-board is connected to TFT-module via Break Out Board. You need 6 signals to connect: SCK, MOSI and MISO are connected to a SPI channel, SS is the chip select signal, PD work as powerdown and INT for interrupts from TFT to MCU.

/media/uploads/Ksenia/4_-22-.jpg

You have to connect VDD to BLVDD at Break Out Board if you use the board:

/media/uploads/Ksenia/4_-5-.jpg

MCU-board to HYT sensor

MCU-board is connected to sensor via I2C. Remember to use pull-up resisrors there:

/media/uploads/Ksenia/freshpaint-20-2016.09.16-10.37.03.png

Подробнее в статьях Как перестать бояться и полюбить mbed [Часть 1 - 5] на https://habrahabr.ru/users/uuuulala/topics/

TFT/display.Draw_3hrsStatistics.cpp

Committer:
Ksenia
Date:
2016-10-07
Revision:
0:5d3131d1b142

File content as of revision 0:5d3131d1b142:

#include "display.h"

/**************************************************************************************************************************
************************** Display data about humidity in the three-hour interval *****************************************
**************************************************************************************************************************/

void Display::StatHumidity_3hrs(volatile uint64_t seconds, short int statistics24hrs[3][288], uint64_t gridSecondsOffset)
{
    // start FT800 display list
    StartDL();
 
    // mark 6 areas for touch input (for zoom in),
    // make each every second zone gray, make the active zone green
    char ZonesCnt = 0;
    for (int i = 25; i < 433; i += 68) {
        (*_TFT).DL(COLOR_RGB(255, 255, 255));
        if (ZonesCnt % 2 == 0) {
            (*_TFT).DL(COLOR_RGB(233, 233, 233));
        }
        if (pressedButton - ZONE_1_PRESS == ZonesCnt) {
            (*_TFT).DL(COLOR_RGB(200, 255, 200));
            timePoint30min = 6 * ZonesCnt;
        }
        (*_TFT).DL(TAG_MASK(1));
        (*_TFT).DL(TAG(ZONE_1_PRESS + ZonesCnt));
        (*_TFT).DL(BEGIN(RECTS));
        (*_TFT).DL(VERTEX2II(i, 100, 0, 0));
        (*_TFT).DL(VERTEX2II(i + 68, 200, 0, 0));
        (*_TFT).DL(TAG_MASK(0));
        ZonesCnt++;
    }
    
    // create time string, GridLines, link to main menu 
    TimeSinceTurnOn(seconds);
    VerticalGrid3hrs(gridSecondsOffset);
    HorisontalGrid_Statistics_Humidity();
    MainMenuReference();

    // draw graph line
    for (int i = 0; i < 36; i++) {
        char currentValue = statistics24hrs[0][i + timePoint3hrs];
        char currentMinValue = statistics24hrs[1][i + timePoint3hrs];
        char currentMaxValue = statistics24hrs[2][i + timePoint3hrs];
        if (currentValue != INIT_STATISTICS_NUMBER) {
            (*_TFT).DL(COLOR_RGB(9, 0, 63));
            if (currentMaxValue - currentMinValue >= DELTA_HUMIDITY) {
                (*_TFT).DL(COLOR_RGB(207, 45, 13));
                (*_TFT).DL(BEGIN(LINES));
                (*_TFT).DL(LINE_WIDTH(16));
                (*_TFT).DL(VERTEX2F(i * 181 + 25 * 16, (200 - currentValue) * 16));
                (*_TFT).DL(VERTEX2F(i * 181 + 25 * 16, (200 - currentMaxValue) * 16));
                (*_TFT).DL(VERTEX2F(i * 181 + 22 * 16, (200 - currentMaxValue) * 16));
                (*_TFT).DL(VERTEX2F(i * 181 + 28 * 16, (200 - currentMaxValue) * 16));
                (*_TFT).DL(END());
                (*_TFT).DL(BEGIN(LINES));
                (*_TFT).DL(LINE_WIDTH(16));
                (*_TFT).DL(VERTEX2F(i * 181 + 25 * 16, (200 - currentValue) * 16));
                (*_TFT).DL(VERTEX2F(i * 181 + 25 * 16, (200 - currentMinValue) * 16));
                (*_TFT).DL(VERTEX2F(i * 181 + 22 * 16, (200 - currentMinValue) * 16));
                (*_TFT).DL(VERTEX2F(i * 181 + 28 * 16, (200 - currentMinValue) * 16));
                (*_TFT).DL(END());
            } 
            (*_TFT).DL(BEGIN(POINTS));
            (*_TFT).DL(POINT_SIZE(45));
            (*_TFT).DL(VERTEX2F(i * 181 + 25 * 16, (200 - currentValue) * 16));
        }
    }
    
    // write main title
    (*_TFT).DL(COLOR_RGB(0, 0, 0));
    (*_TFT).Text(11, 15, 30, 0, "Humidity statistics (3 hrs)");
    
    // finish FT800 display list
    FinishDL();
}

/**************************************************************************************************************************
************************** Display data about temeprature in the three-hour interval **************************************
**************************************************************************************************************************/
void Display::StatTemperature_3hrs(volatile uint64_t seconds, short int statistics24hrs[3][288], uint64_t gridSecondsOffset) 
{
    // start FT800 display list
    StartDL();
 
    // mark 6 areas for touch input (for zoom in),
    // make each every second zone gray, make the active zone green
    char ZonesCnt = 0;
    for (int i = 25; i < 433; i += 68) {
        (*_TFT).DL(COLOR_RGB(255, 255, 255));
        if (ZonesCnt % 2 == 0) {
            (*_TFT).DL(COLOR_RGB(233, 233, 233));
        }
        if (pressedButton - ZONE_1_PRESS == ZonesCnt) {
            (*_TFT).DL(COLOR_RGB(200, 255, 200));
            timePoint30min = 6 * ZonesCnt;
        }
        (*_TFT).DL(TAG_MASK(1));
        (*_TFT).DL(TAG(ZONE_1_PRESS + ZonesCnt));
        (*_TFT).DL(BEGIN(RECTS));
        (*_TFT).DL(VERTEX2II(i, 100, 0, 0));
        (*_TFT).DL(VERTEX2II(i + 68, 200, 0, 0));
        (*_TFT).DL(TAG_MASK(0));
        ZonesCnt++;
    }

    // create time string, GridLines, link to main menu 
    TimeSinceTurnOn(seconds);
    VerticalGrid3hrs(gridSecondsOffset);
    HorisontalGrid_Statistics_Temperature();
    MainMenuReference();
    
    // draw graph line
    for (int i = 0; i < 36; i++) {
        char currentValue = (statistics24hrs[0][i + timePoint3hrs] / TEMPERATURE_MULTIPLIER + 50) * 0.57;
        char currentMinValue = (statistics24hrs[1][i + timePoint3hrs] / TEMPERATURE_MULTIPLIER + 50) * 0.57;
        char currentMaxValue = (statistics24hrs[2][i + timePoint3hrs] / TEMPERATURE_MULTIPLIER + 50) * 0.57;
        char delta = statistics24hrs[2][i + timePoint3hrs] - statistics24hrs[1][i + timePoint3hrs];
        
        if (statistics24hrs[0][i + timePoint3hrs] != INIT_STATISTICS_NUMBER) {
            (*_TFT).DL(COLOR_RGB(9, 0, 63));
            if (delta >= DELTA_TEMPERATURE + TEMPERATURE_MULTIPLIER) {
                (*_TFT).DL(COLOR_RGB(207, 45, 13));
                (*_TFT).DL(BEGIN(LINES));
                (*_TFT).DL(LINE_WIDTH(16));
                (*_TFT).DL(VERTEX2F(i * 181 + 25 * 16, (200 - currentValue) * 16));
                (*_TFT).DL(VERTEX2F(i * 181 + 25 * 16, (200 - currentMaxValue) * 16));
                (*_TFT).DL(VERTEX2F(i * 181 + 22 * 16, (200 - currentMaxValue) * 16));
                (*_TFT).DL(VERTEX2F(i * 181 + 28 * 16, (200 - currentMaxValue) * 16));
                (*_TFT).DL(END());
                (*_TFT).DL(BEGIN(LINES));
                (*_TFT).DL(LINE_WIDTH(16));
                (*_TFT).DL(VERTEX2F(i * 181 + 25 * 16, (200 - currentValue) * 16));
                (*_TFT).DL(VERTEX2F(i * 181 + 25 * 16, (200 - currentMinValue) * 16));
                (*_TFT).DL(VERTEX2F(i * 181 + 22 * 16, (200 - currentMinValue) * 16));
                (*_TFT).DL(VERTEX2F(i * 181 + 28 * 16, (200 - currentMinValue) * 16));
                (*_TFT).DL(END());
            } 
            (*_TFT).DL(BEGIN(POINTS));
            (*_TFT).DL(POINT_SIZE(45));
            (*_TFT).DL(VERTEX2F(i * 181 + 25 * 16, (200 - currentValue) * 16));
        }
    }
    
    // write main title
    (*_TFT).DL(COLOR_RGB(0, 0, 0));
    (*_TFT).Text(11, 15, 30, 0, "Temperature statistics (3 hrs)");
    
    // finish FT800 display list
    FinishDL();  
}