Go Down

Topic: 3.95 inch LCD touch screen ili9488 (Read 46155 times) previous topic - next topic

david_prentice

I make no attempt to support obsolete IDEs.    I just assume that readers of this forum will be running v1.6.5 or newer.

The Ada_GFX_kbv.h header is only used on non-Arduino targets.
You could change the test to > 100 instead of >= 165.    I would not be too confident with very old IDEs.

I suggest that you install the current v1.6.7  or at least v1.6.5.

It will work with the v1.7.x family of IDE.    However,    the v1.6.x developers know what they are doing.

David.

micke78

Hello.

I have a ILI9488 works with uno. I have small problem.
I create strech for ili9341 and i use function "fillArc" now i try to convert to ili9488.
Any ideas how to draw arc with MCUFRIEND_kbv.h library.

Orginal code:
...
 tft.begin();
  tft.fillScreen(ILI9341_BLACK);
  tft.setRotation(iliRotation270);
  tft.setFont(Arial_bold_14);
  tft.setTextScale(2);
  tft.setTextColor(ILI9341_CYAN);
  tft.cursorToXY(130, 90);
  tft.print("km/h");
  tft.fillArc(160, 170, 145, 20, -110, -109, ILI9341_BLUE);
  tft.fillArc(160, 170, 145, 10, -100, -99, ILI9341_BLUE);
  tft.fillArc(160, 170, 145, 20, -90, -89, ILI9341_BLUE);
...

Luka

david_prentice

fillArc() is not an Adafruit_GFX method.
Likewise cursorToXY()

If you really want to methods like this,   write your own class that extends Adafruit_GFX.
It is not difficult to write a filled Arc.   Just calculate the limits for each row,  and draw a coloured line between them.

I suspect that you are trying to port a program from the ILI9341_due library.

David.

micke78

yes.

I found also this class in ili9341_due library but it has another component. So I hate to find all and try to copy to MCUFriend

Thanks for info
Luka

david_prentice

You can look at the ILI9341_due code to see how Marek implements fillArc().

I would not fiddle with the library class.  Just add it as a regular C function.

If you think it is an essential method() that you will be using in every project,   I suggest that you extend the class.

David.

micke78

I think that i not good enough to write this.
I found in cpp and h file code but i 'm not sure how to use it :(((

in .h file:


inline __attribute__((always_inline))
      void fillArc(uint16_t x, uint16_t y, uint16_t radius, uint16_t thickness, float start, float end, uint16_t color)
   {
      beginTransaction();
      if (start == 0 && end == _arcAngleMax)
         fillArcOffsetted(x, y, radius, thickness, 0, _arcAngleMax, color);
      else
         fillArcOffsetted(x, y, radius, thickness, start + (_angleOffset / (float)360)*_arcAngleMax, end + (_angleOffset / (float)360)*_arcAngleMax, color);
      endTransaction();
   }


But in MCUFierd i don't have begin ane endTransaction.


In .cpp file:



void ILI9341_due::fillArcOffsetted(uint16_t cx, uint16_t cy, uint16_t radius, uint16_t thickness, float start, float end, uint16_t color) {
   int16_t xmin = 65535, xmax = -32767, ymin = 32767, ymax = -32767;
   float cosStart, sinStart, cosEnd, sinEnd;
   float r, t;
   float startAngle, endAngle;

   //Serial << "start: " << start << " end: " << end << endl;
   startAngle = (start / _arcAngleMax) * 360;   // 252
   endAngle = (end / _arcAngleMax) * 360;      // 807
   //Serial << "startAngle: " << startAngle << " endAngle: " << endAngle << endl;

   while (startAngle < 0) startAngle += 360;
   while (endAngle < 0) endAngle += 360;
   while (startAngle > 360) startAngle -= 360;
   while (endAngle > 360) endAngle -= 360;
   //Serial << "startAngleAdj: " << startAngle << " endAngleAdj: " << endAngle << endl;
   //if (endAngle == 0) endAngle = 360;

   if (startAngle > endAngle) {
      fillArcOffsetted(cx, cy, radius, thickness, ((startAngle) / (float)360) * _arcAngleMax, _arcAngleMax, color);
      fillArcOffsetted(cx, cy, radius, thickness, 0, ((endAngle) / (float)360) * _arcAngleMax, color);
   }
   else {
      // Calculate bounding box for the arc to be drawn
      cosStart = cosDegrees(startAngle);
      sinStart = sinDegrees(startAngle);
      cosEnd = cosDegrees(endAngle);
      sinEnd = sinDegrees(endAngle);

      //Serial << cosStart << " " << sinStart << " " << cosEnd << " " << sinEnd << endl;

      r = radius;
      // Point 1: radius & startAngle
      t = r * cosStart;
      if (t < xmin) xmin = t;
      if (t > xmax) xmax = t;
      t = r * sinStart;
      if (t < ymin) ymin = t;
      if (t > ymax) ymax = t;

      // Point 2: radius & endAngle
      t = r * cosEnd;
      if (t < xmin) xmin = t;
      if (t > xmax) xmax = t;
      t = r * sinEnd;
      if (t < ymin) ymin = t;
      if (t > ymax) ymax = t;

      r = radius - thickness;
      // Point 3: radius-thickness & startAngle
      t = r * cosStart;
      if (t < xmin) xmin = t;
      if (t > xmax) xmax = t;
      t = r * sinStart;
      if (t < ymin) ymin = t;
      if (t > ymax) ymax = t;

      // Point 4: radius-thickness & endAngle
      t = r * cosEnd;
      if (t < xmin) xmin = t;
      if (t > xmax) xmax = t;
      t = r * sinEnd;
      if (t < ymin) ymin = t;
      if (t > ymax) ymax = t;


      //Serial << xmin << " " << xmax << " " << ymin << " " << ymax << endl;
      // Corrections if arc crosses X or Y axis
      if ((startAngle < 90) && (endAngle > 90)) {
         ymax = radius;
      }

      if ((startAngle < 180) && (endAngle > 180)) {
         xmin = -radius;
      }

      if ((startAngle < 270) && (endAngle > 270)) {
         ymin = -radius;
      }

      // Slopes for the two sides of the arc
      float sslope = (float)cosStart / (float)sinStart;
      float eslope = (float)cosEnd / (float)sinEnd;

      //Serial << "sslope2: " << sslope << " eslope2:" << eslope << endl;

      if (endAngle == 360) eslope = -1000000;

      int ir2 = (radius - thickness) * (radius - thickness);
      int or2 = radius * radius;
      //Serial << "ymin: " << ymin << " ymax: " << ymax << endl;

      fillScanline16(color);

      enableCS();
      for (int x = xmin; x <= xmax; x++) {
         bool y1StartFound = false, y2StartFound = false;
         bool y1EndFound = false, y2EndSearching = false;
         int y1s = 0, y1e = 0, y2s = 0;
         for (int y = ymin; y <= ymax; y++)
         {
            int x2 = x * x;
            int y2 = y * y;

            if (
               (x2 + y2 < or2 && x2 + y2 >= ir2) && (
               (y > 0 && startAngle < 180 && x <= y * sslope) ||
               (y < 0 && startAngle > 180 && x >= y * sslope) ||
               (y < 0 && startAngle <= 180) ||
               (y == 0 && startAngle <= 180 && x < 0) ||
               (y == 0 && startAngle == 0 && x > 0)
               ) && (
               (y > 0 && endAngle < 180 && x >= y * eslope) ||
               (y < 0 && endAngle > 180 && x <= y * eslope) ||
               (y > 0 && endAngle >= 180) ||
               (y == 0 && endAngle >= 180 && x < 0) ||
               (y == 0 && startAngle == 0 && x > 0)))
            {
               if (!y1StartFound)   //start of the higher line found
               {
                  y1StartFound = true;
                  y1s = y;
               }
               else if (y1EndFound && !y2StartFound) //start of the lower line found
               {
                  //Serial << "Found y2 start x: " << x << " y:" << y << endl;
                  y2StartFound = true;
                  //drawPixel_cont(cx+x, cy+y, ILI9341_BLUE);
                  y2s = y;
                  y += y1e - y1s - 1;   // calculate the most probable end of the lower line (in most cases the length of lower line is equal to length of upper line), in the next loop we will validate if the end of line is really there
                  if (y > ymax - 1) // the most probable end of line 2 is beyond ymax so line 2 must be shorter, thus continue with pixel by pixel search
                  {
                     y = y2s;   // reset y and continue with pixel by pixel search
                     y2EndSearching = true;
                  }

                  //Serial << "Upper line length: " << (y1e - y1s) << " Setting y to " << y << endl;
               }
               else if (y2StartFound && !y2EndSearching)
               {
                  // we validated that the probable end of the lower line has a pixel, continue with pixel by pixel search, in most cases next loop with confirm the end of lower line as it will not find a valid pixel
                  y2EndSearching = true;
               }
               //Serial << "x:" << x << " y:" << y << endl;
               //drawPixel_cont(cx+x, cy+y, ILI9341_BLUE);
            }
            else
            {
               if (y1StartFound && !y1EndFound) //higher line end found
               {
                  y1EndFound = true;
                  y1e = y - 1;
                  //Serial << "line: " << y1s << " - " << y1e << endl;
                  drawFastVLine_cont_noFill(cx + x, cy + y1s, y - y1s, color);
                  if (y < 0)
                  {
                     //Serial << x << " " << y << endl;
                     y = abs(y); // skip the empty middle
                  }
                  else
                     break;
               }
               else if (y2StartFound)
               {
                  if (y2EndSearching)
                  {
                     //Serial << "Found final end at y: " << y << endl;
                     // we found the end of the lower line after pixel by pixel search
                     drawFastVLine_cont_noFill(cx + x, cy + y2s, y - y2s, color);
                     y2EndSearching = false;
                     break;
                  }
                  else
                  {
                     //Serial << "Expected end not found" << endl;
                     // the expected end of the lower line is not there so the lower line must be shorter
                     y = y2s;   // put the y back to the lower line start and go pixel by pixel to find the end
                     y2EndSearching = true;
                  }
               }
               //else
               //drawPixel_cont(cx+x, cy+y, ILI9341_RED);
            }
            //

            //delay(75);
         }
         if (y1StartFound && !y1EndFound)
         {
            y1e = ymax;
            //Serial << "line: " << y1s << " - " << y1e << endl;
            drawFastVLine_cont_noFill(cx + x, cy + y1s, y1e - y1s + 1, color);
         }
         else if (y2StartFound && y2EndSearching)   // we found start of lower line but we are still searching for the end
         {                              // which we haven't found in the loop so the last pixel in a column must be the end
            drawFastVLine_cont_noFill(cx + x, cy + y2s, ymax - y2s + 1, color);
         }
      }
      disableCS();
   }
}



