![](/media/cache/profiles/9f0876a200701e5fdece2e58aa965574.jpg.50x50_q85.jpg)
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
- HYT-271 / HYT-221 / HYT-939 humidity and temperature sensor by IST-AG
- TFT module uxTouch by Riverdi
- Break Out Board 20 by Riverdi
- Any mbed platform with I2C interface, SPI interface and 2 free GPIO for PD and INT signals
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.
You have to connect VDD to BLVDD at Break Out Board if you use the board:
MCU-board to HYT sensor
MCU-board is connected to sensor via I2C. Remember to use pull-up resisrors there:
Подробнее в статьях Как перестать бояться и полюбить mbed [Часть 1 - 5] на https://habrahabr.ru/users/uuuulala/topics/
TFT/display.StringsTransform.cpp@0:5d3131d1b142, 2016-10-07 (annotated)
- Committer:
- Ksenia
- Date:
- Fri Oct 07 11:08:19 2016 +0000
- Revision:
- 0:5d3131d1b142
Initial commit;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Ksenia | 0:5d3131d1b142 | 1 | #include "display.h" |
Ksenia | 0:5d3131d1b142 | 2 | |
Ksenia | 0:5d3131d1b142 | 3 | /************************************************************************************************************************** |
Ksenia | 0:5d3131d1b142 | 4 | ************************** Transform humiditity / temperature float value to string *************************************** |
Ksenia | 0:5d3131d1b142 | 5 | **************************************************************************************************************************/ |
Ksenia | 0:5d3131d1b142 | 6 | // If isTemp = 0, resulting string includes |
Ksenia | 0:5d3131d1b142 | 7 | // 1. current humididty |
Ksenia | 0:5d3131d1b142 | 8 | // 3. " %" |
Ksenia | 0:5d3131d1b142 | 9 | |
Ksenia | 0:5d3131d1b142 | 10 | // If isTemp = 1, resulting string includes |
Ksenia | 0:5d3131d1b142 | 11 | // 1. "-" (optional), |
Ksenia | 0:5d3131d1b142 | 12 | // 2. current temperature with decimal mark |
Ksenia | 0:5d3131d1b142 | 13 | // 3. " С" |
Ksenia | 0:5d3131d1b142 | 14 | |
Ksenia | 0:5d3131d1b142 | 15 | // Returns offset using for placing degree sign |
Ksenia | 0:5d3131d1b142 | 16 | char Display::CreateStringTempHum(char *str, float number, bool isTemp) |
Ksenia | 0:5d3131d1b142 | 17 | { |
Ksenia | 0:5d3131d1b142 | 18 | char offsetForDegreeSign; |
Ksenia | 0:5d3131d1b142 | 19 | short int multipedNumber = (short int)(number * 100); |
Ksenia | 0:5d3131d1b142 | 20 | char strCnt = 0; |
Ksenia | 0:5d3131d1b142 | 21 | if (isTemp) { |
Ksenia | 0:5d3131d1b142 | 22 | if (multipedNumber < 0) { |
Ksenia | 0:5d3131d1b142 | 23 | multipedNumber = -multipedNumber; |
Ksenia | 0:5d3131d1b142 | 24 | str[strCnt] = '-'; |
Ksenia | 0:5d3131d1b142 | 25 | strCnt++; |
Ksenia | 0:5d3131d1b142 | 26 | } |
Ksenia | 0:5d3131d1b142 | 27 | } |
Ksenia | 0:5d3131d1b142 | 28 | if (multipedNumber >= 10000) { |
Ksenia | 0:5d3131d1b142 | 29 | str[strCnt] = '0' + (multipedNumber % 100000) / 10000; |
Ksenia | 0:5d3131d1b142 | 30 | strCnt++; |
Ksenia | 0:5d3131d1b142 | 31 | } |
Ksenia | 0:5d3131d1b142 | 32 | if (multipedNumber >= 1000) { |
Ksenia | 0:5d3131d1b142 | 33 | str[strCnt] = '0' + (multipedNumber % 10000) / 1000; |
Ksenia | 0:5d3131d1b142 | 34 | strCnt++; |
Ksenia | 0:5d3131d1b142 | 35 | } |
Ksenia | 0:5d3131d1b142 | 36 | if (multipedNumber >= 100) { |
Ksenia | 0:5d3131d1b142 | 37 | str[strCnt] = '0' + (multipedNumber % 1000) / 100; |
Ksenia | 0:5d3131d1b142 | 38 | strCnt++; |
Ksenia | 0:5d3131d1b142 | 39 | } |
Ksenia | 0:5d3131d1b142 | 40 | if (isTemp) { |
Ksenia | 0:5d3131d1b142 | 41 | str[strCnt] = '.'; |
Ksenia | 0:5d3131d1b142 | 42 | strCnt++; |
Ksenia | 0:5d3131d1b142 | 43 | str[strCnt] = '0' + (multipedNumber % 100) / 10; |
Ksenia | 0:5d3131d1b142 | 44 | strCnt++; |
Ksenia | 0:5d3131d1b142 | 45 | str[strCnt] = ' '; |
Ksenia | 0:5d3131d1b142 | 46 | strCnt++; |
Ksenia | 0:5d3131d1b142 | 47 | offsetForDegreeSign = strCnt; |
Ksenia | 0:5d3131d1b142 | 48 | str[strCnt] = 'C'; |
Ksenia | 0:5d3131d1b142 | 49 | strCnt++; |
Ksenia | 0:5d3131d1b142 | 50 | } else { |
Ksenia | 0:5d3131d1b142 | 51 | str[strCnt] = '%'; |
Ksenia | 0:5d3131d1b142 | 52 | strCnt++; |
Ksenia | 0:5d3131d1b142 | 53 | } |
Ksenia | 0:5d3131d1b142 | 54 | str[strCnt] = 0; |
Ksenia | 0:5d3131d1b142 | 55 | |
Ksenia | 0:5d3131d1b142 | 56 | return offsetForDegreeSign; |
Ksenia | 0:5d3131d1b142 | 57 | } |
Ksenia | 0:5d3131d1b142 | 58 | |
Ksenia | 0:5d3131d1b142 | 59 | |
Ksenia | 0:5d3131d1b142 | 60 | /************************************************************************************************************************** |
Ksenia | 0:5d3131d1b142 | 61 | ************************** Transform multiplied temperature value to string *********************************************** |
Ksenia | 0:5d3131d1b142 | 62 | **************************************************************************************************************************/ |
Ksenia | 0:5d3131d1b142 | 63 | // Resulting string includes |
Ksenia | 0:5d3131d1b142 | 64 | // 1. "-" (optional), |
Ksenia | 0:5d3131d1b142 | 65 | // 2. current temperature with decimal mark |
Ksenia | 0:5d3131d1b142 | 66 | void Display::CreateStringMultipliedTemp(char *str, short int number) |
Ksenia | 0:5d3131d1b142 | 67 | { |
Ksenia | 0:5d3131d1b142 | 68 | char strCnt = 0; |
Ksenia | 0:5d3131d1b142 | 69 | if (number < 0) { |
Ksenia | 0:5d3131d1b142 | 70 | number = -number; |
Ksenia | 0:5d3131d1b142 | 71 | str[strCnt] = '-'; |
Ksenia | 0:5d3131d1b142 | 72 | strCnt++; |
Ksenia | 0:5d3131d1b142 | 73 | } |
Ksenia | 0:5d3131d1b142 | 74 | if (number >= 1000) { |
Ksenia | 0:5d3131d1b142 | 75 | str[strCnt] = '0' + (number % 10000) / 1000; |
Ksenia | 0:5d3131d1b142 | 76 | strCnt++; |
Ksenia | 0:5d3131d1b142 | 77 | } |
Ksenia | 0:5d3131d1b142 | 78 | if (number >= 100) { |
Ksenia | 0:5d3131d1b142 | 79 | str[strCnt] = '0' + (number % 1000) / 100; |
Ksenia | 0:5d3131d1b142 | 80 | strCnt++; |
Ksenia | 0:5d3131d1b142 | 81 | } |
Ksenia | 0:5d3131d1b142 | 82 | if (number >= 10) { |
Ksenia | 0:5d3131d1b142 | 83 | str[strCnt] = '0' + (number % 100) / 10; |
Ksenia | 0:5d3131d1b142 | 84 | strCnt++; |
Ksenia | 0:5d3131d1b142 | 85 | } |
Ksenia | 0:5d3131d1b142 | 86 | str[strCnt] = '.'; |
Ksenia | 0:5d3131d1b142 | 87 | strCnt++; |
Ksenia | 0:5d3131d1b142 | 88 | str[strCnt] = '0' + (number % 100) / 10; |
Ksenia | 0:5d3131d1b142 | 89 | strCnt++; |
Ksenia | 0:5d3131d1b142 | 90 | str[strCnt] = 0; |
Ksenia | 0:5d3131d1b142 | 91 | } |
Ksenia | 0:5d3131d1b142 | 92 | |
Ksenia | 0:5d3131d1b142 | 93 | |
Ksenia | 0:5d3131d1b142 | 94 | /************************************************************************************************************************** |
Ksenia | 0:5d3131d1b142 | 95 | ************************** Transform number of seconds to HH:MM:SS string ************************************************* |
Ksenia | 0:5d3131d1b142 | 96 | **************************************************************************************************************************/ |
Ksenia | 0:5d3131d1b142 | 97 | void Display::CreateStringTime(char *str, uint32_t numberOfSeconds) |
Ksenia | 0:5d3131d1b142 | 98 | { |
Ksenia | 0:5d3131d1b142 | 99 | char hrs = (numberOfSeconds / 3600); |
Ksenia | 0:5d3131d1b142 | 100 | if (hrs < 10) { |
Ksenia | 0:5d3131d1b142 | 101 | str[0] = '0'; |
Ksenia | 0:5d3131d1b142 | 102 | } else { |
Ksenia | 0:5d3131d1b142 | 103 | str[0] = '0' + hrs / 10; |
Ksenia | 0:5d3131d1b142 | 104 | } |
Ksenia | 0:5d3131d1b142 | 105 | str[1] = '0' + hrs % 10; |
Ksenia | 0:5d3131d1b142 | 106 | str[2] = ':'; |
Ksenia | 0:5d3131d1b142 | 107 | char minutes = (numberOfSeconds / 60) % 60; |
Ksenia | 0:5d3131d1b142 | 108 | if (minutes < 10) { |
Ksenia | 0:5d3131d1b142 | 109 | str[3] = '0'; |
Ksenia | 0:5d3131d1b142 | 110 | } else { |
Ksenia | 0:5d3131d1b142 | 111 | str[3] = '0' + minutes / 10; |
Ksenia | 0:5d3131d1b142 | 112 | } |
Ksenia | 0:5d3131d1b142 | 113 | str[4] = '0' + minutes % 10; |
Ksenia | 0:5d3131d1b142 | 114 | str[5] = ':'; |
Ksenia | 0:5d3131d1b142 | 115 | char sec = numberOfSeconds % 60; |
Ksenia | 0:5d3131d1b142 | 116 | if (sec < 10) { |
Ksenia | 0:5d3131d1b142 | 117 | str[6] = '0'; |
Ksenia | 0:5d3131d1b142 | 118 | } else { |
Ksenia | 0:5d3131d1b142 | 119 | str[6] = '0' + sec / 10; |
Ksenia | 0:5d3131d1b142 | 120 | } |
Ksenia | 0:5d3131d1b142 | 121 | str[7] = '0' + sec % 10; |
Ksenia | 0:5d3131d1b142 | 122 | str[8] = 0; |
Ksenia | 0:5d3131d1b142 | 123 | } |