LCD touchscreen, A development thread
average joe
Posts: 795
The purpose of this thread is to gather information about using LCD touchscreens with the propeller chip. There is some great information out there but it seems a lot of people, myself included, have a lot of questions.
The first task is getting the hardware implementation figured out. There are many ways of interfacing these displays. I have a basic layout that I hope will give a starting point for development. The LCD module is wired directly to the propeller, combining the SD card and Touch data and clock pins. Sd card and touch chip selects are controlled directly by the prop, as is LCD reset and RS and WR. LCD CS is not used and connected to ground. LCD RD is not used and connected to +3.3v. Pins 26-27 are used as an ac-coupled sigma-delta analog to digital converter.
An earlier version of my schematic was missing the resistor for LCD backlight, this has been fixed.
As far as code goes, I'm still trying to figure out init procedure. Here's what I have so far.
A note on the hardware. This HW revision is early. I plan on implementing a 2-4 line decoder for the LCD_RESET, SD_CD and touch_cs lines. The final line will be used for address decoding described next. The serial lines will be cascaded to other modules *3 at this time* Serial Data out will flow through a serial-in, parallel-out shift register which will use 3 lines for address. These 3 lines will be fed into a 138, with an enable strobe from previous stage. The final 8 lines will control CS for serial devices. Serial Data Out will be taken from Q3 of shift register. Or something like that.
The first task is getting the hardware implementation figured out. There are many ways of interfacing these displays. I have a basic layout that I hope will give a starting point for development. The LCD module is wired directly to the propeller, combining the SD card and Touch data and clock pins. Sd card and touch chip selects are controlled directly by the prop, as is LCD reset and RS and WR. LCD CS is not used and connected to ground. LCD RD is not used and connected to +3.3v. Pins 26-27 are used as an ac-coupled sigma-delta analog to digital converter.
An earlier version of my schematic was missing the resistor for LCD backlight, this has been fixed.
As far as code goes, I'm still trying to figure out init procedure. Here's what I have so far.
CON RS = 16 WR = 17 LCD_RST = 23 OBJ wait : "timing" ' thanks to parallax PUB Start_SSD1289 EnableDisplayPins ' enable pins 0 to 15 ResetHigh wait.pause1ms(5) ResetLow wait.pause1ms(5) ResetHigh WriteHigh wait.pause1ms(5) Lcd_Write_Com ($00,$07) ''Display Control (R07h) (POR = 0000h) Lcd_Write_Data($00,$21) ''GON = 1 DTE = 0 D[1:0] = 01 Lcd_Write_Com ($00,$00) ''Oscillator (R00h) (POR = 0000h) Lcd_Write_Data($00,$01) '' Lcd_Write_Com ($00,$07) ''Display Control (R07h) (POR = 0000h) Lcd_Write_Data($00,$23) ''GON = 1 DTE = 0 D[1:0] = 11 Lcd_Write_Com ($00,$10) ''Sleep mode (R10h) (POR = 0001h) Lcd_Write_Data($00,$00) '' Lcd_Write_Com ($00,$07) ''Display Control (R07h) (POR = 0000h) Lcd_Write_Data($00,$33) ''GON = 1 DTE = 1 D[1:0] = 11 Lcd_Write_Com ($00,$11) ''Entry Mode (R11h) (POR = 6830h) Lcd_Write_Data($68,$30) '' Lcd_Write_Com ($00,$02) ''LCD-Driving-Waveform Control (R02h) (POR = 0000h) Lcd_Write_Data($10,$00) '' Lcd_Write_Com ($00,$0F) ''Gate Scan Position (R0Fh) (POR = 0000h) Lcd_Write_Data($00,$00) '' Lcd_Write_Com ($00,$01) ''Driver Output Control (R01h) (POR = [0XXXX0X1]3Fh) Lcd_Write_Data($2B,$3F) '' Lcd_Write_Com ($00,$0B) ''Frame Cycle Control (R0Bh) (POR = 5308h) Lcd_Write_Data($53,$08) ' Lcd_Write_Com ($00,$07) ''Display Control (R07h) (POR = 0000h) Lcd_Write_Data($00,$3B) ''GON = 1 DTE = 1 D[1:0] = 11 CM = 1 65K COLOR '********************** private methods ********************* PRI LCD_Writ_Bus(VH,VL) OUTA[7..0] := VL OUTA[15..8] := VH WriteLow ' write pin low WriteHigh ' toggle write pin PRI Lcd_Write_Com(VH,VL) RSLow LCD_Writ_Bus(VH,VL) PRI Lcd_Write_Data(VH,VL) RSHigh LCD_Writ_Bus(VH,VL) PRI EnableDisplayPins DIRA:=%00000000_10000011_11111111_11111111 ' , Reset, WR, RS and 16 data lines active PRI TristateDisplayPins ' tristate all pins - DIRA:=%00000000_10000011_00000000_00000000 PRI RSLow ' RS pin outa[RS] := 0 PRI RSHigh outa[RS] := 1 ' PRI WriteLow outa[WR] := 0 ' PRI WriteHigh outa[WR] := 1 PRI ResetLow outa[LCD_RST] := 0 ' PRI ResetHigh outa[LCD_RST] := 1This is based off Dr. Acula's work on the ILI9325 driver. Not sure where to go from here.
A note on the hardware. This HW revision is early. I plan on implementing a 2-4 line decoder for the LCD_RESET, SD_CD and touch_cs lines. The final line will be used for address decoding described next. The serial lines will be cascaded to other modules *3 at this time* Serial Data out will flow through a serial-in, parallel-out shift register which will use 3 lines for address. These 3 lines will be fed into a 138, with an enable strobe from previous stage. The final 8 lines will control CS for serial devices. Serial Data Out will be taken from Q3 of shift register. Or something like that.
Comments
On the to-do list... Implement Registers for draw control. Test Sd_Card, Touch. I'm also thinking about extended memory... I want to use an SD card. I DO want FAT support, but I plan on bypassing FAT for Extended Memory. I'm also wondering about the font on the prop's ROM. I'll edit this post when the youtube video finishes uploading... NOW
http://youtu.be/smPEVZgX_uQ
Any thoughts?
and all the ILIcmd goes through this
Can you test writing a pixel is working?
call this draw routine and make x1 = 10, y1=10, x2=10,y2=10
Then draw the pixel
and if you make color something like %11111000_00000000 then it should print a red pixel.
If that works then move on to fonts.
Attached is the parallax font in 16 point in the format this program can read.
however, you will have to modify that because it won't fit in hub ram. So instead of reading it into external ram first, open the file each time for each character.
Maybe start with the SD driver and read in just one byte. You have to have some sort of debugging to get this working. The standard propeller way to debug is to include a serial port object, then when you compile and download, open up the serial port debugging object.
If you can open the font file, read just one byte, and send that byte (hex format if you like) back to the propeller serial terminal, then it will be possible to debug things along the way.
DR.A, I will have to look at your code later.
What I have so far is REALLY rough. I will post is sections for clarity. This sets the clock and defines the pins used. Then defines the LCD registers, so we can work with them a bit easier. Makes changing controllers easier hopefully. Finally, the start address for the rom font and the Background and Text colors. This is the basic boot-loader. Should be self-explanatory. The next section is where all the heavy lifting gets done.
So far things seem to be working. I can display characters by selecting a character code in PST. Just finishing up a clear screen. I'm trying to figure out how to rotate the screen from registers. I've played with it a bit, but the only way I could get it working was by using pointer offset indexes every write. This slows things down a ton right now. I will be posting video in a bit. I'm still trying to get the basics of the screen down. Once I feel comfortable with that, I need to figure out Sd card and touch. I still need to draw the schematic for the final hardware. The entire system will use SPI as I have one analog board with 2-spi devices, and another board with at least one spi device. I plan on setting up a locking system with FIFO for spi and possibly parallel. I still want to be able to use the pins 0-16 later down the road. I think it would give a bit of flexibility to the system. Everything is in spin so far, that WILL change. Back to work
youtube video up
http://youtu.be/WDaUkp8kw4Q
* One font
* No external ram needed
* No graphics, just text
* Font data sent out in pasm so faster than spin.
Prints white on blue on a 40x15 text-only mode. Very useful for debugging.
Font is loaded into hub so not much room left (1364 longs free).
Put the font par16.ifn on the sd card. (standard parallax font 8x16)
You will need to change the pins for the actual data output but I think you already have this working.
Have you got a single pixel on the screen yet? (I found getting a single pixel was the hardest bit)
Sorry if I've been obscure. I have pixels on screen. I can draw font by calling PropFont_WriteCr . I have broken this a few times trying to add borders. I think borders is an easy way to make graphics out of the prop's ROM font. Things are a bit slow to write due to being written in spin.
I looked at your demo, very nice. You and your progress have been a huge help to me. I hope you noticed the PRI methods are almost your methods. I think I could write in compatibility for other fonts later.
The goal for me now is getting propFontWrite perfected in spin. I need to implement an abstract data array in DAT blocks for menus. AN003 anyone? I have not even tested SPI, but see no reason it won't work. I need to do some digging on this still, since I will have some strong requirements from the spi bus.
Getting pixels out is the easy part, I found. Making sure they were the right pixels, going to the right place is what I'm struggling with. I NEED to be RGB565 compatible, but I seem to have registers set wrong. If I am correct, $FFFF should be white?
Ok, a few things. First, I see a few places in your code with lines like
Just watch that sort of thing because it gets me all the time. The screen is 240 bytes wide, so if you run a loop from 0 to 240 you get 241 iterations, not 240. So just check and recheck that if a number starts from zero, it ends with finish-1, not finish.
The display is forgiving - if you try to write stuff off the end of the range it still prints things but not in the right place.
The prop font is a fixed width font, like Courier New. So I cheated in that last code and made it 8x16. But the code can handle variable width fonts too and sooner or later you might want to add Times Roman and Arial. The BMFont program is really nifty as it exports all this information, including the height, width of a character as well as the xoffset to add for the next character. There is even a list of Kerning data for character pairs - I don't use this, but it could make fonts look even better.
I'm still learning about this display. It seems happiest sending out blocks of data. It seems very inefficient sending out pixels because the overhead of telling the display where the pixel is to be is more bytes than the actual pixel data. So if you can only send out blocks of data, I figured that things like sending out fonts one pixel at a time are not going to work so well.
So the display seems to lead you towards setting up a font as a data stream, and then send out that data stream. For the propeller font it is 8x16=128 bytes and you just dump those bytes out mindlessly.
One thing I do need to code is the draw routine that sends out the x1 y1 x1 y2 data for the block. That ought to be in pasm, not spin.
Yes correct, and $0000 is black. I started there. Very useful for debugging.
Check in the code for some answers to this. I have some code in pasm that turns a block of data from 3 byte RGB into 2 byte RRRRRGGG GGGBBBBB data. You can send just one pixel if you want
where that "1" at the end of the command says "do just one pixel"
Not the most efficient way but there are situations where this could be useful.
Re
Can you please explain that a bit more, what are you wanting to do?
The display is VERY slow doing random pixel writes. That's why I think setwindow could be really handy for drawing. I saw the set window error after I posted. I will fix this soon. The reason I asked about the hex code for white is because my display is currently inverted. Last time I tried playing with the registers for this, I broke all kinds of things. I think the constant blocks could use some work to make setting discrete values easier. This would also make porting the code to other display controllers easier too, I think. Portability is my main focus right now.
My reference to AN003 is because they have some good jumping off points for indexed arrays and other handy stuff.
What I want to do with what I'm working on now is, implement a simple GUI based on the ROMfont. I think propFontWrite is close, but could still use offsets for Row border and Column border. What I have now is this.
All it takes is a
PropFont_WriteCr(72, 0, 0*16, 0, 0, BGCOLOR, TXTCOLOR)
To kick out a letter. I need to look more into graphics and tv modules to try and find compatibility. I think I'm off to a good start, other than colors being inverse. I would like to have sd and touch working before I release the full source.
I would like to get other fonts working soon, but I will probably need some emm for that. Have I mentioned yet that I'm in WAY over my head, LOL!
Thanks again for your help. It would have taken me forever to get this far without it.
BTW, I have not tried your demo yet. I will fix color inversion and then I will check it out. I'm interested to see how it ports across.
I get
Testing for sd card, good, mounting fat, then nothing. It doesn't matter if I have a card in or not.
Tried getting info out of the touchscreen, nothing yet. Seems to just lock up. idk..
I got the touchscreen going. That was way too easy. Still nothing with the sd card. I'm not sure what I'm doing wrong. I "bypassed" the resistors. Not sure what to do now.
ok, dead prop? or am I a complete retard?
SHOULD make pins high, but does nothing?? tried launching in all cogs. Did my prop die and I not know it?
Still working on it outputs -1 no matter what I do.
I haven't managed to get the SD card working on the actual display - I'm using my own socket. It is either that the resistors are not correct or maybe some pins are not correct on the schematic.
It would simplify things to use the SD socket on these displays. When I get home I might get out the multimeter and actually check what pins go where.
Addit: Looking at the photo at the bottom of this ebay post http://www.ebay.com.au/itm/2-4-TFT-LCD-Module-Display-Touch-Panel-PCB-adapter-/190477028273?pt=LH_DefaultDomain_0&hash=item2c5950cbb1 it appears the resistors are in series with the lines. The standard connection to the propeller chip has no series resistors and it has 10k pullups on CS DO DI and CLK. So I wonder if adding pullups and bypassing the resistors is the secret?
Well I have already tried bypassing the resistors. That didn't help. I then inspected the board closer and found vias on the driven lines (cs,di,ck) I couldn't find anything about them on the schematic. SO, I tried cutting the traces to remove the vias. I then bypassed these with some wires from a ribbon cable. Still nothing. So I'm scratching my head. If I can't use the sd card, I won't be able to develop with sd for a while. Ask the IRS how long, because I don't know. LOL I checked with the multimeter and could not find any faults. This really sucks because without an sd card, I'm going to get stuck real quick.
I also tried adding pullup resistors to di, do, cs, ck and nothing.
The other thing that might be worth doing is putting some bypass caps across the supply pins right at the SD card. Maybe a 10 to 33uF tantalum and a 0.1uf ceramic.
I need to do some more experiments.
I would imagine Do doesn't need a pullup, but...
The resistors don't seem to make a difference. I MUST be doing something wrong. I will check my trace removal and re-wire in a bit. Bypassing might be the issue? Not sure what else it could be.
edit,
Just ordered http://microcontrollershop.com/product_info.php?products_id=3460
hope this solves my problems.
I think those resistors are there for voltage level translation. The board is designed to talk to a 5V micro and the SD card is 3.3V so for 5V => 2k => 3.3V that does the translation.
But with 3V => 3V those resistors are not needed. However, it shouldn't stop the circuit working.
New control commands are formatted as such
I just made a schematic for my external spi bus idea. The only problem is it uses 1 line more than I JUST built the hardware for. I guess I need to use another pin...
I have some ideas how to make this play nice with the fat driver when i get it working, I just need to look into the fat driver itself a bit more. I'm thinking I can use the locking system to control the SPI bus access system. Still trying to figure out how to make the hardware cascading work the way I want it.
1) the 2k series resistors
2) lack of decoupling right at the sd socket
3) The lcd display is running on a local 3V regulator with minimal capacitance on it
4) ?? physical connections inside the SD socket
Of course, the SD card goes upside down with respect to the display.
So a few things to test out and experiment with.
or use a 138 instead of a 139?
Right now I've been trying to get my analog board working. I finished the serial interface and everything seems to test ok. But it doesn't seem to work. More debugging to do. I have way more cascading outputs than I need but I'm sure those will come in handy. For lack of a better mounting solution, the display is taped to the propRPM. It's not pretty but it works.
Re the 139 (and also the 138) - you might need a pullup on the enable pin. When the propeller boots up all the pins are HiZ and so the state of the 139 outputs will be unknown (and probably oscillating all over the place from stray RF). If you put a 10k pullup on the enable pin of the 139 then the outputs of the 139 will be guaranteed to be all high.
I am trying to get the spi bus interface working *this thread, post 24, first schematic* First mistake I found, the 174 has a floating clear. I will tie to 5v and try again.
If so, I am also hoping to get the SD card to work for my product. If I can't get the SD card working, it may be useless to me
Yes that is the same one. We will get it working. There are only so many places this hardware bug can hide. I'm going to start by unsoldering every pin on the sd socket and wiring them in parallel to the socket I know works. Then if that doesn't work, it is the socket. If it does, add back in parts of the original circuit till it fails.
Joe, I have looked at your first demo(ssm1289) and have hooked up the DB0-15 and All other lines properly(I have double and triple checked), but stil when I compile and Run I get nothing no life. I know this isn't much to go off, but if there is any advice or help you can provide that would be most useful.
Thanks,
Tyler