TouchGFX temperature curve
【Foreword】
touchGFX has powerful chart functions, especially dynamic chart controls, which can display data curves. Today, we will use this control to realize real-time temperature curves.
【hardware】
- STM32U599J-DK development board.
- Developed on the stts22h temperature sensor.
【develop software】
- stm32CubeIDE.
- VScode
- TouchGFX 4.22.1
【Study Materials】
【Implementation steps】
- Create a blank project:
- Add dynamic chart tools to the project:
- You can add background images and text (omitted) as you like.
- To modify the properties of a chart:
The graphical interface design is now complete. You can refer to the tutorial for specific setting parameters.
【Code writing】
- Use stm32cubeIDE to open i2c3 and load the stts22h driver library into the project, add the driver compilation file and path:
- Add the stts22h driver header file back to app_freertos.c, and declare a global function to pass the obtained temperature value. Read the value of stts22h in a task in a loop.
I will attach the source code of the specific driver library for reading, you can check it yourself, it is not the focus of this article.
- According to the principle of Model->Presenter->View, add the codes back one by one.
- In model.hpp, we add variables to store temperature and functions to get and save temperature:
- In the tick function of model.cpp, we update the temperature value every 20 ticks.
- In screen1Presenter.hpp we implement a function to get the temperature value:
float getTemp()
{
return model->getTemp();
}
- Add the handleTickEvent virtual function to screen1View.hpp and implement it in screen1Presenter.cpp
- In screen1View.cpp, add a temperature value data point to the graphics control every 60 ticks:
void Screen1View::handleTickEvent()
{
tickCount++;
if(tickCount == 60)
{
dynamicGraph1.addDataPoint((int)presenter->getTemp());
tickCount = 0;
}
}
Now our code and graphical interface are designed, compile and download in touchGFX Designer.
【Effects achieved】
Attached project source code: