STEmWin with Touch Screen on STM32F746G Dicovery – Part 5

In this article we will finally add touch capabilities to our project.

Before You start with this tutorial, You need to finish previous four parts. You can see it here part1, part2, part3 and part4.

We already included the needed .h file:

Next thing we need to do is initialize touch screen. We use function BSP_TS_Init:

In first line we Initialize touch and check if everything is OK. If it is not, the program displays “ERROR” “Touchscreen cannot be initialized” and waits at While loop, othervise it just continues to the next command.

BSP_LCD_GetXSize() and BSP_LCD_GetYSize() are routines to get number of pixels on the LCD.

We also need some kind of variable to store touch data:

We will to add BSP_TS_ResetTouchData(&TS_State); somewhere to reset touch data. We will this later too, to clear touch data to prevent multiple touch sensing when we only pres LCD once. <- This is my way on solving something like “debounce”.

To sense touch we need to call routine called BSP_TS_GetState(&TS_State); to get touch data. When I tried just this routine to check for touch I got over 100 touches at one fingertouch, so I needed to figure something out. After reading a lot of documentation I saw that there is a variable inside TS_Touch called touchEventID and one of it’s values is TOUCH_EVENT_PRESS_DOWN and this is the one I used for “debouncing”.

If we compile and upload this program, we can now detect touches on LCD. It will write X and Y coordinates of touch. I get 1..479 values for X and 1..271 values for Y. From here we can add command acording to coordinates on display.

This concludes this series of tutorials about STEmWin with Touch Screen on STM32F746G Discovery. And here is the link to zipped complete project.

2 thoughts on “STEmWin with Touch Screen on STM32F746G Dicovery – Part 5

  1. Hi,
    I am trying to follow your tutorial to create the project, unfortunately i am not able to make this work. Can you share the whole project?

    • Hi,

      sure, no problem!
      Please let me know where is the problem with your project, so that I can add solution here for anyone else having same problem.

Leave a Reply

Your email address will not be published. Required fields are marked *