Connecting Adafruit 2.8" TFT Touch Shield to a Photon

Oh, I see. Thanks for the tip.

Is there a example code for a TFT touch shield to a Photon Touch screen example code anywhere? All I found was Arduino examples of touchscreen in the TFT touch shield and I don’t know how to change it. I just want to test the code how to see if my wiring is correct from my Photon to my TFT touch shield.

For this the silk print offers some help.
It states that the touch controler is an STMPE610 and searching this very forum for that term brings up these threads.
https://community.particle.io/search?q=stmpe610
I guess one of them should contain some useful information

1 Like

Hey everyone,
Just wanted to put a note on here for anyone trying to connect the Adafruit 2.8" TFT Resistive Touch Shield to a Photon, through a Particle Shield Shield. I couldn’t get it to work, then figured this out and thought I’d share the knowledge…

The TFT shield is hardwired to use the default hardware SPI pins for Arduino, but on the Shield Shield, these pins actually map to Particle’s SPI1, not SPI (there are two SPI ports on the Particle…I’ve read there is perhaps a third?).

To make it work, you need to change any instance of “SPI.xxxxx” to “SPI1.xxxxx” in the following library:

Adafruit_ILI9341.cpp

For example, change:

SPI.beginTransaction(SPISettings(16000000, MSBFIRST, SPI_MODE0));

…to:

SPI1.beginTransaction(SPISettings(16000000, MSBFIRST, SPI_MODE0));

These occur in 6 places in the Adafruit_ILI9341.cpp file (Line numbers approximate):

Line 38:  SPI1.transfer(c);
Line 107: SPI1.begin();
Line 108: SPI1.setClockDivider(SPI_CLOCK_DIV2);	//Full speed @18MHz
Line 109: SPI1.setBitOrder(MSBFIRST);
Line 110: SPI1.setDataMode(SPI_MODE0);
Line 405: r = SPI1.transfer(0x00);

This will have your Particle talking to the correct pins of the TFT shield, through the Shield Shield. And of course, if coming from Arduino, you will need to do the other typical porting changes covered in this and other threads.

Hope this helps someone! :wink:
Jeremy

3 Likes

I am trying to use a tft screen similar to the one talked in this thread but I am not able to use the library in particle web ide. I got a bunch of errors (I thought about copying them here but it is a huge list).

Is the library updated somewhere? Maybe I am getting the wrong version. The one included in web ide says “not ported”. I tried about SPI to SPI1 as the previous message says but I still get errors.

Checking errors, most of them seem to come from BRR and BSRR members which not exists in GPIO_TypeDef

Maybe its useful, my tft screen has these pins: PIN_NO_TEXT, LCD_RST, LCD_CS, LCD_RS, LCD_WR, LCD_RD where PIN_NO_TEXT is the A5 in an arduino UNO board. Which PIN_NO_TEXT I mean a pin without silk name.

This is very similar to mine https://www.google.es/imgres?imgurl=http%3A%2F%2Fceezblog.info%2Fimages%2Fblog%2F4535shield.jpg&imgrefurl=http%3A%2F%2Fceezblog.info%2F2015%2F04%2F20%2F240x320-28-tft-shield-driver-4535-for-arduino&docid=LGmy4g8SOfapbM&tbnid=tUEfrmtPdda1dM%3A&w=805&h=590&bih=794&biw=1600&ved=0ahUKEwjfwbyI_6fPAhVLChoKHVnhAIwQMwgfKAEwAQ&iact=mrc&uact=8

I don’t know that display, but I’d try to use the SD_DI, SD_DO, SD_SCK, LCD_CS, since on the LCD side there is no clock pin so I’d deduct (without looking at the datasheet tho’) that LCD_RD, LCD_WR are note actually meant as SPI pins and since most SPI displays with SD card share the SPI pins (apart from CS) that would fit.

So, if I have this line to initialize the library:

A2 seems to be CS, A1 -> DC and A0 ->RST

Cs and RST are in the LCD side: LCD_RST, LCD_CS. But DC is not in the LCD side neither it is on te SD side.

Also, I don’t know which pins I should connect on SD_D1, SD_D0 and SD_SCK.

I found this on the documentation a friend gave me:

LCD_RST — A4 — LCD bus reset signal
LCD_CS — A3 — LCD bus chip select signals
LCD_RS — A2 — LCD bus command /data selection signal
LCD_WR — A1 — LCD bus write signal
LCD_RD — A0 — LCD bus read signal

About SD pins,
SD_SS ---- 10 ---- SD card SPI bus chip select signals
SD_DI ---- 11 ---- SD card SPI bus MOSI signal
SD_DO ---- 12 ---- SD card SPI bus MISO signal
SD_SCK ---- 13 ---- SD card SPI bus clock signal

Those numbers correspond to UNO/Mega2560 identification

That's not D1/D0 but DI/DO corresepinding to MOSI/MISO

Also looking at the datasheet on the page you linked above this is not an ILI9341 display, so the lib won't work IMHO and the pinout you got of your friend doesn't seem to use SPI for communicating with the display either.
Have a look at the datasheet :wink:

I am not sure but I think it is an ILI9341 controller. watching this screen on ebay: http://www.ebay.es/itm/Display-LCD-TFT-2-4-Pantalla-240x320-SPI-Arduino-Shield-UNO-Mega-SD-card-P0001-/201609691140?hash=item2ef0dfc004:g:g-QAAOSwNsdXRe1I it has that controller and it is quite similar to the one I have.

I am not sure, the documentation is so simple. Just what I wrote here and a list of examples contained in ?? no cd or anything similar.

I will keep looking for a way to make it working. I will ask for an arduino uno to see if it works there with adafruit libraries.

This one is, but the one you linked above seems to use another driver chip :wink:

After a while I tested another screen we bought. This worked like a charm so I think you were right and our previous screen didn’t work with SPI. I will try to read a bit more about that.

I tested the example provided by the library and it works but I tried to refresh just a part of the screen (my first tried was refreshing the whole screen for each change but it seems to be a bit difficult for me to do that.

This is the code I am trying to print something in the second line (a float value):

unsigned long testText(float value) {
	unsigned long start = micros();
	tft.setCursor(0, 0);
	tft.setTextColor(ILI9340_WHITE);  tft.setTextSize(1);
	tft.println(""); //Print nothing to go to the second line
	tft.fillRect(0, 2, 50,30, ILI9340_RED); //x y W H
	tft.setCursor(0, 0);
	tft.setTextColor(ILI9340_WHITE);  tft.setTextSize(1);
	tft.println("");
	tft.setTextColor(ILI9340_YELLOW); tft.setTextSize(2);
	tft.println(value);
	return micros() - start;
}

Because of the different size I don’t know how to set the cursor to the second line directly. I tried and it seems to be about 7-8 in Y axis.

Also, I would want to know how if there is an easy way to calculate a black rectangle to cover the previous text in a line so the new text is over a clean background. How do you guys refresh just a number or a text line? For example if the user needs to click a button to increment a number, I would want to modify just the number. Something like that. Do you know a tutorial/theorical explanation about this?

If you use tft.setTextColor(ILI9340_WHITE, ILI9340_BLACK); the text should be rendered ontop of a black rectangle - I think.
The x- & y-coordinates for text cursors are in pixels and depending on the font and size you should be able to calculate the distance between lines.

The best way to learn how that all works is via a look into the implementation of Adafruit_GFX library - IMHO.

I got it working but I don’t like the way I did it. I have to repaint all the screen with empty blocks setting sizes and tft.println("");… to I get to the line I want to modify. Then I write the previous text in background color and after that, repeat all previous steps again but I set the color to the previous one and paint the new number (storing the previous one in a variable so I can delete next time).

In this case, we just need to modify a number each time so it is easy. But if I wanted to modify a whole line (some text or so) it is needed to have a big array to contain all.

I will try to see this weekend the library in detail so maybe I find a way to do it.

@Suriken, which ILI9341 and Adafruit_GFX library versions are you using?

@peekay123
I think it’s yours: https://github.com/pkourany/ILI9341_SPI_LCD I got it from this repository.

@Suriken, can you post a pic of what you are trying to do. There are more effective ways to update fields on a screen but I need to get an idea of your layout.

I don’t have the screen here right now. I will try to take a photo tonight and upload it but I haven’t written the code for my screen yet. I am still using the print text function from the example.

My idea was something like:

    Alarm Menu
x Hour:       12
  Minute:      0

And then, the user, with some buttons can make the 12 to go up or down (13, 14, 15… or 11, 10, 9…) When he finishes modifying the hour, then clicking another button will display:

    Alarm Menu
  Hour:       17
x Minute:     0

So the “x” marks the line in use. In this moment the user with the previous two buttons would modify minute selection and once finished, by clicking next option button, alarm will be saved.

I am trying to do something like this. Menus are already done in serial console so once I learn how this library works I will try to implement there.

My idea was to update just the numbers each time and the “x” status when needed.

@Suriken, you may want to consider using this library:

The easiest way to display your elements is using absolute text positions (x,y). You can erase previous text by first printing spaces to erase the previous text and printing the new text after resetting the absolute x,y text position. That way, "static" text is only drawn once. :smile:

1 Like

I will try to do as you say and also this weekend I will check that library. Thanks for your suggestions!

1 Like

Hi everybody,
I’m almost in the same situation. I just bought a 2.8" touchscreen I bought on internet and I would like to use is on my photon, but I need to have some free pins to plug 5 sensors en 5 relays, and it looks like the screen need almost all the pin to work.
I tried to plug only LCD_RST, LCD_CS, LCD_RS, LCD_WR, LCD_RD with 5V, 3.3V and GND, but there nothing. I just have the backlight.

So my question is: is there a way to use this screen on my photon and to have some free pins?
If not, do you know a cheap display that have less pins, (like an OLED display or the Nextion display), but not under 2.8".

My display using UC8230 LCD driver.
You can dowload the Datasheet and the manual from this link if it can help : http://gofile.me/6tmiV/VrXHGchAa

Thank you so much for your help.