TFT on Teensy 3.0 (LCD Controller:SSD1289, Touch Screen Controller:ADS7843)

Status
Not open for further replies.

Experimentalist

Well-known member
Has anyone any experience with the following on Teensy 3.0:

LCD Controller: SSD1289
Touch Screen Controller: ADS7843
LCD Type: TFT
LCD Interface: 16-bit parallel
Touch Screen Interface: SPI
Backlight: LED
Resolution: 320*240 DOTS

They are available dirt cheap on eBay so it would be great if they can be used with Teensy 3.0

Anyone?

Ex.
 
I am currently working to port this library to Teensy 3.0! I already have it working on the Teensy 2.0++ but figured I could use some more horsepower of the 3.0.. I'm hoping to have this done and tested by this weekend.
 
I am currently working to port this library to Teensy 3.0! I already have it working on the Teensy 2.0++ but figured I could use some more horsepower of the 3.0.. I'm hoping to have this done and tested by this weekend.

Great, are you willing to post it when you have finished?
 
Here are the details from a private conversation between ZTiK-nl and I that I thought would add value to the thread, all credits to ZTiK-nl. BTW I did ask his permission before posting :)

ZTiK.nl said:
Experimentalist said:
Thanks for all the info. Which Touch library are you using?

Do you have any code you are willing to share?

Ex.


No problem at all :)

For touch I use the 'default' Adafruit Touchscreen library

It worked perfectly right from the start, but I needed to do a little calibrating and re-orientate the touch.

The touchscreen uses portrait mode orientation, so does the display.
Since I wanted to use the screen in landscape mode, my code also has to incorporate the remapping of x-touch coordinates to y-screen coordinates and vice versa.
(I needed to modify the map() function for this)

A bit more important: in my case the TFT screen itself is a few pixels smaller than the touchlayer is.
A friend of mine build a simple testbed, which presses on the 4 outer pixels of the TFT screen, one after another.
After finding the touch x/y coordinates for the outer coordinates display, I applied these to the map() function and now I have 2px accuracy between display and touchlayer (max off by 1px anywhere on the display).
(I needed to modify the TS_MINX>TS_MAXY values for this)

I still have to refine the test I initially did to get 100% accuracy, but this is working so well that it has a low priority on my to-do list.
More important stuff to get to!

I wanted to add my Touchscreen library as a zip file, but it appears I don't have the option in a PM to send attachments.
However, I have not modified the lib in any way, so you can download from the Adafruit link as well.

example of the code I used to remap the screen vs touchlayer:
Code:
#define MINPRESSURE 10 // minimum pressure required to register a hit
#define MAXPRESSURE 1000 // maximum pressure required to register a hit (otherwise it has fallen)
#define TS_MINX 110 // define edges of screen v.s. edges of touchlayer
#define TS_MINY 120 // this is ofcourse in PORTRAIT MODE
#define TS_MAXX 930 // later on, a conversion to landscape mode is initiated
#define TS_MAXY 935 // remember this while testing

void loop() {

  Point p = ts.getPoint(); // a point p holds x y and z coordinates for touchscreen
  touchx = map(p.y, TS_MINY, TS_MAXY, 0, tft.width()); // remap y coordinates of touch to x coordinates of screen
  touchy = map(p.x, TS_MINX, TS_MAXX, tft.height(), 0); // remap y coordinates of touch to x coordinates of screen
  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
    // if pressure is high enough, go do stuff
  }
}

The comments are mostly a reminder to myself, didn't bother to change them, I'm pretty sure you understand the code better than I do ;)
Ow, something I found useful, if(pz < 1) means no pressure, so stuff can happen if there is no press, like a counter start running to dim/sleep the display after x sec. ;)


Let me know if there is anything else I can do for you!
 
That is 100% correct :)

I do not believe there is a controller for the Touch interface in this combination of screen/touch.
 
So, just checked and apparently someone else has already ported utft to teensy3 and a bit better coded than I have..
 
