Menu

ili9341 glcd read pixel

2020-01-20
2020-01-25
  • stan cartwright

    stan cartwright - 2020-01-20

    It's in demos but I just get zeros. no change. It was for mega328p but changed to pic.Same results though.

    '''A demonstration program for GCGB and GCB.
    '''--------------------------------------------------------------------------------------------------------------------------------
    '''This program is a simple GLCD demonstration of the ILI9341 GLCD read pixel capabilities.
    '''The read pixel routine only supports hardware SPI.
    '''It is a nice graphical LCD, suitable for a lot of various projects.
    '''This program draws lines, boxes, circles and prints strings and numbers.
    '''The GLCD is connected to the microprocessor as shown in the hardware section of this code.
    ''':
    '''This has been tested using the hardware SPI option.
    ''':
    '''Note: for the correct operation of this display you MUST connect via a CD4050, see http://forum.arduino.cc/index.php?topic=181679.90
    ''':
    '''@author
    '''@licence GPL
    '''@version 1.0
    '''@date
    '''********************************************************************************
    
      'Chip Settings.
    '  #chip mega328p, 16
    '  #option explicit
    '
    '    #include <glcd.h>
    '    #include <uno_mega328p.h >
    '
    '    #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    ' remove/comment out if you want to use software SPI.
        #chip 18f25k22, 64
        ; pic running on 3.3V so no cd4050 or logic level converter
        #config MCLRE=on
        #option Explicit
        #include <glcd.h>
    
        #define GLCD_TYPE GLCD_TYPE_ILI9341
    
        'Pin mappings for ILI9341
        #define GLCD_DC portc.2
        #define GLCD_CS portc.0
        #define GLCD_RESET portc.1
    
        'As we are using Harware SPI this cannot be change on this chip. This is a non-PPS chip.
        #define GLCD_DI portc.4
        #define GLCD_DO portc.5
        #define GLCD_SCK portc.3
        #define ILI9341_hardwarespi
    
    
        'GLCD selected extension font set. ASCII characters 31-254, the extended font uses 1358 bytes of program memory
        #define GLCD_EXTENDEDFONTSET1
        GLCDfntDefaultsize = 1
    
        'GLCDCLS  supports GLCDBackground as default
        'GLCDCLS  also support passing color parameter.
        'GLCDCLS [color]
        GLCDRotate ( Landscape_rev )     ' optionally you can rotate the screen.
    
    
        'Available colors
        'ILI9341_BLACK
        'ILI9341_RED
        'ILI9341_GREEN
        'ILI9341_BLUE
        'ILI9341_WHITE
        'ILI9341_PURPLE
        'ILI9341_YELLOW
        'ILI9341_CYAN
        'ILI9341_D_GRAY
        'ILI9341_L_GRAY
        'ILI9341_SILVER
        'ILI9341_MAROON
        'ILI9341_OLIVE
        'ILI9341_LIME
        'ILI9341_AQUA
        'ILI9341_TEAL
        'ILI9341_NAVY
        'ILI9341_FUCHSIA
    
        dim pixcol as long
        dim setpixcol as word
    
    
    
        GLCDRotate ( Landscape_rev )     ' optionally you can rotate the screen.
        GLCDCLS ILI9341_BLACK
    
          'Setup above here
          Pset 0,0, ILI9341_RED
          Pset 1,1, ILI9341_WHITE
          Pset 2,2, ILI9341_RED
    
        do
    
          pixcol = ReadPixel_ILI9341( 0,0 )
          GLCDPrint 10, 10, hex( pixcol_U )
          GLCDPrint 26, 10, hex( pixcol_H )
          GLCDPrint 42, 10, hex( pixcol )
    
    
          pixcol = ReadPixel_ILI9341( 1,1 )
          GLCDPrint 10, 20, hex( pixcol_U )
          GLCDPrint 26, 20, hex( pixcol_H )
          GLCDPrint 42, 20, hex( pixcol )
    
          pixcol = ReadPixel_ILI9341( 2,2 )
          GLCDPrint 10, 30, hex( pixcol_U )
          GLCDPrint 26, 30, hex( pixcol_H )
          GLCDPrint 42, 30, hex( pixcol )
    
          Pset 3, 3, setpixcol: setpixcol = setpixcol + 16
          pixcol = ReadPixel_ILI9341( 3,3 )
          GLCDPrint 10, 40, hex( pixcol_U )
          GLCDPrint 26, 40, hex( pixcol_H )
          GLCDPrint 42, 40, hex( pixcol )
    
    
        loop
    
        end
    
     

    Last edit: stan cartwright 2020-01-20
  • stan cartwright

    stan cartwright - 2020-01-21

    I think it's related to the Ili9341 display in use.
    I tried

        GLCDRotate ( Landscape_rev )     ' optionally you can rotate the screen.
        GLCDCLS ILI9341_BLACK
    do
          'Setup above here
          Pset (0,0, ILI9341_blue)
          pixcol = ReadPixel_ILI9341( 0,0 )
          GLCDPrint 10, 10, hex( pixcol_U )
          GLCDPrint 26, 10, hex( pixcol_H )
          GLCDPrint 42, 10, hex( pixcol )
    wait 10 s
           Pset (0,0, ILI9341_white)
          pixcol = ReadPixel_ILI9341( 0,0 )
          GLCDPrint 10, 10, hex( pixcol_U )
          GLCDPrint 26, 10, hex( pixcol_H )
          GLCDPrint 42, 10, hex( pixcol )
      wait 10 s
           Pset (0,0, ILI9341_red)
          pixcol = ReadPixel_ILI9341( 0,0 )
          GLCDPrint 10, 10, hex( pixcol_U )
          GLCDPrint 26, 10, hex( pixcol_H )
          GLCDPrint 42, 10, hex( pixcol )
      wait 10 s
    loop
    

    but got ff ff ff then 00 00 00 then just 00 00 00

    I use a nano for this but it includes #include <uno_mega328p.h>
    is that a problem? I like to use the port names like pic.</uno_mega328p.h>

     
  • Anobium

    Anobium - 2020-01-21

    Stan - can you confirm all is good on the UNO?

    And, where is the PIC code? attach please.

     
  • stan cartwright

    stan cartwright - 2020-01-21

    Gimme time to wire it to uno...set up for nano..diplay works ok.

     
  • stan cartwright

    stan cartwright - 2020-01-21

    Same results using uno. the display working ok otherwise. Hardware spi is working.
    Reading pixe does not seem to work for me.
    It is needed for games.
    The pic code is same as the uno in demos

        #chip 18f25k22, 64
        #config MCLRE=on
        #option Explicit
        #include <glcd.h>
    
        #define GLCD_TYPE GLCD_TYPE_ILI9341
    
        'Pin mappings for ILI9341
        #define GLCD_DC portc.2
        #define GLCD_CS portc.0
        #define GLCD_RESET portc.1
    
        'As we are using Harware SPI this cannot be change on this chip. This is a non-PPS chip.
        #define GLCD_DI portc.4
        #define GLCD_DO portc.5
        #define GLCD_SCK portc.3
        #define ILI9341_hardwarespi
    
    
        'GLCD selected extension font set. ASCII characters 31-254, the extended font uses 1358 bytes of program memory
        #define GLCD_EXTENDEDFONTSET1
        GLCDfntDefaultsize = 1
    
        dim pixcol as long
        dim setpixcol as word
    
        GLCDRotate ( Landscape_rev )     ' optionally you can rotate the screen.
        GLCDCLS ILI9341_BLACK
    
          'Setup above here
          Pset 100,0, ILI9341_RED
          Pset 100,10, ILI9341_WHITE
          Pset 100,20, ILI9341_RED
    
        do
    
          pixcol = ReadPixel_ILI9341( 0,0 )
          GLCDPrint 10, 10, hex( pixcol_U )
          GLCDPrint 26, 10, hex( pixcol_H )
          GLCDPrint 42, 10, hex( pixcol )
    
    
          pixcol = ReadPixel_ILI9341( 0,10 )
          GLCDPrint 10, 20, hex( pixcol_U )
          GLCDPrint 26, 20, hex( pixcol_H )
          GLCDPrint 42, 20, hex( pixcol )
    
          pixcol = ReadPixel_ILI9341( 0,20 )
          GLCDPrint 10, 30, hex( pixcol_U )
          GLCDPrint 26, 30, hex( pixcol_H )
          GLCDPrint 42, 30, hex( pixcol )
    
          Pset 3, 3, setpixcol: setpixcol = setpixcol + 16
          pixcol = ReadPixel_ILI9341( 3,3 )
          GLCDPrint 10, 40, hex( pixcol_U )
          GLCDPrint 26, 40, hex( pixcol_H )
          GLCDPrint 42, 40, hex( pixcol )
    
    
       loop
    
        end
    
     
  • Anobium

    Anobium - 2020-01-21

    Have you tried this demo? C:\GCB@Syn\GreatCowBasic\Demos\glcd_solutions\glcd_read_glcd_pixel_solutions\glcd_read_demonstation_mega328p_for_ili9341@16.gcb

    As it a demo. It must have worked. Has it stopped working?

     
    • stan cartwright

      stan cartwright - 2020-01-21

      It is the one I used. nano first,then pic, then uno.
      I'm not suggesting it's stopped working. It's obviously me, I'm getting too old for this.

       
  • Anobium

    Anobium - 2020-01-21

    I can look in a few days. Busy at mo

     
  • stan cartwright

    stan cartwright - 2020-01-22

    It's a hard include to understand...ili9341.h

    'returns a 24bit pixel color value... as GCB uses a 16bit color value the user will need to complete conversion
    Function  ReadPixel_ILI9341(In ILI9341_GLCDX as word, In ILI9341_GLCDY as word ) as long
    
        DIM ILI9341TempOut as byte
    
        set ILI9341_CS OFF
        set ILI9341_DC OFF
        SPITransfer  ILI9341_CASET,  ILI9341TempOut
        set ILI9341_DC ON;
        SPITransfer  ILI9341_GLCDX_h,  ILI9341TempOut
        SPITransfer  ILI9341_GLCDX,  ILI9341TempOut
        SPITransfer  ILI9341_GLCDX_h,  ILI9341TempOut
        SPITransfer  ILI9341_GLCDX,  ILI9341TempOut
    
        set ILI9341_DC OFF
        SPITransfer  ILI9341_PASET,  ILI9341TempOut
    
        set ILI9341_DC ON
        SPITransfer  ILI9341_GLCDY_h,  ILI9341TempOut
        SPITransfer  ILI9341_GLCDY,  ILI9341TempOut
        SPITransfer  ILI9341_GLCDY_h,  ILI9341TempOut
        SPITransfer  ILI9341_GLCDY,  ILI9341TempOut
    
        set ILI9341_DC OFF
        SPITransfer  ILI9341_RAMRD, ILI9341TempOut
    
        set ILI9341_DC ON
        SPITransfer  1,  ReadPixel_ILI9341_e  'dummy read - use the highest byte
        SPITransfer  2,  ReadPixel_ILI9341_u
        SPITransfer  3,  ReadPixel_ILI9341_h
        SPITransfer  4,  [byte]ReadPixel_ILI9341
        set ILI9341_CS ON
    
    End Function
    
     
  • Anobium

    Anobium - 2020-01-22

    That is pretty simple code.

    Ignoring the CD and DC lines as they are pretty obvious.

    Get the datasheet out. This is what is happening.
    CASET sets the X positional window. This creates a one pixel window
    PASET sets the Y positional window. This creates a one pixel window
    So, at this point we have created a windows in the GLCD ram of 1 pixel window.
    RAMRD reads the ram position created by the window.
    Then, read the bytes into the long. And, we need to read one dummy and then three bytes.

    Most of the GLCD have this method as this is correct method.

     
  • stan cartwright

    stan cartwright - 2020-01-22

    Nice one Anobium. It's a nice .h lib. I managed to write word data ie 8 pixels a while back for sprites.
    Seeing if given pixel is not background colour is needed for games.
    I was thinking of Lunar Lander. It could be as simple as "A" with "v" under as flame...or a sprite.
    Drawing would be to slow I think. Simulating gravity is fun and the movement is only one pixel at a time so easyish.
    Any game suggestions? Is scrolling land scape possible? ie erase chars, scroll,reprint chars, so it looks like they're moving...when they not really.

     
  • Anobium

    Anobium - 2020-01-23

    Have a look at what others have created on othr platforms. This will give you ideas.

    But, if you have time. Port FortNite.

     
    • stan cartwright

      stan cartwright - 2020-01-23

      It'll take two weeks :)

       
  • stan cartwright

    stan cartwright - 2020-01-23

    I don't know why this always returns 0 for pset any colour-

        dim pixcol as long
        GLCDRotate ( Landscape_rev )     ' optionally you can rotate the screen.
        GLCDCLS ILI9341_BLACK
     Pset 100,100, ILI9341_silver
     pixcol = ReadPixel_ILI9341( 100,100 )
          GLCDPrint 10, 10, hex( pixcol_U )
          GLCDPrint 26, 10, hex( pixcol_H )
          GLCDPrint 42, 10, hex( pixcol )
          glcdprint 0,50, str32 (pixcol)
    do
    loop
    
     
  • stan cartwright

    stan cartwright - 2020-01-25

    It DOES work!
    Stupid me got miso line wrong connection.
    Please delete all my help requests and please accept my sincere apologies for wasting peoples time.

     
  • stan cartwright

    stan cartwright - 2020-01-25

    A black background is 00 00 00....anything else is not...so can check if sprite has hit anything.

     

Log in to post a comment.