Abstract
This system uses temperature sensor DS18B20, Bluetooth module HC-05, microcontroller STM32f103ZET6, LCD display with 8080 port, RTC clock and alarm circuit to achieve portable temperature measurement rapidly. It can accurately measure the temperature and the deviation is kept within 0.5 degrees. The collected temperature data and the current time are displayed on the display screen. Send the collected temperature data at regular time and receive by APP mobile phone. When users want to get temperature data remotely on their phones, press the send button on the touch screen, press the up button and send the “wendu#” command to the cell phone APP to get the temperature data collected. When the temperature is over 37
Keywords
Introduction
Temperature is a basic physical quantity. All processes in nature are closely related to temperature. With the continuous progress and development of science and technology, the types of temperature sensors are increasingly numerous and widely used. In our daily life, the traditional mercury thermometer is with a variety of inconveniences factors such as serious pollution of mercury, inconvenient carrying, easily broken, the measurement time is too long. In order to solve this problem, a portable digital temperature display meter is designed. The temperature measurement time has an absolute advantage over the mercury thermometer and the accuracy is also different from the mercury thermometer [1, 2]. This system uses the STM32F103ZET6 chip which is based on the 32 – bit microprocessor of the ARM Cortex-M3 series. Use its internal clock RTC clock to time, use chip 9341 LCD resistance screen as a display module, LED lamp as a prompt function. DS18B20 temperature sensor is used to collect temperature data and HC-05 Bluetooth module is used to communicate with mobile phone [3, 4].
Design of temperature collection system
DS18B20 sensor has only one data line to control time series that is a single bus system. A single bus signal system consists of a bus controller and one or more slave machines. DS18B20 sensor always acts as a slave machine. Lower order data are first transmitted through a single bus among all the data and instructions. The equipment on each bus must be open or three state output. The single bus port (DQ pin) of DS18B20 is a leaky type. This system sensor connection circuit is shown in Fig. 1. DQ is to the PG11 pin, configure PG11 into two modes (push-pull output and floating input). The single bus requires an external pull resistance of a 4.7 K Omega that makes the bus idle state high. The bus must stay in free form whenever a time needs to be suspended and a response is required. During the recovery period, the reloading of the register and the register can be indefinitely long if the single bus is idle. If the data line is pulled down and maintained for 480 us, all the devices on the bus are in the working state [5].
Hardware connection diagram of sensor.
The normal work of DS18B20 depends on different sequences. The initialization time sequence of the I/O port: (1) DS18B20 reset sequence: Use the push-pull output mode of PG11, pull down PG11 level for at least 480 us then pull up DQ for 15 us. (2) DS18B20 response sequence: Use the floating input mode of PG11.Judge whether PG11 is low level in 200 us. If it is high it proves that DS18B20 sensor is not connected successfully. Judge whether PG11 level is high in 240 us if it is low. If no there is no response otherwise there is a successful response to B20. Writing time sequence: (1) Write 1 timing series: use push-pull output mode of PG11, pull PG11 down for 2 us then pull PG11 up for 60 us. (2) Write 0 time series: use push-pull output mode of PG11, pull it down for 60 us then pull it high for 2 us. Reading time sequence, use push-pull output mode at first, pull PG11 down for 2 us to pull it high. Then configure it for the floating input mode. Determine PG11 pin state for 12 us, if high the bit is 1, otherwise 0. The initialization flow chart of the system is shown in Fig. 2.
Initialization flow chart.
This system uses resistance liquid crystal lattice screen with 240*320 pixels. The control chip is 9341, the connection interface is 8080, and it is a hardware interface format.
Working principle of touch screen
The system touch screen uses the XPT2046 chip. The value of the reference voltage directly determines the output data of the chip.The chip contains a programmable analog to digital converter ADC which can be configured as a single or differential mode. Configure it as a differential mode when it is used as a touch screen. This mode can be portable to eliminate the measurement error caused by the driving switch so that the precision of the converted data can be effectively improved and easy to use. X axis and Y axis should be judged respectively when the coordinates are obtained. X axis coordinates are judged by adding voltage to X axis and reading the voltage value of Y axis. Y axis coordinates are judged by adding voltage to Y axis and reading the voltage value of X axis. Then obtain the coordinate values of pixels after the value of obtained voltage is calibrated. The connection diagram of each pin of the touch screen and the chip is shown in Fig. 3 [6, 7].
Touch screen and chip pin connection diagram.
Physical connection
Touch screen uses SPI communication protocol that is full duplex synchronous serial communication. The SPI communication protocol has two data lines and a clock line, MISO data line, MOSI data line and SCK clock line. After connecting MISO data line, the main device is used as an input device and slave unit as an output device. Send data from the slave machine and the host unit receives data. The main device under the MOSI data line is used as an output device and slave unit as an output device. Send data from the host machine and the slave unit receives data. The touch screen has a NSS chip select function line in this design. This is an optional pin to select the main device or the slave device. After this pin is enabled, it can be used as output pin and the level will be lowered as the host mode. When the device is a host, MATR can automatically clear the device into the slave mode that is master mode and slave mode can be switched each other [8].
Timing sequence
In the same cycle the master and slave device start to send data when the clock line is high and stop sending data when it is low. Send data when the data line is in the rising edge and receive data when it is in the down edge. SPI communication protocol can change the reception timing which comes down to the relationship between the clock polarity (CPOL) and the clock phase (CPHA). CPOL represents the state of the clock line when the data line does not send data. When CPOL equals 1, it represents the high level of the clock line in the idle state. When the data is sent, the clock line will be pulled down as the starting position. CPHA determines that the data line sends along the rising edge or the falling edge. It means that sending data on the rising edge and receiving data on the falling edge when CPHA equal to 1. When CPHA equals 0, it is the opposite. A specific sequence diagram is shown as shown in Fig. 4.
SPI sequence diagram.
Working mode
Bluetooth is a wireless technology which refers to two or more devices that can be wireless communication without contact. The communication distance is relatively close generally within 10 m. This design uses embedded Bluetooth serial communication module HC-05 which has two working modes command response mode and normal working mode.
The serial port module uses the pin PIO8 which is connected with one indicator light showing the working state of the module. The module is flicker after electricity and different flicker intervals are different. PIO11 is connected to a button for module state switching. It defaults to low level, at this time the Bluetooth module is in regular working state. After pressing this button, the pin changes to high level [9, 10]. At this time, the Bluetooth module is in command response state. The module defaults to work in the direct slave mode after power up. The main module is set up in 5 steps: The first step is to pull up PIO11 level. The second step is to power the module and let the module enter AT command response state. The third step is to use serial assistant. The baud rate of Bluetooth module is 38400, data bits are 8 bits, stop bits are 1 bit, there is no parity bit and no hardware flow control. The fourth step is to send “AT
Instruction set and debug of Bluetooth module
This Bluetooth module uses the serial assistant for debugging. AT instructions used:
Test instruction: AT Response: OK Module reset command: AT Response: OK Get version model: AT Response: Restore default state: AT Response: OK Get Bluetooth module address: AT Response: Set Bluetooth module device name: AT Response: OK Set Bluetooth module device password: AT Response: OK Set the master-slave or loopback mode: AT Response: OK
Switch the module to automatic connection mode and download Bluetooth serial port software.
Mobile phone interface.
Computer serial port diagram.
Bluetooth module hardware circuit diagram.
The communication between computer and mobile phone is realized by Bluetooth module, the display of mobile phone interface is shown in Fig. 5. The upper computer display is shown in Fig. 6. Search device after entering mobile app. Enter the password and connect the device. Change the baud rate on the serial assistant to 9600. Send Chinese characters you want to send on the send command bar of the serial assistant. For example, send “test Bluetooth” four Chinese characters. The sent Chinese characters can be received on the mobile app. Send the word “Bluetooth test successful” on the mobile-phone, and the font can be displayed on the serial port assistant. At this point it can be determined that all Bluetooth functions can be realized.
Serial port configuration and interrupt flow chart.
The communication protocol is a serial communication protocol UART. This design uses the first serial port of STM32.Connect the Bluetooth module to the two pins PA9 and PA10. UART is a universal synchronous or asynchronous transceiver. It is a full duplex communication mode that can be exchanged with the external devices for serial data exchange. The baud rate of UART controls the speed of its transmission. This can support not only full duplex two-way communication but also synchronous one-way communication and half duplex single line communication. Use a buffer to configure DMA to achieve high speed data communication. UART programmable data length can be 8 bits or 9 bits which can support one or two stop bits [11].
The process of sending data in UART is as follows: Send a start bit (one bit, low level), then send data bits (8 bits or 9 bits), then send the parity (number of 1 in a data, odd check and parity check). The check bit is not used in this design. At last send stop bit (0.5
Hardware and software implementation of Bluetooth module
The hardware connection circuit between Bluetooth module and single chip microcomputer is shown in Fig. 7. Since they all use TTL level, connect directly no need for a level conversion. The two pins connected to the single chip microcomputer are TXD and RXD. TXD of Bluetooth module is connected to P10 of MCU (receiving pin RXD of MCU). RXD needs to connect to P9 of MCU (sending pin TXD of MCU). START pin is connected to one of LED pins on the MCU. In different working conditions, the brightness flicker time of LED will change. EN is the enable port to receive a high level of pipe foot.
STM32 chip has an interruption of an independent serial port. After the basic configuration of the serial port is completed, configure the channel manager NVIC and open interrupt, the serial port interrupt mechanism can be used. The specific flow chart is shown in Fig. 8. The initialization serial port includes the serial port baud rate, data bit, receiving and sending mode, stop bit [12], check bit, and whether the hardware retention control is required. When the mobile phone sends data to MCU through Bluetooth module, it triggers the serial interrupt mode of it, thus enter the serial interrupt service function. Collect the received data in this function, call these data in other programs to implement the corresponding functional serial interrupt service function.
This design uses serial port configuration to receive interrupt mode. In this mode, when using the mobile phone to send data to the MCU through Bluetooth module, the serial port interrupt mode of the MCU will be triggered and the serial port interrupt service function will be entered. In this function, collect the received data and call them in other programs to achieve the corresponding function, serial interrupt service function.
if(USART_GetITStatus(USART1,USART_IT_RXNE)==SET)
{
USART_ClearITPendingBit(USART1,USART_IT_RXNE); //Clear receive flag bit
shuzu[i]
i++;
if(shuzu[i-1] == ’#’) // Stop saving character when #
{
shuzu[i]
i
}
}
System clock design
This design requires a regular collection of temperature data then sent to the mobile APP, so a precise clock is needed to calculate the time. This design uses RTC real time clock as the chronograph.
System time setting
The advantage of adopting the RTC module is that its time configuration system is located in the reserve storage area. When the system is reset, it is forbidden to access the backup register. So using RTC as a clock, it can achieve the effect of reset power and no loss of data if the button battery is installed. Press the digital button to display date on the top of year month day hour and minute on the system interface. When all the settings are set up, press determine key button to make the new time into the current time. The implementation of this function involves touch screen operation, LCD display operation, system backup register operation, RTC clock counter operation, etc. The RTC clock is to save the data to the backup register. If system time is to be modified, the backup register can be modified. Need to enable RCC_APB1 register then enable back clock register. The operation of the specific program is as follows:
RCC->APB1ENR
After the backup register is operated to protect it from being modified, it is also required to be locked. The specific procedures are as follows:
RCC->APB1ENR &
To modify the time of system, need to have a ratio. In this design, the time of system is set to January 1, 1970. The modified system time is compared with the initial date, and the difference between the modified system time and this date is calculated. It involves the calculation of the average year and the leap year. A leap year can be divided by 4, not divisible by 100 or divided by 400. The rest is a flat year. First, calculate the different year between the modified system date and 1970 and convert it into seconds (average year number *365*24*60*60 add leap year number *366*24*60*60). Then calculate the day number of the set year. For example, the system time is set at 12:11 on March 24, 2020, the March 24th 12:11 will be converted into seconds, plus the number of seconds converted into the year. Send the value to the RTC clock counter. This completes the setup of system time.
RTC clock software operation
RTC clock has a programmable prefrequency coefficient which can reach 2^20. It has 32 bit programmable counters that can be timed for about 136.2 years enough to be designed. It has two separate clocks: PCLK1 and RTC clocks (the frequency must be less than 1/4 of PCLK1 clock frequency). The following three clock sources can be selected as the clock source of RTC: HSE clock (dividing its clock frequency by 128), LSE oscillator clock and LSI oscillator clock. RTC has 3 specialized shielding interrupts: alarm interruption, second interrupt and overflow interrupt. This design uses second interruption which is used to generate a programmable periodic interrupt signal (up to 1 sec) [13, 14].
The process that enables RTC to work normally is as follows. First, initialize the BKP register and allow backup area operation. Use external high-speed clock source (clock frequency 32.768 KHZ) as RTC clock source. Then initialize RTC clock source and detect whether the initialization is completed. If it is not finished, it has been waiting for its initialization. If it is finished set RTC clock frequency division and initialize the counter. Wait to complete the last write register operation and APB1 to synchronize with RTC. Set the register mode to a pattern that can be modified, and set the initial time value of RTC. Then exit the mode to modify the register. Configure interrupt manager, enable RTC clock and open RTC interrupt, write RTC interrupt service function to use the RTC system clock.
Design of clock display
This design has an independent RTC numeric value acquisition function which is converted to annual, month, day, hour, minute, and second. Then it will be encapsulated as an array of strings and will be lit up on the screen to show our time. The function of displaying time is placed in an interruption or a dead cycle to achieve the beat of time, so that 24 hours of accurate time per day can be achieved. RTC is hardware timing not affected by software. The counter will not run because of the program cause, resulting in inaccurate time. RTC clock also has a great advantage that reset is not lost.
Use of tick clocks
The design of sensor timing, LCD screen configuration and so on, there are many places need to delay, so it is essential to use the precise delay. The tick clock is part of the CORTEX-M3 kernel. Its clock source is the AHB clock as the running clock [15]. The counter counts by counting down and value of the interrupt counter decreases by 1 until 0. When it is reduced to 0, the hardware automatically loads the data stored in the load register to the counter which means that it will automatically reload. To make tick clock work normally, it must be initialized. Its configuration is very simple. There are only three control bits and one flag bit that are all located in the register. According to the bits in the register, it can be configured. Then write interrupt service function of the tick clock. After everything is done, use counters in the kernel to configure the precise time delay in the sequence diagram.
Software program design
The total program flow is shown in Fig. 9. The initialization functions of each component include serial port grouping function, serial port initialization function, key initialization function, tick initialization function, outside FLASH initialization function, LCD initialization function, touch screen initialization function, RTC clock initialization function, display background slice function, display card function, and initial LED lamp Initialization function and B20 reset timing function.
Total program flow.
Interface design
It takes three steps to display the picture on the LCD screen. Because LCD used in this design is a 240*320 screen, if the color picture is completely displayed on the screen, the size of the picture needs to be changed to 240*320 size in the drawing software. Then the software of image module generates a C language data from each pixel of the picture. The maximum height is set to 320, the maximum width is set to 240, and output grayscale is set to 16 bit true color, the rest is on the line by default. Click save in the upper right corner to mark the generated array file name in .C format. Finally add the file to the software, display this array on the LCD screen to display the two images on the screen.
This design can detect whether the temperature sensor is connected successfully. If the connection is not successful, the LCD will indicate that the temperature sensor connection has failed. This requires manual connection of the sensor. The principle procedure of detecting whether the sensor is connected successfully is as follows. If the return value of this function is 0, DS18B20 connection is successful and the temperature measurement operation can be carried out. Otherwise the sensor needs to be checked. The screen display of unsuccessful connection is shown in Fig. 10.
u8 B20_Check(void)
{
u8 retry
B20_OUT_Config(); // Configure to output mode
B20(LOW); //Pull down DQ
Delay_us(750); //Pull down750us
B20(HIGH); //Pull up DQ
Delay_us(15); //15us
B20_IN_Config(); // Configure as input mode
while (B20_S&&retry<200) //Whether detection level changes to low level within 200us
{
retry++;
Delay_us(1);
}
if(retry>=200)
return 1;
else
retry
while (!B20_S&&retry<240) //Whether detection level changes to high level within 240us
{
retry++;
Delay_us(1);
}
if(retry>=240)
return 1;
else
return 0;
}
Sensor connection failure diagram.
Display temperature interface.
The collected temperature data is displayed on the LCD. The set system time (i.e. 1970-01-01) is accurately displayed on the LCD without loss of reset. The normal display of temperature and time is shown in Fig. 11. Over temperature display is shown in Fig. 12. These temperature and time data are collected in real time and always updated. In order to display the data on screen, the data is encapsulated into two string data. The specific program is as follows:
// Temperature encapsulated string
TEM[0]
TEM[1]
TEM[2]
TEM[3]
TEM[4]
TEM[5]
// Time data encapsulated string
//(1) Hour, minute, second data encapsulated string
time_s[0]
time_s[1]
time_s[2]
time_s[3]
time_s[4]
time_s[5]
time_s[6]
time_s[7]
time_s[8]
//(2) UTF8gbsn年月日数据封装的字符串
data[0]
data[1]
data[2]
data[3]
data[4]
data[5]
data[6]
data[7]
data[8]
data[9]
data[10]
Display exception prompt interface.
Real time temperature interface of mobile phone.
In the experiment in order to facilitate the demonstration, this design will collect temperature data every 10 seconds through the Bluetooth module sent to the mobile app. Visually display temperature at different times of one day and if the data is too high, it will send “too high, please pay attention!” word. The specific display of mobile app is shown in Fig. 13. Plan out an area on the touch screen and write the word “send”. At the same time, connect the up button on the circuit board with the system. Press the area on the touch screen or the up button to send the temperature data to the mobile phone app through the Bluetooth module.
The hardware connection diagram of the key is shown in Fig. 14. When the key is pressed, PA0 port is in the low level state. When the key is not pressed, PA0 is in the high level state. The state of PA0 is detected cyclically. When the pin status bit is low, the collected temperature data is sent.
key hardware connection diagram.
Plan out an area on the touch screen and write “Set”. Click this area to enter the modification time interface. Click OK button to exit and return to the main interface displaying the temperature after modifying the set time. At this time, the time and date of the main interface are set in the modify date interface. Send the word “Wendu#” directly from your mobile phone, the temperature data at that time can be fed back to the mobile phone.
This design has been realized through the DS18B20 temperature sensor, the HC-05 Bluetooth module and the STM32f103ZET6 chip. The basic functions of the thermometer have been realized. It can monitor temperature in real time, display temperature data on the mobile phone APP regularly and get the temperature data in time when necessary. The design also optimizes the display interface. The system time can be modified on the interface to achieve the humanized function for daily use.
The core of the whole system is the communication between sensor and chip, Bluetooth module and chip. In the process of communication implementation, it is necessary to debug comprehensively to ensure that communication will not be confused. After the communication is realized, the LCD is displayed. All kinds of temperature, time and other data need to be displayed on the screen without error. The choice of system clock is also an important link. The clock needs to be debugged precisely. It must be timed by hardware to ensure its accuracy. Overall, this design has high use value.
Footnotes
Acknowledgments
This work was supported by Henan University Science and Technology Innovation Team Support Program (19IRTSTHN011), Natural Science Foundation of Henan Province (Grant: 182300410104), Zhengzhou Measurement and Control Technology and Instrument Key Laboratory (Grant: 121PYFZX181). This work is supported by Henan province science and technology research project (Grant: 1721022103 70).
