Cambio font su tft 2,8"

Sto realizzando un anemometro per chiudere le veneziane in caso di vento eccessivo.
Il tutto è composto da un circuito master che legge i sensori e comanda le veneziane,
ed uno slave con un touch screen da 2,8" per visualizzare ed impostare i vari parameti.
Problema: ingrandendolo ( tft.setTextSize(14) ) il carattere diventa brutto.
Leggendo in giro sembre che la libreria Adafuit GFX prmetta il cambio di font,
ma io non ci riesco, ho inserito il comando #include <Fonts/FreeSerif18pt7b.h> ma il compilatore mi dà errore:

C:\Users\Utente\AppData\Local\Temp\arduino_modified_sketch_828733\Display_NO-flick_OK.ino: In function 'void testVent()':
Display_NO-flick_OK:154:61: error: no matching function for call to 'MCUFRIEND_kbv::setFont(const GFXfont&)'
else tft.setCursor(5, 60); tft.setFont(FreeSerif18pt7b);
^
In file included from C:\Users\Utente\AppData\Local\Temp\arduino_modified_sketch_828733\Display_NO-flick_OK.ino:10:0:
C:\Users\Utente\Documents\Arduino\libraries\Adafruit-GFX-Library-master/Adafruit_GFX.h:122:8: note: candidate: void Adafruit_GFX::setFont(const GFXfont*)
void setFont(const GFXfont f = NULL);
^~~~~~~
C:\Users\Utente\Documents\Arduino\libraries\Adafruit-GFX-Library-master/Adafruit_GFX.h:122:8: note: no known conversion for argument 1 from 'const GFXfont' to 'const GFXfont
'

Ringrazio anticipatamente.
Gianfranco

Dovresti anche mettere il codice del programma oltre all'errore.
Comunque, sembra che l'errore sia nella chiamata:
MCUFRIEND_kbv::setFont(const GFXfont&)

Mi sa che hai copiato da qualche sito, non capisco cosa possa c'entrare MCUFRIENDxxx (di solito una lib che di rifilano certi venditori cinesi) con la libreria GFX Adafruit.

Purtroppo in inglese, ma il sito di Adafruit ha dei wiki/tutorial fatti molto bene.
"Overview | Adafruit GFX Graphics Library | Adafruit Learning System"
Hai provato a leggere li ? C'e' anche la sezione relativa ai fonts

Il tutorial Adafruit l'ho letto e riletto e provato a mettere in pratica i suggerimenti , ma misba.
ok Ok mi hai beccato a scopiazzare! infatti ho preso qua e là dagli esempi forniti con l'hardware, così ho "ereditato" quella libreria.
Proverò ad eliminarla vediamo che succede...

Questo è il codice,

// IMPORTANT: Adafruit_TFTLCD LIBRARY MUST BE SPECIFICALLY
// CONFIGURED FOR EITHER THE TFT SHIELD OR THE BREAKOUT BOARD.
// SEE RELEVANT COMMENTS IN Adafruit_TFTLCD.h FOR SETUP.
//Technical support:goodtft@163.com

//  ANEMOMETRO
//  4 GIRI/s = 10 kM/H      1 M/s = 3,6 kM/H      sensore 16 finestre
//  1 NODO = 1,852 kM/H     1 M/s = 1,944 Nodi

#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_TFTLCD.h> // Hardware-specific library
#include <registers.h>
#include <pin_magic.h>
#include <TouchScreen.h>
#include <Fonts/FreeSerif18pt7b.h>


// #include <MCUFRIEND_kbv.h>
//  MCUFRIEND_kbv tft;
// If using the shield, all control and data lines are fixed, and
// a simpler declaration can optionally be used:
   Adafruit_TFTLCD tft;

#define YP A3  // must be an analog pin, use "An" notation!
#define XM A2  // must be an analog pin, use "An" notation!
#define YM 9   // can be a digital pin
#define XP 8   // can be a digital pin

#define TS_MINX 100
#define TS_MAXX 920

#define TS_MINY 70
#define TS_MAXY 900

/*
  #define TS_MINX 125
  #define TS_MAXX 913

  #define TS_MINY 118
  #define TS_MAXY 833
*/
// For better pressure precision, we need to know the resistance
// between X+ and X- Use any multimeter to read it
// For the one we're using, its 300 ohms across the X plate
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

// The control pins for the LCD can be assigned to any digital or
// analog pins...but we'll use the analog pins as this allows us to
// double up the pins with the touch screen (see the TFT paint example).
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0

#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin

// Assign human-readable names to some common 16-bit color values:
#define	BLACK   0x0000
#define	BLUE    0x001F
#define	RED     0xF800
#define	GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

#define MINPRESSURE 10
#define MAXPRESSURE 1000

int Colore =  WHITE;
int Displ1 = 2;
int Velocita = 0;
int VelMax = 250;
int Displ2 = 2;
int Vunitmis = 1;
int OldVel = 0;
int a = 0;

int PulsUnit = 0;
int PulsLiMax = 0;
int Kiave = 0;
int PulsSuu = 0;
int PulsGiu = 0;
int PaccoDati [8];
int Temperatura = 0;
int Umidita = 0;

unsigned long VaiTime = 0;
unsigned long EraTime = 0;
unsigned long Refresh = 2000;




void negat ( ) {
  tft.setRotation(1);
  tft.setCursor(10, 210);
  tft.setTextSize(3);
  if (PulsLiMax != 32) {
 //   tft.fillRect(0, 185,  155, 60, (BLACK));
    tft.setTextColor(MAGENTA, BLACK);
    tft.println("CHIUDE A");
  }
  else  {
 //   tft.fillRect(0, 200,  160, 60, (MAGENTA));
    tft.setTextColor(WHITE, MAGENTA);
    tft.println("CHIUDE A");
  }
}

void testSuu() {
  tft.setRotation(2);        tft.setCursor(20, 20);
  tft.setTextColor(GREEN);   tft.setTextSize(6);
  tft.println("< ");         tft.setRotation(1);
}
void testGiu() {
  tft.setRotation(2);       tft.setCursor(180, 20);
  tft.setTextColor(RED);    tft.setTextSize(6);
  tft.println(">");         tft.setRotation(1);
}
/*
void testText() {
  tft.setRotation(1);        tft.setCursor(0, 10);
  tft.setTextColor(WHITE);   tft.setTextSize(4);
  tft.println("Vento ");
}*/

void testUnit() {
 // tft.fillRect(0, 0, 200, 50, BLACK);
  tft.setRotation(1);       tft.setCursor(0, 10);
  tft.setTextColor(WHITE, BLACK);  tft.setTextSize(3);
  switch (Vunitmis) {
    case 0:
      tft.println("Vento   m/s ");
      break;
    case 1:
      tft.println("Vento  Km/h ");
      break;
    case 2:
      tft.println("Vento  Nodi ");
      break;
    case 3:
      tft.println("Temperatura ");
      break;
    default:
      tft.println("Umidita'  % ");
      break;
  }
}

void testVent() {

  tft.setRotation(1); if (Displ1 > 0) {
    if (Displ1 < 100) tft.setCursor(85, 60);
    else tft.setCursor(5, 60);  tft.setFont(FreeSerif18pt7b);
    tft.setTextColor(Colore, BLACK);  tft.setTextSize(14);
    tft.fillRect(0, 50, 320, 135,  BLACK);
    tft.print(int (Displ1 / 10));
    tft.setCursor(175, 90);
    tft.setTextSize(10);
    tft.print(int (Displ1 % 10));
  }
}

void testMax() {
//  tft.fillRect(155, 185, 90, 70,  BLACK);
  tft.setRotation(1);       tft.setCursor(180, 200);
  tft.setTextColor(MAGENTA, BLACK);    tft.setTextSize(5);
  if (Displ2 > 0) {
  if (Displ2 < 100) tft.print("   "); tft.setCursor(180, 200);
  tft.println(int (Displ2 / 10));
  }
}

void setup(void) {


  Serial.begin(19200);
  while (!Serial) {
    ;
  }

  tft.reset();
  uint16_t identifier = tft.readID();
  tft.begin(identifier);

  tft.setRotation(1);
  tft.fillScreen(BLACK);

  /*     // Attivare per avere un riferimento
      tft.drawRect(0, 200,  155, 40, MAGENTA);  // testo
      tft.drawRect(155, 200,  60, 40, MAGENTA); // numero
      //    tft.drawRect(0, 150,  155, 40, YELLOW);   // testo
      //    tft.fillRect(155, 150,  60, 40, YELLOW);  // numero
      tft.drawRect(240, 150, 80, 80, RED);
      tft.drawRect(240, 0, 80, 80, GREEN);
      tft.drawRect(130, 0, 80, 50, BLUE);
      //  tft.drawRect(0, 55, 225, 90, WHITE);
      //  tft.fillRect(BOXSIZE*5, 0, BOXSIZE, BOXSIZE, WHITE);
 */  

  pinMode(13, OUTPUT);
}
void loop(void) {

  // Visualizza schermata
  //  testVent ();
 // testText ();
  testSuu ();
  testGiu ();
  //  testUnit ();
  //  testMax ();
  //  negat ();



  Serial.flush();
  a = 0;
  if (Serial.available() >= 8) { // ricevo pacco Dati
    for (a = 0; a < 8; a++) {
      PaccoDati [a] = Serial.read();
    }
  }
  VelMax   =    ( PaccoDati [0] * 256 + PaccoDati[1]);
  Velocita =    ( PaccoDati [2] * 256 + PaccoDati[3]);
  Umidita  =     (PaccoDati [4] * 256 + PaccoDati[5]);
 Temperatura  = ( PaccoDati [6] * 256 + PaccoDati[7]);

  if (VelMax > 900 || VelMax < 1) VelMax = 10;
  if (Velocita > 999 || Velocita < 1) Velocita = 1;

  //     VelMax   =  250;
  //     Velocita =  random (255);

  if (Velocita > VelMax) Colore = RED;
  else Colore = WHITE;

  switch (Vunitmis) {
    case 0:
      Displ1 = Velocita / 3.6;
      Displ2 = VelMax / 3.6;
      break;
    case 1:
      Displ1 = Velocita;
      Displ2 = VelMax;
      break;
    case 2:
      Displ1 = Velocita / 1.852;
      Displ2 = VelMax / 1.852;
      break;
    case 3:
      Displ1 = Temperatura;
      Displ2 = 0;
      break;
    default:
      Displ1 = Umidita;
      Displ2 = 0;
      break;
  }

  negat ();
  testUnit ();
  testMax ();

  VaiTime = millis();
  if (VaiTime - EraTime > Refresh) {
    testVent ();
    EraTime = VaiTime;
  }





  digitalWrite(13, HIGH);
  TSPoint p = ts.getPoint();
  digitalWrite(13, LOW);

  // if sharing pins, you'll need to fix the directions of the touchscreen pins
  //  pinMode(XP, OUTPUT);
  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);
  //  pinMode(YM, OUTPUT);

  // we have some minimum pressure we consider 'valid'
  // pressure of 0 means no pressing!
  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {
    /*
        Serial.print("X = "); Serial.print(p.x);
        Serial.print("  Y = "); Serial.print(p.y);
        Serial.print("  Press "); Serial.println(p.z);
    */
    if (p.x < 390 && p.y > 710) {
      tft.fillRect(240, 0, 80, 80,  GREEN);
      PulsSuu = 32 ;
      if (PulsLiMax == 32) {
        Kiave = 0;
      }
      else Kiave = 32;
      delay(50);              //    PulsSuu
      tft.fillRect(240, 0, 80, 80,  BLACK);
      //   tft.drawRect(240, 0, 80, 80,  GREEN);
    }

    if (p.x > 640 && p.y > 715) {
      tft.fillRect(240, 150, 80, 80, RED);
      PulsGiu = 32;
      if (PulsLiMax == 32) {
        Kiave = 0;
      }
      else Kiave = 32;
      delay(50);             //     Pulsante Giu
      tft.fillRect(240, 150, 80, 80, BLACK);
      //     tft.drawRect(240, 150, 80, 80,  RED);
    }

    if (p.x < 300 && p.y > 430  && p.y < 620) {
      tft.fillRect(130, 0, 80, 50, BLUE);
      PulsUnit = 32;      // Pulsante Unità di misura
      delay(50);
      tft.fillRect(130, 0, 80, 50, BLACK);
      //     tft.drawRect(130, 0, 80, 50, BLUE);
    }

    if (p.x > 800 && p.y < 440) {
      tft.fillRect(0, 200,  140, 40, MAGENTA);
      delay(100);          //    Pulsante settaggio limite Max
      PulsLiMax = PulsLiMax + 8;
      if (PulsLiMax > 32) PulsLiMax = 0;
      tft.fillRect(0, 200,  140, 40, BLACK);
    }
  }


  if ( PulsUnit == 32)  {
    Vunitmis++;
    PulsUnit = 8;
    if (Vunitmis > 4) Vunitmis = 0;
  }
  Serial.flush();
  if  (Serial.availableForWrite () >= 4) {
    Serial.write(PulsLiMax);
    Serial.write(PulsSuu); // invio pacchetto pulsanti
    Serial.write(PulsGiu);
    Serial.write(Kiave);
  }

  PulsSuu = PulsLiMax;
  PulsSuu = 4;
  PulsGiu = 5;
  Kiave   = 6;

}

