element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum How to test the 2.8" TFT Touch shield v1.0 display
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 10 replies
  • Subscribers 392 subscribers
  • Views 1478 views
  • Users 0 members are here
  • openhardware
  • arduino
  • opensource
Related

How to test the 2.8" TFT Touch shield v1.0 display

Former Member
Former Member over 11 years ago

I am looking for script that I can test my 2.8" TFT Touch shield v1.0 display on the arduino uno or Mega 2560. I have download a script but got this error when I compile it. I don't understand what has to be done. Feed back will be appreciated.

 

Here is the Error

C:\Program Files (x86)\Arduino\libraries\TFT\utility\Adafruit_ST7735.cpp: In member function 'void Adafruit_ST7735::spiwrite(uint8_t)':
C:\Program Files (x86)\Arduino\libraries\TFT\utility\Adafruit_ST7735.cpp:59: error: 'SPI' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\TFT\utility\Adafruit_ST7735.cpp: In member function 'void Adafruit_ST7735::commonInit(uint8_t*)':
C:\Program Files (x86)\Arduino\libraries\TFT\utility\Adafruit_ST7735.cpp:272: error: 'SPI' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\TFT\utility\Adafruit_ST7735.cpp:276: error: 'SPI_CLOCK_DIV4' was not declared in this scope
C:\Program Files (x86)\Arduino\libraries\TFT\utility\Adafruit_ST7735.cpp:279: error: 'SPI_MODE0' was not declared in this scope

  • Sign in to reply
  • Cancel

Top Replies

  • Former Member
    Former Member over 10 years ago +1
    The issue you are running into is because the TFT library that is included with the Arduino IDE uses the same name as the SeeedStudio TFT library. The Arduino IDE's TFT library will not work with the SeeedStudio…
Parents
  • Robert Peter Oakes
    0 Robert Peter Oakes over 11 years ago

    Based on that it looks like you do not have the SPI library included into your script or not the specific one the example requires

     

    what you should have at the top of the sketch is something like this

     

    #include <SPI.h>

     

    please post your complete sketch as an attachment or paste into the post if it is not too big and we can have a look

     

    look on adafruit site to se if they have a custom SPI library too, they often enhance the libraries for the better and some of the errors look like they may depend on this rather than the standard Arduino SPI library

     

    Regards

     

    Peter

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to Robert Peter Oakes

    I try the new include header but got this error.

    core.a(main.cpp.o): In function `main':
    C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/main.cpp:5: undefined reference to `setup'
    C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/main.cpp:15: undefined reference to `loop'


    This is the sketch that I am using.
    /*
       ST7781R TFT Library. 


       2011 Copyright (c) Seeed Technology Inc.
      
       Authors: Albert.Miao, Visweswara R (with initializtion code from TFT vendor)
       
       This library is free software; you can redistribute it and/or
       modify it under the terms of the GNU Lesser General Public
       License as published by the Free Software Foundation; either
       version 2.1 of the License, or (at your option) any later version.


       This library is distributed in the hope that it will be useful,
       but WITHOUT ANY WARRANTY; without even the implied warranty of
       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       Lesser General Public License for more details.


       You should have received a copy of the GNU Lesser General Public
       License along with this library; if not, write to the Free Software
       Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
       */
       /*
         Modified record:
         2012.3.27 by Frankie.Chu
           Add funtion:setDisplayDirect.
           Add more conditional statements in funtions,fillRectangle,drawChar,drawString 
           to deal with different directions displaying.
       */
       #include "TFT.h"
       #include <SPI.h>
      

       void TFT::pushData(unsigned char data)
       {
           all_pin_low();
       #ifdef SEEEDUINO
           PORTD |= (data<<2);
           PORTB |= (data>>6);
       #endif


       #ifdef MEGA


           PORTE |= ((data<<4) & (0x30));
           PORTG |= ((data<<3) & (0x20));
           PORTE |= ((data & 0x08));
           PORTH |= ((data>>1) & (0x78));


       #endif


       #ifdef MAPLE
       #endif
       }


      unsigned char TFT::getData(void)
       {
           unsigned char data=0;
           delay(1);
           data |= ((PIND&0xfc)>>2);
           data |= ((PINB&0x03)<<6);
           return data;
       }
      

       void TFT::sendCommand(unsigned int index)
       {
           CS_LOW;
           RS_LOW;
           RD_HIGH;
           WR_HIGH;
      

           WR_LOW;
           pushData(0);
           WR_HIGH;
           WR_LOW;
           pushData(index&0xff);
           WR_HIGH;
      

           CS_HIGH;
       }
      

       void TFT::sendData(unsigned int data)
       {
           CS_LOW;
           RS_HIGH;
           RD_HIGH;
      

           WR_LOW;
           pushData((data&0xff00)>>8);
           WR_HIGH;
      

           WR_LOW;
           pushData(data&0xff);
           WR_HIGH;


           CS_HIGH;
       }
      

       unsigned int TFT::readRegister(unsigned int index)
       {
           unsigned int data=0;
      

           CS_LOW;
            RS_LOW;
            RD_HIGH;
       

            all_pin_output();
       

            WR_LOW;
            pushData(0);
            WR_HIGH;
       

            WR_LOW;
            pushData(index);
            WR_HIGH;
       

            all_pin_input();
            all_pin_low();
            RS_HIGH;
       

            RD_LOW;
            RD_HIGH;
            data |= getData()<<8;
       

            RD_LOW;
            RD_HIGH;
            data |= getData();
       

            CS_HIGH;
            all_pin_output();
            return data;
        }
       

        void  TFT::init (void)
        {
            CS_OUTPUT;
            RD_OUTPUT;
            WR_OUTPUT;
            RS_OUTPUT;
       

            Tft.all_pin_output();
            Tft.all_pin_low();
       

            delay(100);
       

       

            sendCommand(0x0001);
            sendData(0x0100);
            sendCommand(0x0002);
            sendData(0x0700);
            sendCommand(0x0003);
            sendData(0x1030);
            sendCommand(0x0004);
            sendData(0x0000);
            sendCommand(0x0008);
            sendData(0x0302);
            sendCommand(0x000A);
            sendData(0x0000);
            sendCommand(0x000C);
            sendData(0x0000);
            sendCommand(0x000D);
            sendData(0x0000);
            sendCommand(0x000F);
            sendData(0x0000);
       

            delay(100);
       

            sendCommand(0x0030);
            sendData(0x0000);
            sendCommand(0x0031);
            sendData(0x0405);
            sendCommand(0x0032);
            sendData(0x0203);
            sendCommand(0x0035);
            sendData(0x0004);
            sendCommand(0x0036);
            sendData(0x0B07);
            sendCommand(0x0037);
            sendData(0x0000);
            sendCommand(0x0038);
            sendData(0x0405);
            sendCommand(0x0039);
            sendData(0x0203);
            sendCommand(0x003c);
            sendData(0x0004);
            sendCommand(0x003d);
            sendData(0x0B07);
            sendCommand(0x0020);
            sendData(0x0000);
            sendCommand(0x0021);
            sendData(0x0000);
            sendCommand(0x0050);
            sendData(0x0000);
            sendCommand(0x0051);
            sendData(0x00ef);
            sendCommand(0x0052);
            sendData(0x0000);
            sendCommand(0x0053);
            sendData(0x013f);
       

            delay(100);
       

            sendCommand(0x0060);
            sendData(0xa700);
            sendCommand(0x0061);
            sendData(0x0001);
            sendCommand(0x0090);
            sendData(0x003A);
            sendCommand(0x0095);
            sendData(0x021E);
            sendCommand(0x0080);
            sendData(0x0000);
            sendCommand(0x0081);
            sendData(0x0000);
            sendCommand(0x0082);
            sendData(0x0000);
            sendCommand(0x0083);
            sendData(0x0000);
            sendCommand(0x0084);
            sendData(0x0000);
            sendCommand(0x0085);
            sendData(0x0000);
            sendCommand(0x00FF);
            sendData(0x0001);
           sendCommand(0x00B0);
            sendData(0x140D);
            sendCommand(0x00FF);
            sendData(0x0000);
            delay(100);
            sendCommand(0x0007);
            sendData(0x0133);
            delay(50);
            exitStandBy();
            sendCommand(0x0022);
       

            //paint screen black
            paintScreenBlack();
       }
       

        void TFT::paintScreenBlack(void)
        {
            for(unsigned char i=0;i<2;i++)
            {
                for(unsigned int f=0;f<38400;f++)
                {
                    sendData(BLACK);
                }
            }
        }
       

        void TFT::exitStandBy(void)
        {
            sendCommand(0x0010);
            sendData(0x14E0);
            delay(100);
            sendCommand(0x0007);
            sendData(0x0133);
        }
       

        void TFT::setOrientation(unsigned int HV)//horizontal or vertical
        {
            sendCommand(0x03);
            if(HV==1)//vertical
            {
                sendData(0x5038);
            }
            else//horizontal
            {
                sendData(0x5030);
            }
            sendCommand(0x0022); //Start to write to display RAM
        }
       

        void TFT::setDisplayDirect(unsigned char Direction) 
        {
          DisplayDirect = Direction;
        }
       

        void TFT::setXY(unsigned int poX, unsigned int poY)
        {
            sendCommand(0x0020);//X
            sendData(poX);
            sendCommand(0x0021);//Y
            sendData(poY);
            sendCommand(0x0022);//Start to write to display RAM
        }
       

        void TFT::setPixel(unsigned int poX, unsigned int poY,unsigned int color)
        {
            setXY(poX,poY);
            sendData(color);
        }
       

        void TFT::drawCircle(int poX, int poY, int r,unsigned int color)
        {
            int x = -r, y = 0, err = 2-2*r, e2; 
            do {
                setPixel(poX-x, poY+y,color); 
                setPixel(poX+x, poY+y,color); 
                setPixel(poX+x, poY-y,color); 
                setPixel(poX-x, poY-y,color); 
                e2 = err;
                if (e2 <= y) { 
                    err += ++y*2+1;
                    if (-x == y && e2 <= x) e2 = 0; 
                }
                if (e2 > x) err += ++x*2+1; 
            } while (x <= 0);
        }
       

        void TFT::fillCircle(int poX, int poY, int r,unsigned int color)
        {
            int x = -r, y = 0, err = 2-2*r, e2;
            do {
       

                drawVerticalLine(poX-x,poY-y,2*y,color);
                drawVerticalLine(poX+x,poY-y,2*y,color);
       

                e2 = err;
                if (e2 <= y) {
                    err += ++y*2+1;
                    if (-x == y && e2 <= x) e2 = 0;
                }
                if (e2 > x) err += ++x*2+1;
            } while (x <= 0);
       

        }
       

       

        void TFT::drawLine(unsigned int x0,unsigned int y0,unsigned int x1,unsigned int y1,unsigned int color)
        {
            int x = x1-x0;
            int y = y1-y0;
            int dx = abs(x), sx = x0<x1 ? 1 : -1;
            int dy = -abs(y), sy = y0<y1 ? 1 : -1;
            int err = dx+dy, e2; /* error value e_xy */
            for (;;){ /* loop */
                setPixel(x0,y0,color);
                e2 = 2*err;
                if (e2 >= dy) { /* e_xy+e_x > 0 */
                    if (x0 == x1) break;
                    err += dy; x0 += sx;
                }
                if (e2 <= dx) { /* e_xy+e_y < 0 */
                    if (y0 == y1) break;
                    err += dx; y0 += sy;
                }
            }
        }
       

       

        void TFT::drawVerticalLine(unsigned int poX, unsigned int poY,unsigned int length,unsigned int color)
        {
            setXY(poX,poY);
            setOrientation(1);
            if(length+poY>MAX_Y)
            {
                length=MAX_Y-poY;
            }
       

            for(unsigned int i=0;i<length;i++)
            {
                sendData(color);
            }
        }
       

        void  TFT::drawHorizontalLine(unsigned int poX, unsigned int poY,unsigned int length,unsigned int color)
        {
            setXY(poX,poY);
            setOrientation(0);
            if(length+poX>MAX_X)
            {
                length=MAX_X-poX;
            }
            for(unsigned int i=0;i<length;i++)
            {
                sendData(color);
            }
        }
       

       

        void TFT::drawRectangle(unsigned int poX, unsigned int poY, unsigned int length,unsigned int width,unsigned int color)
        {
            drawHorizontalLine(poX, poY, length, color);
            drawHorizontalLine(poX, poY+width, length, color);
       

            drawVerticalLine(poX, poY, width,color);
            drawVerticalLine(poX + length, poY, width,color);
        }
       

        void TFT::fillRectangle(unsigned int poX, unsigned int poY, unsigned int length, unsigned int width, unsigned int color)
        {
            for(unsigned int i=0;i<width;i++)
            {
                if(DisplayDirect == LEFT2RIGHT)
                  drawHorizontalLine(poX, poY+i, length, color);
                  else if (DisplayDirect ==  DOWN2UP)
                    drawHorizontalLine(poX, poY-i, length, color);
                    else if(DisplayDirect == RIGHT2LEFT)
                      drawHorizontalLine(poX, poY-i, length, color);
                      else if(DisplayDirect == UP2DOWN)
                        drawHorizontalLine(poX, poY+i, length, color);
                      
            }
        }
       

        void TFT::drawChar(unsigned char ascii,unsigned int poX, unsigned int poY,unsigned int size, unsigned int fgcolor)
        {
            
            setXY(poX,poY);
            
            if((ascii < 0x20)||(ascii > 0x7e))//Unsupported char.
            {
                ascii = '?';
            }
            for(unsigned char i=0;i<8;i++)
            {
                unsigned char temp = pgm_read_byte(&simpleFont[ascii-0x20][i]);
                for(unsigned char f=0;f<8;f++)
                {
                    if((temp>>f)&0x01)
                    {
                        if(DisplayDirect == LEFT2RIGHT)
                          fillRectangle(poX+i*size, poY+f*size, size, size, fgcolor);
                          else if(DisplayDirect == DOWN2UP)
                            fillRectangle(poX+f*size, poY-i*size, size, size, fgcolor);
                            else if(DisplayDirect == RIGHT2LEFT)
                              fillRectangle(poX-i*size, poY-f*size, size, size, fgcolor);
                              else if(DisplayDirect == UP2DOWN)
                                fillRectangle(poX-f*size, poY+i*size, size, size, fgcolor);
                    }
       

                }
            }
        }
       

        void TFT::drawString(char *string,unsigned int poX, unsigned int poY,unsigned int size,unsigned int fgcolor)
        {
            while(*string)
            {
                for(unsigned char i=0;i<8;i++)
                {
                    drawChar(*string, poX, poY, size, fgcolor);
                }
                *string++;
                if(DisplayDirect == LEFT2RIGHT)
                {
                  if(poX < MAX_X)
                  {
                      poX+=8*size; // Move cursor right
                  }
                }
                  else if(DisplayDirect == DOWN2UP)
                  {
                    if(poY > 0)
                    {
                        poY-=8*size; // Move cursor right
                    }
                  }
                  else if(DisplayDirect == RIGHT2LEFT)
                {
                  if(poX > 0)
                  {
                      poX-=8*size; // Move cursor right
                  }
                }
                  else if(DisplayDirect == UP2DOWN)
                  {
                    if(poY < MAX_Y)
                    {
                        poY+=8*size; // Move cursor right
                    }
                  }
                  
                  
       

            }
        }
       

        void TFT::all_pin_input(void)
        {
        #ifdef SEEEDUINO
            DDRD &=~ 0xfc;
            DDRB &=~ 0x03;
        #endif
       

        #ifdef MEGA
            DDRE &=~ 0x38;
            DDRG &=~ 0x20;
            DDRH &=~ 0x78;
        #endif
       

        #ifdef MAPLE
       

        #endif
       

        }
       

        void TFT::all_pin_output(void)
        {
        #ifdef SEEEDUINO
            DDRD |= 0xfc;
            DDRB |= 0x03;
        #endif
       

        #ifdef MEGA
            DDRE |= 0x38;
            DDRG |= 0x20;
            DDRH |= 0x78;
        #endif
       

        #ifdef MAPLE
       

        #endif
        }
       

        void TFT::all_pin_low(void)
        {
        #ifdef SEEEDUINO
            PORTD &=~ 0xfc;
            PORTB &=~ 0x03;
        #endif
       

        #ifdef MEGA
            PORTE &=~ 0x38;
            PORTG &=~ 0x20;
            PORTH &=~ 0x78;
        #endif
       

        #ifdef MAPLE
       

        #endif
        }
       

        TFT Tft=TFT();

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • Former Member
    0 Former Member over 11 years ago in reply to Robert Peter Oakes

    I try the new include header but got this error.

    core.a(main.cpp.o): In function `main':
    C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/main.cpp:5: undefined reference to `setup'
    C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/main.cpp:15: undefined reference to `loop'


    This is the sketch that I am using.
    /*
       ST7781R TFT Library. 


       2011 Copyright (c) Seeed Technology Inc.
      
       Authors: Albert.Miao, Visweswara R (with initializtion code from TFT vendor)
       
       This library is free software; you can redistribute it and/or
       modify it under the terms of the GNU Lesser General Public
       License as published by the Free Software Foundation; either
       version 2.1 of the License, or (at your option) any later version.


       This library is distributed in the hope that it will be useful,
       but WITHOUT ANY WARRANTY; without even the implied warranty of
       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
       Lesser General Public License for more details.


       You should have received a copy of the GNU Lesser General Public
       License along with this library; if not, write to the Free Software
       Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
       */
       /*
         Modified record:
         2012.3.27 by Frankie.Chu
           Add funtion:setDisplayDirect.
           Add more conditional statements in funtions,fillRectangle,drawChar,drawString 
           to deal with different directions displaying.
       */
       #include "TFT.h"
       #include <SPI.h>
      

       void TFT::pushData(unsigned char data)
       {
           all_pin_low();
       #ifdef SEEEDUINO
           PORTD |= (data<<2);
           PORTB |= (data>>6);
       #endif


       #ifdef MEGA


           PORTE |= ((data<<4) & (0x30));
           PORTG |= ((data<<3) & (0x20));
           PORTE |= ((data & 0x08));
           PORTH |= ((data>>1) & (0x78));


       #endif


       #ifdef MAPLE
       #endif
       }


      unsigned char TFT::getData(void)
       {
           unsigned char data=0;
           delay(1);
           data |= ((PIND&0xfc)>>2);
           data |= ((PINB&0x03)<<6);
           return data;
       }
      

       void TFT::sendCommand(unsigned int index)
       {
           CS_LOW;
           RS_LOW;
           RD_HIGH;
           WR_HIGH;
      

           WR_LOW;
           pushData(0);
           WR_HIGH;
           WR_LOW;
           pushData(index&0xff);
           WR_HIGH;
      

           CS_HIGH;
       }
      

       void TFT::sendData(unsigned int data)
       {
           CS_LOW;
           RS_HIGH;
           RD_HIGH;
      

           WR_LOW;
           pushData((data&0xff00)>>8);
           WR_HIGH;
      

           WR_LOW;
           pushData(data&0xff);
           WR_HIGH;


           CS_HIGH;
       }
      

       unsigned int TFT::readRegister(unsigned int index)
       {
           unsigned int data=0;
      

           CS_LOW;
            RS_LOW;
            RD_HIGH;
       

            all_pin_output();
       

            WR_LOW;
            pushData(0);
            WR_HIGH;
       

            WR_LOW;
            pushData(index);
            WR_HIGH;
       

            all_pin_input();
            all_pin_low();
            RS_HIGH;
       

            RD_LOW;
            RD_HIGH;
            data |= getData()<<8;
       

            RD_LOW;
            RD_HIGH;
            data |= getData();
       

            CS_HIGH;
            all_pin_output();
            return data;
        }
       

        void  TFT::init (void)
        {
            CS_OUTPUT;
            RD_OUTPUT;
            WR_OUTPUT;
            RS_OUTPUT;
       

            Tft.all_pin_output();
            Tft.all_pin_low();
       

            delay(100);
       

       

            sendCommand(0x0001);
            sendData(0x0100);
            sendCommand(0x0002);
            sendData(0x0700);
            sendCommand(0x0003);
            sendData(0x1030);
            sendCommand(0x0004);
            sendData(0x0000);
            sendCommand(0x0008);
            sendData(0x0302);
            sendCommand(0x000A);
            sendData(0x0000);
            sendCommand(0x000C);
            sendData(0x0000);
            sendCommand(0x000D);
            sendData(0x0000);
            sendCommand(0x000F);
            sendData(0x0000);
       

            delay(100);
       

            sendCommand(0x0030);
            sendData(0x0000);
            sendCommand(0x0031);
            sendData(0x0405);
            sendCommand(0x0032);
            sendData(0x0203);
            sendCommand(0x0035);
            sendData(0x0004);
            sendCommand(0x0036);
            sendData(0x0B07);
            sendCommand(0x0037);
            sendData(0x0000);
            sendCommand(0x0038);
            sendData(0x0405);
            sendCommand(0x0039);
            sendData(0x0203);
            sendCommand(0x003c);
            sendData(0x0004);
            sendCommand(0x003d);
            sendData(0x0B07);
            sendCommand(0x0020);
            sendData(0x0000);
            sendCommand(0x0021);
            sendData(0x0000);
            sendCommand(0x0050);
            sendData(0x0000);
            sendCommand(0x0051);
            sendData(0x00ef);
            sendCommand(0x0052);
            sendData(0x0000);
            sendCommand(0x0053);
            sendData(0x013f);
       

            delay(100);
       

            sendCommand(0x0060);
            sendData(0xa700);
            sendCommand(0x0061);
            sendData(0x0001);
            sendCommand(0x0090);
            sendData(0x003A);
            sendCommand(0x0095);
            sendData(0x021E);
            sendCommand(0x0080);
            sendData(0x0000);
            sendCommand(0x0081);
            sendData(0x0000);
            sendCommand(0x0082);
            sendData(0x0000);
            sendCommand(0x0083);
            sendData(0x0000);
            sendCommand(0x0084);
            sendData(0x0000);
            sendCommand(0x0085);
            sendData(0x0000);
            sendCommand(0x00FF);
            sendData(0x0001);
           sendCommand(0x00B0);
            sendData(0x140D);
            sendCommand(0x00FF);
            sendData(0x0000);
            delay(100);
            sendCommand(0x0007);
            sendData(0x0133);
            delay(50);
            exitStandBy();
            sendCommand(0x0022);
       

            //paint screen black
            paintScreenBlack();
       }
       

        void TFT::paintScreenBlack(void)
        {
            for(unsigned char i=0;i<2;i++)
            {
                for(unsigned int f=0;f<38400;f++)
                {
                    sendData(BLACK);
                }
            }
        }
       

        void TFT::exitStandBy(void)
        {
            sendCommand(0x0010);
            sendData(0x14E0);
            delay(100);
            sendCommand(0x0007);
            sendData(0x0133);
        }
       

        void TFT::setOrientation(unsigned int HV)//horizontal or vertical
        {
            sendCommand(0x03);
            if(HV==1)//vertical
            {
                sendData(0x5038);
            }
            else//horizontal
            {
                sendData(0x5030);
            }
            sendCommand(0x0022); //Start to write to display RAM
        }
       

        void TFT::setDisplayDirect(unsigned char Direction) 
        {
          DisplayDirect = Direction;
        }
       

        void TFT::setXY(unsigned int poX, unsigned int poY)
        {
            sendCommand(0x0020);//X
            sendData(poX);
            sendCommand(0x0021);//Y
            sendData(poY);
            sendCommand(0x0022);//Start to write to display RAM
        }
       

        void TFT::setPixel(unsigned int poX, unsigned int poY,unsigned int color)
        {
            setXY(poX,poY);
            sendData(color);
        }
       

        void TFT::drawCircle(int poX, int poY, int r,unsigned int color)
        {
            int x = -r, y = 0, err = 2-2*r, e2; 
            do {
                setPixel(poX-x, poY+y,color); 
                setPixel(poX+x, poY+y,color); 
                setPixel(poX+x, poY-y,color); 
                setPixel(poX-x, poY-y,color); 
                e2 = err;
                if (e2 <= y) { 
                    err += ++y*2+1;
                    if (-x == y && e2 <= x) e2 = 0; 
                }
                if (e2 > x) err += ++x*2+1; 
            } while (x <= 0);
        }
       

        void TFT::fillCircle(int poX, int poY, int r,unsigned int color)
        {
            int x = -r, y = 0, err = 2-2*r, e2;
            do {
       

                drawVerticalLine(poX-x,poY-y,2*y,color);
                drawVerticalLine(poX+x,poY-y,2*y,color);
       

                e2 = err;
                if (e2 <= y) {
                    err += ++y*2+1;
                    if (-x == y && e2 <= x) e2 = 0;
                }
                if (e2 > x) err += ++x*2+1;
            } while (x <= 0);
       

        }
       

       

        void TFT::drawLine(unsigned int x0,unsigned int y0,unsigned int x1,unsigned int y1,unsigned int color)
        {
            int x = x1-x0;
            int y = y1-y0;
            int dx = abs(x), sx = x0<x1 ? 1 : -1;
            int dy = -abs(y), sy = y0<y1 ? 1 : -1;
            int err = dx+dy, e2; /* error value e_xy */
            for (;;){ /* loop */
                setPixel(x0,y0,color);
                e2 = 2*err;
                if (e2 >= dy) { /* e_xy+e_x > 0 */
                    if (x0 == x1) break;
                    err += dy; x0 += sx;
                }
                if (e2 <= dx) { /* e_xy+e_y < 0 */
                    if (y0 == y1) break;
                    err += dx; y0 += sy;
                }
            }
        }
       

       

        void TFT::drawVerticalLine(unsigned int poX, unsigned int poY,unsigned int length,unsigned int color)
        {
            setXY(poX,poY);
            setOrientation(1);
            if(length+poY>MAX_Y)
            {
                length=MAX_Y-poY;
            }
       

            for(unsigned int i=0;i<length;i++)
            {
                sendData(color);
            }
        }
       

        void  TFT::drawHorizontalLine(unsigned int poX, unsigned int poY,unsigned int length,unsigned int color)
        {
            setXY(poX,poY);
            setOrientation(0);
            if(length+poX>MAX_X)
            {
                length=MAX_X-poX;
            }
            for(unsigned int i=0;i<length;i++)
            {
                sendData(color);
            }
        }
       

       

        void TFT::drawRectangle(unsigned int poX, unsigned int poY, unsigned int length,unsigned int width,unsigned int color)
        {
            drawHorizontalLine(poX, poY, length, color);
            drawHorizontalLine(poX, poY+width, length, color);
       

            drawVerticalLine(poX, poY, width,color);
            drawVerticalLine(poX + length, poY, width,color);
        }
       

        void TFT::fillRectangle(unsigned int poX, unsigned int poY, unsigned int length, unsigned int width, unsigned int color)
        {
            for(unsigned int i=0;i<width;i++)
            {
                if(DisplayDirect == LEFT2RIGHT)
                  drawHorizontalLine(poX, poY+i, length, color);
                  else if (DisplayDirect ==  DOWN2UP)
                    drawHorizontalLine(poX, poY-i, length, color);
                    else if(DisplayDirect == RIGHT2LEFT)
                      drawHorizontalLine(poX, poY-i, length, color);
                      else if(DisplayDirect == UP2DOWN)
                        drawHorizontalLine(poX, poY+i, length, color);
                      
            }
        }
       

        void TFT::drawChar(unsigned char ascii,unsigned int poX, unsigned int poY,unsigned int size, unsigned int fgcolor)
        {
            
            setXY(poX,poY);
            
            if((ascii < 0x20)||(ascii > 0x7e))//Unsupported char.
            {
                ascii = '?';
            }
            for(unsigned char i=0;i<8;i++)
            {
                unsigned char temp = pgm_read_byte(&simpleFont[ascii-0x20][i]);
                for(unsigned char f=0;f<8;f++)
                {
                    if((temp>>f)&0x01)
                    {
                        if(DisplayDirect == LEFT2RIGHT)
                          fillRectangle(poX+i*size, poY+f*size, size, size, fgcolor);
                          else if(DisplayDirect == DOWN2UP)
                            fillRectangle(poX+f*size, poY-i*size, size, size, fgcolor);
                            else if(DisplayDirect == RIGHT2LEFT)
                              fillRectangle(poX-i*size, poY-f*size, size, size, fgcolor);
                              else if(DisplayDirect == UP2DOWN)
                                fillRectangle(poX-f*size, poY+i*size, size, size, fgcolor);
                    }
       

                }
            }
        }
       

        void TFT::drawString(char *string,unsigned int poX, unsigned int poY,unsigned int size,unsigned int fgcolor)
        {
            while(*string)
            {
                for(unsigned char i=0;i<8;i++)
                {
                    drawChar(*string, poX, poY, size, fgcolor);
                }
                *string++;
                if(DisplayDirect == LEFT2RIGHT)
                {
                  if(poX < MAX_X)
                  {
                      poX+=8*size; // Move cursor right
                  }
                }
                  else if(DisplayDirect == DOWN2UP)
                  {
                    if(poY > 0)
                    {
                        poY-=8*size; // Move cursor right
                    }
                  }
                  else if(DisplayDirect == RIGHT2LEFT)
                {
                  if(poX > 0)
                  {
                      poX-=8*size; // Move cursor right
                  }
                }
                  else if(DisplayDirect == UP2DOWN)
                  {
                    if(poY < MAX_Y)
                    {
                        poY+=8*size; // Move cursor right
                    }
                  }
                  
                  
       

            }
        }
       

        void TFT::all_pin_input(void)
        {
        #ifdef SEEEDUINO
            DDRD &=~ 0xfc;
            DDRB &=~ 0x03;
        #endif
       

        #ifdef MEGA
            DDRE &=~ 0x38;
            DDRG &=~ 0x20;
            DDRH &=~ 0x78;
        #endif
       

        #ifdef MAPLE
       

        #endif
       

        }
       

        void TFT::all_pin_output(void)
        {
        #ifdef SEEEDUINO
            DDRD |= 0xfc;
            DDRB |= 0x03;
        #endif
       

        #ifdef MEGA
            DDRE |= 0x38;
            DDRG |= 0x20;
            DDRH |= 0x78;
        #endif
       

        #ifdef MAPLE
       

        #endif
        }
       

        void TFT::all_pin_low(void)
        {
        #ifdef SEEEDUINO
            PORTD &=~ 0xfc;
            PORTB &=~ 0x03;
        #endif
       

        #ifdef MEGA
            PORTE &=~ 0x38;
            PORTG &=~ 0x20;
            PORTH &=~ 0x78;
        #endif
       

        #ifdef MAPLE
       

        #endif
        }
       

        TFT Tft=TFT();

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
  • Robert Peter Oakes
    0 Robert Peter Oakes over 11 years ago in reply to Former Member

    This seems to be the Library, not the main sketch

     

     

     

    You should have a sketch that looks like this

     

     

     

    /*

     

      Arduino TFT text example

     

       

     

      This example demonstrates how to draw text on the

     

      TFT with an Arduino. The Arduino reads the value

     

      of an analog sensor attached to pin A0, and writes

     

      the value to the LCD screen, updating every

     

      quarter second.

     

       

     

      This example code is in the public domain

     

     

     

      Created 15 April 2013 by Scott Fitzgerald

     

      http://arduino.cc/en/Tutorial/TFTDisplayText

     

    */

     

     

     

    #include <TFT.h>  // Arduino LCD library  <-- replace this with yours

     

    #include <SPI.h>

     

     

     

    // pin definition for the Uno

     

    #define cs   10

     

    #define dc   9

     

    #define rst  8 

     

     

     

    // pin definition for the Leonardo

     

    // #define cs   7

     

    // #define dc   0

     

    // #define rst  1

     

     

     

    // create an instance of the library

     

    TFT TFTscreen = TFT(cs, dc, rst);

     

     

     

    // char array to print to the screen

     

    char sensorPrintout[4];

     

     

     

    void setup() {

     

       

     

      // Put this line at the beginning of every sketch that uses the GLCD:

     

      TFTscreen.begin();

     

     

     

      // clear the screen with a black background

     

      TFTscreen.background(0, 0, 0);

     

       

     

      // write the static text to the screen

     

      // set the font color to white

     

      TFTscreen.stroke(255,255,255);

     

      // set the font size

     

      TFTscreen.setTextSize(2);

     

      // write the text to the top left corner of the screen

     

      TFTscreen.text("Sensor Value :\n ",0,0);

     

      // ste the font size very large for the loop

     

      TFTscreen.setTextSize(5);

     

    }

     

     

     

    void loop() {

     

     

     

      // Read the value of the sensor on A0

     

      String sensorVal = String(analogRead(A0));

     

      // convert the reading to a char array

     

      sensorVal.toCharArray(sensorPrintout, 4);

     

     

     

      // set the font color

     

      TFTscreen.stroke(255,255,255);

     

      // print the sensor value

     

      TFTscreen.text(sensorPrintout, 0, 20);

     

      // wait for a moment

     

      delay(250);

     

      // erase the text you just wrote

     

      TFTscreen.stroke(0,0,0);

     

      TFTscreen.text(sensorPrintout, 0, 20);

     

    }

     

     

     

    The areas highlighted are the two main program functions. Setup is called once, loop is repeatedly called in a loop from the underlying wiring framework

     

     

     

    What you showed me is the library and it will not run without a sketch. If you look at the top of the one I included here you will see the TFT library include, this should be the name of your library, then the SPI library.

     

     

     

    What you posted seems to indicate you are trying to run the library directly

     

     

     

    Btw, the sample I put above comes straight from the IDE samples under FTF.

     

     

     

    Your library should have also with luck included some example sketches

     

     

     

    Regards

     

     

     

    Peter

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to Robert Peter Oakes

    Well I try the new sketch that you sent me and I went through.

    PLus I change the board to UNO and will now pass it to the microcontroller .

    Thank you, until the next time.

    Freddy King Jr.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to Robert Peter Oakes

    I am looking for the identification of the "2.8 TFT Touch Shield v1.0" From seeed studio?

    On the back it show power PB,PC and PD. I don't know what each pin is.

    Can you send me to a site that identified these pins?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 10 years ago in reply to Former Member

    Freddy,

     

    Which Arduino board are you using? If you drop the shield onto either the Uno or the Mega, it'll line up perfectly. From there, you can identify which pins are what.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube