2.8" TFT touchscreen + Teensy 3.0
Moderators: adafruit_support_bill, adafruit

2.8" TFT touchscreen + Teensy 3.0

by ZTiK.nl on Fri Jan 18, 2013 8:38 am

Hello everybody,

I have a few questions concerning the TFTLCD Library, because I am unable to compile the example on my Teensy.

I am using the [url="http://www.adafruit.com/products/335"]2.8" 18-bit color TFT LCD with touchscreen breakout board - ILI9325[/url] on a Teensy 3.0.
I am powering the screen through a second powersupply ([url="http://www.pieterfloris.nl/shop/product.php?id_product=492"]Breadboard Power Supply USB - 5V/3.3V[/url] using the 3.3v since the screen allows it)
Below is a picture of my setup without connections between Teensy & screen (first step of tutorial was to test the backlight this way):
Touchscreen backlight working.jpg
touchscreen on power only
Touchscreen backlight working.jpg (392.45 KiB) Viewed 1672 times


I have downloaded, extracted and renamed both libraries from Adafruit and placed these into \arduino-1.0.3\libraries\ :
[url="https://github.com/adafruit/TFTLCD-Library"]TFT LCD library[/url]
[url="https://github.com/adafruit/Adafruit-GFX-Library"]GFX library[/url]

According to the tutorial on Adafruit I am supposed to alter line 12 in TFTLCD.h :
"In the TFTLCD Library folder, you will need to edit TFTLCD.h. On about line 12, you will see "#define USE_ADAFRUIT_SHIELD_PINOUT". Comment out this line and save the file."

I have done this, saved the file, reopened arduino.exe, loaded the graphicstest example that comes with the TFT LCD library and tried to verify/compile it, but here I get errors:
Code: Select all | TOGGLE FULL SIZE
In file included from D:\arduino-1.0.3-beta\libraries\Adafruit_TFTLCD\Adafruit_TFTLCD.cpp:11:0:
D:\arduino-1.0.3-beta\libraries\Adafruit_TFTLCD\pin_magic.h:224:3: error: #error "Board type unsupported / not recognized"
D:\arduino-1.0.3-beta\libraries\Adafruit_TFTLCD\Adafruit_TFTLCD.cpp: In member function 'void Adafruit_TFTLCD::write8(uint8_t)':
D:\arduino-1.0.3-beta\libraries\Adafruit_TFTLCD\Adafruit_TFTLCD.cpp:763:21: error: 'write8inline' was not declared in this scope
D:\arduino-1.0.3-beta\libraries\Adafruit_TFTLCD\Adafruit_TFTLCD.cpp: In member function 'uint8_t Adafruit_TFTLCD::read8()':
D:\arduino-1.0.3-beta\libraries\Adafruit_TFTLCD\Adafruit_TFTLCD.cpp:770:27: error: 'read8inline' was not declared in this scope
D:\arduino-1.0.3-beta\libraries\Adafruit_TFTLCD\Adafruit_TFTLCD.cpp: In member function 'void Adafruit_TFTLCD::setWriteDir()':
D:\arduino-1.0.3-beta\libraries\Adafruit_TFTLCD\Adafruit_TFTLCD.cpp:777:21: error: 'setWriteDirInline' was not declared in this scope
D:\arduino-1.0.3-beta\libraries\Adafruit_TFTLCD\Adafruit_TFTLCD.cpp: In member function 'void Adafruit_TFTLCD::setReadDir()':
D:\arduino-1.0.3-beta\libraries\Adafruit_TFTLCD\Adafruit_TFTLCD.cpp:783:20: error: 'setReadDirInline' was not declared in this scope


For as far as I can tell, these display libraries only seem to recognize Arduino chips, but not Teensy's ARM



Concerning the connections I made (the wiring), I tried to follow [url="http://learn.adafruit.com/2-8-tft-touchscreen/tft-wiring"]the tutorial[/url] as much as possible, but it is a bit confusing to me:

"Start at the end of the TFT (other side than the power pins) and in order connect the pins to digital 7 thru 2. If you're using a mega, connect the TFT Data Pins #0-7 to Mega pins #22-29, in that order. Those Mega pins are on the 'double' header.
Then connect the next two pins to digital 9 and 8."


The pins on the screen are labeled D7 to D2, and I tried to connect them to digital 7 to 2 on the Teensy, along with D1 to dig.9 & D0 to dig.8