Last edited:
Well...I've got good news, and bad news.

The good news is that the UTouch library works with teensy 3 without needing any changes. Just plug in and go.

The bad news is that it doesn't work through the SPI interface/pins - at least with the SdFat library also in use. It detects touch, but reports co-ordinates of 0,0 using the SPI pins (works fine on normal pins though).

If anyone has any ideas for what would be needed to make it work with SdFat also in use, I'd appreciate it! I'll keep poking at it to see if I can get anywhere.
 
. . . to make it work with SdFat also in use

Hi

This is exactly the problem I will be facing, when my displays finally wing there way from China to the UK. I don't quite understand what you mean by

works fine on normal pins though
Do you mean you have disconnected the touch screen from the controller chip and used a different library? I thought this library had to use the SPI bus?

Could you detail your hardware setup with regard to the LED display and touch interface. e.g. is it using a SSD1289 for the TFT controller and ADS7843 chip or compatible for the touch screen controller?

Sorry for any stupid questions I am on a very steep learning curve with SPI devices, I originally thought it was a port not a bus!

Thanks in advance for any info you can share to help me understand better

Ex.
 
Hi

This is exactly the problem I will be facing, when my displays finally wing there way from China to the UK. I don't quite understand what you mean by

Do you mean you have disconnected the touch screen from the controller chip and used a different library? I thought this library had to use the SPI bus?

Could you detail your hardware setup with regard to the LED display and touch interface. e.g. is it using a SSD1289 for the TFT controller and ADS7843 chip or compatible for the touch screen controller?

Sorry for any stupid questions I am on a very steep learning curve with SPI devices, I originally thought it was a port not a bus!

Thanks in advance for any info you can share to help me understand better

Ex.

During initialisation, you set the pins.

e.g.
Code:
uint8_t t_Clk = 14;
uint8_t t_CS = 20;
uint8_t t_DIn = 16;
uint8_t t_DOut = 15;
uint8_t t_IRQ = 33;
UTouch myTouch(t_Clk, t_CS, t_DIn, t_DOut, t_IRQ);

// In setup:
        myTouch.InitTouch(LANDSCAPE);
        myTouch.setPrecision(PREC_MEDIUM);
If the clock/DIn/DOut pins are set to the SPI pins 13/11/12, the touch screen reads the co-ordinates 0,0 (and yes, I have tried swapping DIn & DOut over in case I had them backwards). If they're set to pins that are NOT on the SPI ports, it reads fine.

While the controller chip itself apparently uses SPI, the UTouch library is bit-banging communications to the chip. The UTouch library doesn't use Arduino SPI libraries (writing directly instead), so it works on pins other than the Teensy SPI pins.

My issue comes in when I wanted to use it on the SPI interface while also using SdFat on SPI (different chip select lines, same clock/DIn/DOut lines). If I wire it up that way, the library fails to read the touch co-ordinates. I've only put a few hours into investigating this today, so I'm not sure why it won't read the data from the touch controller over the SPI lines, but I suspect that the SPI initialization that SdFat is doing to get good SD Card access (i.e. turning on the hardware spi, setting it to 16bit reads, etc) is conflicting with the 8-bit bit-banging that the UTouch library is using to access the touch data.

I'm more than happy for someone to prove that wrong...it's just my initial hypothesis as to why it works on non-spi connections but not on the spi ones.

The screen I'm using is one I got from Ebay...initially I was told it used a Himex HX8347-A chip for the TFT controller...later testing proved it was in fact a mislabled SSD1289 controller instead (not that I really cared which was used - I just wanted to be able to initialize it!). The ebay seller said that the touch interface was "an ADS7843-compatible touch panel controller"...and treating it as one seems to work with the exception of the SPI interface issue above.

Using UTouch, it's literally a case of:
Code:
        if (myTouch.dataAvailable())
        {
            myTouch.read();
            int x=myTouch.getX();
            int y=myTouch.getY();
            Serial.print("Touch data available: X=");

            Serial.print(x);
            Serial.print(", Y=");
            Serial.println(y);
        }
