RA8875 from Buydisplay

Not open for further replies.
@KurtE - @defragster - @pd0lew

Just downloaded your updated library. Testing on my Adafruit 5" display (800x480). It works better but when I go from corner to corner it draws starting from opposite corner in all rotations.

Pen at 0, 0 with rotation 0 gives:
TX: 766 TY: 479

Sorry for delay but was playing with the BNO055.
Hi @mjs513, what is the values of your calibration settings:
Mine are:
#define TOUCSRCAL_XLOW  80
#define TOUCSRCAL_YLOW  149

I should probably verify that I set the right values when using something like: tft.setTouchCalibrationData(40,996,68,890);

Is this the Adafruit one? I should test on mine...
It may turn out that their touch screen is connected the opposite direction and you need to instead use values like:
tft.setTouchCalibrationData(996, 40,890, 68);
That the Min value is > Max value...

If so I probably need an update to say calibrated...

That is in the function set touch calibration, I have:
	_calibrated = ((minX >= maxX) || (minY >= maxY)) ? false : true;

Maybe should be something simple like:
	_calibrated = ((minX || maxX) && (minY || maxY));

Yes - this is with the Adafruit RA8875.

I used the following cal in the header:
#define TOUCSRCAL_XLOW  40
#define TOUCSRCAL_YLOW  68
Didn't use the settouchCalibration. I also used your values and it did the same thing. I also reversed the min/max values which made it worse.

Update: just tried it with setTouchCalibration and it showed the same behavior. Also tested with the min/max values reversed.

I turned on the T4 with the adafruit one 480x272... And tried doing a calibration and I am seeing Strange values....
I mucked up the calibrate sketch to print out more data and to allow me to run it on one that has calibration data...
/* Simply Touch screen library calibration V2:
  this will help you to calibrate your touch screen by modify
  4 parameters inside RA8875/_utility/RA8875Calibration.h file:
  TOUCSRCAL_XLOW  //min value of x you can get
  TOUCSRCAL_XHIGH  //max value of x you can get
  TOUCSRCAL_YLOW //min value of y you can get
  TOUCSRCAL_YHIGH  //max value of y you can get
  Normally those parameters are set as 0.
  It's not a bullet-proof scientist alghorithm but calibrate
  using this method will be fast and enough accurate for basic
  touch screen operations like buttons, etc. If you need more
  precision and you don't want waste resources consider a capacitive touch!
  Now run this program and open Serial Monitor or follow screen instrunctions.
  Works with Arduino 1.0.6 IDE, Arduino 1.6.x IDE
#include <SPI.h>
#include <RA8875.h>

  You are using 4 wire SPI here, so:
  MOSI:  11//DUE refere to arduino site
  MISO:  12//DUE refere to arduino site
  SCK:   13//DUE refere to arduino site
  the rest of pin below:

#define RA8875_INT 3 //any pin
#define RA8875_CS 10 //see below...
/* DUE: should be any but not sure */
#define RA8875_RESET 9//any pin or nothing!

RA8875 tft = RA8875(RA8875_CS, RA8875_RESET); //arduino's

const uint8_t samples = 20;
uint16_t tempData[samples][2];
volatile int count = 0;
uint16_t tx, ty;//used as temp
uint16_t _XLOW_VAR;
uint16_t _YLOW_VAR;
uint16_t _XHIGH_VAR;
uint16_t _YHIGH_VAR;
bool proceed;
int scount = 0;

#if !defined(USE_RA8875_TOUCH) || defined(_AVOID_TOUCHSCREEN)
#error "you need to enable resistive touchscreen by uncommenting USE_RA8875_TOUCH in settings!"

void setup() {
  long unsigned debug_start = millis ();
  while (!Serial && ((millis () - debug_start) <= 5000)) ;
  //  begin display: Choose from: RA8875_480x272, RA8875_800x480, RA8875_800x480ALT, Adafruit_480x272, Adafruit_800x480
  tft.begin(Adafruit_480x272, 16, 12000000);//initialize RA8875
  /* Adafruit_480x272 Adafruit_800x480 RA8875_480x272 RA8875_800x480 */
  tft.useINT(RA8875_INT);//We use generic int helper for Internal Resistive Touch
  tft.touchBegin();//enable touch support for RA8875
  if (tft.touchCalibrated()) {//already calibrated?
    if (tft.width() > 480)  tft.setFontScale(1);
    Serial.println("You have old calibration data present!\n");
    Serial.println("Will temporarliy clear it!\n");
    tft.setCursor(0, 0);
    tft.println("---> You have old calibration data present! <---");
    tft.println("Will temporarily remove it\n");

  Serial.println("Start calibration, please follow indications...\n");
  Serial.println("\nPlease press FIRMLY the TOP/LEFT angle of your screen now!\n");
  if (tft.width() > 480)  tft.setFontScale(1);
  tft.setCursor(CENTER, CENTER);
  tft.print("Please press the TOP/LEFT angle now!");
  tft.fillCircle(5, 5, 5, RA8875_RED);
  proceed = true;
  //this enable an ISR on CPU and RA8875 INT
  //You can avoid ISR by simple ignore the line above
  //it will use the slower digitalRead(pin) alternative internally

void loop() {
  if (proceed) {
    if (tft.touched()) {
      if (count >= samples) {
        count = 0;//reset counts
        uint32_t valx = 0;
        uint32_t valy = 0;

        if (scount < 1) {
          for (uint8_t i = 0; i < samples; i++) {
            valx += tempData[i][0];
            valy += tempData[i][1];
          valx = valx / samples;
          valy = valy / samples;
          if (tft.width() > 480)  tft.setFontScale(1);
          tft.setCursor(CENTER, CENTER);
          tft.println("Top/Left done. Please do not touch screen...");
          tft.print("Please do not touch screen!");
          Serial.print("Top/Left done...");
          Serial.print("Please do not touch screen...");
          _XLOW_VAR = valx;
          _YLOW_VAR = valy;
          tft.fillCircle(tft.width() - 5, tft.height() - 5, 5, RA8875_RED);
          if (tft.width() > 480)  tft.setFontScale(1);
          tft.setCursor(CENTER, CENTER);
          tft.print("ok, Now Touch Bottom/Right angle!");
          Serial.println("\n...done, Now Touch Bottom/Right angle!");
        } else if (scount >= 1) {
          for (uint8_t i = 0; i < samples; i++) {
            valx += tempData[i][0];
            valy += tempData[i][1];
          valx = valx / samples;
          valy = valy / samples;
          tft.setCursor(0, 20);
          tft.println("Calibration done...watch results!");
          Serial.println("\nCalibration done...watch results");
          _XHIGH_VAR = valx;
          _YHIGH_VAR = valy;
          tft.println("Now open file:");
          Serial.println("\nNow open file RA8875/_utility/RA8875Calibration.h\n");
          Serial.println("Change the following:\n");
          tft.println("Change the following:");
          tft.println(" ");
          tft.print("#define TOUCSRCAL_XLOW   ");
          tft.println(_XLOW_VAR, DEC);
          tft.print("#define TOUCSRCAL_YLOW   ");
          tft.println(_YLOW_VAR, DEC);
          tft.print("#define TOUCSRCAL_XHIGH  ");
          tft.println(_XHIGH_VAR, DEC);
          tft.print("#define TOUCSRCAL_YHIGH  ");
          tft.println(_YHIGH_VAR, DEC);
          tft.println(" ");
          tft.println("...then save file and you are calibrated!");
          Serial.println("#define TOUCSRCAL_XLOW  0");
          Serial.println("#define TOUCSRCAL_YLOW  0");
          Serial.println("#define TOUCSRCAL_XHIGH 0");
          Serial.println("#define TOUCSRCAL_YHIGH 0");
          Serial.print("#define TOUCSRCAL_XLOW  ");
          Serial.println(_XLOW_VAR, DEC);
          Serial.print("#define TOUCSRCAL_YLOW  ");
          Serial.println(_YLOW_VAR, DEC);
          Serial.print("#define TOUCSRCAL_XHIGH ");
          Serial.println(_XHIGH_VAR, DEC);
          Serial.print("#define TOUCSRCAL_YHIGH ");
          Serial.println(_YHIGH_VAR, DEC);
          Serial.println("\nSave and Have a nice day!");
          proceed = false;
      } else {//continue get samples
        tft.touchReadAdc(&tx, &ty);//we using 10bit adc data here
        if (count >= 0) {
          tempData[count][0] = tx;
          tempData[count][1] = ty;
          Serial.printf("count: %d x:%u y:%u\n", count, tx, ty);
And I am getting weird values...
You have old calibration data present!

Will temporarliy clear it!

Start calibration, please follow indications...

Please press FIRMLY the TOP/LEFT angle of your screen now!

count: 0 x:1036 y:975
count: 1 x:1043 y:978
count: 2 x:1038 y:974
count: 3 x:1042 y:974
count: 4 x:1037 y:1069
count: 5 x:1041 y:982
count: 6 x:1043 y:864
count: 7 x:1038 y:979
count: 8 x:1044 y:985
count: 9 x:1041 y:982
count: 10 x:1043 y:978
count: 11 x:1037 y:1079
count: 12 x:1036 y:982
count: 13 x:1037 y:902
count: 14 x:1038 y:985
count: 15 x:1039 y:981
count: 16 x:1041 y:985
count: 17 x:1039 y:984
count: 18 x:1043 y:1036
count: 19 x:1037 y:985
Top/Left done...Please do not touch screen...
...done, Now Touch Bottom/Right angle!
count: 0 x:3 y:65527
count: 1 x:7 y:65527
count: 2 x:0 y:65531
count: 3 x:3 y:65530
count: 4 x:4 y:65534
count: 5 x:4 y:0
count: 6 x:0 y:65524
count: 7 x:8 y:65524
count: 8 x:4 y:65531
count: 9 x:7 y:65524
count: 10 x:11 y:65532
count: 11 x:3 y:65521
count: 12 x:6 y:65528
count: 13 x:8 y:65531
count: 14 x:7 y:65530
count: 15 x:7 y:65527
count: 16 x:11 y:65528
count: 17 x:6 y:65528
count: 18 x:8 y:13
count: 19 x:4 y:65524

Calibration done...watch results

Now open file RA8875/_utility/RA8875Calibration.h

Change the following:



#define TOUCSRCAL_XLOW  1039
#define TOUCSRCAL_YLOW  982
#define TOUCSRCAL_YHIGH 58975

Save and Have a nice day!
I am guessing I need to update a couple more places including what I mentioned about allowing min > max

instead of calling it min and max, it should probably be called something like TOUCHCAL_UL_X TOUCHCAL_UL_Y TOUCHCAL_LR_X TOUCHCAL_LR_Y
or the like, but don't know if I wish to muck up everything...

So will let you know when I have something that works on this one... Hopefully it does not require changing other stuff like the clocks...
Last edited:
@mjs513 - I now have it working on my Adafruit...

Pushed up changes, that properly clear out the calibration data when you are asking for ADC value and not point when there is calibration data.
Also allows MIN > MAX for calibration.

So ran the calibration stuff on Adafruit display, left the Buydisplay values in header file.
It printed out new values to be used, that was: tft.setTouchCalibrationData(946, 77, 880, 130);

So added that to my touch test program, and all 4 directions appeared to draw properly...

Put my calibration values in the header (min > max) and it works perfectly in all 4 rotations. So I think you broke the code. Assuming it still works on the BuyDisplay?

Think we got one more problem to solve - not with touch though. Just tried the easyPaint sketch real quick. It did work (at least the touch did once I remember to fix the constructor) with the except that the colors are messed up. No red's no whites not magenta - there is cyan, green, blue....
I assume your constructor has the Adafruit with the right settings...

You might also try with Adafruit library and sketch to see if your display is working?

Here is mine running updated, for my display
void setup() 
  //while (!Serial) {;}
  Serial.println("RA8875 start");

  //  begin display: Choose from: RA8875_480x272, RA8875_800x480, RA8875_800x480ALT, Adafruit_480x272, Adafruit_800x480
  tft.begin(Adafruit_480x272, 16, 12000000);//initialize library
  tft.setTouchCalibrationData(946, 77, 880, 130);
  tft.useINT(RA8875_INT);//We use generic int helper for Internal Resistive Touch
  tft.touchBegin();//enable Touch support!


Got to run
Hi @mjs513 and @neurofun - As a test you might try changing SPI.cpp

To see if maybe the settings that I am experimenting with make a difference... About line 1284

// uint32_t fastio = IOMUXC_PAD_SRE | IOMUXC_PAD_DSE(3) | IOMUXC_PAD_SPEED(3);
uint32_t fastio = IOMUXC_PAD_DSE(6) | IOMUXC_PAD_SPEED(1);
Just want to confirm that this indeed makes a difference.
My initial test had the 4.3" display plugged straight in my T4 protoboard and it worked without these settings.
After adding a 20cm(8") long flat cable the display stopped working.
Now with these settings the display works again.
I was even able to push SPI speed up to 25.1MHz. At 25.2MHz it stopped working.
@mjs513 and @neurofun and ...

Good someone tested some of the capacitive touch stuff. I probably won't be doing that for awhile... Yesterday I was going to look at some of it, including adding similar support for multiple displays with touch, when I must have hooked up something wrong..

Actually I was hooking it up to use power supply from other board with DC/DC converter, and then saw the magic smoke :(

Got it unplugged reasonably quickly (burning thumb which hit a very hot capacitor and some of it stuck to thumb)...


Red arrow shows the CAP that obviously fried, marked C26. Not sure what else might have fried or full cause. Maybe GND from main board lost contact....?
I will have to decide at some point if I want to order another one to enhance the touch stuff or not....

Ouch, it looks you might have powered your display with the wrong polarity. C26 is part of the backlight driver circuit and is connected between GND and the 3.3V rail. Electrolytic capacitors don't like reverse polarity.
If you are willing to try a repair I can help you troubleshooting. Or if you live in europe, you could send it to me and I will look at it free of charge. And If you plan to trash it, trash it in my direction, will pay for shipping.
I always like a good repair challenge.

Concerning the capacitive touch stuff. The 5 point touch coordinates work in all 4 orientations. The gesture id's(up, down, left, right) are only relative to setRotation(3). Don't know if this needs fixing, it's probably used for swiping.
Thanks @neurofun, I might try to fix so any suggestions would be great. Wonder what is needed for that Cap. I may have some around that would be sufficient. Would also need to make sure I know what the proper orientation ... Any other suggestions before I try to desolder it and try putting on a different one?

I also put a message to BuyDisplay through Ebay - asking for advice. Who knows maybe they will take pity on me as I am mainly only doing this to support the Teensy and our doing it is probably helping them sell some more of their displays...
First you need to carefully desolder the cap and remove burned residues from the pcb with some solvent, I usually use isopropyl alcohol.
Then next thing to do is to measure for continuity between GND and 3.3V, between GND and 5V, between 5V and 3.3V.
If there is a short, something else is fried too.
If no shorts, you can replace the cap. Power the board and measure if you have 3.3V.
The cap is a 10uF 16V tantalium capacitor. It is connected between 5V and GND, the led driver circuit is powered by the 5V rail.
with your pic as reference, the stripe(+) on the cap is facing to the right.
The cap is a 10uF 16V tantalium capacitor. It is connected between 5V and GND, the led driver circuit is powered by the 5V rail.
with your pic as reference, the stripe(+) on the cap is facing to the right.

Thanks, I might be getting lucky (maybe not)

But I was able to remove the cap (in pieces). cleaned area with isopropyl alcohol, tested resistances, no dead shorts... So found I had some CAP TANT 10uf 16v 10% 1210 caps, also verified location orientation looks like my other displays. Soldered on. Got brave hooked up to Power supply of T3.2 with DC/DC converter. No smoke... checked jumper area that would be closed if 3.3v setup (J8) and have 3.3v... next up maybe hook up rest of display, to same T3.2... Not much of loss if it does not work...

EDIT: But so far nothing outputs... So not much luck so far...
Last edited:
Update: I think some of the display is working and some not so much.

That is if I run the Adafruit library at buildtest program, I will see the display startup some brightness and dim, and then see a red display that dims to black and then you see nothing.

Likewise with the benchmark program I can add the call tft.backlight() and see the initial screen showing rotation 0.

But it then dims out and don't see anything else... Wonder if one of the other components is not working?

So close to fixing the display. Maybe with changing the cap you need to play with turning the backlight on manually with the backlight pin.
If you short J15 and open J16 and then connect pin15(BL_CONTROL) to 5V, the backlight turns on as soon as you power the display.
If the backlight then shows the same behaviour when you power the display, it is very likely that the led driver U3 (part nr PT4110E89E) is toast and needs replacement.
Thanks @nerofun - I am going to assume that chip is toast... Question is trying to find someone who sells it. So far no one like Mouser or Digikey sell them. Some of the places I found, want minimum of $100 orders, plus ship from china...

Wonder if there are alternative chips. Will do a little more investigation.
Not open for further replies.