The Analog connections were quite simple, I followed the tutorial to the letter on my Teensy 3, but I am unsure if this works:
"Connect the third pin CS (Chip Select) to Analog 3
Connect the fourth pin C/D (Command/Data) to Analog 2
Connect the fifth pin WR (Write) to Analog 1
Connect the sixth pin RD (Read) to Analog 0
Connect the seventh pin RST (Reset) to the Arduino Reset line. This will reset the panel when the Arduino is Reset. You can also use a digital pin for the LCD reset but this will save us a pin."


I have tried to make a picture of all cables connected, but its too much wire on too little surface to take a detailed picture :
everything.jpg
Everything connected
everything.jpg (472.42 KiB) Viewed 1672 times



-Can I update the library with some small changes, or do I have to add a new section to/rewrite the library ?
-How do I know which digital port should go into which I/O pin on the Teensy ?
-Any other pointers, advice, (well placed) criticism is always welcome :)

Regards,

Michel

edit, posted error output of test-code, not actual library
ZTiK.nl
 
Posts: 21
Joined: Thu Jan 17, 2013 2:43 pm

Re: 2.8" TFT touchscreen + Teensy 3.0

by adafruit_support_bill on Fri Jan 18, 2013 8:53 am

The code in the library is optimized. It makes use of port-level I/O for speed. Since the port/pin mappings vary between the different processors and boards, the code is very board specific.

It should be possible to modify "pin_magic.h" to add definitions for the Teensy. You will need to understand the Port/Pin mappings on the Teensy. A good understanding of C++ macros is essential as well.
User avatar
adafruit_support_bill
 
Posts: 29199
Joined: Sat Feb 07, 2009 9:11 am

Re: 2.8" TFT touchscreen + Teensy 3.0

by ZTiK.nl on Fri Jan 18, 2013 8:54 am

here is another image, but here the analog pins are connected too:
everything including analog.jpg
everything including analog.jpg (446.56 KiB) Viewed 1666 times
ZTiK.nl
 
Posts: 21
Joined: Thu Jan 17, 2013 2:43 pm

Re: 2.8" TFT touchscreen + Teensy 3.0

by ZTiK.nl on Fri Jan 18, 2013 9:09 am

Thank you for the quick reply, wasnt expecting something yet :)

So far I can still follow, but what I'd like to know is if that is 'all' that is required,

Should I go towards replacing :
Code: Select all | TOGGLE FULL SIZE
 #error "Board type unsupported / not recognized"


with something like (but modded for Teensy) :
Code: Select all | TOGGLE FULL SIZE
 #ifdef USE_ADAFRUIT_SHIELD_PINOUT

  #define RD_PORT PORTF
  #define WR_PORT PORTF
  #define CD_PORT PORTF
  #define CS_PORT PORTF
  #define RD_MASK B10000000
  #define WR_MASK B01000000
  #define CD_MASK B00100000
  #define CS_MASK B00010000

  #define write8inline(d) { \
   PORTE = (PORTE & B10111111) | (((d) & B10000000)>>1); \
   PORTD = (PORTD & B01101111) | (((d) & B01000000)<<1) | ((d) & B00010000); \
   PORTC = (PORTC & B01111111) | (((d) & B00100000)<<2); \
   PORTB = (PORTB & B00001111) | (((d) & B00001111)<<4); \
   WR_STROBE; }
  #define read8inline() (RD_STROBE, \
   (((PINE & B01000000) << 1) | ((PIND & B10000000) >> 1) | \
    ((PINC & B10000000) >> 2) | ((PINB & B11110000) >> 4) | \
     (PIND & B00010000)))
  #define setWriteDirInline() { \
   DDRE |=  B01000000; DDRD |=  B10010000; \
   DDRC |=  B10000000; DDRB |=  B11110000; }
  #define setReadDirInline() { \
   DDRE &= ~B01000000; DDRD &= ~B10010000; \
   DDRC &= ~B10000000; DDRB &= ~B11110000; }

 #else // Leonardo w/Breakout board

  #define write8inline(d) { \
   uint8_t dr1 = (d) >> 1, dl1 = (d) << 1; \
   PORTE = (PORTE & B10111111) | (dr1 & B01000000); \
   PORTD = (PORTD & B01101100) | (dl1 & B10000000) | (((d) & B00001000)>>3) | \
                                 (dr1 & B00000010) |  ((d) & B00010000); \
   PORTC = (PORTC & B10111111) | (dl1 & B01000000); \
   PORTB = (PORTB & B11001111) |(((d) & B00000011)<<4); \
   WR_STROBE; }

  #define read8inline() (RD_STROBE, \
   (((PINE & B01000000) | (PIND & B00000010)) << 1) | \
   (((PINC & B01000000) | (PIND & B10000000)) >> 1) | \
    ((PIND & B00000001)<<3) | ((PINB & B00110000)>>4) | (PIND & B00010000))
  #define setWriteDirInline() { \
   DDRE |=  B01000000; DDRD |=  B10010011; \
   DDRC |=  B01000000; DDRB |=  B00110000; }
  #define setReadDirInline() { \
   DDRE &= ~B01000000; DDRD &= ~B10010011; \
   DDRC &= ~B01000000; DDRB &= ~B00110000; }

 #endif

  #define write8 write8inline


Or do I have to define the processor itself too somewhere ?
(or perhaps I am completely missing the picture here)
ZTiK.nl
 
Posts: 21
Joined: Thu Jan 17, 2013 2:43 pm

Re: 2.8" TFT touchscreen + Teensy 3.0

by adafruit_support_bill on Fri Jan 18, 2013 9:26 am

what I'd like to know is if that is 'all' that is required,

From looking at the code, I think that is correct. All of the processor-specific stuff seems to be in pin_magic.h.
User avatar
adafruit_support_bill
 
Posts: 29199
Joined: Sat Feb 07, 2009 9:11 am

Re: 2.8" TFT touchscreen + Teensy 3.0

by ZTiK.nl on Fri Jan 18, 2013 9:33 am

haha, I won't hold it against you if it turns out otherwise, but it gives me a general direction to work towards to.

I know I am new to all this and have a lot to learn, so thanks again for both the quick reply and trying to think along with me!
ZTiK.nl
 
Posts: 21
Joined: Thu Jan 17, 2013 2:43 pm

Re: 2.8" TFT touchscreen + Teensy 3.0

by ZTiK.nl on Thu Jan 31, 2013 11:26 pm

Some progress, the lcd chip is being identified correctly on my Teensy 3.

The following was added to pin_magic.h:
Code: Select all | TOGGLE FULL SIZE
#elif defined(__MK20DX128__)
// LCD Data Bit :   7   6   5   4   3   2   1   0
// T3 dig. pin  :  5   21  20   6   8   7  14   2
// T3 GPIO/pin  :  D7  D6  D5  D4  D3  D2  D1  D0
// Teensy 3.0 Test code:

  #define write8inline(d) { \
   PORTD = (GPIOD_PDOR & B00000000) | ((d) & B11111111); \
   WR_STROBE; }
  #define read8inline() (RD_STROBE, (GPIOD_PDIR&  B11111111))
 
//  #define setWriteDirInline() {GPIOD_PDDR|= B11111111;}
//  #define setReadDirInline() {GPIOD_PDDR &=~B11111111;}
 
  #define setWriteDirInline() { \
    pinMode(2, OUTPUT); \
    pinMode(14, OUTPUT); \
    pinMode(7, OUTPUT); \
    pinMode(8, OUTPUT); \
    pinMode(6, OUTPUT); \
    pinMode(20, OUTPUT); \
    pinMode(21, OUTPUT); \
    pinMode(5, OUTPUT); }
  #define setReadDirInline() { \
    pinMode(2, INPUT); \
    pinMode(14, INPUT); \
    pinMode(7, INPUT); \
    pinMode(8, INPUT); \
    pinMode(6, INPUT); \
    pinMode(20, INPUT); \
    pinMode(21, INPUT); \
    pinMode(5, INPUT); }

  // As part of the inline control, macros reference other macros...if any
  // of these are left undefined, an equivalent function version (non-inline)
  // is declared later.  The Uno has a moderate amount of program space, so
  // only write8() is inlined -- that one provides the most performance
  // benefit, but also generates the most bloat.
  #define write8 write8inline

#else


This code is a mix of original UNO breakout code, code that Paul Stoffregen provided along with a conversion to GPIO.
I have not been able to succesfully convert setWriteDirInline() and setReadDirInline() to GPIOD_PDDR.
(information on how I got here and the code that Mr. Stoffregen provided can be found here

When I run either the graphicstest or the tftbmp example, the identification part works now, but the screen doesnt display anything other than the backlight, and a quick flicker (<20ms or so) at the exact moment something is drawn to the screen.

graphicstest example:
Code: Select all | TOGGLE FULL SIZE
Using Adafruit 2.8" TFT Breakout Board Pinout
Found ILI9325 LCD driver
Benchmark                Time (microseconds)
Screen fill              1049012
Text                     149587
Lines                    909085
Horiz/Vert Lines         139525
Rectangles (outline)     98754
Rectangles (filled)      3138285
Circles (filled)         1106782
Circles (outline)        395576
Triangles (outline)      288681
Triangles (filled)       1380602
Rounded rects (outline)  195202
Rounded rects (filled)   3678084
Done!

tftbmp example:
Code: Select all | TOGGLE FULL SIZE
Found ILI9325 LCD driver
Initializing SD card...OK!

Loading image 'woof.bmp'
File size: 230456
Image Offset: 54
Header size: 40
Bit Depth: 24
Image size: 240x320
Loaded in 28303 ms

Loading image 'miniwoof.bmp'
File size: 57654
Image Offset: 54
Header size: 40
Bit Depth: 24
Image size: 120x160
Loaded in 9810 ms

Loading image 'miniwoof.bmp'
File size: 57654
Image Offset: 54
Header size: 40
Bit Depth: 24
Image size: 120x160
Loaded in 9809 ms


If you want I can post a new picture of my wiring as it is now, but for now I think the first additional lines to pin_magic.h should cover that.
At the moment I would like to know if this new code "should" work and which direction I should focus my attention towards.

(I do understand that you cannot directly support me with this, so feel free to tell me to go fix it myself if I'm becoming a pain in the ... behind)
ZTiK.nl
 
Posts: 21
Joined: Thu Jan 17, 2013 2:43 pm

Re: 2.8" TFT touchscreen + Teensy 3.0

by adafruit_support_bill on Fri Feb 01, 2013 6:12 am

It looks like you are on the right track there.
User avatar
adafruit_support_bill
 
Posts: 29199
Joined: Sat Feb 07, 2009 9:11 am

Re: 2.8" TFT touchscreen + Teensy 3.0

by ZTiK.nl on Fri Feb 01, 2013 11:12 am

Thank you, glad to hear that!

I tried to change the order of the 8 lcd data lines, but this results in an incorrect id :
Code: Select all | TOGGLE FULL SIZE
Unknown LCD driver chip: C9A4

I also tried to use 5v instead of 3.3v, the id is correct, but still no display.

Do you have any suggestions on how to troubleshoot further when the id is correct but the display stays blank?
I have browsed 70 pages of forum searchresults on "2.8 TFT", but pretty much everyone who had this issue has gotten an offer for a replacement, so I am unsure how to move forward from here.

I do not believe the screen is faulty/damaged, it has been handled extremely delicately, but I have to be honest and say that I don't know how to rule this out.
ZTiK.nl
 
Posts: 21
Joined: Thu Jan 17, 2013 2:43 pm

Re: 2.8" TFT touchscreen + Teensy 3.0

by adafruit_support_bill on Fri Feb 01, 2013 12:25 pm

Do you have access to a standard Arduino (Duemilanove, UNO)? If you can run on that with the unmodified software then you know the display is good.
User avatar
adafruit_support_bill
 
Posts: 29199
Joined: Sat Feb 07, 2009 9:11 am

Re: 2.8" TFT touchscreen + Teensy 3.0

by ZTiK.nl on Fri Feb 01, 2013 12:34 pm

adafruit_support wrote:Do you have access to a standard Arduino (Duemilanove, UNO)? If you can run on that with the unmodified software then you know the display is good.


Hmmmm, why I didn't think of that...
I don't have one here, but I have no problem running to the stores tomorrow and getting one, always useful to have one at hand.

Again, thanks for yet another push forward :)
ZTiK.nl
 
Posts: 21
Joined: Thu Jan 17, 2013 2:43 pm

Re: 2.8" TFT touchscreen + Teensy 3.0

by ZTiK.nl on Fri Feb 01, 2013 8:22 pm

Finally some good news, I got it working :)

For anyone interested in the code, it can be found here
I have requested Paul to take a look at the code before I send it here (IF you want it ofcourse!), might as well do it right.

Again thank you for your patience with somebody with a very limited amount of knowledge on the subject.
Also, I am aware that you don't/can't support Teensy, so in my opinion you have reached out to me further than you needed to!
*two-thumbs-up*
ZTiK.nl
 
