#FIXED# TFT LCD character clearing problems  - Page 1
Forum section: electronics / general

author: FotatoPotato
author_rank: Regular Contributor
timestamp: May 24, 2019, 08:16:21 pm
content: 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-

author: mariush
author_rank: Super Contributor
timestamp: May 24, 2019, 08:30:28 pm
content: 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..

author: FotatoPotato
author_rank: Regular Contributor
timestamp: May 24, 2019, 08:41:58 pm
content: 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

author: Buriedcode
author_rank: Super Contributor
timestamp: May 24, 2019, 08:46:56 pm
content: 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.

author: mariush
author_rank: Super Contributor
timestamp: May 24, 2019, 08:49:10 pm
content: 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 stuffbefore trying to print value.

author: FotatoPotato
author_rank: Regular Contributor
timestamp: May 24, 2019, 08:53:26 pm
content: 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!

author: FotatoPotato
author_rank: Regular Contributor
timestamp: May 24, 2019, 08:55:31 pm
content: 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.

author: mariush
author_rank: Super Contributor
timestamp: May 24, 2019, 09:00:47 pm
content: add a floating point variable called VoltagePrev or whatevermeasure the voltage.if measured voltage different than previous voltage :go to position where the voltage is printedprint previous voltage with the background color to erase the previous readinggo to position where the voltage is printedprint new voltage with the text colorset the previous voltage value to the new voltage valueend ifWhen 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.pdfGo to page 17 : 9.3.3 Full-Scale Range (FSR) and LSB SizeIf 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 bitsex ... if you read 1200 ... 1200 >> 3 = 150mV

author: MasterT
author_rank: Frequent Contributor
timestamp: May 24, 2019, 10:04:26 pm
content: 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.

author: FotatoPotato
author_rank: Regular Contributor
timestamp: May 25, 2019, 03:25:13 am
content: 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. 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!!!ThanksEDIT: 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!

author: FotatoPotato
author_rank: Regular Contributor
timestamp: May 25, 2019, 04:03:22 am
content: 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 delayThanks to all that tried helping me, I really appreciate it!