And I don't know what can i delete and what can I copy.

Object, class this isn't my good side... :(((




micke78

Hi

I make a world simple...

int i = analogRead(A5);
   i= map(i, 0, 1024, 277, 83);
  //for(int i = 277; i>=83; i--){
    float x; //=i*2.25;
    x=i*3.1415;
    x=x/180;
    x=sin(x);
    x=x*210;
    float y; //=i*2.25;
    y=i*3.1415;
    y=y/180;
    y=cos(y);
    y=y*210;
     
     tft.fillRect(x+242,y+240,5,5, CYAN);
     

I paint arc like this:

I try to do a universal function. Now middle of ark is in x=242, y=240 and r=210 and thickness = 5...

politea

Hello beginner programmer asking for some help.
I have a:
3.95" 480 x 320 with ili9488 TFT display
on a:
Arduino UNO

I have tried diger67's library. To start im trying to run the program, graphicstest. Is there anything i need to alter in code for it to work on my setup? If i run it as is i get this error:

/Applications/Arduino.app/Contents/Java/libraries/Adafruit_TFTLCD/examples/graphicstest/graphicstest.ino: In function 'void loop()':
graphicstest:33: error: 'A15' was not declared in this scope
 #define SensorPin A15
                   ^
/Applications/Arduino.app/Contents/Java/libraries/Adafruit_TFTLCD/examples/graphicstest/graphicstest.ino:224:42: note: in expansion of macro 'SensorPin'
       pHArray[pHArrayIndex++]=analogRead(SensorPin);
                                          ^
exit status 1
'A15' was not declared in this scope

 Now i have enough knowledge to know the uno doesn't have 15 analog inputs so if i change it from A15 to A5, i get even more errors. What should i do?

micke78

HI
What kind of errors You get when You use A5?
A have the same display and also uno, I use A5 and works OK.
I used MCUFRIEND_kbv.h.

Luka

id76453140

<< 3.95 inch LCD touch screen ili9488 >> and arduino mega2560 They work, but there is the size of the problem.

politea

okay i have gotten the display to work for this 3.95" TFT ili9488 on my arduino uno. My question is: i dont want to use the touch screen or SD car slot. I only want to use it as a display. Which digital and analog inputs are required then? in other words how many digital and analog i/o pins will i be left with that are unused? I plan on possibly hooking up a few sensors as well and displaying the readings on the display, just need to know if its possible. and if not i may have to upgrade to an arduino mega...?

david_prentice

#41
Feb 16, 2016, 12:19 am Last Edit: Feb 16, 2016, 12:20 am by david_prentice
This is answered in message #1, #2 here

If you have a Uno clone with extra header holes,  you can solder some angled header pins.   Or you just steal the signals from the 3x2 ICSP header.    A 6-way ribbon cable will fit without disturbing the shield.

David.

politea

Thank you david_prentice for all your help! My next question would be regarding the libraries. Im currently using:

#include "Adafruit_GFX.h"
#include <MCUFRIEND_kbv.h>

how would I change the default font? I have the Adafruit_GFX lib that you supplied, however it is a little outdated and does not have the new fonts library. what do I need to do in order to use the new fonts and/or upgrade to the new lib?

david_prentice

I have never supplied any Adafruit_GFX library.

The current library from Adafruit handles fonts and buttons.    Just replace your old library with the new one.

Mind you,    there are several issues with the new library.    e.g. Flash location on big Mega or Due projects.
The use of glyphs is only really relevant for italic fonts.     Personally,    I do not think they are appropriate for most TFT projects.     It also makes them incompatible with every font format used in other graphics libraries.

Since it is from Adafruit I would guess that they will resolve this one day.     And for most projects with one or two fonts they will work just fine with the current library.

David.

rdevet

Maybe a stupid question ,but is this screen easy to use with your finger or need to use a stylus for controlling the touchscreen ?

Go Up