3.2" TFT text scrolls off screen

Good evening guys,

Firstly, any help to my problem would be greatly appreciated. I've spent the last few days trawling forums/Google, with little success...

Precursor: Arduino mega // 3.2" TFT screen.

I'm looking to build a terminal to display RS232 data onto a 3.2" TFT screen. Data is being sent anywhere from 1-100hz to the terminal.

Problem: I have the data displaying on the screen but it only display the first few lines of data before the rest prints off the bottom of the screen. As a temporary solution I'm clearing the screen by filling it the colour black every 2 seconds. This does work, but isn't very elegant as depending on the speed of the data I'm receiving either the screen is only half filled up before the screen is wiped, or, lots of data runs off the screen and then after the allotted 2 seconds, it clears the screen. Ideally, I'd like the screen to fill up only 3/4 of the screen, and then data starts displaying at the top again. (i'm saving the bottom 1/4 of the screen to display the baud rate, stop bits, data bits and parity of the serial communications.

I'm using the command: tft.write(mySerial.read()); to display the data because if I use tft.print(mySerial.read()); I just get a load of "-1" on the screen and not the real data. Another side problem is that the data is not using and as such is just printing in a constant feed of text, and not placing the new data on a new line. I suspected this might be because I'm not using tft.println () command, but this doesn't display the text correctly (again, just "-1")

Things tried: I've tried the tft.setWindow() command to set the bounds of the displayed text, but this doesn't stop the text scrolling off the bottom of the screen.

I've tried using text padding to overwrite the old text but again, no success.

Thanks for taking the time to read this post, and if you do comment, thank you in advance.

Below is my code

/*
  Software serial multple serial test

 Receives from the hardware serial, sends to software serial.
 Receives from software serial, sends to hardware serial.

 The circuit:
 * RX is digital pin 10 (connect to TX of other device)
 * TX is digital pin 11 (connect to RX of other device)

 Note:
 Not all pins on the Mega and Mega 2560 support change interrupts,
 so only the following can be used for RX:
 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69

 Not all pins on the Leonardo and Micro support change interrupts,
 so only the following can be used for RX:
 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).

 created back in the mists of time
 modified 25 May 2012
 by Tom Igoe
 based on Mikal Hart's example

 This example code is in the public domain.

 */
#include <SoftwareSerial.h>
SoftwareSerial mySerial(10, 11); // RX, TX
#include <TFT_HX8357.h> // Hardware-specific library



#endif // LOAD_GFXFF




TFT_HX8357 tft = TFT_HX8357();       // Invoke custom library

long count = 0; // Loop count


void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);

  // Setup the LCD
    tft.init();
  tft.setRotation(1);
  tft.setFreeFont(FM9);    // Select the font
  tft.fillScreen(TFT_BLACK);
  tft.setTextColor(TFT_YELLOW); 
  tft.setTextSize(1); 
  tft.setWindow(0,0,480,320);
}

void loop() { // run over and over

 {
    tft.write(mySerial.read());
    Serial.print(mySerial.read());
    

    

}
          
  if (2000 == count++){
    count = 100;
    tft.fillScreen(TFT_BLACK);
    tft.setCursor(0,20);
  }
}

Ideally, I'd like the screen to fill up only 3/4 of the screen, and then data starts displaying at the top again.

How many characters is that?

void loop() { // run over and over

 {
    tft.write(mySerial.read());
    Serial.print(mySerial.read());

Read one character, regardless of whether or not there is anything to read, and send it to the TFT. Then, read another character, regardless of whether or not there is anything to read, and send it to the Serial port.

Makes no sense to me.

How would I know the number of characters 3/4 of the screen is? Is there a command to set the number of characters to print before it refreshers the screen?

And the reason I had it it printing to the TFT and the serial port was just for testing the data through serial monitor and on the tft at the same time.

How would I know the number of characters 3/4 of the screen is?

Count them. 1, 2, 3, 4...

Is there a command to set the number of characters to print before it refreshers the screen?

No. You need to keep track of the number of characters you have written, and when that matches a "screenful", clear the screen.

And the reason I had it it printing to the TFT and the serial port was just for testing the data through serial monitor and on the tft at the same time.

But, you are NOT printing the same data to each place. Read ONCE; write TWICE. And, only read when there is data to read.

Thanks Paul,

Sorry if this is elementary, but how exactly would I keep track of the number of characters printed? The data coming in isn't a fixed length.

Would I have to incorporate an "if" argument into the code? If so, how is this done?

Regards,

David