Showing objects of screens

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
amiros
 
Posts: 4
Joined: Mon Feb 19, 2018 5:28 am

Showing objects of screens

Post by amiros »

Hey,
my screen of adafruit has broken, so I bough a new TFT 2.8'' LCD shield restative, but when I upload the program to my arduino, nothing happens. I don't know what the problem is, but I need the screen to show my gui of using the arduino. the example of code is:

Code: Select all

#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <Adafruit_STMPE610.h>
#include <string.h>
#include <Wire.h>
// all of this in common.h
#define TFT_CS 10
#define TFT_DC 9
#define STMPE_CS 8
#define BUTTON_NUMBER_HEIGHT 45
#define BUTTON_NUMBER_WIDTH 45

#define TS_MINX  150
#define TS_MINY 130
#define TS_MAXX 3800
#define TS_MAXY 4000

#define DIALHEIGHT 50
#define DIALWIDTH 50
#define DIALY 300
#define DIALX 110
#define MESSAGEX 150


#define SIZE_TEXT_BUTTON 2
#define INCREAMENT 55
#define MAXLENGTHPHONENUMBER 11



#define DELETE_X 200
#define DELETE_Y 20
#define DELETE_HEIGHT 40
#define DELETE_WIDTH 40

#define PRINT_X_START 20
#define PRINT_Y_START 20
#define PRINT_HEIGHT 14
#define PRINT_WIDTH 140
#define FONT_SIZE_INPUT_PHONE 2

Adafruit_ILI9341 tft=Adafruit_ILI9341(TFT_CS,TFT_DC);
Adafruit_STMPE610 ts=Adafruit_STMPE610(STMPE_CS);
Adafruit_GFX_Button myButtons[12],eraseButton,dialButton,messageButton;
char* buttonsLabel[12]={"1","2","3","4","5","6","7","8","9","*","0","#"},phoneNumber[MAXLENGTHPHONENUMBER+1];
int x=60, y=80,starterx=x;
const int buttonsLength=sizeof(myButtons)/sizeof(myButtons[0]);
TS_Point lastPointChecked;
bool doUpdate,firstTime=true,hasCursor=false;

void buttonsInit()
{
   eraseButton=Adafruit_GFX_Button();
   dialButton=Adafruit_GFX_Button();
   messageButton=Adafruit_GFX_Button();
   for(int i=0;i<buttonsLength;i++)
   {
      myButtons[i]=Adafruit_GFX_Button();
      if(i%3==0&&i!=0)
      {
          x=starterx;
          y+=INCREAMENT;
      }
    myButtons[i].initButton(&tft,x,y,BUTTON_NUMBER_WIDTH,BUTTON_NUMBER_HEIGHT,ILI9341_ORANGE,ILI9341_BLUE,ILI9341_BLACK,buttonsLabel[i],SIZE_TEXT_BUTTON);
      x+=INCREAMENT; 
      
   }
}
void beginAll()
{ 
  tft.begin();
  ts.begin();
  tft.fillScreen(ILI9341_WHITE);
  Serial.begin(9600);
  while(!Serial);
  phoneNumber[0]=0;
}

void drawNumbers()
{
  if(firstTime)
  {
     for(int i=0;i<buttonsLength;i++)
     {
       myButtons[i].drawButton();
     }
     return;
  } 
  if(ts.touched()==false)
  {
    doUpdate=false;
    return;
  }
  doUpdate = true;
  for(int i=0;i<buttonsLength;i++)
  {
    myButtons[i].drawButton(myButtons[i].isPressed());
  }
}



void ChangeEditButtonsVisiblity(bool destVisible)
{
  if(destVisible==true)
  {
    eraseButton.initButton(&tft,DELETE_X, DELETE_Y,DELETE_WIDTH,DELETE_HEIGHT,ILI9341_BLACK,ILI9341_BLACK,ILI9341_WHITE,"<--",SIZE_TEXT_BUTTON);
    eraseButton.drawButton();
    dialButton.initButton(&tft,DIALX,DIALY,DIALWIDTH,DIALHEIGHT, ILI9341_GREEN,ILI9341_GREEN, ILI9341_WHITE, "Dial",SIZE_TEXT_BUTTON);
    dialButton.drawButton();
    /*messageButton.initButton(&tft, MESSAGEX,DIALY,DIALWIDTH,DIALHEIGHT,ILI9341_YELLOW, ILI9341_YELLOW, ILI9341_BLACK,"Message",SIZE_TEXT_BUTTON/4);
    messageButton.drawButton();*/
    return;
  }
   eraseButton.initButton(&tft,DELETE_X, DELETE_Y,DELETE_WIDTH,DELETE_HEIGHT,ILI9341_WHITE,ILI9341_WHITE,ILI9341_WHITE,"",SIZE_TEXT_BUTTON);
   eraseButton.drawButton();
  dialButton.initButton(&tft,DIALX,DIALY,DIALWIDTH,DIALHEIGHT, ILI9341_WHITE,ILI9341_WHITE, ILI9341_WHITE, "",SIZE_TEXT_BUTTON);
  dialButton.drawButton();
  /*messageButton.initButton(&tft, MESSAGEX,DIALY,DIALWIDTH,DIALHEIGHT,ILI9341_WHITE, ILI9341_WHITE, ILI9341_WHITE,"",SIZE_TEXT_BUTTON);
  messageButton.drawButton();*/
}

