Need help of TFT display

Hey guys

My project is to have a TDS(total dissolved matter) value on a TFT display.
I manage to spaguetti code my way till its time to display the values on screen,
on serial monitor it displays the correct(after verification)values on liquids, but i cant seem to point it to screen, doesnt matter where in screen, just that values being displayed correctly.

#include <Adafruit_GFX.h>    
#include <MCUFRIEND_kbv.h>
#include "TouchScreen.h"
#include <EEPROM.h>
#include "GravityTDS.h"

 
#define BLACK 0x0000
#define PURPLE 0x780F
#define BLUE 0x001F
#define GREEN 0x07E0
#define CYAN 0x07FF
#define RED 0xF800
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF

 
#define TdsSensorPin A0
GravityTDS gravityTds;


#define YP A1 
#define XM A2  
#define YM 7   
#define XP 6  

#define MINPRESSURE 10
#define MAXPRESSURE 1000

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 250);
TSPoint p;

MCUFRIEND_kbv tft;
float temperature = 25,tdsValue = 0;
uint16_t g_identifier;
uint8_t rotation=3;
uint32_t when = millis();
uint8_t size = 4;
uint8_t cor = 0;
uint32_t tdsSensorPin =0;

void setup()
{
    tft.begin(9600);
  tft.reset();
  Serial.begin(9600);

  g_identifier = tft.readID();  // get id 
  tft.begin(0x7793);            // to enable ST7793 driver code 

  tft.setRotation(rotation);    // sets text direction
  tft.fillScreen(BLACK);        // clear screen

    gravityTds.setPin(TdsSensorPin);
    gravityTds.setAref(3.3);  //reference voltage on ADC, default 5.0V on Arduino UNO
    gravityTds.setAdcRange(1024);  //1024 for 10bit ADC;4096 for 12bit ADC
    gravityTds.begin();  //initialization
   
}
 
void loop()
{
    
   

    //temperature = readTemperature();  //add your temperature sensor and read it
    gravityTds.setTemperature(temperature);  // set the temperature and execute temperature compensation
    gravityTds.update();  //sample and calculate
    tdsValue = gravityTds.getTdsValue();  // then get the value
    tft.setTextColor(WHITE,BLACK);
    tft.print(tdsValue);
    Serial.print(tdsValue-35,0);
    Serial.println("ppm");
    delay(1000);
     
} 

thanks for the help.

Have you tried running one of the example sketches to make sure that the TFT is connected up correctly and working properly?

TFT is displaying everything good, this code is just to pin point the reason the variable tdsValue does not show correctly on the TFT.

Ok, fair enough. So what is it displaying on the TFT when compared with Serial Monitor?

On serial monitor, its displays like

165ppm
165ppm
165ppm
Etc.

On tft simply does not show nothing. No matter where i setCursor.
Thats why for test purpose i let it start @ 0.0

Study the TFT example programs more carefully.

You appear to be missing calls to .display(), which is required to actually send the data to the screen.

Try removing or commenting out the line:

tft.begin(9600);

You already have:

tft.begin(0x7793);

done that, still with same problem.
i manage to set up the gui and so far this is my first display issue with the screen itself.
ill give a few turns on the tft.print

I must admit I used calls to .display() rather than .print() in my sketch, but I was using a different library. This MCUFRIEND example has a call to setCursor(), so you might try adding:

tft.setCursor(0,0);

of whatever position you want to place the text, before your call to print();

Example:
^https://github.com/prenticedavid/MCUFRIEND_kbv/blob/master/examples/Font_simple/Font_simple.ino

My mistake, the MCUFRIEND_kbv library does not use the .display() method. I was thinking of another TFT library.

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