Questo è il nuovo errore, sembra che non venga riconosciuto il comando tft.setFont()

C:\Users\semo\AppData\Local\Temp\arduino_modified_sketch_842090\Display_NO-flick_OK.ino: In function 'void testVent()':
Display_NO-flick_OK:156:65: error: no matching function for call to 'Adafruit_TFTLCD::setFont(const GFXfont&)'
else tft.setCursor(5, 60); tft.setFont(FreeSerif18pt7b);
^
In file included from C:\Users\semo\AppData\Local\Temp\arduino_modified_sketch_842090\Display_NO-flick_OK.ino:10:0:
C:\Users\semo\Documents\Arduino\libraries\Adafruit-GFX-Library-master/Adafruit_GFX.h:122:8: note: candidate: void Adafruit_GFX::setFont(const GFXfont*)
void setFont(const GFXfont f = NULL);
^~~~~~~
C:\Users\semo\Documents\Arduino\libraries\Adafruit-GFX-Library-master/Adafruit_GFX.h:122:8: note: no known conversion for argument 1 from 'const GFXfont' to 'const GFXfont
'

Prova così:

tft.setFont(&FreeSerif18pt7b);

Infatti ti informa che:

C:\Users\semo\Documents\Arduino\libraries\Adafruit-GFX-Library-master/Adafruit_GFX.h:122:8: note: candidate: void Adafruit_GFX::setFont(const GFXfont*)

si aspetta un puntatore a GFXfont* e non un riferimento a GFXfont&

Ciao.

BINGOOOO!
Problema risolto, ora carica le font: dovrò fare un pò di pratica con dimensioni e posizioni per riostruire le schermate ma non importa, era da un paio di mesi che ci sbattevo le corna.
Vi ringrazio ed avete la mia eterna gratituine.

P.S.
Ogni tentativo di disfarni della MCUFRIEND mi ha dato nebbia in val padana, nel senso che lo schermo è rimasto bianco, avete qualche dritta anche per questo problemino?

Gianfranco

??? Nel codice che hai postato, quella parte è remmata (quindi non la usi)

// #include <MCUFRIEND_kbv.h>
//  MCUFRIEND_kbv tft;

Infatti ora l'oggetto tft è di tipo Adafruit_TFTLCD e non più di tipo MCUFRIEND_kbv

Devo aver fatto un po di casino con le modifiche, lasciatemi fare qualche prova per chiarirmi le ideee.

Ricapitolando:
Con la benedetta & la font viene caricata, ma per le diverse proporzioni sullo schermo i caratteri si accavallano che è un piacere (no problem rifarò le schermate).

Eliminano MCUFRIEND non riconosce più il comano tft.

Attivando Adafruit_TFTLCD tft; lo schermo rimane bianco

Non dici che schermo hai.
Se usando adafruit rimane bianco, sbagli qualche parametro, ma non sapendo che driver monta il tft possiamo dire poco.

Il display è questo: 2.8inch_UC8230_V1.1
240 x 320 pixels
Found ILI9341 LCD driver
(Appene capisco come si fa allego una foto)

Penso che togliendo quella libreria si perda qualche riferimento ai collegamenti dei pin.
Comunque sono già abbastanza soddisfatto del risultato: rispetto a prima non c'è paragone!
Pazienza se devo tenermi la MCUFRIEND.

Tutto quelle righe che hai nel setup per quel display, sono specifiche per quella vecchia libreria.
La libreria Adafruit si usa in maniera diversa. Bisogna poi adeguare anche tutto il resto, ad esempio la setFont
"Overview | Adafruit 2.8" and 3.2" Color TFT Touchscreen Breakout v2 | Adafruit Learning System"

"Adafruit_ILI9341/examples/graphicstest/graphicstest.ino at master · adafruit/Adafruit_ILI9341 · GitHub"
Oltre alla Adafruit_GFX dovresti scaricare la Adafruit_ILI9341
Va detto che le lib GFX di Adafruit sono grosse e pesantine.

La mia scheda è diversa. i pin sono disposti in modo da corrispondere esattamente ad arduino uno, non è possibile alcuna variazione.
La ILI9341 ce l'ho ma non la so usare...

