Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : MM2: Colour touchscreen
Author | Message | ||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8603 |
OK so I'm not an artist This was a bit of a struggle getting to work as I came across a firmware bug in 4.6b26 relating to analogue input modifying the status of other pins. This has been reported to Geoff. The 2.4" TFT Arduino shield puts the touch input connections onto some of the same pins as are needed for the display. As part of debugging the problem above I disconnected these from the shared pins and connected them directly to the Micromite - you can see the soldered-on connections in the picture. To understand how to drive directly a resistive touchscreen see the excellent note from NXP I've also converted an additional routine (fcirch) into a cFunction to speed up filled-circle drawing which I use for drawing the trace. The code currently polls for a touch but it is easy to set up an interrupt which is triggered by a touch - the statement to do this is identified with a comment in the code. The Basic code that does the work is pretty simple: sub T24_test dim integer XP=2 dim integer XM=9 dim integer YP=3 dim integer YM=10 local integer xint,yint,colour=red T24.setrot(0) preparescreen 'clear the screen and write the colour bar do setpin XP,ain setpin XM,DOUT pin(XM)=0 SETPIN YM,DIN,pullup 'This could also set up an interrupt setpin YP,AIN do while pin(YM)=1 'when the screen is touched this pin will go to zero loop readtouch(xint,yint) poke word &HBF886114,3 'Overcome firmware bug poke word &HBF886104,3 if xint>=0 and yint>30 and xint<=239 and yint<=319 then T24.fcirc(xint,yint,3,colour) else if yint>319 and xint<30 then 'touch on the "home" icon at the bottom of the screen preparescreen 'clear the screen and rewrite the colour bar else if yint<=30 then if xint<30 then colour=red if xint >=30 and xint<60 then colour=blue if xint >=60 and xint<90 then colour=green if xint >=90 and xint<120 then colour=magenta if xint >=120 and xint<150 then colour=cyan if xint >=150 and xint<180 then colour=yellow if xint >=180 and xint<210 then colour=white if xint >=210 then colour=black endif endif endif loop end sub ' sub preparescreen T24_fillscreen(black) T24.FRECT(0,0,30,30,red) T24.FRECT(30,0,30,30,blue) T24.FRECT(60,0,30,30,green) T24.FRECT(90,0,30,30,magenta) T24.FRECT(120,0,30,30,cyan) T24.FRECT(150,0,30,30,yellow) T24.FRECT(180,0,30,30,white) T24.FRECT(210,0,30,30,black) t24.frect(0,30,240,1,white) T24.drect(0, 0, T24_params(T24_width), T24_params(T24_height), white) end sub ' sub readtouch(xpos as integer,ypos as integer) const xstart=0.346774 const xend=2.82473 const ystart=.21828 const yend=2.82258 local integer xvalues(3),yvalues(3) local integer i=2 do while i>=0 'read the input three times to help filter noise setpin XP,DOUT pin(XP)=1 SETPIN XM,DOUT PIN(XM)=0 SETPIN YM,off SETPIN YP,AIN xvalues(i)=(pin(YP)-xstart)/(xend-xstart)*240 setpin YP,dout pin(YP)=1 setpin YM,DOUT pin(YM)=0 setpin XM,off SETPIN XP,AIN yvalues(i)=(pin(XP)-ystart)/(yend-ystart)*320 i=i-1 loop xpos=filter(xvalues()) ypos=filter(yvalues()) end sub ' function filter(values() as integer) as integer 'algorithm to try and get rid of duff readings - tune/change as required local integer AB,BC,AC AB=abs(values(0)-values(1)) BC=ABS(values(1)-values(2)) AC=ABS(values(0)-values(2)) if AB<=BC and AB<=AC then filter=(values(0)+values(1))\2 if BC<=AB and BC<=AC then filter=(values(1)+values(2))\2 IF AC<=AB and AC<=BC then filter=(values(0)+values(2))\2 end function Complete code and updated cFunctions attached: 2014-12-17_123542_TFT24.zip |
||||
MicroBlocks Guru Joined: 12/05/2012 Location: ThailandPosts: 2209 |
Very nice! Just a small thing to get you some more speed and efficiency in BASIC because now all the IF's will be run always even when xint is for example 20 and is valid in the first IF. It is also a little easier to maintain as it does not need the test values twice. [code] if yint<=30 then if xint<30 then colour=red elseif xint<60 then colour=blue elseif xint<90 then colour=green elseif xint<120 then colour=magenta elseif xint<150 then colour=cyan elseif xint<180 then colour=yellow elseif xint<210 then colour=white else colour=black endif endif [/code] Even better would be to divide xint by 30 and use the result as an index in a lookup table or if the colors are 0-7 then you have the value right away. Microblocks. Build with logic. |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8603 |
You are right of course, this is much better sub T24_test dim integer colours(7)=(red,blue,green,magenta,cyan,yellow,white,black) dim integer XP=2 dim integer XM=9 dim integer YP=3 dim integer YM=10 local integer xint,yint,colour=red T24.setrot(0) preparescreen do setpin XP,off setpin XM,DOUT pin(XM)=0 SETPIN YM,DIN,pullup setpin YP,off do while pin(YM)=1 loop readtouch(xint,yint) poke word &HBF886114,3 'Overcome firmware bug poke word &HBF886104,3 if xint>=0 and yint>30 and xint<=239 and yint<=319 then T24.fcirc(xint,yint,3,colour) else if yint>319 and xint<30 then preparescreen else if xint<239 then colour=colours(xint\30) endif endif loop end sub |
||||
bigmik Guru Joined: 20/06/2011 Location: AustraliaPosts: 2870 |
Wow Matherp, I have ordered one of those displays,, That is fantastic, I cant wait to play with it when it arrives. Keep up the fantastic work.. Mick Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<< |
||||
plasma Guru Joined: 08/04/2012 Location: GermanyPosts: 437 |
Sorry for chime in here but can anyone send me 2-3 displays to germany because the seller Wont sell to germany! Thx |
||||
retepsnikrep Senior Member Joined: 31/12/2007 Location: United KingdomPosts: 131 |
Brilliant work. Sorry I'm also a bit confused and my display arrived today. Can someone post a schematic (idiots guide) showing the pinouts and connections between this unit and the MM2. Thanks Gen1 Honda Insights. |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8603 |
The bottom of the display should be silkscreened as above connect: LCD__CS to Micromite Pin 4 LCD__CD to Micromite Pin 5 LCD__WR to Micromite Pin 6 LCD__RD to Micromite Pin 7 LCD__RST to Micromite Pin 14 LCD__D0 to Micromite Pin 17 LCD__D1 to Micromite Pin 18 LCD__D2 to Micromite Pin 21 LCD__D3 to Micromite Pin 22 LCD__D4 to Micromite Pin 23 LCD__D5 to Micromite Pin 24 LCD__D6 to Micromite Pin 25 LCD__D7 to Micromite Pin 26 You also need to connect 5V, 3V3 and GND The touchscreen code I listed won't work as I have butchered my display to break out the touchscreen pins from the shared pins on the normal board. Use this code to get you going: 2014-12-18_155351_T24BAS_2.zip |
||||
plasma Guru Joined: 08/04/2012 Location: GermanyPosts: 437 |
Will it work with the spfd5408 controller ? |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8603 |
In theory yes but I haven't tested it. Also the ILI9320 should work. If not the changes will be in a small number of the set up parameters but the main drawing code and cFunctions should work |
||||
bigmik Guru Joined: 20/06/2011 Location: AustraliaPosts: 2870 |
Gday Matherp, My display arrived today, it looks identical to your picture above except it has a very small resistor network near the top, center. Your wiring list states: LCD__CD to Micromite Pin 5 But there is no LCD_CD pin labelled. The only LCD_PIN not used in the list above is LCD_RS is this the pin that connects to pin(5)? If so my display doesnt work with your sample code.. It changes the display to be every second row off (from every row on at power up). The code reports Controller type 0000 My controller chip (as stated by the seller) is supposed to be spfd5408 controller with built in video RAM buffer Any ideas? Do I have to cut the touch screen wires away to run the code? Regards, Mick Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<< |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8603 |
Mick LCD_RS is the pin to connect to the micromite's LCD_CD input (basically selects between register select and data mode). Sorry the naming in the program didn't get edited from a different display. Lets try and get the display running first and then tackle the touchscreen. I've found some different Arduino initialisation code for the SPD5408 rather than the ST7731 and edited it to fit in with my code. In routine sub T24.initdisplay try replacing lines between the second pause 100 (after the reset) and the final pause 50 with the following: T24.wreg(&H00e5,&H8000) T24.wreg(&H0000,&H0001) T24.wreg(&H0001,&H0100) T24.wreg(&H0002,&H0700) T24.wreg(&H0003,&H1030) T24.wreg(&H0004,&H0000) T24.wreg(&H0008,&H0202) T24.wreg(&H0009,&H0000) T24.wreg(&H000a,&H0000) T24.wreg(&H000c,&H0000) T24.wreg(&H000d,&H0000) T24.wreg(&H000f,&H0000) '*********************************************Power On T24.wreg(&H0010,&H0000) T24.wreg(&H0011,&H0000) T24.wreg(&H0012,&H0000) T24.wreg(&H0013,&H0000) T24.wreg(&H0010,&H17b0) T24.wreg(&H0011,&H0037) T24.wreg(&H0012,&H0138) T24.wreg(&H0013,&H1700) T24.wreg(&H0029,&H000d) T24.wreg(&H0020,&H0000) T24.wreg(&H0021,&H0000) '*********************************************Set gamma T24.wreg(&H0030,&H0001) T24.wreg(&H0031,&H0606) T24.wreg(&H0032,&H0304) T24.wreg(&H0033,&H0202) T24.wreg(&H0034,&H0202) T24.wreg(&H0035,&H0103) T24.wreg(&H0036,&H011d) T24.wreg(&H0037,&H0404) T24.wreg(&H0038,&H0404) T24.wreg(&H0039,&H0404) T24.wreg(&H003c,&H0700) T24.wreg(&H003d,&H0a1f) **********************************************Set Gram aera T24.wreg(&H0050,&H0000) T24.wreg(&H0051,&H00ef) T24.wreg(&H0052,&H0000) T24.wreg(&H0053,&H013f) T24.wreg(&H0060,&H2700) T24.wreg(&H0061,&H0001) T24.wreg(&H006a,&H0000) '*********************************************Partial display T24.wreg(&H0090,&H0010) T24.wreg(&H0092,&H0000) T24.wreg(&H0093,&H0003) T24.wreg(&H0095,&H0101) T24.wreg(&H0097,&H0000) T24.wreg(&H0098,&H0000) '******************************************** Plan Control T24.wreg(&H0007,&H0021) T24.wreg(&H0007,&H0031) T24.wreg(&H0007,&H0173) |
||||
plasma Guru Joined: 08/04/2012 Location: GermanyPosts: 437 |
i ordered the same modul , hope we are able to run this |
||||
bigmik Guru Joined: 20/06/2011 Location: AustraliaPosts: 2870 |
Hi Matherp, I tried that change (had to add a ' to the Set Gram area. The result is very similar it inits to every second line off but goes through a few screen flash/refreshes but never see any sensible output.. It is late, I will try again tomorrow, maybe I didnt read the change correctly. I still get controller type 0000 ... what should I get there? Should I cut the touch screen wires as they may have an adverse affect on the data pins. Regards, Mick Mick's uMite Stuff can be found >>> HERE (Kindly hosted by Dontronics) <<< |
||||
matherp Guru Joined: 11/12/2012 Location: United KingdomPosts: 8603 |
Mick Probably better to continue trying to resolve this via PM rather than cluttering the Board then we can post the solution once solved. I'll PM you in reply to the above. Best Regards Peter |
||||
Print this page |