Arduino UNO e ILI9341 rimane schermo bianco

Sto provando il display ILI9341 con Arduino uno utilizzando lo sketch graphicstest che ho trovato negli esempi ma mi evidenzio solo uno schermo bianco anche se uso i 3v per l'ingresso LED sul display.
Per abbassare la tensione in ingresso al display ho collegato in serie ai pin delle resistenze da 10k, come consigliato su sito internet.
I collegamenti ai pin sono i seguenti:

VCC		5v 
GND       GND
CS		10 
RESET 	8
DC 		9
SDI/MOSI 	11
SCK 		13
LED 		3v
SDD/MISO 	12
T_CLK 	3
T_CS 		4
T_DIN 	5
T_DO 		6
T_IRQ 	7

Lo sketch è il seguente:

/***************************************************
    This is our GFX example for the Adafruit ILI9341 Breakout and Shield
    ----> http://www.adafruit.com/products/1651
  
    Check out the links above for our tutorials and wiring diagrams
    These displays use SPI to communicate, 4 or 5 pins are required to
    interface (RST is optional)
    Adafruit invests time and resources providing this open source code,
    please support Adafruit and open-source hardware by purchasing
    products from Adafruit!
  
    Written by Limor Fried/Ladyada for Adafruit Industries.
    MIT license, all text above must be included in any redistribution
   ****************************************************/
  
  
  #include "SPI.h"
  #include "Adafruit_GFX.h"
  #include "Adafruit_ILI9341.h"
  
  // For the Adafruit shield, these are the default.
  #define TFT_DC 9
  #define TFT_CS 10
  
  // 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);
  
  void setup() {
    Serial.begin(9600);
    Serial.println("ILI9341 Test!"); 
   
    tft.begin();
  
    // read diagnostics (optional but can help debug problems)
    uint8_t x = tft.readcommand8(ILI9341_RDMODE);
    Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
    x = tft.readcommand8(ILI9341_RDMADCTL);
    Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
    x = tft.readcommand8(ILI9341_RDPIXFMT);
    Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
    x = tft.readcommand8(ILI9341_RDIMGFMT);
    Serial.print("Image Format: 0x"); Serial.println(x, HEX);
    x = tft.readcommand8(ILI9341_RDSELFDIAG);
    Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX); 
    
    Serial.println(F("Benchmark                Time (microseconds)"));
    delay(10);
    Serial.print(F("Screen fill              "));
    Serial.println(testFillScreen());
    delay(500);
  
    Serial.print(F("Text                     "));
    Serial.println(testText());
    delay(3000);
  
    Serial.print(F("Lines                    "));
    Serial.println(testLines(ILI9341_CYAN));
    delay(500);
  
    Serial.print(F("Horiz/Vert Lines         "));
    Serial.println(testFastLines(ILI9341_RED, ILI9341_BLUE));
    delay(500);
  
    Serial.print(F("Rectangles (outline)     "));
    Serial.println(testRects(ILI9341_GREEN));
    delay(500);
  
    Serial.print(F("Rectangles (filled)      "));
    Serial.println(testFilledRects(ILI9341_YELLOW, ILI9341_MAGENTA));
    delay(500);
  
    Serial.print(F("Circles (filled)         "));
    Serial.println(testFilledCircles(10, ILI9341_MAGENTA));
  
    Serial.print(F("Circles (outline)        "));
    Serial.println(testCircles(10, ILI9341_WHITE));
    delay(500);
  
    Serial.print(F("Triangles (outline)      "));
    Serial.println(testTriangles());
    delay(500);
  
    Serial.print(F("Triangles (filled)       "));
    Serial.println(testFilledTriangles());
    delay(500);
  
    Serial.print(F("Rounded rects (outline)  "));
    Serial.println(testRoundRects());
    delay(500);
  
    Serial.print(F("Rounded rects (filled)   "));
    Serial.println(testFilledRoundRects());
    delay(500);
  
    Serial.println(F("Done!"));
  
  }
  
  
  void loop(void) {
    for(uint8_t rotation=0; rotation<4; rotation++) {
      tft.setRotation(rotation);
      testText();
      delay(1000);
    }
  }
  
  unsigned long testFillScreen() {
    unsigned long start = micros();
    tft.fillScreen(ILI9341_BLACK);
    yield();
    tft.fillScreen(ILI9341_RED);
    yield();
    tft.fillScreen(ILI9341_GREEN);
    yield();
    tft.fillScreen(ILI9341_BLUE);
    yield();
    tft.fillScreen(ILI9341_BLACK);
    yield();
    return micros() - start;
  }
  
  unsigned long testText() {
    tft.fillScreen(ILI9341_BLACK);
    unsigned long start = micros();
    tft.setCursor(0, 0);
    tft.setTextColor(ILI9341_WHITE);  tft.setTextSize(1);
    tft.println("Hello World!");
    tft.setTextColor(ILI9341_YELLOW); tft.setTextSize(2);
    tft.println(1234.56);
    tft.setTextColor(ILI9341_RED);    tft.setTextSize(3);
    tft.println(0xDEADBEEF, HEX);
    tft.println();
    tft.setTextColor(ILI9341_GREEN);
    tft.setTextSize(5);
    tft.println("Groop");
    tft.setTextSize(2);
    tft.println("I implore thee,");
    tft.setTextSize(1);
    tft.println("my foonting turlingdromes.");
    tft.println("And hooptiously drangle me");
    tft.println("with crinkly bindlewurdles,");
    tft.println("Or I will rend thee");
    tft.println("in the gobberwarts");
    tft.println("with my blurglecruncheon,");
    tft.println("see if I don't!");
    return micros() - start;
  }
  
  unsigned long testLines(uint16_t color) {
    unsigned long start, t;
    int           x1, y1, x2, y2,
                  w = tft.width(),
                  h = tft.height();
  
    tft.fillScreen(ILI9341_BLACK);
    yield();
    
    x1 = y1 = 0;
    y2    = h - 1;
    start = micros();
    for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
    x2    = w - 1;
    for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
    t     = micros() - start; // fillScreen doesn't count against timing
  
    yield();
    tft.fillScreen(ILI9341_BLACK);
    yield();
  
    x1    = w - 1;
    y1    = 0;
    y2    = h - 1;
    start = micros();
    for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
    x2    = 0;
    for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
    t    += micros() - start;
  
    yield();
    tft.fillScreen(ILI9341_BLACK);
    yield();
  
    x1    = 0;
    y1    = h - 1;
    y2    = 0;
    start = micros();
    for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
    x2    = w - 1;
    for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
    t    += micros() - start;
  
    yield();
    tft.fillScreen(ILI9341_BLACK);
    yield();
  
    x1    = w - 1;
    y1    = h - 1;
    y2    = 0;
    start = micros();
    for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
    x2    = 0;
    for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
  
    yield();
    return micros() - start;
  }
  
  unsigned long testFastLines(uint16_t color1, uint16_t color2) {
    unsigned long start;
    int           x, y, w = tft.width(), h = tft.height();
  
    tft.fillScreen(ILI9341_BLACK);
    start = micros();
    for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1);
    for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2);
  
    return micros() - start;
  }
  
  unsigned long testRects(uint16_t color) {
    unsigned long start;
    int           n, i, i2,
                  cx = tft.width()  / 2,
                  cy = tft.height() / 2;
  
    tft.fillScreen(ILI9341_BLACK);
    n     = min(tft.width(), tft.height());
    start = micros();
    for(i=2; i<n; i+=6) {
      i2 = i / 2;
      tft.drawRect(cx-i2, cy-i2, i, i, color);
    }
  
    return micros() - start;
  }
  
  unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
    unsigned long start, t = 0;
    int           n, i, i2,
                  cx = tft.width()  / 2 - 1,
                  cy = tft.height() / 2 - 1;
  
    tft.fillScreen(ILI9341_BLACK);
    n = min(tft.width(), tft.height());
    for(i=n; i>0; i-=6) {
      i2    = i / 2;
      start = micros();
      tft.fillRect(cx-i2, cy-i2, i, i, color1);
      t    += micros() - start;
      // Outlines are not included in timing results
      tft.drawRect(cx-i2, cy-i2, i, i, color2);
      yield();
    }
  
    return t;
  }
  
  unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
    unsigned long start;
    int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;
  
    tft.fillScreen(ILI9341_BLACK);
    start = micros();
    for(x=radius; x<w; x+=r2) {
      for(y=radius; y<h; y+=r2) {
        tft.fillCircle(x, y, radius, color);
      }
    }
  
    return micros() - start;
  }
  
  unsigned long testCircles(uint8_t radius, uint16_t color) {
    unsigned long start;
    int           x, y, r2 = radius * 2,
                  w = tft.width()  + radius,
                  h = tft.height() + radius;
  
    // Screen is not cleared for this one -- this is
    // intentional and does not affect the reported time.
    start = micros();
    for(x=0; x<w; x+=r2) {
      for(y=0; y<h; y+=r2) {
        tft.drawCircle(x, y, radius, color);
      }
    }
  
    return micros() - start;
  }
  
  unsigned long testTriangles() {
    unsigned long start;
    int           n, i, cx = tft.width()  / 2 - 1,
                        cy = tft.height() / 2 - 1;
  
    tft.fillScreen(ILI9341_BLACK);
    n     = min(cx, cy);
    start = micros();
    for(i=0; i<n; i+=5) {
      tft.drawTriangle(
        cx    , cy - i, // peak
        cx - i, cy + i, // bottom left
        cx + i, cy + i, // bottom right
        tft.color565(i, i, i));
    }
  
    return micros() - start;
  }
  
  unsigned long testFilledTriangles() {
    unsigned long start, t = 0;
    int           i, cx = tft.width()  / 2 - 1,
                     cy = tft.height() / 2 - 1;
  
    tft.fillScreen(ILI9341_BLACK);
    start = micros();
    for(i=min(cx,cy); i>10; i-=5) {
      start = micros();
      tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
        tft.color565(0, i*10, i*10));
      t += micros() - start;
      tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
        tft.color565(i*10, i*10, 0));
      yield();
    }
  
    return t;
  }
  
  unsigned long testRoundRects() {
    unsigned long start;
    int           w, i, i2,
                  cx = tft.width()  / 2 - 1,
                  cy = tft.height() / 2 - 1;
  
    tft.fillScreen(ILI9341_BLACK);
    w     = min(tft.width(), tft.height());
    start = micros();
    for(i=0; i<w; i+=6) {
      i2 = i / 2;
      tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0));
    }
  
    return micros() - start;
  }
  
  unsigned long testFilledRoundRects() {
    unsigned long start;
    int           i, i2,
                  cx = tft.width()  / 2 - 1,
                  cy = tft.height() / 2 - 1;
  
    tft.fillScreen(ILI9341_BLACK);
    start = micros();
    for(i=min(tft.width(), tft.height()); i>20; i-=6) {
      i2 = i / 2;
      tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0));
      yield();
    }
  
    return micros() - start;
  }

I collegamenti sono stati copiati dal disegno sul sito "Display TFT 2.4″ SPI ILI9341 con Touch-Screen - Fattelo da Solo"

EzioGi

Beh intanto non capisco, per abbassare la tensione da 5 a 3.3 V mettono una resistenza da 10k in serie, e non il classico piccolo partitore? Ossia:


Ti basta calcolare le resistenze in base al rapporto tra Vin e Vout:
Vout/Vin = R2 / (R1+R2)
Altrimenti un semplice traslatore di tensione è la soluzione migliore.

PS: tra l'altro, come ulteriore punto che non mi fa considerare molto affidabile quella pagina, le resistenze che si vedono nello schema a me sembrano sbagliate, da 220 Ohm e non da 10k...

E il monitor seriale cosa dice?

Ciao, Ale.

Il monitor seriale mia vedere che lo sketch gira regolarmente e mi presenta le varie videate che sta costruendo e che dovrei vedere a video.
Mi è venuto il dubbio che siano sbagliati i pin associati ai comandi.
Comincio a pensare anche io che il sito non sia molto affidabile.
Ho provato lo sketch con un ESP8266 NODE MCU e mi da anche lui lo schermo bianco.

EzioGi

Al posto tuo proverei per prima cosa a levare le resistenze da 10k (che secondo me non fanno passare sufficiente corrente) sostituendole con altrettanti "veri" partitori per convertire da 5 a 3.3V: calcola in base a quella formula, che in pratica dice che "VOUT sta a VIN come R2 sta a (R1+R2)" quindi nel tuo caso R2/(R1+R2)=0.66 ossia, semplificando, R2=2*R1. Ad esempio R1=4.7k quindi approssimando i 9.4k teorici potresti mettere la più vicina quindi 10k Ohm.

Ok, domani vado a prendere i resistori.
Grazie

EzioGi

Ho voluto fare un'altra prova utilizzando un ESP32 NODE MCU con questo sketch, alimentandolo a 3,3v:

/***************************************************
    This is our GFX example for the Adafruit ILI9341 Breakout and Shield
    ----> http://www.adafruit.com/products/1651
    Check out the links above for our tutorials and wiring diagrams
    These displays use SPI to communicate, 4 or 5 pins are required to
    interface (RST is optional)
    Adafruit invests time and resources providing this open source code,
    please support Adafruit and open-source hardware by purchasing
    products from Adafruit!
    Written by Limor Fried/Ladyada for Adafruit Industries.
    MIT license, all text above must be included in any redistribution
    
   ****************************************************/
  #include "SPI.h"
  #include "Adafruit_GFX.h"
  #include "Adafruit_ILI9341.h"
  // For the Adafruit shield, these are the default.
  #define TFT_CS    D2
  #define TFT_RST   D3
  #define TFT_DC    D4
  #define TFT_MOSI  D5
  #define TFT_CLK   D6
  #define TFT_MISO  D7
  // 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);
  void setup() {
    Serial.begin(9600);
    Serial.println("ILI9341 Test!");
    tft.begin();
    // read diagnostics (optional but can help debug problems)
    uint8_t x = tft.readcommand8(ILI9341_RDMODE);
    Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
    x = tft.readcommand8(ILI9341_RDMADCTL);
    Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
    x = tft.readcommand8(ILI9341_RDPIXFMT);
    Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
    x = tft.readcommand8(ILI9341_RDIMGFMT);
    Serial.print("Image Format: 0x"); Serial.println(x, HEX);
    x = tft.readcommand8(ILI9341_RDSELFDIAG);
    Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX);
    Serial.println(F("Benchmark                Time (microseconds)"));
    delay(10);
    Serial.print(F("Screen fill              "));
    Serial.println(testFillScreen());
    delay(500);
    Serial.print(F("Text                     "));
    Serial.println(testText());
    delay(3000);
    Serial.print(F("Lines                    "));
    Serial.println(testLines(ILI9341_CYAN));
    delay(500);
    Serial.print(F("Horiz/Vert Lines         "));
    Serial.println(testFastLines(ILI9341_RED, ILI9341_BLUE));
    delay(500);
    Serial.print(F("Rectangles (outline)     "));
    Serial.println(testRects(ILI9341_GREEN));
    delay(500);
    Serial.print(F("Rectangles (filled)      "));
    Serial.println(testFilledRects(ILI9341_YELLOW, ILI9341_MAGENTA));
    delay(500);
    Serial.print(F("Circles (filled)         "));
    Serial.println(testFilledCircles(10, ILI9341_MAGENTA));
    Serial.print(F("Circles (outline)        "));
    Serial.println(testCircles(10, ILI9341_WHITE));
    delay(500);
    Serial.print(F("Triangles (outline)      "));
    Serial.println(testTriangles());
    delay(500);
    Serial.print(F("Triangles (filled)       "));
    Serial.println(testFilledTriangles());
    delay(500);
    Serial.print(F("Rounded rects (outline)  "));
    Serial.println(testRoundRects());
    delay(500);
    Serial.print(F("Rounded rects (filled)   "));
    Serial.println(testFilledRoundRects());
    delay(500);
    Serial.println(F("Done!"));
  }
  void loop(void) {
    for(uint8_t rotation=0; rotation<4; rotation++) {
      tft.setRotation(rotation);
      testText();
      delay(1000);
    }
  }
  unsigned long testFillScreen() {
    unsigned long start = micros();
    tft.fillScreen(ILI9341_BLACK);
    yield();
    tft.fillScreen(ILI9341_RED);
    yield();
    tft.fillScreen(ILI9341_GREEN);
    yield();
    tft.fillScreen(ILI9341_BLUE);
    yield();
    tft.fillScreen(ILI9341_BLACK);
    yield();
    return micros() - start;
  }
  unsigned long testText() {
    tft.fillScreen(ILI9341_BLACK);
    unsigned long start = micros();
    tft.setCursor(0, 0);
    tft.setTextColor(ILI9341_WHITE);  tft.setTextSize(1);
    tft.println("Hello World!");
    tft.setTextColor(ILI9341_YELLOW); tft.setTextSize(2);
    tft.println(1234.56);
    tft.setTextColor(ILI9341_RED);    tft.setTextSize(3);
    tft.println(0xDEADBEEF, HEX);
    tft.println();
    tft.setTextColor(ILI9341_GREEN);
    tft.setTextSize(5);
    tft.println("Groop");
    tft.setTextSize(2);
    tft.println("I implore thee,");
    tft.setTextSize(1);
    tft.println("my foonting turlingdromes.");
    tft.println("And hooptiously drangle me");
    tft.println("with crinkly bindlewurdles,");
    tft.println("Or I will rend thee");
    tft.println("in the gobberwarts");
    tft.println("with my blurglecruncheon,");
    tft.println("see if I don't!");
    return micros() - start;
  }
  unsigned long testLines(uint16_t color) {
    unsigned long start, t;
    int           x1, y1, x2, y2,
                  w = tft.width(),
                  h = tft.height();
    tft.fillScreen(ILI9341_BLACK);
    yield();
    x1 = y1 = 0;
    y2    = h - 1;
    start = micros();
    for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
    x2    = w - 1;
    for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
    t     = micros() - start; // fillScreen doesn't count against timing
    yield();
    tft.fillScreen(ILI9341_BLACK);
    yield();
    x1    = w - 1;
    y1    = 0;
    y2    = h - 1;
    start = micros();
    for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
    x2    = 0;
    for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
    t    += micros() - start;
    yield();
    tft.fillScreen(ILI9341_BLACK);
    yield();
    x1    = 0;
    y1    = h - 1;
    y2    = 0;
    start = micros();
    for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
    x2    = w - 1;
    for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
    t    += micros() - start;
    yield();
    tft.fillScreen(ILI9341_BLACK);
    yield();
    x1    = w - 1;
    y1    = h - 1;
    y2    = 0;
    start = micros();
    for(x2=0; x2<w; x2+=6) tft.drawLine(x1, y1, x2, y2, color);
    x2    = 0;
    for(y2=0; y2<h; y2+=6) tft.drawLine(x1, y1, x2, y2, color);
    yield();
    return micros() - start;
  }
  unsigned long testFastLines(uint16_t color1, uint16_t color2) {
    unsigned long start;
    int           x, y, w = tft.width(), h = tft.height();
    tft.fillScreen(ILI9341_BLACK);
    start = micros();
    for(y=0; y<h; y+=5) tft.drawFastHLine(0, y, w, color1);
    for(x=0; x<w; x+=5) tft.drawFastVLine(x, 0, h, color2);
    return micros() - start;
  }
  unsigned long testRects(uint16_t color) {
    unsigned long start;
    int           n, i, i2,
                  cx = tft.width()  / 2,
                  cy = tft.height() / 2;
    tft.fillScreen(ILI9341_BLACK);
    n     = min(tft.width(), tft.height());
    start = micros();
    for(i=2; i<n; i+=6) {
      i2 = i / 2;
      tft.drawRect(cx-i2, cy-i2, i, i, color);
    }
    return micros() - start;
  }
  unsigned long testFilledRects(uint16_t color1, uint16_t color2) {
    unsigned long start, t = 0;
    int           n, i, i2,
                  cx = tft.width()  / 2 - 1,
                  cy = tft.height() / 2 - 1;
    tft.fillScreen(ILI9341_BLACK);
    n = min(tft.width(), tft.height());
    for(i=n; i>0; i-=6) {
      i2    = i / 2;
      start = micros();
      tft.fillRect(cx-i2, cy-i2, i, i, color1);
      t    += micros() - start;
      // Outlines are not included in timing results
      tft.drawRect(cx-i2, cy-i2, i, i, color2);
      yield();
    }
    return t;
  }
  unsigned long testFilledCircles(uint8_t radius, uint16_t color) {
    unsigned long start;
    int x, y, w = tft.width(), h = tft.height(), r2 = radius * 2;
    tft.fillScreen(ILI9341_BLACK);
    start = micros();
    for(x=radius; x<w; x+=r2) {
      for(y=radius; y<h; y+=r2) {
        tft.fillCircle(x, y, radius, color);
      }
    }
    return micros() - start;
  }
  unsigned long testCircles(uint8_t radius, uint16_t color) {
    unsigned long start;
    int           x, y, r2 = radius * 2,
                  w = tft.width()  + radius,
                  h = tft.height() + radius;
    // Screen is not cleared for this one -- this is
    // intentional and does not affect the reported time.
    start = micros();
    for(x=0; x<w; x+=r2) {
      for(y=0; y<h; y+=r2) {
        tft.drawCircle(x, y, radius, color);
      }
    }
    return micros() - start;
  }
  unsigned long testTriangles() {
    unsigned long start;
    int           n, i, cx = tft.width()  / 2 - 1,
                        cy = tft.height() / 2 - 1;
    tft.fillScreen(ILI9341_BLACK);
    n     = min(cx, cy);
    start = micros();
    for(i=0; i<n; i+=5) {
      tft.drawTriangle(
        cx    , cy - i, // peak
        cx - i, cy + i, // bottom left
        cx + i, cy + i, // bottom right
        tft.color565(i, i, i));
    }
    return micros() - start;
  }
  unsigned long testFilledTriangles() {
    unsigned long start, t = 0;
    int           i, cx = tft.width()  / 2 - 1,
                     cy = tft.height() / 2 - 1;
    tft.fillScreen(ILI9341_BLACK);
    start = micros();
    for(i=min(cx,cy); i>10; i-=5) {
      start = micros();
      tft.fillTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
        tft.color565(0, i*10, i*10));
      t += micros() - start;
      tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i,
        tft.color565(i*10, i*10, 0));
      yield();
    }
    return t;
  }
  unsigned long testRoundRects() {
    unsigned long start;
    int           w, i, i2,
                  cx = tft.width()  / 2 - 1,
                  cy = tft.height() / 2 - 1;
    tft.fillScreen(ILI9341_BLACK);
    w     = min(tft.width(), tft.height());
    start = micros();
    for(i=0; i<w; i+=6) {
      i2 = i / 2;
      tft.drawRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(i, 0, 0));
    }
    return micros() - start;
  }
  unsigned long testFilledRoundRects() {
    unsigned long start;
    int           i, i2,
                  cx = tft.width()  / 2 - 1,
                  cy = tft.height() / 2 - 1;
    tft.fillScreen(ILI9341_BLACK);
    start = micros();
    for(i=min(tft.width(), tft.height()); i>20; i-=6) {
      i2 = i / 2;
      tft.fillRoundRect(cx-i2, cy-i2, i, i, i/8, tft.color565(0, i, 0));
      yield();
    }
    return micros() - start;
  }

Ma il risultato non cambia, lo schermo rimane bianco.
Ho verificato scrupolosamente, più volte, i collegamenti tra il display e il micro.
Comincio a pensare che il display sia difettoso.

EzioGi

Perdona, Adafruit ha a catalogo vari display con IL8342 e ... da SEMPRE gli esempi di collegamento ed i programmini di DEMO da usare per provare se il display funziona.

La cosa si complica SE hai comprato un clonaccio Cinese di quei display, perché capita che abbiano pinout differenti o manchino di alcune funzionalità ... :roll_eyes:

La prima cosa è studiarsi i collegamento/gli esempi dal sito di Adafruit (esempi che funzionano ... almeno con i LORO display) e poi confrontare quello che si ha in mano.

Tu dove hai preso quel display? È Adafruit originale o un clone? Metti un link ...

Guglielmo

Si non è un originale Adafruit, l'ho preso da "ebay" qui: 1PCS NEW 2.8 inch SPI LCD module 240*320 TFT with touch ILI9341 #YT | eBay.
Ho verificato i collegamenti che sono scritti sul retro del display e ho usato quelli come riferimento.

EzioGi

Quindi i valori riportati dai vari Pixel Format, Image Format, etc sono coerenti con quanto riporta il datasheet?
In caso affermativo allora direi che il display ha dei problemi, altrimenti il problema è di comunicazione.

Ciao, Ale.

Devo fare la verifica con quello che ho visto sul datasheet che mi hai consigliato.

EzioGI

I pin della SPI sono fissi su AVR, ma con ESP32 possono essere assegnati a qualsiasi GPIO.
Ho visto che la libreria Adafruit non fa nulla di tutto ciò (giustamente perché è onere dell'utente) e quindi usa quelli di default che sono diversi da quelli che hai definito tu nello sketch.

Le strade sono quindi due:

  • usare i pin di default definiti per la scheda che stai usando. Ad esempio questi sono quelli per le due SPI disponibili per un classico NoderMCU-32

  • riconfigurare il bus SPI coerentemente con le tue connessioni prima di chiamare tft.begin()

SPI.begin(TFT_CLK, TFT_MISO, TFT_MOSI, TFT_CS);

Attenzione però che con ESP32 alcuni GPIO sono riservati e/o in condivisione con altre periferiche.

Risolto!
Il cip NODE MCU era guasto, devo aver creato qualche casino con l'alimentazione.
Oggi mi è arrivato quello nuovo e collegato correttamente con i pin giusti, il display funziona utilizzando il secondo sketch.
Adesso devo portare il tutto su l'Arduino UNO e provare se funziona anche li, ovviamente adattando la disposizione dei pin al UNO.
Mi deve arrivare un ESP32 NODE MCU DEV KIT e farò qualche prova anche con lui.
Grazie comunque per l'aiuto, i consigli che mi avete dato e che terrò presente.

EzioGi

Ho bisogno un chiarimento su questa istruzione presente nello sketch sopracitato.
Cosa fa questa istruzione?:
return micros() - start;
Cosa fa in pratica la funzione "yield();" presente nello sketch?.
Dove posso trovare le informazioni delle funzioni che posso far fare al LCD?
Grazie

EzioGi

yield() non fa nulla su arduino uno. Se oltre al core usi un RTOS o comunque un task scheduler questi implementano una yield(), richiamandola si cede il controllo a questo scheduler.

Ci devi arrivare da solo.

void quantoTempoImpiega() {
    unsigned long start = micros();
    delay(1000);
    Serial.println(micros() - start);
}

Ciao.

Capito!
E' come la funzione millis, è il comando "return" che mi ha spaesato.

EzioGi

Ho comunque un'altro problema perché non esegue tutte le funzioni che ci sono nello sketch, ma si blocca alla visualizzazione della funzione "Rectangles (filled) ".
Il monitor seriale mi scrive queste cose:

,⸮ILI9341 Test!
Display Power Mode: 0x94
MADCTL Mode: 0x48
Pixel Format: 0x5
Image Format: 0x80
Self Diagnostic: 0xC0
Benchmark                Time (microseconds)
Screen fill              31392073
Text                     1195104
Lines                    11523600
Horiz/Vert Lines         2540958
Rectangles (outline)     1614138
Rectangles (filled)      
--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Soft WDT reset

Exception (4):
epc1=0x40101010 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

>>>stack>>>

ctx: cont
sp: 3ffffda0 end: 3fffffd0 offset: 0160
3fffff00:  00004e20 00000000 3ffee618 40203881  
3fffff10:  00000003 0000ffe0 3ffee618 402038f0  
3fffff20:  40105d41 00000000 00000004 000000ea  
3fffff30:  0000002a 00000002 000000ea 40203b79  
3fffff40:  0000ffe0 3ffee618 3ffe85e0 004736f7  
3fffff50:  0000f81f 0000ffe0 40204ae2 0000ffe0  
3fffff60:  0000f81f 004736f7 000000ea 40201596  
3fffff70:  0000009f 00000077 00000002 0000002a  
3fffff80:  0864ef01 0000007f 00000080 3ffee830  
3fffff90:  00000080 0001f922 000001f4 3ffee830  
3fffffa0:  00000080 0000f81f 3ffee7b0 40201c1d  
3fffffb0:  3fffdad0 00000000 3ffee804 40204c70  
3fffffc0:  feefeffe feefeffe 3fffdab0 40100cf5  
<<<stack<<<

E non sono in grado di capire il perché.

EzioGi

Noto problema degli ESP8266 ... passate agli ESP32 ... :grin:

In pratica, ESP8266 è un mono-core in cui, l'unico core fa tutto e, se tu occupi per troppo tempo la MCU, non dando modo hai task di sistema (WiFi, Bluetooth, ecc.) di essere eseguiti, il ESP8266 si protegge con un meccanismo di Watchdog che scatta e manda in "abort" il programma. Consiglio ESP32, che ormai costa praticamente come un vecchio ed obsoleto ESP8266, perché è un dual-core e i task di sistema girano su un core separato da quelli dell'utente che, anche se fanno cose lunghe, non bloccano comunque le cose importanti di sistema.

Tornando al tuo caso, probabilmente la routine che scrive i rettangoli (riempiti) tiene il controllo del processore per troppo tempo (ci saranno dei for o dei while) e quindi scatta il WDT.
In questo caso è utile la yield() di cui chiedevi prima ... inserita, ad esempio, nei cicli, permette comunque il passaggio del controllo hai task di sistema e "dovrebbe" evitare il problema ... puoi provare ...

Guglielmo

Ma l'output mi fa capire che si tratta di ESP32, che è tutto un altro pianeta. C'è FreeRTOS, ci sono due core cpu, c'è il cane da guardia (watchdog).

Infatti mi sembra di capire che è intervenuto il watchdog

Soft WDT reset

Ciao.

Dici? io quel messaggio l'ho sempre visto solo sugli ESP8266 ... gli ESP32, grazie ai due core, difficilmente hanno questo problema con il codice utente ... :roll_eyes:

@eziogi: che cosa stai usando per fare le prove?

Guglielmo

1 Like