element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • 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
  • About Us
  • 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
Design for a Cause - Design Challenge
  • Challenges & Projects
  • Design Challenges
  • Design for a Cause - Design Challenge
  • More
  • Cancel
Design for a Cause - Design Challenge
Blog 5" TFT Display and Module RA8875
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: roborob1266
  • Date Created: 24 Jul 2018 1:58 PM Date Created
  • Views 4755 views
  • Likes 7 likes
  • Comments 12 comments
  • ra8875
  • tft screen
  • wiring
  • design for a cause - design challenge
  • uno
  • arduino coding
  • mkr2uno
  • mkr1000
Related
Recommended

5" TFT Display and Module RA8875

roborob1266
roborob1266
24 Jul 2018

I received the Adafruit 5.0" 40-pin TFT Display 800x480 with Touchscreen PRODUCT ID: 1596 and the RA8875 Driver Board for 40-pin TFT Touch Displays 800 x 480 Max PRODUCT ID: 1590.

I had a hard time getting the display to work with the MKR1000 device so I checked the Adafruit website but no luck on the wiring diagrams or instructions.

I tried the Arduino website and no one had any information on how to wire it up. I tried Google and YouTube for any wiring videos.

I connected my Uno to the RA8875 module and put the jumper wires to the ports listed in the Arduino ino file for the ts_calibration and the TFT display lit up and I was able to get the touch readings!

So with doing that, I tried the MKR2UNO module and wired it as I did with my Uno and it didn't work.

Not be defeated, I looked at the MKR2UNO schematics and compared Pin to Pin with how I had it connected to the Uno and tried some different pins, modified the ino code for the ts_calibration under the Adafruit RA8875 library that I added to Arduino and it worked!

Here are the RA8875 pins and the MKR1000 pins that need to be used for the calibration.

RA8875/ MKR1000

VIN/ PIN 14 = +5

GND/ PIN 11 = GND

SCK/ PIN 09 = SCK

MISO/ PIN 10 = MISO

MOSI/ PIN 08 = MOSI

CS/ PIN 06 = Defined as CS in code

RST/ PIN 02 = Defined as RST

INT/ PIN 03 = Defined as INT

 

I modified the code to look like these pins:

 

#include <SPI.h>

#include "Adafruit_GFX.h"

#include "Adafruit_RA8875.h"

 

 

#define RA8875_INT     3

#define RA8875_CS      6

#define RA8875_RESET   2

 

and finally, I changed the code to reflect the 800x400 rather than the 480x272 display:

 

void setup()

