Pages: [1]   Go Down
Author Topic: 2.8" Touch Shield question  (Read 1569 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just shelled out $50 for a Seeeduino Touch Screen V1.0 [2.8" TFT Touch Shield] at Radio Shack

My first problem is that somehow Radio Shack still exists. How is this possible?

My second problem is that no matter what I do, I always get trouble compiling the example sketches will always fail. Some with more or less errors than others.

The only real scrap of help google could give me was this:
http://arduino.cc/forum/index.php?topic=131465.0
Which at least got me the correct libraries.

So far, "paint" has given me the least trouble, but I still get this:

Code:
paint:50: error: 'A2' was not declared in this scope
paint:50: error: 'A1' was not declared in this scope
which refers to this line:
Code:
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300); //init TouchScreen port pins
I can't find any references to A1 or A2 in either of the libraries I am using.

I have tried EVERYTHING, even the newer libraries for the v2.0 (I don't even know why).

I have an original Uno and I'm using Arduino IDE version 1.0.4
I'm not having trouble with anything else involving the Uno. In fact, it's not even plugged in. None of the examples will compile.

What am I missing?

[P.S. You would think the people who manufacture and sell these things would provide more documentation rather than making their users maintain their wiki]
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Can you please post the code you are trying to compile, plus a link to wherever you got the libraries from.

How to use this forum
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Also, what Arduino do you have, and what one have you selected in the IDE's Tools->Board menu?

A1 and A2 normally refer to analog ports 1 and 2.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm using an Arduino Uno, original 1.0

I'm using the TFT.h, TouchScreen.h and the examples which are included in the package found in the resources downloads on the wiki page for the device
http://www.seeedstudio.com/wiki/2.8''_TFT_Touch_Shield_V1.0#Resources

I haven't modified the code at all. I would post it here if I was at my computer.

I can't find A1 or A2 anywhere in the tft or touch screen libraries. I haven't checked the other libraries used by the sketches yet. I get the not declared part, buy I'm not sure what "in this scope" means.

I think the fundamental problem is that I'm using either outdated, incompatible, or insufficient code to interface a product primarily designed for seeeduino with arduino.
Logged

Pennsylvania
Offline Offline
Newbie
*
Karma: 0
Posts: 40
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Go to this topic on the SEEED Shields forum: 2.8" Touch Shield w/ Arduino Uno: TFT IC_CODE Error.  There you will find the correct libraries to download.

Post back your result.
Logged

Software's good, software's impressive, but it's hardware that does the work.

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Tried new libraries. Same Result.

Here are the files I am using:

TFT.h
Code:
/*
  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 the macro definitions,public funtion and private variable for the char display direction.
*/
#include <Arduino.h>
#include <avr/pgmspace.h>

#ifndef TFT_h
#define TFT_h

#define SEEEDUINO

//Basic Colors
#define RED 0xf800
#define GREEN 0x07e0
#define BLUE 0x001f
#define BLACK 0x0000
#define YELLOW 0xffe0
#define WHITE 0xffff

//Other Colors
#define CYAN 0x07ff
#define BRIGHT_RED 0xf810
#define GRAY1 0x8410  
#define GRAY2 0x4208  

//TFT resolution 240*320
#define MIN_X 0
#define MIN_Y 0
#define MAX_X 240
#define MAX_Y 320

#ifdef SEEEDUINO

//========================================
#define DDR_CS      DDRB
#define PORT_CS     PORTB
#define CS_BIT      0x04
#define CS_OUTPUT   {DDR_CS|=CS_BIT;}
#define CS_HIGH     {PORT_CS|=CS_BIT;}
#define CS_LOW      {PORT_CS&=~CS_BIT;}

//-----------------------------------------

#define DDR_RS      DDRB
#define PORT_RS     PORTB
#define RS_BIT      0x08
#define RS_OUTPUT   {DDR_RS|=RS_BIT;}
#define RS_HIGH     {PORT_RS|=RS_BIT;}
#define RS_LOW      {PORT_RS&=~RS_BIT;}

//-----------------------------------------

#define DDR_WR      DDRB
#define PORT_WR     PORTB
#define WR_BIT      0x10
#define WR_OUTPUT   {DDR_WR|=WR_BIT;}
#define WR_HIGH     {PORT_WR|=WR_BIT;}
#define WR_LOW      {PORT_WR&=~WR_BIT;}
#define WR_RISING   {PORT_WR|=WR_BIT;PORT_WR&=~WR_BIT;}

//-----------------------------------------

#define DDR_RD      DDRB
#define PORT_RD     PORTB
#define RD_BIT      0x20
#define RD_OUTPUT   {DDR_RD|=RD_BIT;}
#define RD_HIGH     {PORT_RD|=RD_BIT;}
#define RD_LOW      {PORT_RD&=~RD_BIT;}
#define RD_RISING   {PORT_RD|=RD_BIT;PORT_RD&=~RD_BIT;}
//========================================

#endif

#ifdef MEGA
//==================/CS=====================
#define DDR_CS      DDRB
#define PORT_CS     PORTB
#define CS_BIT      0x10
#define CS_OUTPUT   {DDR_CS|=CS_BIT;}
#define CS_HIGH     {PORT_CS|=CS_BIT;}
#define CS_LOW      {PORT_CS&=~CS_BIT;}

//------------------RS----------------------

#define DDR_RS      DDRB
#define PORT_RS     PORTB
#define RS_BIT      0x20
#define RS_OUTPUT   {DDR_RS|=RS_BIT;}
#define RS_HIGH     {PORT_RS|=RS_BIT;}
#define RS_LOW      {PORT_RS&=~RS_BIT;}

//------------------WR----------------------

#define DDR_WR      DDRB
#define PORT_WR     PORTB
#define WR_BIT      0x40
#define WR_OUTPUT   {DDR_WR|=WR_BIT;}
#define WR_HIGH     {PORT_WR|=WR_BIT;}
#define WR_LOW      {PORT_WR&=~WR_BIT;}
#define WR_RISING   {PORT_WR|=WR_BIT;PORT_WR&=~WR_BIT;}

//------------------RD---------------------

#define DDR_RD      DDRB
#define PORT_RD     PORTB
#define RD_BIT      0x80
#define RD_OUTPUT   {DDR_RD|=RD_BIT;}
#define RD_HIGH     {PORT_RD|=RD_BIT;}
#define RD_LOW      {PORT_RD&=~RD_BIT;}
#define RD_RISING   {PORT_RD|=RD_BIT;PORT_RD&=~RD_BIT;}
//========================================

#endif

#ifdef MAPLE
 // not yet implemented
#endif

/**Macro definitions for char display direction**/
#define LEFT2RIGHT 0
#define DOWN2UP    1
#define RIGHT2LEFT 2
#define UP2DOWN    3

extern unsigned char simpleFont[][8];

class TFT
{
public:

    void init (void);
    void sendCommand(unsigned int index);
    void sendData(unsigned int data);
    void pushData(unsigned char data);
    unsigned char getData(void);
    unsigned int readRegister(unsigned int index);

    void setXY(unsigned int poX, unsigned int poY);
    void setPixel(unsigned int poX, unsigned int poY,unsigned int color);
    void drawLine(unsigned int x0,unsigned int y0,unsigned int x1,unsigned int y1,unsigned int color);
    void drawVerticalLine(unsigned int poX, unsigned int poY,unsigned int length,unsigned int color);
    void drawHorizontalLine(unsigned int poX, unsigned int poY,unsigned int length,unsigned int color);
    void drawRectangle(unsigned int poX, unsigned int poY, unsigned int length,unsigned int width,unsigned int color);
    void fillRectangle(unsigned int poX, unsigned int poY, unsigned int length, unsigned int width, unsigned int color);
    void drawCircle(int poX, int poY, int r,unsigned int color);
    void fillCircle(int poX, int poY, int r,unsigned int color);
    void drawChar(unsigned char ascii,unsigned int poX, unsigned int poY,unsigned int size, unsigned int fgcolor);
    void drawString(char *string,unsigned int poX, unsigned int poY,unsigned int size,unsigned int fgcolor);
    
    void all_pin_input(void);
    void all_pin_output(void);
    void all_pin_low(void);

    void setOrientation(unsigned int HV);
    void setDisplayDirect(unsigned char = LEFT2RIGHT);
    void paintScreenBlack(void);
private:
    void exitStandBy(void);
    unsigned char DisplayDirect;
};

extern TFT Tft;

#endif



TouchScreen.h

Code:
// Touch screen library with X Y and Z (pressure) readings as well
// as oversampling to avoid 'bouncing'
// (c) ladyada / adafruit
// Code under MIT License

class Point {
 public:
  Point(void);
  Point(int16_t x, int16_t y, int16_t z);
  
  bool operator==(Point);
  bool operator!=(Point);

  int16_t x, y, z;
};

class TouchScreen {
 public:
  TouchScreen(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym);
  TouchScreen(uint8_t xp, uint8_t yp, uint8_t xm, uint8_t ym, uint16_t rx);

  bool isTouching(void);
  uint16_t pressure(void);
  int readTouchY();
  int readTouchX();
  Point getPoint();
  int16_t pressureThreshhold;

private:
  uint8_t _yp, _ym, _xm, _xp;
  uint16_t _rxplate;
};

Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

paint.ino (The sketch I am trying to compile
Code:
// Paint application - Demonstate both TFT and Touch Screen
//  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
#include <stdint.h>
#include <TouchScreen.h>
#include <TFT.h>

#ifdef SEEEDUINO
  #define YP A2   // must be an analog pin, use "An" notation!
  #define XM A1   // must be an analog pin, use "An" notation!
  #define YM 14   // can be a digital pin, this is A0
  #define XP 17   // can be a digital pin, this is A3
#endif

#ifdef MEGA
  #define YP A2   // must be an analog pin, use "An" notation!
  #define XM A1   // must be an analog pin, use "An" notation!
  #define YM 54   // can be a digital pin, this is A0
  #define XP 57   // can be a digital pin, this is A3
#endif
//Measured ADC values for (0,0) and (210-1,320-1)
//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 = 240 -1
//TS_MAXY corresponds to ADC value when Y = 320 -1

#define TS_MINX 140
#define TS_MAXX 900
#define TS_MINY 120
#define TS_MAXY 940

int color = WHITE;  //Paint brush color

// 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, 300); //init TouchScreen port pins

void setup()
{

Tft.init();  //init TFT library
pinMode(0,OUTPUT);
//Draw the pallet
Tft.fillRectangle(0,0,30,10,BLACK);
Tft.fillRectangle(30,0,30,10,RED);
Tft.fillRectangle(60,0,30,10,GREEN);
Tft.fillRectangle(90,0,30,10,BLUE);
Tft.fillRectangle(120,0,30,10,CYAN);
Tft.fillRectangle(150,0,30,10,YELLOW);
Tft.fillRectangle(180,0,30,10,WHITE);
Tft.fillRectangle(210,0,30,10,GRAY1);

}

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

  //map the ADC value read to into pixel co-ordinates

  p.x = map(p.x, TS_MINX, TS_MAXX, 240, 0);
  p.y = map(p.y, TS_MINY, TS_MAXY, 320, 0);
 
  // we have some minimum pressure we consider 'valid'
  // pressure of 0 means no pressing!

  if (p.z > ts.pressureThreshhold) {
 
 
 // Detect  paint brush color change
 if(p.y < 15)
  {
    if(p.x >= 0 && p.x < 30)
    {
      color = BLACK;
    }
    if(p.x >= 30 && p.x < 60)
    {
      color = RED;
      digitalWrite(0,HIGH);
    }
    if(p.x >= 60 && p.x < 90)
    {
      color = GREEN;
    }
    if(p.x >= 90 && p.x < 110)
    {
      color = BLUE;
      digitalWrite(0,LOW);
    }
    if(p.x >= 120 && p.x < 150)
    {
      color = CYAN;
    }
    if(p.x >= 150 && p.x < 180)
    {
      color = YELLOW;
    }
    if(p.x >= 180 && p.x < 210)
    {
      color = WHITE;
    }
    if(p.x >= 210 && p.x < 240)
    {
      color = GRAY1;
    }   
  }
  else   
  {
      Tft.fillCircle(p.x,p.y,2,color);
  }
     
 }

}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry for triple post.

I tried replacing A1 and A2 with the actual pin numbers, and ended up with these errors instead:

Code:
In file included from D:\Program Files\Robot\arduino\hardware\arduino\cores\arduino/wiring_private.h:33,
                 from D:\Program Files\Robot\arduino\libraries\TouchScreen\TouchScreen.cpp:7:
D:\Program Files\Robot\arduino\hardware\arduino\cores\arduino/pins_arduino.h:66: error: previous declaration of 'const uint16_t port_to_mode_PGM []' with 'C++' linkage
D:\Program Files\Robot\arduino\hardware\arduino\cores\arduino/Arduino.h:127: error: conflicts with new declaration with 'C' linkage
D:\Program Files\Robot\arduino\hardware\arduino\cores\arduino/pins_arduino.h:67: error: previous declaration of 'const uint16_t port_to_input_PGM []' with 'C++' linkage
D:\Program Files\Robot\arduino\hardware\arduino\cores\arduino/Arduino.h:128: error: conflicts with new declaration with 'C' linkage
D:\Program Files\Robot\arduino\hardware\arduino\cores\arduino/pins_arduino.h:68: error: previous declaration of 'const uint16_t port_to_output_PGM []' with 'C++' linkage
D:\Program Files\Robot\arduino\hardware\arduino\cores\arduino/Arduino.h:129: error: conflicts with new declaration with 'C' linkage
D:\Program Files\Robot\arduino\hardware\arduino\cores\arduino/pins_arduino.h:70: error: previous declaration of 'const uint8_t digital_pin_to_port_PGM []' with 'C++' linkage
D:\Program Files\Robot\arduino\hardware\arduino\cores\arduino/Arduino.h:131: error: conflicts with new declaration with 'C' linkage
D:\Program Files\Robot\arduino\hardware\arduino\cores\arduino/pins_arduino.h:72: error: previous declaration of 'const uint8_t digital_pin_to_bit_mask_PGM []' with 'C++' linkage
D:\Program Files\Robot\arduino\hardware\arduino\cores\arduino/Arduino.h:133: error: conflicts with new declaration with 'C' linkage
D:\Program Files\Robot\arduino\hardware\arduino\cores\arduino/pins_arduino.h:73: error: previous declaration of 'const uint8_t digital_pin_to_timer_PGM []' with 'C++' linkage
D:\Program Files\Robot\arduino\hardware\arduino\cores\arduino/Arduino.h:134: error: conflicts with new declaration with 'C' linkage


Edit: Which looks like the error I get when I try any other example sketch
« Last Edit: March 27, 2013, 08:27:34 pm by SuperMechaCow » Logged

Pennsylvania
Offline Offline
Newbie
*
Karma: 0
Posts: 40
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The only thing left that I can think of is to verify your libraries are in the one and only correct location, and that there are no other libraries with similar names, such as TFT.old.h, or TFT.h.mod, etc. 
I found that libraries I had modified to try various things were getting read, even though they were named differently, but still contained TFT (for example).  I had to remove all experimental libraries from my folder where the TFT and Touch libraries reside.

I use a Mac so I don't know the location for your libraries.

I have verified that the Paint sketch does run with Arduino 1.04.

Post back results.

-__-
Logged

Software's good, software's impressive, but it's hardware that does the work.

Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yea I took it back to radioshack. I figured I'll

A: Not buy parts compulsively and save a lot of money by getting them online after doing research on them

B: Tackle this kind of stuff when I'm a little more educated on hardware
Logged

Pages: [1]   Go Up
Jump to: