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.

P.S.: Don’t forget to check the BONUS article!!!

9 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.

  2. Hello,
    Thank you for the series, now I have understood the STemWin. Can you make a series about the Ethernet of the F746-DISCO? I am thinking about a MQTT using mbedtls and MQTT Paho library with the F7-DISCO but it seems I haven’t known the use of the Ethernet.
    Thank you again,
    Best regards,
    Duy

    • Hello!

      I haven’t done anything with ethernet on the STM32 yet, so it might take some time, before I do…

      Regards!

      • Hi Slemi, glad that you say so. I’ll be waiting for it.
        Best regards!

    • I am not yet using JPGs, so I can’t really help now. Hope the forum will have more knowledge.

      Regards!

    • You would have to make all the changes for different display and it MIGHT work.

Comments are closed.