Dei collegamenti non ci interessa nulla. In quei link l'importante è vedere come la libreria di adafruit è un pò diversa da quella MCUFRIEND_kbv

Questo esempio l'ho provato, sia ccopiandolo pari pari sia adattando i pin:

// For the Adafruit shield, these are the default.
#define TFT_DC A2
#define TFT_CS A3

#define TFT_MOSI 11
#define TFT_CLK 13
#define TFT_RST A4
#define TFT_MISO 12
// Use hardware SPI (on Uno, #13, #12, #11) and the above for CS/DC
// Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
// If using the breakout, change pins as desired
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);

Il risultato sempre nebbia = schermo bianco.
Ho anche ficcanasato nelle librerie (senza cavarci un granchè.

La tua shield ha interfaccia parallela.

#if 0
//################################### UNO ##############################
#elif defined(__AVR_ATmega328P__) || defined(__AVR_ATmega328PB__)       //regular UNO shield on UNO
//LCD pins  |D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0 | |RD |WR |RS |CS |RST|
//AVR   pin |PD7|PD6|PD5|PD4|PD3|PD2|PB1|PB0| |PC0|PC1|PC2|PC3|PC4|
//UNO pins  |7  |6  |5  |4  |3  |2  |9  |8  | |A0 |A1 |A2 |A3 |A4 |

Ciao.

MaurotecTesla

13hpost #16

La tua shield ha interfaccia parallela.


#if 0
//################################### UNO ##############################
#elif defined(AVR_ATmega328P) || defined(AVR_ATmega328PB) //regular UNO shield on UNO
//LCD pins |D7 |D6 |D5 |D4 |D3 |D2 |D1 |D0 | |RD |WR |RS |CS |RST|
//AVR pin |PD7|PD6|PD5|PD4|PD3|PD2|PB1|PB0| |PC0|PC1|PC2|PC3|PC4|
//UNO pins |7 |6 |5 |4 |3 |2 |9 |8 | |A0 |A1 |A2 |A3 |A4 |

Scusa ma non capisco, la piedinatura l'ho già ricavata dall'hardware ma è come farla "digerire" allo skech che mi manca.

#if
#elif
sono comandi che non conosco.

(Mcufriend_kbv with ili9341 SPI display - #4 by david_prentice)post

Da quel che leggo in giro, la lib di adafruit è per tft con collegamento SPI, mentre la lib MCUFRIEND_kbv è per collegamento parallelo.
Quindi non c'è modo di usare la adafruit sul tuo tft

// @file Adafruit_ILI9341.cpp
/**************************************************************************/
/*!
    @brief  Instantiate Adafruit ILI9341 driver using parallel interface.
    @param  busWidth  If tft16 (enumeration in Adafruit_SPITFT.h), is a
                      16-bit interface, else 8-bit.
    @param  d0        Data pin 0 (MUST be a byte- or word-aligned LSB of a
                      PORT register -- pins 1-n are extrapolated from this).
    @param  wr        Write strobe pin # (required).
    @param  dc        Data/Command pin # (required).
    @param  cs        Chip select pin # (optional, pass -1 if unused and CS
                      is tied to GND).
    @param  rst       Reset pin # (optional, pass -1 if unused).
    @param  rd        Read strobe pin # (optional, pass -1 if unused).
*/
/**************************************************************************/
Adafruit_ILI9341::Adafruit_ILI9341(tftBusWidth busWidth, int8_t d0, int8_t wr,
                                   int8_t dc, int8_t cs, int8_t rst, int8_t rd)
    : Adafruit_SPITFT(ILI9341_TFTWIDTH, ILI9341_TFTHEIGHT, busWidth, d0, wr, dc,
                      cs, rst, rd) {}

// @file Adafruit_SPITFT.h
enum tftBusWidth { tft8bitbus, tft16bitbus };
// dal tuo post
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0

#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin

chiamata al costruttore per interfaccia parallela

Adafruit_ILI9341::Adafruit_ILI9341(tft8bitbus, 8, LCD_WR,
                                   LCD_CD, LCD_CS, LCD_RESET, LCD_RD)

Ok la chiamata sopra potrebbe funzionare. Se non funziona io direi di lasciare stare e tenersi la MCUFRIEND.

Ciao.

Concordo, farò ancora qualche prova: se ottengo qualche risultato Ve lo farò sapere.
Per ora grazie di tutto.
Gianfranco