mcufriend problem

hello everybody.

I am working in a project using arduino mega 2560 with mcufriend tft screen (shown in attachment). I am trying to apply the attached code but I still get the white screen !

I need your help.

thanks in advance

ring meter.zip (52.9 KB)

Go on. You have a TFT with parallel interface. i.e. regular Mcufriend shield.

The Adafruit_ILI9341_AS library is for SPI interface.
The xxxx_AS is a bit of a kludge. These kludges are not supported by Adafruit or by the Library Manager.

I suggest that you install the proper Adafruit_GFX library and the MCUFRIEND_kbv library via the Library Manager.

These shields are designed for a Uno. It works with a Mega but will be slower than a Uno.

If the Ring_Meter sketch really interests you, I can probably show you a MCUFRIEND_kbv version.

David.

I'll be really thankful if you help me with MCUFRIEND_kbv version.

Different libraries have different includes and constructors.

They might have slightly different initialisation methods e.g. init() or begin()
And most importantly, methods for rendering fonts.

Regular Adafruit_GFX style libraries can only draw FreeFonts transparently.
But they can draw the 7x5 “system” font transparently or with background.

This particular sketch uses different fonts and sizes. So I have added a helper function.
Look for comments with .kbv to see what I have done.

Note that overwriting text in variable width fonts gets a bit fiddly. “9999” is wider than “1111”.
And “123” is narrower than “1234”.

So you normally calculate the size of the old text to re-paint the background.
This example only knows the new text. So you need to guess the width of background required to rub out the old text.

Note that you can adapt this program for any GFX style library e.g. Adafruit_ILI9341 or Adafruit_TFTLCD
And Bodmer’s libraries support the “horrible” GFX_AS style methods natively.

Please let me know how you get on.

David.

Meter_ring_1_kbv.ino (9.45 KB)

thank you.
I will try it

thank you so much,
its working now :))))

I was a little horrified by how slowly the example in #3 works.
There are several reasons:

  1. Each coloured segment of the “meter” is drawn with two filled triangles. These require a lot of work from the graphics library.
  2. The whole “meter” is redrawn every time.
  3. Calculating the coordinates of the triangles requires floating point and trigonometry.

A simple optimisation is to only draw the segments that have changed colour. i.e. keep track of old values of each meter.

I have attached another version: It works 10x faster.

The number at the bottom left corner represents the milliseconds to update the screen
You can alter the repeat time in loop() if you want to see the maximum speed of operation.
It is dramatic on a 180MHz STM32F446 but is still impressive on a Uno.

David.

Meter_ring_2_kbv.ino (10.3 KB)