Author Topic: #FIXED# TFT LCD character clearing problems  (Read 2291 times)

0 Members and 1 Guest are viewing this topic.

Offline FotatoPotatoTopic starter

  • Regular Contributor
  • *
  • Posts: 126
  • Country: us
  • It's probably in reverse...
#FIXED# TFT LCD character clearing problems
« on: May 24, 2019, 08:16:21 pm »
Hi all,

So I'm using the adafruit 3.5" TFT LCD and an Arduino Mega for a DMM and I want to display the voltage from my ADC next to where it says "voltage". I have it working somewhat but the displayed voltage isn't erased once a new reading is sent and the voltage readings just display over each other until I get 3 white rectangles. I'm using the Adafruit TFT and GFX libraries and I'm not quite sure how to fix this and erase the voltage reading and display the new one. I'll link a video of the problem and the code below.

If you guys have any suggestions or fixes I would really appreciate hearing them.

Thanks!

Video: https://drive.google.com/open?id=1RSerxS01f-XkIPLv9BWwwdeXBMTyzU8-
« Last Edit: May 25, 2019, 04:10:05 am by FotatoPotato »
 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 4984
  • Country: ro
  • .
Re: TFT LCD character clearing problems
« Reply #1 on: May 24, 2019, 08:30:28 pm »
A simple fix would be printing the previous value with the text color set as background color. Then print the new value with your regular color.
How about defining a rectangle and filling it with the background color to the right of the "voltage:" text..
 
The following users thanked this post: FotatoPotato

Offline FotatoPotatoTopic starter

  • Regular Contributor
  • *
  • Posts: 126
  • Country: us
  • It's probably in reverse...
Re: TFT LCD character clearing problems
« Reply #2 on: May 24, 2019, 08:41:58 pm »
Thanks for the quick reply!

That did work but is there any other way? It just seems quite inefficient especially since I want to display the readings in real time with a little delay which means I will have to be redrawing the rectangle very quickly which might slow things down. Is there any other way of doing this so that just the text is replaced, or is this the only way? 

Also I get this awful flickering which only goes away if I slow down the delay times, which I can't do since I want to constantly be updating the voltage.

