Жк-экран и его подключение к ардуино
- Войдите на сайт для отправки комментариев
Пнд, 17/10/2016 - 15:31
Добрый день!
Купил на Али-рессе жк-экранчик, маленький - https://ru.aliexpress.com/item/Brand-LCD-Module-TFT-2-4-inch-TFT-touch-LCD-screen-for-Arduino-UNO-R3-Board/32598873860.html?spm=2114.13010608.0.0.sa1jpd&detailNewVersion=&categoryId=400401
установил библиотеку SPFD 5408. Начинаю загружать примеры - куча ошибок.
Экран белый и никак не реагирует...
Если можно подсказать, буду очень признателен.
Заранее спасибо
А сообщения о ошибках Вам Клапауций 322 запретил выложить?
А сообщения о ошибках Вам Клапауций 322 запретил выложить?
я запрещаю упоминать имя мое в суе.
Как изволите Ваше пр-во, только не нервничайте, а то санитарам прийдется бежать к Вам прервав ужин, и они долго злые будут ;)
Если добавляю такой тестовый код :
// BMP-loading example specifically for the TFTLCD breakout board. // If using the Arduino shield, use the tftbmp_shield.pde sketch instead! // If using an Arduino Mega, make sure the SD library is configured for // 'soft' SPI in the file Sd2Card.h. /////// ***** Not Tested yet on SPFD5408 - next version I do it #include <Adafruit_GFX.h> // Core graphics library #include <Adafruit_TFTLCD.h> // Hardware-specific library #include <SD.h> // 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 // When using the BREAKOUT BOARD only, use these 8 data lines to the LCD: // For the Arduino Uno, Duemilanove, Diecimila, etc.: // D0 connects to digital pin 8 (Notice these are // D1 connects to digital pin 9 NOT in order!) // D2 connects to digital pin 2 // D3 connects to digital pin 3 // D4 connects to digital pin 4 // D5 connects to digital pin 5 // D6 connects to digital pin 6 // D7 connects to digital pin 7 // For the Arduino Mega, use digital pins 22 through 29 // (on the 2-row header at the end of the board). // For Arduino Uno/Duemilanove, etc // connect the SD card with DI going to pin 11, DO going to pin 12 and SCK going to pin 13 (standard) // Then pin 10 goes to CS (or whatever you have set up) #define SD_CS 10 // Set the chip select line to whatever you use (10 doesnt conflict with the library) // In the SD card, place 24 bit color BMP files (be sure they are 24-bit!) // There are examples in the sketch folder // our TFT wiring Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, A4); void setup() { Serial.begin(9600); digitalWrite(35, HIGH); //I use this on mega for LCD Backlight tft.reset(); uint16_t identifier = tft.readID(); if(identifier == 0x9325) { progmemPrintln(PSTR("Found ILI9325 LCD driver")); } else if(identifier == 0x9328) { progmemPrintln(PSTR("Found ILI9328 LCD driver")); } else if(identifier == 0x7575) { progmemPrintln(PSTR("Found HX8347G LCD driver")); } else { progmemPrint(PSTR("Unknown LCD driver chip: ")); Serial.println(identifier, HEX); progmemPrintln(PSTR("If using the Adafruit 2.8\" TFT Arduino shield, the line:")); progmemPrintln(PSTR(" #define USE_ADAFRUIT_SHIELD_PINOUT")); progmemPrintln(PSTR("should appear in the library header (Adafruit_TFT.h).")); progmemPrintln(PSTR("If using the breakout board, it should NOT be #defined!")); progmemPrintln(PSTR("Also if using the breakout, double-check that all wiring")); progmemPrintln(PSTR("matches the tutorial.")); return; } tft.begin(identifier); progmemPrint(PSTR("Initializing SD card...")); if (!SD.begin(SD_CS)) { progmemPrintln(PSTR("failed!")); return; } progmemPrintln(PSTR("OK!")); bmpDraw("woof.bmp", 0, 0); delay(1000); } void loop() { for(int i = 0; i<4; i++) { tft.setRotation(i); tft.fillScreen(0); for(int j=0; j <= 200; j += 50) { bmpDraw("miniwoof.bmp", j, j); } delay(1000); } } // This function opens a Windows Bitmap (BMP) file and // displays it at the given coordinates. It's sped up // by reading many pixels worth of data at a time // (rather than pixel by pixel). Increasing the buffer // size takes more of the Arduino's precious RAM but // makes loading a little faster. 20 pixels seems a // good balance. #define BUFFPIXEL 20 void bmpDraw(char *filename, int x, int y) { File bmpFile; int bmpWidth, bmpHeight; // W+H in pixels uint8_t bmpDepth; // Bit depth (currently must be 24) uint32_t bmpImageoffset; // Start of image data in file uint32_t rowSize; // Not always = bmpWidth; may have padding uint8_t sdbuffer[3*BUFFPIXEL]; // pixel in buffer (R+G+B per pixel) uint16_t lcdbuffer[BUFFPIXEL]; // pixel out buffer (16-bit per pixel) uint8_t buffidx = sizeof(sdbuffer); // Current position in sdbuffer boolean goodBmp = false; // Set to true on valid header parse boolean flip = true; // BMP is stored bottom-to-top int w, h, row, col; uint8_t r, g, b; uint32_t pos = 0, startTime = millis(); uint8_t lcdidx = 0; boolean first = true; if((x >= tft.width()) || (y >= tft.height())) return; Serial.println(); progmemPrint(PSTR("Loading image '")); Serial.print(filename); Serial.println('\''); // Open requested file on SD card if ((bmpFile = SD.open(filename)) == NULL) { progmemPrintln(PSTR("File not found")); return; } // Parse BMP header if(read16(bmpFile) == 0x4D42) { // BMP signature progmemPrint(PSTR("File size: ")); Serial.println(read32(bmpFile)); (void)read32(bmpFile); // Read & ignore creator bytes bmpImageoffset = read32(bmpFile); // Start of image data progmemPrint(PSTR("Image Offset: ")); Serial.println(bmpImageoffset, DEC); // Read DIB header progmemPrint(PSTR("Header size: ")); Serial.println(read32(bmpFile)); bmpWidth = read32(bmpFile); bmpHeight = read32(bmpFile); if(read16(bmpFile) == 1) { // # planes -- must be '1' bmpDepth = read16(bmpFile); // bits per pixel progmemPrint(PSTR("Bit Depth: ")); Serial.println(bmpDepth); if((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed goodBmp = true; // Supported BMP format -- proceed! progmemPrint(PSTR("Image size: ")); Serial.print(bmpWidth); Serial.print('x'); Serial.println(bmpHeight); // BMP rows are padded (if needed) to 4-byte boundary rowSize = (bmpWidth * 3 + 3) & ~3; // If bmpHeight is negative, image is in top-down order. // This is not canon but has been observed in the wild. if(bmpHeight < 0) { bmpHeight = -bmpHeight; flip = false; } // Crop area to be loaded w = bmpWidth; h = bmpHeight; if((x+w-1) >= tft.width()) w = tft.width() - x; if((y+h-1) >= tft.height()) h = tft.height() - y; // Set TFT address window to clipped image bounds tft.setAddrWindow(x, y, x+w-1, y+h-1); for (row=0; row<h; row++) { // For each scanline... // Seek to start of scan line. It might seem labor- // intensive to be doing this on every line, but this // method covers a lot of gritty details like cropping // and scanline padding. Also, the seek only takes // place if the file position actually needs to change // (avoids a lot of cluster math in SD library). if(flip) // Bitmap is stored bottom-to-top order (normal BMP) pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize; else // Bitmap is stored top-to-bottom pos = bmpImageoffset + row * rowSize; if(bmpFile.position() != pos) { // Need seek? bmpFile.seek(pos); buffidx = sizeof(sdbuffer); // Force buffer reload } for (col=0; col<w; col++) { // For each column... // Time to read more pixel data? if (buffidx >= sizeof(sdbuffer)) { // Indeed // Push LCD buffer to the display first if(lcdidx > 0) { tft.pushColors(lcdbuffer, lcdidx, first); lcdidx = 0; first = false; } bmpFile.read(sdbuffer, sizeof(sdbuffer)); buffidx = 0; // Set index to beginning } // Convert pixel from BMP to TFT format b = sdbuffer[buffidx++]; g = sdbuffer[buffidx++]; r = sdbuffer[buffidx++]; lcdbuffer[lcdidx++] = tft.color565(r,g,b); } // end pixel } // end scanline // Write any remaining data to LCD if(lcdidx > 0) { tft.pushColors(lcdbuffer, lcdidx, first); } progmemPrint(PSTR("Loaded in ")); Serial.print(millis() - startTime); Serial.println(" ms"); } // end goodBmp } } bmpFile.close(); if(!goodBmp) progmemPrintln(PSTR("BMP format not recognized.")); } // These read 16- and 32-bit types from the SD card file. // BMP data is stored little-endian, Arduino is little-endian too. // May need to reverse subscript order if porting elsewhere. uint16_t read16(File f) { uint16_t result; ((uint8_t *)&result)[0] = f.read(); // LSB ((uint8_t *)&result)[1] = f.read(); // MSB return result; } uint32_t read32(File f) { uint32_t result; ((uint8_t *)&result)[0] = f.read(); // LSB ((uint8_t *)&result)[1] = f.read(); ((uint8_t *)&result)[2] = f.read(); ((uint8_t *)&result)[3] = f.read(); // MSB return result; } // Copy string from flash to serial port // Source string MUST be inside a PSTR() declaration! void progmemPrint(const char *str) { char c; while(c = pgm_read_byte(str++)) Serial.print(c); } // Same as above, with trailing newline void progmemPrintln(const char *str) { progmemPrint(str); Serial.println(); }То выходит такая ошибка:
Ошибка компиляции для платы Arduino/Genuino Uno.
Если такой:
// 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. // Modified for SPFD5408 Library by Joao Lopes // Version 0.9.2 - Rotation for Mega and screen initial // *** SPFD5408 change -- Begin #include <SPFD5408_Adafruit_GFX.h> // Core graphics library #include <SPFD5408_Adafruit_TFTLCD.h> // Hardware-specific library #include <SPFD5408_TouchScreen.h> // *** SPFD5408 change -- End // 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 // When using the BREAKOUT BOARD only, use these 8 data lines to the LCD: // For the Arduino Uno, Duemilanove, Diecimila, etc.: // D0 connects to digital pin 8 (Notice these are // D1 connects to digital pin 9 NOT in order!) // D2 connects to digital pin 2 // D3 connects to digital pin 3 // D4 connects to digital pin 4 // D5 connects to digital pin 5 // D6 connects to digital pin 6 // D7 connects to digital pin 7 // For the Arduino Mega, use digital pins 22 through 29 // (on the 2-row header at the end of the board). // 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 Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET); // If using the shield, all control and data lines are fixed, and // a simpler declaration can optionally be used: // Adafruit_TFTLCD tft; // -- Setup void setup(void) { Serial.begin(9600); progmemPrintln(PSTR("TFT LCD test")); #ifdef USE_ADAFRUIT_SHIELD_PINOUT progmemPrintln(PSTR("Using Adafruit 2.8\" TFT Arduino Shield Pinout")); #else progmemPrintln(PSTR("Using Adafruit 2.8\" TFT Breakout Board Pinout")); #endif tft.reset(); // *** SPFD5408 change -- Begin // Original code commented // uint16_t identifier = tft.readID(); // // if(identifier == 0x9325) { // Serial.println(F("Found ILI9325 LCD driver")); // } else if(identifier == 0x9328) { // Serial.println(F("Found ILI9328 LCD driver")); // } else if(identifier == 0x7575) { // Serial.println(F("Found HX8347G LCD driver")); // } else if(identifier == 0x9341) { // Serial.println(F("Found ILI9341 LCD driver")); // } else if(identifier == 0x8357) { // Serial.println(F("Found HX8357D LCD driver")); // } else { // Serial.print(F("Unknown LCD driver chip: ")); // Serial.println(identifier, HEX); // Serial.println(F("If using the Adafruit 2.8\" TFT Arduino shield, the line:")); // Serial.println(F(" #define USE_ADAFRUIT_SHIELD_PINOUT")); // Serial.println(F("should appear in the library header (Adafruit_TFT.h).")); // Serial.println(F("If using the breakout board, it should NOT be #defined!")); // Serial.println(F("Also if using the breakout, double-check that all wiring")); // Serial.println(F("matches the tutorial.")); // return; // } // // tft.begin(identifier); // Code changed to works tft.begin(0x9341); // SDFP5408 tft.setRotation(0); // Need for the Mega, please changed for your choice or rotation initial // *** SPFD5408 change -- End progmemPrintln(PSTR("Benchmark Time (microseconds)")); progmemPrint(PSTR("Screen fill ")); Serial.println(testFillScreen()); delay(500); progmemPrint(PSTR("Text ")); Serial.println(testText()); delay(3000); progmemPrint(PSTR("Lines ")); Serial.println(testLines(CYAN)); delay(500); progmemPrint(PSTR("Horiz/Vert Lines ")); Serial.println(testFastLines(RED, BLUE)); delay(500); progmemPrint(PSTR("Rectangles (outline) ")); Serial.println(testRects(GREEN)); delay(500); progmemPrint(PSTR("Rectangles (filled) ")); Serial.println(testFilledRects(YELLOW, MAGENTA)); delay(500); progmemPrint(PSTR("Circles (filled) ")); Serial.println(testFilledCircles(10, MAGENTA)); progmemPrint(PSTR("Circles (outline) ")); Serial.println(testCircles(10, WHITE)); delay(500); progmemPrint(PSTR("Triangles (outline) ")); Serial.println(testTriangles()); delay(500); progmemPrint(PSTR("Triangles (filled) ")); Serial.println(testFilledTriangles()); delay(500); progmemPrint(PSTR("Rounded rects (outline) ")); Serial.println(testRoundRects()); delay(500); progmemPrint(PSTR("Rounded rects (filled) ")); Serial.println(testFilledRoundRects()); delay(500); progmemPrintln(PSTR("Done!")); } void loop(void) { for(uint8_t rotation=0; rotation<4; rotation++) { tft.setRotation(rotation); testText(); delay(2000); } } unsigned long testFillScreen() { unsigned long start = micros(); tft.fillScreen(BLACK); tft.fillScreen(RED); tft.fillScreen(GREEN); tft.fillScreen(BLUE); tft.fillScreen(BLACK); return micros() - start; } unsigned long testText() { tft.fillScreen(BLACK); unsigned long start = micros(); tft.setCursor(0, 0); tft.setTextColor(WHITE); tft.setTextSize(1); tft.println("Hello World!"); tft.setTextColor(YELLOW); tft.setTextSize(2); tft.println(1234.56); tft.setTextColor(RED); tft.setTextSize(3); tft.println(0xDEADBEEF, HEX); tft.println(); tft.setTextColor(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(BLACK); 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 tft.fillScreen(BLACK); 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; tft.fillScreen(BLACK); 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; tft.fillScreen(BLACK); 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); 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(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(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(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); } 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(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(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(0, 0, 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(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, i)); t += micros() - start; tft.drawTriangle(cx, cy - i, cx - i, cy + i, cx + i, cy + i, tft.color565(i, i, 0)); } return t; } unsigned long testRoundRects() { unsigned long start; int w, i, i2, cx = tft.width() / 2 - 1, cy = tft.height() / 2 - 1; tft.fillScreen(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(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)); } return micros() - start; } // Copy string from flash to serial port // Source string MUST be inside a PSTR() declaration! void progmemPrint(const char *str) { char c; while(c = pgm_read_byte(str++)) Serial.print(c); } // Same as above, with trailing newline void progmemPrintln(const char *str) { progmemPrint(str); Serial.println(); }То компиляция происходит, но выходит предупреждение:
А на экране ноль измененией
Клапауций 232 , моё почтение!)
Столько раз мне помогал)
Какая ардуина? На уне у меня работает.
https://github.com/JoaoLopesF/SPFD5408
И Уно и Мега, китайские, да, именно эту библиотеку брал. Не работает...
Windows 10... Хотя я и на XP пробовал раньше
Пробую
Файл-Примеры- SPFD-5408-master ->tftbmp
выходит ошибка -
Ошибка компиляции для платы Arduino/Genuino Uno.
Ну? отсутствует файл. Распакуй библиотеку заново. От винды ничего не зависит. Плата же у тебя видится и пример пытается загрузиться?
А IDE не слишком новой версии?
Слишком))
Есть там этот файл. Adafruit_TFTLCD.h вручную просмотрел. Именно в папке библиотеке
Есть там этот файл. Adafruit_TFTLCD.h вручную просмотрел. Именно в папке библиотеке
Либо там, но не этот, либо этот но не там. Компилер напраслину не погонит, он его не видет просто.
Попробуй другую библиотеку. UTFT на пример.
поробовал... Но экран всё белый)
Хотя, ошибок с UTFT Нет)
попробуйте эту
https://github.com/prenticedavid/MCUFRIEND_kbv
О!!! Вот оно и есть!!!
Спасибо огромное!!!!
Походу дело не в библиотеке а в настройках контроллера. Скорее всего последняя библиотека совпала по настройкам с контроллером вашего дисплея. По сути любая библиотека подойдет. Главное правильно кантроллер настроить. На эту тему есть отдельный равернутый топик http://arduino.ru/forum/apparatnye-voprosy/arduino-i-displei-ot-sotikov-mobilnykh-telefonov
Китаец с Али, прислал этот файл.
Сказал, что библиотека, но установить не могу)) Может вы сможете объяснить, что это)) Да и может пригодится еще кому)
https://yadi.sk/d/l3suQMALxCNV5