void deleteAll()
{
  if(hasCursor)
  {
    return;
  }
  phoneNumber[0]=0;
  ChangeEditButtonsVisiblity(false);
  tft.fillRect(PRINT_X_START, DELETE_Y, PRINT_WIDTH,PRINT_HEIGHT, ILI9341_WHITE);
  printPhoneNumberToScreen();
}

void deleteDigit()
{
  if(!hasCursor)
  {
    int phoneLength=strlen(phoneNumber);
    if(phoneLength==0)
    {
        return;
    }
    phoneNumber[phoneLength-1]=0;
    if(strlen(phoneNumber)==0)
    {
     ChangeEditButtonsVisiblity(false);
    }
    tft.fillRect(PRINT_X_START, DELETE_Y, PRINT_WIDTH,PRINT_HEIGHT, ILI9341_WHITE);
    printPhoneNumberToScreen();
  }
}

void printPhoneNumberToScreen()
{
   tft.setCursor(PRINT_X_START , PRINT_Y_START); 
   tft.setTextColor(ILI9341_BLACK);  tft.setTextSize(FONT_SIZE_INPUT_PHONE);
   tft.print(phoneNumber);
}

int pointOfLastTouch()
{
  int finResult=millis();
  while(!ts.bufferEmpty())
  {
     delay(30);
     lastPointChecked=ts.getPoint();
  } 
  finResult=millis()-finResult;
  return finResult;
}
void mappingThePoint()
{
   lastPointChecked.x=map(lastPointChecked.x, TS_MINX,TS_MAXX,0,ILI9341_TFTWIDTH);
   lastPointChecked.y=map(lastPointChecked.y, TS_MINY,TS_MAXY,0,ILI9341_TFTHEIGHT);
}

void checkifDigitNumPressed()
{
  bool pressed;
  for(int i=0;i<buttonsLength;i++)
  {
    pressed=myButtons[i].contains( lastPointChecked.x, lastPointChecked.y);
    myButtons[i].press(pressed);
    if(pressed)
    {
      strcat(phoneNumber,buttonsLabel[i]);
      if(strlen(phoneNumber)==1)
      {
         ChangeEditButtonsVisiblity(true);
      }
      printPhoneNumberToScreen();
    } 
  }
}

void checkTouch()
{
  bool pressed;
  int timepressed;
  if(firstTime==true)
  {
     checkifDigitNumPressed();
     firstTime=false;
     return;
  }
  timepressed=pointOfLastTouch();
  mappingThePoint();
  if(strlen(phoneNumber)>0)
  {
     pressed=eraseButton.contains(lastPointChecked.x,lastPointChecked.y);
     eraseButton.press(pressed);
     if(pressed)
     {
       if(timepressed<1000)
       {
         deleteDigit();
         return;
       }
       deleteAll();
       return;
     } 
     pressed= dialButton.contains(lastPointChecked.x,lastPointChecked.y);
     dialButton.press(pressed);
     if(pressed)
     {
        //use method on gsm dial(phoneNumber);
        Serial.println("Now Dialing");
     }
  }
 
  if(strlen(phoneNumber)== MAXLENGTHPHONENUMBER)
  {
    return;   
  }
  
 checkifDigitNumPressed();
}

bool BANNED(int num, int mini,int maxi)
{
  if(num<mini||num>maxi)
  {
    return false;
  }
}
void setup() {
  // put your setup code here, to run once:
  beginAll();
  buttonsInit();
   drawNumbers();
  doUpdate = false;
}

void loop() {
  // put your main code here, to run repeatedly:
  if(!ts.bufferEmpty()) checkTouch();
  if(doUpdate) drawNumbers(); 

}

I am adding also pdf of pictures that shows the differences of uploading same code that is related above.
Attachments
adafruit.pdf
(449.6 KiB) Downloaded 21 times

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Showing objects of screens

Post by adafruit_support_carter »

Looks like you soldered the ICSP jumpers on your previous screen. Is that also needed on your new one?

User avatar
amiros
 
Posts: 4
Joined: Mon Feb 19, 2018 5:28 am

Re: Showing objects of screens

Post by amiros »

I think that's the problem, so I wanna to make sure if this is the problem.
Have you idea where can I buy a new ICSP jumpers?

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Showing objects of screens

Post by adafruit_support_carter »

There's nothing to buy. It's just solder. On your older shield, they are soldered:
old_shield.jpg
old_shield.jpg (24.35 KiB) Viewed 244 times
but on your newer one, they are not:
new_shield.jpg
new_shield.jpg (37.77 KiB) Viewed 244 times

User avatar
amiros
 
Posts: 4
Joined: Mon Feb 19, 2018 5:28 am

Re: Showing objects of screens

Post by amiros »

Can I do it my self of electronic equipment and the screen wiil work? something like weld the vertical ICSP jumpers with tin? or return the screen and get new one or refund?

User avatar
adafruit_support_carter
 
Posts: 29168
Joined: Tue Nov 29, 2016 2:45 pm

Re: Showing objects of screens

Post by adafruit_support_carter »

Can I do it my self of electronic equipment and the screen wiil work?
Don't know. It depends on why the jumpers were soldered on the original screen and what board you are using to drive the display. Why were the jumpers soldered on the original screen? What board are you using to drive the display?
something like weld the vertical ICSP jumpers with tin?
Yes. That's how it's done.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”