[SIMPLE PROGRAM] HYT humidity & temp sensor polling / showing received data at TFT with capacitive touchscreen

Dependencies:   FT800_2 HYT mbed

HYT humidity and temperature sensor polling & showing received 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_CurrentValuesGraphs.cpp

Committer:
Ksenia
Date:
2016-10-05
Revision:
1:e20b5da0c912
Parent:
0:1f5444f2977d

File content as of revision 1:e20b5da0c912:

#include "display.h"

/**************************************************************************************************************************
************************** Display real-time humidity *********************************************************************
**************************************************************************************************************************/
void Display::CurrentHumidity(float humidity)
{
    // accelerator for x-axis data output
    char accelerator = 6;
    // create string including current humididty and " %"
    CreateStringTempHum(humidityStr, humidity, 0);
    // write the new scalable (* 1.5) data to the next available array position
    currentHumidity_Y[currentHumidity_X] = (char)(humidity * 1.5);

    // start FT800 display list
    StartDL();
    
    // draw bottom color for graph line
    (*_TFT).DL(COLOR_RGB(200, 200, 200));
    (*_TFT).DL(BEGIN(EDGE_STRIP_B));
    for (int i = 0; i < 68; i++) {
        if (currentHumidity_Y[i] != 0 && i <= currentHumidity_X) {
            (*_TFT).DL(VERTEX2F((i * accelerator + 15) * 16, (220 - currentHumidity_Y[i]) * 16));
        }
    }
    
    // draw horisontal grid for humidity (0 .. 100)
    HorisontalGrid_CurrentHumidity();
    
    // draw main graph line
    (*_TFT).DL(COLOR_RGB(9, 0, 63));
    (*_TFT).DL(BEGIN(POINTS));
    (*_TFT).DL(POINT_SIZE(25));
    for (int i = 0; i < 68; i++) {
        if (currentHumidity_Y[i] != 0 && (i < currentHumidity_X || i >= currentHumidity_X + 13)) {
            (*_TFT).DL(VERTEX2F((i * accelerator + 15) * 16, (222 - currentHumidity_Y[i]) * 16));
        }
    }

    // draw subtitle for main graph line
    (*_TFT).DL(COLOR_RGB(255, 255, 255));
    (*_TFT).DL(BEGIN(RECTS));
    (*_TFT).DL(VERTEX2II((currentHumidity_X * accelerator + 40) + 25, (200 - currentHumidity_Y[currentHumidity_X]), 0, 0));
    (*_TFT).DL(VERTEX2II((currentHumidity_X * accelerator + 40), (177 - currentHumidity_Y[currentHumidity_X]), 0, 0));
    (*_TFT).DL(COLOR_RGB(255, 0, 0));
    (*_TFT).Text((currentHumidity_X * accelerator + 30), (180 - currentHumidity_Y[currentHumidity_X] - 7), 28, 0, humidityStr);
    (*_TFT).DL(BEGIN(LINES));
    (*_TFT).DL(LINE_WIDTH(8));
    (*_TFT).DL(VERTEX2F((currentHumidity_X * accelerator + 15) * 16, (220 - currentHumidity_Y[currentHumidity_X]) * 16));
    (*_TFT).DL(VERTEX2F((currentHumidity_X * accelerator + 35) * 16, (200 - currentHumidity_Y[currentHumidity_X]) * 16));
    (*_TFT).DL(COLOR_RGB(255, 30, 33));
    (*_TFT).DL(BEGIN(POINTS));
    (*_TFT).DL(POINT_SIZE(33));
    (*_TFT).DL(VERTEX2F((currentHumidity_X * accelerator + 15) * 16, (220 - currentHumidity_Y[currentHumidity_X]) * 16));
    (*_TFT).DL(END());

    // write main title
    (*_TFT).DL(COLOR_RGB(0, 0, 0));
    (*_TFT).Text(15, 15, 30, 0, "Current humidity, rH");

    // clean the space under the plot, create link to the main menu
    (*_TFT).DL(SCISSOR_XY(15, 222));
    (*_TFT).DL(SCISSOR_SIZE(420, 53));
    (*_TFT).Gradient(0, 256, 0xFFFFFF, 450, 16, 0xFFFFFF);
    MainMenuReference();

    // finish FT801 display list
    FinishDL();

    // manage the index for array
    if (currentHumidity_X >= 68) {
        currentHumidity_X = 0;
    } else {
        currentHumidity_X ++;
    }
    if (pressedButton == MENU_PRESS) {
        for (int i = 0; i < 68; i++) {
            currentHumidity_Y[i] = 0;
            currentHumidity_X = 0;
        }
    }
}

/**************************************************************************************************************************
************************** Display real-time temperature ******************************************************************
**************************************************************************************************************************/
void Display::CurrentTemperature(float temperature)
{
    // accelerator for x-axis data output
    char accelerator = 6;
    // create string including current temperature with decimal mark and " С"
    CreateStringTempHum(temperatureStr, temperature, 1);
    // write the new scalable (* 0.88 + 45) data to the next available array position
    currentTemperature_Y[currentTemperature_X] = (char)(temperature * 0.88 + 45);

    // start FT800 display list
    StartDL();

    // draw bottom color for graph line
    (*_TFT).DL(COLOR_RGB(200, 177, 199));
    (*_TFT).DL(BEGIN(EDGE_STRIP_B));
    for (int i = 0; i < 68; i++) {
        if (currentTemperature_Y[i] != 0 && i <= currentTemperature_X) {
            (*_TFT).DL(VERTEX2F((i * accelerator + 15) * 16, (220 - currentTemperature_Y[i]) * 16));
        }
    }

    // draw horisontal grid for temperature (-50 .. +125)
    HorisontalGrid_CurrentTemp();

    // draw main graph line
    (*_TFT).DL(COLOR_RGB(9, 0, 63));
    (*_TFT).DL(BEGIN(POINTS));
    (*_TFT).DL(POINT_SIZE(25));
    for (int i = 0; i < 68; i++) {
        if (currentTemperature_Y[i] != 0 && (i < currentTemperature_X || i >= currentTemperature_X + 13)) {
            (*_TFT).DL(VERTEX2F((i * accelerator + 15) * 16, (222 - currentTemperature_Y[i]) * 16));
        }
    }

    // draw subtitle for main graph line
    (*_TFT).DL(COLOR_RGB(255, 255, 255));
    (*_TFT).DL(BEGIN(RECTS));
    (*_TFT).DL(VERTEX2II((currentTemperature_X * accelerator + 40) + 25, (200 - currentTemperature_Y[currentTemperature_X]), 0, 0));
    (*_TFT).DL(VERTEX2II((currentTemperature_X * accelerator + 40), (177 - currentTemperature_Y[currentTemperature_X]), 0, 0));
    (*_TFT).DL(COLOR_RGB(255, 0, 0));
    (*_TFT).Text((currentTemperature_X * accelerator + 25), (173 - currentTemperature_Y[currentTemperature_X]), 28, 0, temperatureStr);
    (*_TFT).DL(BEGIN(LINES));
    (*_TFT).DL(LINE_WIDTH(8));
    (*_TFT).DL(VERTEX2F((currentTemperature_X * accelerator + 15) * 16, (220 - currentTemperature_Y[currentTemperature_X]) * 16));
    (*_TFT).DL(VERTEX2F((currentTemperature_X * accelerator + 35) * 16, (200 - currentTemperature_Y[currentTemperature_X]) * 16));
    (*_TFT).DL(COLOR_RGB(255, 30, 33));
    (*_TFT).DL(BEGIN(POINTS));
    (*_TFT).DL(POINT_SIZE(33));
    (*_TFT).DL(VERTEX2F((currentTemperature_X * accelerator + 15) * 16, (220 - currentTemperature_Y[currentTemperature_X]) * 16));
    (*_TFT).DL(END());

    // write main title
    (*_TFT).DL(COLOR_RGB(0, 0, 0));
    (*_TFT).Text(15, 15, 30, 0, "Current temperature");

    // clean the space under the plot, create link to the main menu
    (*_TFT).DL(SCISSOR_XY(15, 225));
    (*_TFT).DL(SCISSOR_SIZE(420, 53));
    (*_TFT).Gradient(0, 256, 0xFFFFFF, 450, 16, 0xFFFFFF);
    MainMenuReference();

    // finish FT801 display list
    FinishDL();

    // manage the index for array
    if (currentTemperature_X >= 68) {
        currentTemperature_X = 0;
    } else {
        currentTemperature_X ++;
    }
    if (pressedButton == MENU_PRESS) {
        for (int i = 0; i < 68; i++) {
            currentTemperature_Y[i] = 0;
            currentTemperature_X = 0;
        }
    }
}