#define LCD_CS 33 // Chip Select goes to Analog 3
#define LCD_RS 15 // LCD_RS = Register Select or LCD_CD = Command/Data goes to Analog 2
#define LCD_WR 4 // LCD Write goes to Analog 1
#define LCD_RD 2 // LCD Read goes to Analog 0
#define LCD_RESET 32 // Can alternately just connect to Arduino's reset pin
//#include <SPI.h> // f.k. for Arduino-1.5.2
//#include "Adafruit_GFX.h"// Hardware-specific library -----------------------------------------------
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
String tempstr;
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
tft.reset(); //hardware reset
uint16_t ID = tft.readID(); //
if (ID == 0xD3D3) ID = 0x9481; // write-only shield
tft.begin(ID);
tft.setRotation(3);
tft.fillScreen(BLUE);
pinMode(22, INPUT);
digitalWrite(22, LOW);
delay(3000); Serial1.println("AT+CM03");
}
void loop() {
if (Serial.available()>0) {
Serial1.write(Serial.read());
}
if (Serial1.available()>0) {
//Serial.write(Serial1.read());
tempstr=Serial1.readString();
Serial.println(tempstr);
}
if(digitalRead(22)==HIGH) {
tft.setCursor(0, 10);
tft.setTextColor(WHITE); tft.setTextSize(2);
tft.fillScreen(BLUE);
tft.print(tempstr);
}
}
A certain text arrives at the port. I write it to the tempstr variable.
When I read this variable it is printed on the tft screen with spaces. I am using the command tft.print(tempstr);
Also, when the text in the port changes, everything remains in the variable and is not overwritten.