Beginner: Need help on 2.2" TFT SPI + Nano 3 project

I found code on the web for a bubble level using 0.96" 128 x 64 Micro OLED display, and I have adapted it to use a bigger display, an Itead ITDB02-2.2S 2.2" SPI TFT LCD

The arduino is a Nano 3 clone.

It mostly works, but screen update is very slow - about 2 per second

Can someone please look and see where I have made an error, or if the hardware is not up to the job.

[code]
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
#include <Adafruit_ILI9340.h>


#if defined(__SAM3X8E__)
    #undef __FlashStringHelper::F(string_literal)
    #define F(string_literal) string_literal
#endif

#define _sclk 13
#define _miso 12
#define _mosi 11
#define _cs 10
#define _dc 9
#define _rst 8
 
Adafruit_ILI9340 tft = Adafruit_ILI9340(_cs, _dc, _rst);
 
// accel of gravity
const float G = 9.80665;
 
// tilt sensor (i2c connections SDA and SCL connected to Mini Pro's A4 and A5):
Adafruit_ADXL345_Unified tilt = Adafruit_ADXL345_Unified(0);
  
void setup() 
{
  Serial.begin(9600);
  while (!Serial);
  tft.begin();
  tft.fillScreen(ILI9340_BLACK);
  tft.setTextSize(3);
  tft.setTextColor(ILI9340_WHITE);
  
 // init tilt:
 tilt.begin();

 tilt.setRange(ADXL345_RANGE_2_G);
 tilt.setDataRate(ADXL345_DATARATE_25_HZ);
}
  
void loop()
{
 sensors_event_t event; 
 float accelX, accelY, bx, by;
 float centreX = 120, centreY = 160; //circle centres
 int crossHair = 75; //crosshair length
 int circleDiameter = 50; //outer circle diameter
 int bubbleDiameter = 25; //bubble diameter
 float bubbleX, bubbleY;
  
 // get the latest event:
 tilt.getEvent(&event);
  
 // get the accel readings from the event:
 accelX = event.acceleration.x; // m/s^2
 accelY = event.acceleration.y; // m/s^2
 
 // calculate degrees from horizontal
 float degreesX = (accelX/G)*90;
 float degreesY = (accelY/G)*90;

//clear screen 
  tft.fillScreen(ILI9340_BLACK);
  
 // print x degrees
 tft.setCursor(0, 0);
 tft.print("X: ");
 tft.setCursor(40, 0);
 tft.print(degreesX,0);
 tft.write(247); // deg symbol 
 
 // print y degrees
 tft.setCursor(0, 45);
 tft.print("Y: ");
 tft.setCursor(40, 45);
 tft.print(degreesY,0);
 tft.write(247); // deg symbol 


  // bubble location: 22.5 deg is half of screen width
 bubbleX = (((accelX /(G/4)) * 120) + centreX);
 bubbleY = (((accelY /(G/4)) * 120) + centreY);
  
 // Draw the middle circle
 tft.drawCircle(centreX, centreY, circleDiameter, ILI9340_WHITE);

// Draw  the crosshairs
 tft.drawLine(centreX, centreY-crossHair, centreX, centreY+crossHair, ILI9340_WHITE); 
 tft.drawLine(centreX-crossHair, centreY, centreX+crossHair, centreY, ILI9340_WHITE); 
  
 // within this tolerance bubble circle turns WHITE to indicate levelness
 int tol = 8;
 if(bubbleX < (centreX + tol) && bubbleX > (centreX - tol) && bubbleY < (centreY + tol) && bubbleY > (bubbleY - tol))
 {
 tft.fillCircle(bubbleX, bubbleY, bubbleDiameter, ILI9340_WHITE);
 }
 else
 {
 tft.drawCircle(bubbleX, bubbleY, bubbleDiameter, ILI9340_WHITE);
 }

}

[/code]

Rather than re-drawing the screen, just print to the serial port. Is that slow, too? If not, the problem is with how long it takes to clear and redraw the screen.

I can see how to print text, but I'm not sure how to print the draw commands to the serial port ie. drawCircle? Also with serial.print, how can I set the cursor position?

Thanks

I can see how to print text, but I'm not sure how to print the draw commands to the serial port ie. drawCircle? Also with serial.print, how can I set the cursor position?

You don't. Instead of using the data from the sensor to draw text and graphics, just write the data to the serial port. The thing that you are trying to figure out is does getting the data take all time or does using the data take all the time. If you replace the code that uses the data (drawing on the TFT) with a process that takes a known (but small) amount of time, and the overall process does not get any faster, the it is getting the data that takes time. If, instead, you can print 100 values per second, then it is the screen clear and text and graphic generation that takes the bulk of the time.

It is useless to try to improve the drawing time if it takes half a second to get the data.