{

  Serial.begin(9600);

  Serial.println("Hello, RA8875!");

 

 

  /* Initialise the display using 'RA8875_480x272' or 'RA8875_800x480' */

    if (!tft.begin(RA8875_800x480))

  {

    Serial.println("RA8875 not found ... check your wires!");

    while (1);

  }

image

  • Sign in to reply

Top Comments

  • roborob1266
    roborob1266 over 7 years ago in reply to genebren +2
    Thank you Gene! The hardship was well worth it since it is working now! Never give up, never surrender!
  • Andrew J
    Andrew J over 5 years ago in reply to roborob1266 +2
    I'm not taking account, per-se, of touch down, move release. When I ask for status (line 05), the response will be -1 if no touch detected, or another value that equates to TOUCH_PRESSED, TOUCH_MOVED,…
  • genebren
    genebren over 7 years ago +1
    Nice update on your design challenge project. Good work on getting everything connected and running. That was some first class detective work there. Gene
Parents
  • genebren
    genebren over 7 years ago

    Nice update on your design challenge project.  Good work on getting everything connected and running.  That was some first class detective work there.

    Gene

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • roborob1266
    roborob1266 over 5 years ago in reply to genebren

    Hi Gene, Are you familiar with Arduino code? I am having an issue with this project (I picked it back up again using an Arduino Mega 2560 connected to an RA8875 (with 5 inch touch screen) and also the VS1053 audio player with SD slot).

    When I touch the screen, the VS1053 plays the audio file twice as if I pressed it twice.

    I think the touch screen connected to the RA8875 is registering when I press the screen and also when I let my finger up.

    I don't know how to stop that from happening. From what I am reading on the web, I think it could be a possible debounce issue but I am not sure nor am I familiar enough with Arduino code.

    I checked many places on the web to see how I can get this to work but I do not understand software debounce in regards to my specific code.

    Any assistance is appreciated. 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • roborob1266
    roborob1266 over 5 years ago in reply to Andrew J

    Hi Andrew

    Not sure if the code i placed above shows what you are looking for. I agree with you that it has to be on a release but what if someone presses one touch screen button then slides their finger to another image and let go there?

    how is that accounted for with your code?

     

    Regards

    Rob

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Andrew J
    Andrew J over 5 years ago in reply to roborob1266

    I'm not taking account, per-se, of touch down, move release.  When I ask for status (line 05), the response will be -1 if no touch detected, or another value that equates to TOUCH_PRESSED, TOUCH_MOVED, TOUCH_RELEASED.  Whilst I don't directly action on the TOUCH_MOVE status, when I get the TOUCH_PRESSED I capture the widget index that was touched (line 08).  When the status is TOUCH_RELEASED, I compare the widget index that was reported at that point with the one at the time of touch and if they are the same then I know that the person touched down and released on the same widget (line 16.)

     

    I looked at the code before to determine that it works on a touch point (co-ordinate) rather than reporting 'what' was touched.  So you will need to do this comparison yourself.  Relevant code appear to be:

     

    void waitForTouchEvent(tsPoint_t * point) {
      /* Clear the touch data object and placeholder variables */
      memset(point, 0, sizeof(tsPoint_t));
    
      /* Clear any previous interrupts to avoid false buffered reads */
      uint16_t x, y;
      tft.touchRead(&x, &y);
      delay(1);
    
    
      /* Wait around for a new touch event (INT pin goes low) */
      while (digitalRead(RA8875_INT)) {
      }
    
      /* Make sure this is really a touch event */
      if (tft.touched()) {
        tft.touchRead(&x, &y);
        point->x = x;
        point->y = y;
        Serial.print("Touch: ");
        Serial.print(point->x); Serial.print(", "); Serial.println(point->y);
      }  else {
        point->x = 0;
        point->y = 0;
      }
    }

     

    Line 12 is waiting for a touch and looping until it detects one - digitalRead(RA8875_INT) becomes 0.  This sets an interrupt flag on the controller. 

     

    Line 16 then tests to see if the screen was touched (returns true if the interrupt flag is set) and if it was, gets the co-ordinates into variables X and Y ( line 17) - reading the co-ordinates clears the flag.  So these three bits of code give you the code for detecting a touch and where.  I suspect you may be right with this controller: the code may run fast enough that it detects a touch, reports it and reads it, before the finger is removed and then it reports a touch again.  To debounce it you will want to 'wait' to process a touch for a small amount of time.

     

    Using the above as an example - you should be able to adjust for your own use:

     

    unsigned long lastTouchTime = millis();
    
    void waitForTouchEvent(tsPoint_t * point) {
      /* Clear the touch data object and placeholder variables */
      memset(point, 0, sizeof(tsPoint_t));
    
      /* Clear any previous interrupts to avoid false buffered reads */
      uint16_t x, y;
      tft.touchRead(&x, &y);
      delay(1);
    
    
      /* Wait around for a new touch event (INT pin goes low) */
      while (digitalRead(RA8875_INT)) {
      }
    
      /* Make sure this is really a touch event */
      if (tft.touched()) {
        tft.touchRead(&x, &y);
        if(millis() - lastTouchTime > 500) {     // if 500mS have passed since last processing a touch then process it.
             point->x = x;
             point->y = y;
             Serial.print("Touch: ");
             Serial.print(point->x); Serial.print(", "); Serial.println(point->y);
        } else {
              // ignore the press as it happened too quickly
              // This else clause is only needed if you need to do something when ignoring the press.
        }
        lastTouchTime = millis();
      } else {
        point->x = 0;
        point->y = 0;
      }
    }

     

    I added line 01 to declare a global variable to keep track of the time the screen was touched.  I added line 20 and 25-28 to wrap around the code to process the touch and if less than 500mS has passed, it ignores it. Line 29 then sets the time it was last touched. You can play around with this value and make it as small as possible - for example, I used a value of 150mS to debounce a mechanical rotary encoder pushswitch. 

     

    You must still execute the tft.touchRead(&x, &y) (line 19) because it is responsible for clearing the flag.

     

    So, this should work by:

    1. waiting for a touch event (line 14)
    2. detect if it was a real touch (is the touch flag set?) - line 18
    3. read the co-ordinates and reset the flag - line 19
    4. check that at least 500mS has passed since last processing a touch - line 20
    5. capture the time of the last press - line 29

    I can't test this of course but it looks ok.  Line 14 you will need to work out for your own application: in the code above it loops forever waiting for a touch - if this isn't something you want, then you'll need to adjust.  The three bits of code I pointed out are the ones you need to work with.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • roborob1266
    roborob1266 over 5 years ago in reply to Andrew J

    Thank you Andrew, I will try this code when i get off of work.

    I was thinking that the Interrupt pin (18) was the key and i was even going try the hardware way of putting a capacitor in line if i couldn't figure out the code.

     

    Thank you again for letting me try this code and I will let you know the outcome!

    Regards,

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • roborob1266
    roborob1266 over 5 years ago in reply to roborob1266

    Hello Andrew,

    i just tried the code (just got some time to try it) and it did not work.

    I noticed that if i hold my finger on the screen, it continue to speak to me saying the same thing as if i keep pressing it.

    very interesting dilemma.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Andrew J
    Andrew J over 5 years ago in reply to roborob1266

    I don't have one of these to test unfortunately.  A bit of googling indicates that the interrupt pin goes HIGH when the panel is being touched, so the while() loop on line 14 isn't quite right I don't think.  Can you cut your code down to the absolute simplest version you can, just to get a grip on the touch handling - in fact, start a new sketch that just does screen touch detect, outputting the X,Y co-ordinates to the Serial monitor every time it detects a touch.  What we should be aiming for, in pseudocode, is something like:

     

    loop()

         clear touch data and reset read interrupts

         while(not touched)  <-- interrupt pin is LOW

              do nothing

         while(touched) <-- interrupt pin is HIGH

              save X,Y coordinates

         if touched and time since last touch > 500mS

              print X,Y coordinates

              save last touch time

         end if

    end loop

     

    What this should do is wait until it detects a touch, then stores the X,Y coordinates until it no longer detects a touch, then prints out the co-ordinates if enough time has passed.

     

    For the moment, forget playing your audio file. startup() should do the minimum it needs to initialise the serial monitor and the display, and loop() should do the above code.  See what happens: are you getting multiple output to the Serial monitor every time you press?  You could try it without the time elapsed element first if you want - it may be clever enough to already detect 'bounce', or indeed not bounce at all.  If we can get this working, then you can expand on it incrementally to detect movement whilst touching (X,Y changes as it detects touches) and so on.

     

    Can I ask - how much coding experience do you have? 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Comment
  • Andrew J
    Andrew J over 5 years ago in reply to roborob1266

    I don't have one of these to test unfortunately.  A bit of googling indicates that the interrupt pin goes HIGH when the panel is being touched, so the while() loop on line 14 isn't quite right I don't think.  Can you cut your code down to the absolute simplest version you can, just to get a grip on the touch handling - in fact, start a new sketch that just does screen touch detect, outputting the X,Y co-ordinates to the Serial monitor every time it detects a touch.  What we should be aiming for, in pseudocode, is something like:

     

    loop()

         clear touch data and reset read interrupts

         while(not touched)  <-- interrupt pin is LOW

              do nothing

         while(touched) <-- interrupt pin is HIGH

              save X,Y coordinates

         if touched and time since last touch > 500mS

              print X,Y coordinates

              save last touch time

         end if

    end loop

     

    What this should do is wait until it detects a touch, then stores the X,Y coordinates until it no longer detects a touch, then prints out the co-ordinates if enough time has passed.

     

    For the moment, forget playing your audio file. startup() should do the minimum it needs to initialise the serial monitor and the display, and loop() should do the above code.  See what happens: are you getting multiple output to the Serial monitor every time you press?  You could try it without the time elapsed element first if you want - it may be clever enough to already detect 'bounce', or indeed not bounce at all.  If we can get this working, then you can expand on it incrementally to detect movement whilst touching (X,Y changes as it detects touches) and so on.

     

    Can I ask - how much coding experience do you have? 

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
Children
No Data
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