Menu

ili9341 touch

Help
2022-01-17
2022-01-18
  • stan cartwright

    stan cartwright - 2022-01-17

    I am using the lgt328 ili9341 touch demo. It's interesting. I stripped it down to a minimum and it just draws circles where you touch the screen. here's the minimum code.

        #chip LGT8F328P
        #option explicit
    
        #include <glcd.h>
        #include <xpt2046.h>
        #include <LGT8F328P.h >
    
        '******************************************************************************************************
        'Setup the GLCD
    
        #define GLCD_TYPE GLCD_TYPE_ILI9341
    
        'Pin mappings for SPI - this GLCD driver supports Hardware SPI and Software SPI
        #define GLCD_DC       DIGITAL_8           ' Data command line
        #define GLCD_CS       DIGITAL_10          ' Chip select line
        #define GLCD_RESET    DIGITAL_9           ' Reset line
        #define GLCD_DI       DIGITAL_12          ' Data in | MISO    - Not used therefore not really required
        #define GLCD_DO       DIGITAL_11          ' Data out | MOSI
        #define GLCD_SCK      DIGITAL_13          ' Clock Line
    
        #define ILI9341_HARDWARESPI
        'Setup the XPT2046
        'Typical Calibration range for Software SPI when using XPT2046
        #define XPT2046XMIN   30
        #define XPT2046YMIN   25
        #define XPT2046XMAX   210
        #define XPT2046YMAX   225
    
        #define XPT2046_DI       DIGITAL_12          ' Data in | MISO
        #define XPT2046_DO       DIGITAL_11          ' Data out | MOSI
        #define XPT2046_SCK      DIGITAL_13          ' Clock Line
        #define XPT2046_CS       DIGITAL_2           ' Chip select line
        #define XPT2046_IRQ      ANALOG_5
    
        #define XPT2046_SOFTWARESPI
        #define LGT_XPT_HWSPIMODE  MASTER  'optionally can be MASTERSLOW
    
        'Main program
        GLCDRotate Portrait
        GLCDCLS TFT_BLUE
        SetCalibation_XPT2046 ( XPT2046XMIN, XPT2046XMAX, XPT2046YMIN, XPT2046YMAX, GLCD_WIDTH, GLCD_HEIGHT )
    ;    ScreenLayout
    
        dim Xconverge, Yconverge as Integer
        dim convergeCounter as byte
        do
    
          Xconverge = 0
          Yconverge = 0
          convergeCounter = 1
    
          do
              repeat 5
                  'get the values -
                  GetXY_XPT2046( XTouchPoint_XPT2046, YTouchPoint_XPT2046 )
              end Repeat
              'test for settling by testing for convergance
              if ABS( ( Xconverge - XTouchPoint_XPT2046 ) ) > 1  or  ABS( ( Yconverge - YTouchPoint_XPT2046 ) ) > 1  then
                  Xconverge = XTouchPoint_XPT2046
                  Yconverge = YTouchPoint_XPT2046
                  convergeCounter++
              Else
                  'converged
                  exit do
              end if
          Loop
    ;      Flip the data to handle for the screen rotation
          YTouchPoint_XPT2046 = Current_GLCD_HEIGHT - YTouchPoint_XPT2046
    
               FilledCircle XTouchPoint_XPT2046, YTouchPoint_XPT2046, 3, TFT_LIGHTGREY
    
        loop
    

    I don't understand the code. I can't see what convergeCounter++ is for.
    Does YTouchPoint_XPT2046 = Current_GLCD_HEIGHT - YTouchPoint_XPT2046 need to be in the main loop?
    It's a good gcb include but how does it work ?
    What is

        'Typical Calibration range for Software SPI when using XPT2046
        #define XPT2046XMIN   30
        #define XPT2046YMIN   25
        #define XPT2046XMAX   210
        #define XPT2046YMAX   225
    

    about please?
    I notice an increasing x axis error as you touch screen further right??
    The display is 240x320. The x axis error is a problem. I can do a youtube video to show the error.
    ps #define GLCD_TYPE GLCD_TYPE_ILI9341 seems new.
    Also why TFT_LIGHTGREY instead of ili9341 colours? asked before.

     

    Last edit: stan cartwright 2022-01-17
  • Anobium

    Anobium - 2022-01-17

    Stan - how cool!


    convergeCounter

    convergeCounter is a method to ensure the pointer is in the same place within 1 returned pixel value

    If reads the position of the event 5 times then if the read is with 1 pixel of the last one it exits the do loop - this stops the XPT sensor returning wild results.


    It's a good gcb include but how does it work ?

    The include is relatively simple.

    1. Setups the ports etc and sets the interrupt
    2. It sends the calibration data to the XPT
    3. Take a load of samples by sending a request for a sample but for the LGT turn off harware SPI prior to request and restore SPI state after the request has completed.
    4. Return an average of the sensor values

    What is

    'Typical Calibration range for Software SPI when using XPT2046
    #define XPT2046XMIN   30
    #define XPT2046YMIN   25
    #define XPT2046XMAX   210
    #define XPT2046YMAX   225
    

    about please?

    These are the calibration values. Use the original demo to set the returned values. See https://youtu.be/wN35LwRgOAQ


    I notice an increasing x axis error as you touch screen further right??

    Recalibrate please.


    Also why TFT_LIGHTGREY instead of ili9341 colours? asked before.

    TFT_LIGHTGREY is the same value as the ILI9341 constant. I created the ILI9341 constants before I was thinking about just using TFT_color_code_constants

    :-)

     
  • stan cartwright

    stan cartwright - 2022-01-17

    Nice one Anobium. Thinking a 50Hz timer interrupt for getting x,y touched. You mention 20ms before touch the screen.
    The x,y is from where the circle is drawn so getting there.
    I just want to test an x,y co-ordinate of a screen pressed position but in a program would need a way of getting the screen touched event.
    I'm not the brightest crayon in the box so lots of thinking to do.
    I got to try the mega328 interrupts with LGT328. TimerCalulator program ?? what to set it? Assume interrupt happen twice as fast??

     
  • stan cartwright

    stan cartwright - 2022-01-17

    Your video https://www.youtube.com/watch?v=wN35LwRgOAQ explains a lot about the mechanics. Cheers.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.