Using 2.8'' inch Arduino compatible shield with PSoC 4

Hi,

I am using 2.8’’ TFT shield with PSoC 4 Pioneer kit. I have migrated the code into C as required by PSoC Creator, but the project doesn’t seem to work.

Could you let me know if there are certain points to be noted while using this shield? Or could you let us know some simple operation which we can test on this so that we will know if it works?

Thanks.

Hi,

Sorry for taking so long time to answer your question.
The TFT Touch Shield SPI signal is from the ISP(2x3pin) header, do you connect it?

Thanks
Albert

hi jimsathome here

what 2.8’’ TFT shield do you have?

2.8’’ TFT shield v1.0 or 2.8’’ TFT shield v2.0

if 2.8’’ TFT shield 1.0 look up seeed 2.8’’ TFT shield v1.0 and copy code for demo touch shield then
load the libs

#include <stdint.h>
#include <TouchScreen.h>
#include <TFT.h>

or convert my sketch

#include <stdint.h>
#include <TouchScreen.h>
#include <TFT.h>

// Arduino uno #3 to 2.8 tft v1.0
//Measured ADC values for (0,0) and (238,319)
//TS_MINX corresponds to ADC value when X = 0
//TS_MINY corresponds to ADC value when Y = 0
//TS_MAXX corresponds to ADC value when X = 238
//TS_MAXY corresponds to ADC value when Y = 319

static unsigned int TS_MINX, TS_MAXX, TS_MINY, TS_MAXY;

//Touch Screen Co-ordinate mapping register
static unsigned int MapX1, MapX2, MapY1, MapY2;

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// The 2.8" TFT Touch shield v1.0 has 300 ohms across the X plate

/* Usage: TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
Where, XP = X plus, YP = Y plus, XM = X minus and YM = Y minus and 300 ohms resistence between X+ and X- */

// These are the pins for the uno #3 shield!

int TFTRES=300; // touch screen resistance is 300

#define XP A3 // tft v1.0 uno #3 pin A3
#define YP A2 // tft v1.0 uno #3 pin A2
#define XM A1 // tft v1.0 uno #3 pin A1
#define YM A0 // tft v1.0 uno #3 pin A0

TouchScreen ts = TouchScreen(XP, YP, XM, YM, TFTRES);

int ltzrn=0; //left top zero
int rtzrn=ltzrn; //right top zero
int rtcorn=238; //right top corner
int rbcorn=315; //right bottom corner
int lbcorn=rbcorn; //left bottom corner = right bottom corner

void setup(void)
{
Tft.init(); //init TFT
BoarderClear(); // fillRectangle with BLACK clears screen
Boarder(); // drawRectangle with RED make rectangle with red lines around edges
WhatTwo(); // Define something in text this location
MakeString(); // drawString in red
WhatOne(); // Define something in text this location
ButtonOne(); // drawRectangle with RED make small rectangle with red lines in location
ButtonTwo(); // drawRectangle with RED make small rectangle with red lines in location
}

void loop(void)
{
Point p = ts.getPoint(); // a point object holds x y and z coordinates

p.x = map(p.x, 120, 910, 230, 0);
p.y = map(p.y, 120, 950, 310, 0);

// we have some minimum pressure we consider ‘valid’
// pressure of 0 means no pressing!

if (p.z > ts.pressureThreshhold)
{
//Is touch in top of screen
if ((p.x > 0 && p.y > 0) && (p.x < 238 && p.y < 160)){ // (p.x > 170 and p.y > 270) and (p.x > 205 and p.y > 295)
Tft.fillCircle(p.x,p.y,1,WHITE); // with detected touch use p.x,p.y location and put a 1 diameter WHITE circle
}
// Is the touch in button 2 (&& is and) if true clear screen; redraw boarder; redraw string; redraw ButtonOne; redraw ButtonTwo;
if ((p.x > 170 && p.y > 270) && (p.x < 205 && p.y < 295)){ // (p.x > 170 and p.y > 270) and (p.x > 205 and p.y > 295)
BoarderClear(); // fillRectangle with BLACK clears screen
Boarder(); // drawRectangle with RED make rectangle with red lines around edges
WhatTwo(); // Define something in text this location
MakeString(); // drawString in red
WhatOne(); // Define something in text this location
ButtonOne(); // drawRectangle with RED make small rectangle with red lines in location
ButtonTwo(); // drawRectangle with RED make small rectangle with red lines in location
}
// Is the touch in button 1
if ((p.x > 31 && p.y > 270) && (p.x < 70 && p.y < 295)){ // (p.x > 31 and p.y > 270) and (p.x > 70 and p.y > 295)
BoarderClear(); // fillRectangle with BLACK clears screen
Boarder(); // drawRectangle with RED make rectangle with red lines around edges
WhatTwo(); // Define something in text this location
MakeString(); // drawString in red
WhatOne(); // Define something in text this location
ButtonOne(); // drawRectangle with RED make small rectangle with red lines in location
ButtonTwo(); // drawRectangle with RED make small rectangle with red lines in location

}
}
}
void ButtonOne()
{
Tft.drawRectangle(30,270,40,30,RED);//Make the button. Draw a rectangle, X=30, Y=270, length=40(X-AXIS), higth=30(Y-AXIS) color RED
Tft.drawChar(‘1’,45,280,2,RED); //Put character in button. Draw a char, start from point(45,280) font size 2(16*16) color RED
}

void ButtonTwo()
{
Tft.drawRectangle(170,270,40,30,RED);//Make the button. Draw a rectangle, X=170, Y=270, length=40(X-AXIS), higth=30(Y-AXIS) color RED
Tft.drawChar(‘2’,185,280,2,RED); //Put character in button. Draw a char, start from point(185,280) font size 2(16*16) color RED
}

void MakeString()
{
Tft.drawString(“HELLO”,25,200,5,RED);//draw a string, start from point(3,166) font size 5(16*16) color RED
}

void WhatOne()
{
Tft.drawString(“Draw on Screen Above”,45,170,1,RED);//draw a string, start from point(3,166) font size 5(16*16) color RED
}

void WhatTwo()
{
Tft.drawString(“Press 1 or 2 to Erase Screen”,5,250,1,RED);//draw a string, start from point(3,166) font size 5(16*16) color RED
}

void Boarder()
{
// left top zero (ltzrn), right top zero (rtzrn), right top corner (rtcorn), right bottom corner (rbcorn)
Tft.drawRectangle(ltzrn,rtzrn,rtcorn,rbcorn,RED);//draw a rectangle, Start at ltzrn, rtzrn, length=rtcorn(X-AXIS), width=rbcorn(Y-AXIS)
}

void BoarderClear()
{
Tft.fillRectangle(ltzrn,rtzrn,rtcorn,rbcorn,BLACK);//draw a BLACK rectangle, length=ltcorn(X-AXIS), width=rbcorn(Y-AXIS)
}

end sketch

this sketch draws a red box portrait style around the screen then enters text lower half and sensitizes the upper half of the screen for drawing and makes and identifies two square buttons at the bottom of the screen inside the main square and sensitizes them for touch only

if 2.8’’ TFT shield 2.0 look up seeed 2.8’’ TFT shield v2.0 and copy code for demo touch shield then
load the libs
#include <stdint.h>
#include <TFTv2.h>
#include <SPI.h>
and scratch head because I don’t know how to get stuff on the screen!!!

touch works fine
my code

// Modified for Arduino Uno R3 by Jim Shoffner 6/27/2013
#include <stdint.h>
#include <SeeedTouchScreen.h>
#include <TFTv2.h>
#include <SPI.h>

int ColorPaletteHigh = 30;
int color = WHITE; //Paint brush color
unsigned int colors[8] = {BLACK, RED, GREEN, BLUE, CYAN, YELLOW, WHITE, GRAY1};

/* Usage: TouchScreen ts = TouchScreen(XP, YP, XM, YM);
Where, XP = X plus, YP = Y plus, XM = X minus and YM = Y minus */

/* In TFTv2.h

#define XP A3 // tft v1.0 uno #3 pin A3
#define YP A2 // tft v1.0 uno #3 pin A2
#define XM A1 // tft v1.0 uno #3 pin A1
#define YM A0 // tft v1.0 uno #3 pin A0

//Measured ADC values for (0,0) and (140,205)
//TS_MINX corresponds to ADC value when X = 205
//TS_MINY corresponds to ADC value when Y = 140
//TS_MAXX corresponds to ADC value when X = 1830
//TS_MAXY corresponds to ADC value when Y = 1834

#define TS_MINX 205
#define TS_MINY 140
#define TS_MAXX 1830
#define TS_MAXY 1834
In TFTv2.h */

// declare three strings:
String PRawX, PRawY, PRawZ, PMapX, PMapY, PMapZ, PZ;

// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// The 2.8" TFT Touch shield has 300 ohms across the X plate

TouchScreen ts = TouchScreen(XP, YP, XM, YM);

void setup()
{
Serial.begin(9600);

Serial.println(“void setup() TFT_BL_ON; jim”);

       TFT_BL_ON;                                          //turn on the background light 

Serial.println(“void setup() Tft.TFTinit(); jim”);

       Tft.TFTinit();  //init TFT library

PRawX = String("PRaw X = “);
PRawY = String(”\tPRaw Y = “);
PZ = String(”\tPPressure = “);
PMapX = String(”\tPMap X = “);
PMapY = String(”\tPMap Y = “);
PMapZ = String(”\tPPressure = ");

for(int i = 0; i<8; i++) //Draw the pallet
{
Serial.println(“void setup() Tft.fillRectangle(i*30, 0, 30, ColorPaletteHigh, colors[i]); jim”);

Tft.fillRectangle(i*30, 0, 30, ColorPaletteHigh, colors[i]);
}
Serial.println(“void loop() TFT_BL_ON; jim”);
TFT_BL_OFF; //turn on the background light

}

void loop() {

// a point object holds x y and z coordinates
Point p = ts.getPoint();

if (p.z > __PRESURE)
{
Serial.println(“void loop() TFT_BL_ON; jim”);
TFT_BL_ON; //turn on the background light

Serial.print(PRawX+p.x+PRawY+p.y+PZ+p.z); 

}

p.x = map(p.x, TS_MINX, TS_MAXX, 0, 240);
p.y = map(p.y, TS_MINY, TS_MAXY, 0, 320);

// we have some minimum pressure we consider ‘valid’
// pressure of 0 means no pressing!

if (p.z > __PRESURE)
{
Serial.println(PMapX+p.x+PMapY+p.y+PZ+p.z);

       TFT_BL_OFF;                                          //turn on the background light 
Serial.println("void loop() TFT_BL_OFF; jim"); 

}

delay(100);

}

Tft.TFTinit(); dose not seem to work nor dose Tft.fillRectangle(i*30, 0, 30, ColorPaletteHigh, colors[i]); so there you are just color me stumped

Jim Shoffner
jimsathome:at:sbcglobal:dot:net
:at: = @
:dot: = .