Posts: 21
Joined: Thu Jan 17, 2013 2:43 pm

Re: 2.8" TFT touchscreen + Teensy 3.0

by adafruit_support_bill on Sat Feb 02, 2013 6:54 am

Congratulations. :D
User avatar
adafruit_support_bill
 
Posts: 29199
Joined: Sat Feb 07, 2009 9:11 am

Re: 2.8" TFT touchscreen + Teensy 3.0

by ZTiK.nl on Sat Feb 02, 2013 6:10 pm

Haha, thank you ;)

One thing I have noticed during the graphicstest example and manual testing with the text output is that fontsize 5 will be distorted.
It appears that a horizontal line of pixels (1px high) is moved 1 or 2 pixels to the right all the way from the left side of the screen up to the right.
This always happens on the same spot of the letters, no matter of their position on the screen.

I haven't been able to pinpoint the source of this yet, but I will report back when I do.

With kind regards,
ZTiK.nl
 
Posts: 21
Joined: Thu Jan 17, 2013 2:43 pm

Re: 2.8" TFT touchscreen + Teensy 3.0

by ZTiK.nl on Wed Feb 06, 2013 8:15 pm

I don't really have anything new to add, just wanted to say that the display is exceeding my expectations in every way.

The touchsensitivity is (after calibrating a little) accurate up to 2 pixels now, still need to refine a little more to get 1px accuracy
The screen itself is very vivid and details are displayed quite sharp.
Drawing to the screen (lines, triangles, rectangles) is instantaneous, I'm drawing quite a lot of horizontal/vertical lines, 2 triangles and a bit of text, but I cannot see any delay.
Loading from the SD is terribly slow, mainly because the libs haven't been updated to SdFat yet.
I've done some testing with SdFat and it improved my read/write speeds at least tenfold, so I will be working on rewriting the libs to SdFat soon.

Here is a youtube vid I made (30+ sec. long) displaying a project I'm working on, but it shows quite nice how accurate the display/touch sensitivity is

I do not think that the code used for Teensy support in pin_magic.h can/will be optimized any further except maybe change the pins to a more grouped section of pins, mine are all over the board now...
I haven't heard back from Paul Stoffregen yet, he has enough on his mind already, so as far as I'm concerned you can add it to the library for general Teensy 3.0 support.
Unless you feel that it is unwise ofcourse :)

pin_magic.h
Code: Select all | TOGGLE FULL SIZE
#elif defined(__MK20DX128__)
// My mix of original Uno code, Paul Stoffregen's code and a cenversion to GPIO pin/port mapping, id checks now results in 0x9325
// LCD Data Bit :   7   6   5   4   3   2   1   0
// T3 dig. pin  :   5  21  20   6   8   7  14   2
// T3 port/pin  : PD7 PD6 PD5 PD4 PD3 PD2 PD1 PD0

  // GPIO conversion thanks to immortalSpirit!
  #define write8inline(d) { GPIOD_PDOR = (d); WR_STROBE; }
  #define read8inline() (RD_STROBE, GPIOD_PDIR)

  // works, thank you Paul!
  #define setWriteDirInline() { \
    pinMode(2, OUTPUT); \
    pinMode(14, OUTPUT); \
    pinMode(7, OUTPUT); \
    pinMode(8, OUTPUT); \
    pinMode(6, OUTPUT); \
    pinMode(20, OUTPUT); \
    pinMode(21, OUTPUT); \
    pinMode(5, OUTPUT); }
  #define setReadDirInline() { \
    pinMode(2, INPUT); \
    pinMode(14, INPUT); \
    pinMode(7, INPUT); \
    pinMode(8, INPUT); \
    pinMode(6, INPUT); \
    pinMode(20, INPUT); \
    pinMode(21, INPUT); \
    pinMode(5, INPUT); }

   // MEGA macro's !!!
  #define write8            write8inline
  #define read8             read8inline
  #define setWriteDir       setWriteDirInline
  #define setReadDir        setReadDirInline
  #define writeRegister8    writeRegister8inline
  #define writeRegister16   writeRegister16inline
  #define writeRegisterPair writeRegisterPairInline 
#else


P.S. If you credit anyone for T3 support, it should be Paul Stoffregen and immortalSpirit!
ZTiK.nl
 
Posts: 21
Joined: Thu Jan 17, 2013 2:43 pm