Video of the flickering (it's much worse to the eye): https://drive.google.com/open?id=17-yZ9_ygveKtPltoit2aRCo_6DXzAruz
 

Offline Buriedcode

  • Super Contributor
  • ***
  • Posts: 1610
  • Country: gb
Re: TFT LCD character clearing problems
« Reply #3 on: May 24, 2019, 08:46:56 pm »
THe problem with the GFX libraries - and the newer U8x8 - is that often with the SPI TFT's, when they write a character, they draw individual pixels used, but ignore the white space around - so the character is printed on top of a background.  This is often desired, but as you found out, also means you end up with a mess when its changing. 

The options are to either just draw a rectangle where the characters are, with the background colour before re-writing a character, or modify the library to print a character with a fixed area (width and height) and foreground (character) and background colour.

The other annoying things about those libaries is, for almost every function they call "drawpixel" which sends the address off the pixel followed by two bytes of colour.  The upshot is, every pixel requires several SPI writes, where-as the controllers have the facility to declare a rectangle using X1Y1 and X2Y2 where the address auto-increments and wraps around - making drawing rectangles very quick and simple.  For most apps this doesn't matter, but it does mean that the above libraries are about 4x slower than they need to be.

Edit/update: Re: flickering. It appears thats because it takes time to "black out" the character, and a similar time to redraw the new character.  This means the character flashes at pretty much a 50% duty cycle.  I could be wrong but I think the only way would either be to speed up the display writing - either faster SPI or a faster MCU - or slow down the display update.
« Last Edit: May 24, 2019, 08:50:31 pm by Buriedcode »
 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 4984
  • Country: ro
  • .
Re: TFT LCD character clearing problems
« Reply #4 on: May 24, 2019, 08:49:10 pm »
Try only redrawing the value, if it's different than the previous value.

It's as simple as adding an: IF new_value != prev_value then do stuff

before trying to print value.
 

Offline FotatoPotatoTopic starter

  • Regular Contributor
  • *
  • Posts: 126
  • Country: us
  • It's probably in reverse...
Re: TFT LCD character clearing problems
« Reply #5 on: May 24, 2019, 08:53:26 pm »
Isn't that what I'm already doing? In my loop, I'm only redrawing the voltage and not the static text. But it doesn't erase the previous text. Would you mind explaining a bit more?

Thanks!
 

Offline FotatoPotatoTopic starter

  • Regular Contributor
  • *
  • Posts: 126
  • Country: us
  • It's probably in reverse...
Re: TFT LCD character clearing problems
« Reply #6 on: May 24, 2019, 08:55:31 pm »
I see what you're saying, I'll see if there is a different library that I can use. Also, I'm using the TFT in 8bit mode and not SPI mode but I don't think that matters all that much.
 

Offline mariush

  • Super Contributor
  • ***
  • Posts: 4984
  • Country: ro
  • .
Re: TFT LCD character clearing problems
« Reply #7 on: May 24, 2019, 09:00:47 pm »
add a floating point variable called VoltagePrev  or whatever

measure the voltage.

if measured voltage different than previous voltage :

go to position where the voltage is printed
print previous voltage with the background color to erase the previous reading
go to position where the voltage is printed
print new voltage with the text color
set the previous voltage value to the new voltage value

end if

When the voltage is measured again, the previous voltage variable holds the voltage used last time the screen was updated, so if the measured voltage is the same as last displayed voltage, you're not printing anything.


By the way... see datasheet of that ADS1115 : http://www.ti.com/lit/ds/symlink/ads1114.pdf
Go to page 17 : 9.3.3 Full-Scale Range (FSR) and LSB Size

If you don't need that full range, you can set the maximum to 4.096v which gives you 125uV per bit so that would save you a floating point division ...  8 units give you 1mV  so you could simply shift right by 3 bits
ex ... if you read 1200 ... 1200 >> 3 = 150mV
 
« Last Edit: May 24, 2019, 09:14:17 pm by mariush »
 

Offline MasterT

  • Frequent Contributor
  • **
  • Posts: 783
  • Country: ca
Re: TFT LCD character clearing problems
« Reply #8 on: May 24, 2019, 10:04:26 pm »
Flickering was annoying me too, even using much faster uCPU like stm32H743 (400 MHz). The problem is that library subfunction tft.print(ddd, DEC) or tft.print(fff, 3) treats new value as a whole object, and re-write all digits brainlessly. What I mean, if last value was let say 123456789, and new value is 125556789 library would redraw everything. What makes things worse, is that erasing with blanking symbol ( or same value changing color to background),  creates time gap, that has maximum at digit "9", since it would be re-drawn last and would inevitably blinking .
The only option I came up with, its create my own printNumber sets of subfunctions for integer and float numbers, that 1) redraw a single digit only if its changed; 2) redraw each digit one by one.
 

Offline FotatoPotatoTopic starter

  • Regular Contributor
  • *
  • Posts: 126
  • Country: us
  • It's probably in reverse...
Re: TFT LCD character clearing problems
« Reply #9 on: May 25, 2019, 03:25:13 am »
Ok, well after hours upon fucking hours of trying to get other TFT libraries to work, especially UTFT since it seems like the best one out there I just can't get anything to work  |O. I don't know what I'm doing wrong but nothing except the Adafruit libraries work. So unless any of you guys know how to set up the 2.8" ILI9341 adafruit TFT to work with the UTFT library, I'm going to have to figure out how to get the adafruit libraries to work, only problem is that I'm a total noob when it comes to this stuff, so I'm gonna need all of the help I can get.

If any of you guys can help me out or know how the get this display to work with the UTFT library on an Arduino mega 2560 then I would GREATLY appreciate it!!!

Thanks  :-+

EDIT: I found out that the UTFT library isn't compatible with the 3.5" adafruit displays since they use the HX8357D drivers, so I went out and bought the adafruit 2.8" TFT since it uses the ILI9341 driver which is supported by UTFT. Now I'm fine with having to use the 2.8" display but if it is possible to use the 3.5" one and get rid of this text clearing issue that would be great!
« Last Edit: May 25, 2019, 03:30:54 am by FotatoPotato »
 

Offline FotatoPotatoTopic starter

  • Regular Contributor
  • *
  • Posts: 126
  • Country: us
  • It's probably in reverse...
Re: TFT LCD character clearing problems
« Reply #10 on: May 25, 2019, 04:03:22 am »
Welp, I just fixed it, turns out there is a command  tft.setTextColor(ILI9341_WHITE,ILI9341_BLACK); that automatically erases the text before without any delay  :)

Thanks to all that tried helping me, I really appreciate it!
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf