Analog read on 2.8" tft lcd flashing.

Hello I’m trying to do a analog read on analog pin using the 2.8" tft LCD screen here. But the problem I’m having is when it refresh on the screen it flashes on updating the value. I uses the adafruit example and just comment out most things and put a analog read.

#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"

//XIAO
#define TFT_DC 1
#define TFT_CS 2
#define TFT_RST 3
#define TFT_MISO 9
#define TFT_MOSI 10
#define TFT_CLK 8
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
// If using the breakout, change pins as desired
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);

void setup() {
  Serial.begin(9600);
  //Serial.println("ILI9341 Test!"); 
 
  tft.begin();

  // read diagnostics (optional but can help debug problems)
  uint8_t x = tft.readcommand8(ILI9341_RDMODE);
  //Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDMADCTL);
  //Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDPIXFMT);
 // Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDIMGFMT);
 // Serial.print("Image Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDSELFDIAG);
  //Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX); 
  

}


void loop(void) {
  for(uint8_t rotation=0; rotation<4; rotation++) {
    //tft.setRotation(rotation);
    testText();
    delay(1000);
  }
}

unsigned long testFillScreen() {
  unsigned long start = micros();
//  tft.fillScreen(ILI9341_BLACK);
//  yield();
//  tft.fillScreen(ILI9341_RED);
//  yield();
//  tft.fillScreen(ILI9341_GREEN);
//  yield();
//  tft.fillScreen(ILI9341_BLUE);
//  yield();
//  tft.fillScreen(ILI9341_BLACK);
//  yield();
  return micros() - start;
}

unsigned long testText() {
  int sensorValue = analogRead(A0);
  // print out the value you read:
 // Serial.println(sensorValue);
  tft.fillScreen(ILI9341_BLACK);
  unsigned long start = micros();
  tft.setCursor(0, 0);
  tft.setTextColor(ILI9341_WHITE);  tft.setTextSize(1);
  tft.println(sensorValue);
//  tft.setTextColor(ILI9341_YELLOW); tft.setTextSize(2);
//  tft.println(1234.56);
//  tft.setTextColor(ILI9341_RED);    tft.setTextSize(3);
//  tft.println(0xDEADBEEF, HEX);
//  tft.println();
//  tft.setTextColor(ILI9341_GREEN);
//  tft.setTextSize(5);
//  tft.println("Groop");
//  tft.setTextSize(2);
//  tft.println("I implore thee,");
//  tft.setTextSize(1);
//  tft.println("my foonting turlingdromes.");
//  tft.println("And hooptiously drangle me");
//  tft.println("with crinkly bindlewurdles,");
//  tft.println("Or I will rend thee");
//  tft.println("in the gobberwarts");
//  tft.println("with my blurglecruncheon,");
//  tft.println("see if I don't!");
  return micros() - start;
}

I’m not sure how to change it to stop flashing and just update it. Also I’m using the seeedstudio Xaio here. Can someone please help me to stop this flashing?

Joseph

For transfer of 16bit color 320 * 240 dots by simple calculation at least 320 * 240 * 16 = 1,228,800 bits are required.
This is a significant amount of data: 51.2ms even if the SPI speed is 24MHz.
The actual data packets are need more command and more time consuming.

The time required to update the entire screen is sufficient for the human eye to recognize the display update.
So you will feel flashing.

As a workaround, instead of clearing all screens every time you will need to fill only the area where you want the new text to appear with the background color.

When flicker free high resolution image signals, you need a very fast transfer bus.
Of course, the MCU too.

Hello Chrisknightley, Thank you for that information. I’m really unsure how i can do that. Coding wasn’t my strong part. My skills are mostly hardware and trying to figure this out mostly R&D. I’m trying with coding but it is way over my head. I’m okay with moding a little here and there but that is all.

Joseph

I don't currently have that TFT module so I'm not sure if it will work...

May be possible to overwrite the previous text with a background color and then display the new text.
For that store the previous text in a program that displays the text.

For example, how does the following code work?

#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"

//XIAO
#define TFT_DC 1
#define TFT_CS 2
#define TFT_RST 3
#define TFT_MISO 9
#define TFT_MOSI 10
#define TFT_CLK 8
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
// If using the breakout, change pins as desired
//Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);

void setup() {
  Serial.begin(9600);
  //Serial.println("ILI9341 Test!");

  tft.begin();

  // read diagnostics (optional but can help debug problems)
  uint8_t x = tft.readcommand8(ILI9341_RDMODE);
  //Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDMADCTL);
  //Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDPIXFMT);
  // Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDIMGFMT);
  // Serial.print("Image Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDSELFDIAG);
  //Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX);

  tft.fillScreen(ILI9341_BLACK); // ***** Clear screen once *****
}


void loop(void) {
  testText();
  delay(1000);
}

unsigned long testFillScreen() {
  unsigned long start = micros();
  tft.fillScreen(ILI9341_BLACK);
  return micros() - start;
}

unsigned long testText() {
  static int sensorValueOld;
  int sensorValue = analogRead(A0);
  unsigned long start = micros();
  tft.setTextSize(1);
  tft.setCursor(0, 0);
  tft.setTextColor(ILI9341_BLACK);
  tft.println(sensorValueOld); // ***** Delete previous text by back-color overwritten *****
  tft.setCursor(0, 0);
  tft.setTextColor(ILI9341_WHITE);
  tft.println(sensorValue);  // ***** Print new text *****
  sensorValueOld = sensorValue; // ***** Store currently displayed text *****
  return micros() - start;
}

(I'm sorry, I omitted the comment part.)

However, this method can be difficult when a lot of information is displayed on the TFT.
Of course, to display a lot of information, you have to rewrite the entire screen, which results in the problem described at the beginning.

Could you draw a picture of what you would actually like the screen to look like? Maybe then someone could help you?

Just thinking in text here..

-jim lee

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.