If I use the SPI clock/data pins, x&y are 0. If I use any other pins, x&y have sensible values.
 
Last edited:
I didn't realise you could emulate SPI without using the SPI pins so I understand now.

Ideally I also wanted to use the SPI bus as intended, as a bus, for both SD FAT and UTouch. However, for my project I should be able to find enough pins to have SD FAT use the SPI bus and the UTouch library have its own 5 pins but it will not leave much opportunity for expansion later.

I wanted to use it on the SPI interface while also using SdFat

Out of interest have you tried the UTouch library on the SPI pins without SD FAT in your testing as yet? From what I read the SPI standard is so loose it seems very hard to get multiple devices to play nicely on it.
 
Last edited:
Out of interest have you tried the UTouch library on the SPI pins without SD FAT in your testing as yet? From what I read the SPI standard is so loose it seems very hard to get multiple devices to play nicely on it.

Not yet. For what I'm doing, the Sd Card is a must-have...the touch interface is just a nice-to-have. If I had to choose between the two, I'd choose the SD Card. I am hoping to find some information on why they're not working together and how to fix them, but if not...*shrug*
 
Not yet. For what I'm doing, the Sd Card is a must-have...the touch interface is just a nice-to-have. If I had to choose between the two, I'd choose the SD Card. I am hoping to find some information on why they're not working together and how to fix them, but if not...*shrug*

I was just thinking in a fault finding sense really just to understand if it worked that way, but as I said I have not got any as yet or I would try it myself
 
It seems to work on those pins, but it conflicts with the SD card pin definitions...you can have either one or the other but not both with the library as it is.

I'm slowly going through SdFat, UTouch, and the ADS7843 data sheets to see if I can modify the UTouch library to use the same kind of SPI connections that SdFat uses. I haven't done anything with SPI before though, so it'll take me a while to step through it all.

Worst case scenario will be that you can use the two together as-is so long as you don't use the touch screen on the same pins as the SD card (just use any other digital pins instead). SdFat uses some of the Teensy's hardware smarts with SPI to achieve improved performance for SD card access, so if you had to choose which one got to use the hardware SPI pins on the Teensy you'd be far better off using them for the SD card.

I *think* to read the touch, it uses:
* 1 byte command to set to read X
* 2 bytes read (12 bits actually containing data, as 7+5, with the first bit and last 3 bits 0-padded)
* 1 byte command to set to read Y
* 2 bytes read (12 bits actually containing data, as 7+5, with the first bit and last 3 bits 0-padded)
and a max SPI clock-rate of 2Mb (if I'm reading the notes on the spec sheet right).

The first bit in the read is 0, because it needs one more clock-cycle to finish the A-D conversion. The last 3 bits are 0 just to pad it out to 2 bytes. Being 1 byte writes, 2 byte reads means it should be possible to use the same FIFO SPI buffers that SdFat uses (just stepping the SPI clock down) to do the read/writes, but it'll take me a while to work out exactly how to integrate SdFat's SPI access with the UTouch library. And to test it and see if it actually works, of course ;). It's all a bit beyond what I've done before...but it looks like it should work in theory so I just need to get the theory and actual to match up *lol*.

Edit: I'm not having any luck with this...each time I try, I manage to throw my Teensy 3 into a state in which it won't reprogram, and it won't get out of that state until I remove the wires to the touch controller and change USB ports that the Teensy is plugged into (and hold the reset button down on the Teensy when I plug it in so it doesn't run anything before reprogramming). Just unplugging the touch, just changing USB ports, or just unplugging/replugging with reset held isn't enough to get it programmable again - I need to do all 3 together to get it working again. :confused: At this point, I'm going to give up on this for the moment. If anyone else has a go and can get the touch working on SPI with SdFat, I'd appreciate the patch/help to make it work.
 
Last edited:
Status
Not open for further replies.
Back
Top