2 в 1 Набор Дисплей 3,5 TFT 480x320 + Arduino MEGA 2560 R3 + USB-кабель

Код:01188
Артикул:TFT-3.5-MEGA
В наличии:есть
2 085 руб
1
2 в 1 Набор Дисплей 3,5 TFT 480x320 + Контроллер, совместимый с Arduino MEGA R3 2560 + USB-кабель

Техническое описание (англ.яз.). Driver:  ILI9486L








Пример вывода изображения с SD для Adafruit:

001	// This sketch has been Refurbished by BUHOSOFT
002	// BMP-loading example specifically for the TFTLCD breakout board.
003	// If using the Arduino shield, use the tftbmp_shield.pde sketch instead!
004	// If using an Arduino Mega make sure to use its hardware SPI pins, OR make
005	// sure the SD library is configured for 'soft' SPI in the file Sd2Card.h.
006	//No DEBUG Mode: Sketch uses 30.070 bytes (93%) of program storage space. Maximum is 32.256 bytes.
007	//DEBUG Mode: Sketch uses 31.046 bytes (96%) of program storage space. Maximum is 32.256 bytes.
008	 
009	#define DEBUG
010	#include <Adafruit_GFX.h>    // Core graphics library
011	#include <Adafruit_TFTLCD.h> // Hardware-specific library
012	#include <SPI.h>
013	#include <SD.h>
014	 
015	// The control pins for the LCD can be assigned to any digital or
016	// analog pins...but we'll use the analog pins as this allows us to
017	// double up the pins with the touch screen (see the TFT paint example).
018	#define LCD_CS A3 // Chip Select goes to Analog 3
019	#define LCD_CD A2 // Command/Data goes to Analog 2
020	#define LCD_WR A1 // LCD Write goes to Analog 1
021	#define LCD_RD A0 // LCD Read goes to Analog 0
022	 
023	// When using the BREAKOUT BOARD only, use these 8 data lines to the LCD:
024	// For the Arduino Uno, Duemilanove, Diecimila, etc.:
025	//   D0 connects to digital pin 8  (Notice these are
026	//   D1 connects to digital pin 9   NOT in order!)
027	//   D2 connects to digital pin 2
028	//   D3 connects to digital pin 3
029	//   D4 connects to digital pin 4
030	//   D5 connects to digital pin 5
031	//   D6 connects to digital pin 6
032	//   D7 connects to digital pin 7
033	// For the Arduino Mega, use digital pins 22 through 29
034	// (on the 2-row header at the end of the board).
035	 
036	// For Arduino Uno/Duemilanove, etc
037	//  connect the SD card with DI going to pin 11, DO going to pin 12 and SCK going to pin 13 (standard)
038	//  Then pin 10 goes to CS (or whatever you have set up)
039	#if defined __AVR_ATmega2560__
040	#define SD_SCK 13
041	#define SD_MISO 12
042	#define SD_MOSI 11
043	 
044	#endif
045	#define SD_CS 10     // Set the chip select line to whatever you use (10 doesnt conflict with the library)
046	 
047	// In the SD card, place 24 bit color BMP files (be sure they are 24-bit!)
048	// There are examples in the sketch folder
049	 
050	// our TFT wiring
051	Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, A4);
052	 
053	void setup()
054	{
055	  tft.reset();
056	//this sketch force the  ILI9341 LCD driver chage the next code line to chage the driver
057	//0x9325  ILI9325 LCD driver
058	//0x9328  ILI9328 LCD driver
059	//0x7575  HX8347G LCD driver
060	//0x9341  ILI9341 LCD driver
061	//0x8357  HX8357D LCD driver
062	  tft.begin(0x9341);
063	  tft.setTextSize(2);
064	  tft.fillScreen(0);
065	  tft.setRotation(1);
066	  tft.println(F("Initializing SD card..."));
067	  #if defined __AVR_ATmega2560__
068	  if (!SD.begin(SD_CS, SD_MOSI, SD_MISO, SD_SCK )) {
069	    tft.println(F("failed!"));
070	    return;
071	  }
072	  #else
073	  if (!SD.begin(SD_CS)) {
074	    tft.println(F("failed!"));
075	    return;
076	  }
077	  #endif
078	  delay(500);
079	 
080	  bmpDraw("Test.bmp", 0, 0);
081	 
082	}
083	 
084	void loop()
085	{
086	    delay(2000);
087	    bmpDraw("arduinoW.bmp", 0, 0);
088	    delay(2000);
089	    bmpDraw("AUnoR3.bmp", 0, 0);
090	    delay(2000);
091	    bmpDraw("arduinoG.bmp", 0, 0);
092	    delay(1000);
093	#ifndef DEBUG
094	  for(int i = 0; i<4; i++) {
095	    delay(1000);
096	    tft.setRotation(i);
097	    tft.fillScreen(0);
098	    for(int j=0; j <= 200; j += 50) {
099	      bmpDraw("miniardu.bmp", j, j);
100	    }
101	 
102	  }
103	#endif
104	}
105	 
106	// This function opens a Windows Bitmap (BMP) file and
107	// displays it at the given coordinates.  It's sped up
108	// by reading many pixels worth of data at a time
109	// (rather than pixel by pixel).  Increasing the buffer
110	// size takes more of the Arduino's precious RAM but
111	// makes loading a little faster.  20 pixels seems a
112	// good balance.
113	 
114	#define BUFFPIXEL 20
115	 
116	void bmpDraw(char *filename, int x, int y) {
117	 
118	  File     bmpFile;
119	  int      bmpWidth, bmpHeight;   // W+H in pixels
120	  uint8_t  bmpDepth;              // Bit depth (currently must be 24)
121	  uint32_t bmpImageoffset;        // Start of image data in file
122	  uint32_t rowSize;               // Not always = bmpWidth; may have padding
123	  uint8_t  sdbuffer[3*BUFFPIXEL]; // pixel in buffer (R+G+B per pixel)
124	  uint16_t lcdbuffer[BUFFPIXEL];  // pixel out buffer (16-bit per pixel)
125	  uint8_t  buffidx = sizeof(sdbuffer); // Current position in sdbuffer
126	  boolean  goodBmp = false;       // Set to true on valid header parse
127	  boolean  flip    = true;        // BMP is stored bottom-to-top
128	  int      w, h, row, col;
129	  uint8_t  r, g, b;
130	  uint32_t pos = 0, startTime = millis();
131	  uint8_t  lcdidx = 0;
132	  boolean  first = true;
133	 
134	  if((x >= tft.width()) || (y >= tft.height())) return;
135	 
136	#ifdef DEBUG
137	  tft.fillScreen(0);
138	  tft.setCursor(0,0);
139	  tft.print(F("Loading image '"));
140	  tft.print(filename);
141	  tft.println('\'');
142	#endif
143	  // Open requested file on SD card
144	  if ((bmpFile = SD.open(filename)) == NULL) {
145	    #ifdef DEBUG
146	    tft.println(F("File not found"));
147	    #endif
148	    return;
149	  }
150	 
151	  // Parse BMP header
152	  if(read16(bmpFile) == 0x4D42) {
153	      // BMP signature
154	    #ifdef DEBUG
155	    tft.println(F("File size: ")); tft.println(read32(bmpFile));
156	    #else
157	        read32(bmpFile);
158	    #endif
159	    (void)read32(bmpFile); // Read & ignore creator bytes
160	    bmpImageoffset = read32(bmpFile); // Start of image data
161	    #ifdef DEBUG
162	    tft.print(F("Image Offset: ")); tft.println(bmpImageoffset, DEC);
163	    // Read DIB header
164	    tft.print(F("Header size: ")); tft.println(read32(bmpFile));
165	    #else
166	    read32(bmpFile);
167	    #endif
168	 
169	    bmpWidth  = read32(bmpFile);
170	    bmpHeight = read32(bmpFile);
171	    if(read16(bmpFile) == 1) { // # planes -- must be '1'
172	      bmpDepth = read16(bmpFile); // bits per pixel
173	      #ifdef DEBUG
174	      Serial.print(F("Bit Depth: ")); Serial.println(bmpDepth);
175	      #endif
176	      if((bmpDepth == 24) && (read32(bmpFile) == 0)) { // 0 = uncompressed
177	 
178	        goodBmp = true; // Supported BMP format -- proceed!
179	        #ifdef DEBUG
180	        tft.print(F("Image size: "));
181	        tft.print(bmpWidth);
182	        tft.print('x');
183	        tft.println(bmpHeight);
184	        delay(3000);
185	        #endif
186	        // BMP rows are padded (if needed) to 4-byte boundary
187	        rowSize = (bmpWidth * 3 + 3) & ~3;
188	 
189	        // If bmpHeight is negative, image is in top-down order.
190	        // This is not canon but has been observed in the wild.
191	        if(bmpHeight < 0) {
192	          bmpHeight = -bmpHeight;
193	          flip      = false;
194	        }
195	 
196	        // Crop area to be loaded
197	        w = bmpWidth;
198	        h = bmpHeight;
199	        if((x+w-1) >= tft.width())  w = tft.width()  - x;
200	        if((y+h-1) >= tft.height()) h = tft.height() - y;
201	 
202	        // Set TFT address window to clipped image bounds
203	        tft.setAddrWindow(x, y, x+w-1, y+h-1);
204	 
205	        for (row=0; row<h; row++) { // For each scanline...
206	          // Seek to start of scan line.  It might seem labor-
207	          // intensive to be doing this on every line, but this
208	          // method covers a lot of gritty details like cropping
209	          // and scanline padding.  Also, the seek only takes
210	          // place if the file position actually needs to change
211	          // (avoids a lot of cluster math in SD library).
212	          if(flip) // Bitmap is stored bottom-to-top order (normal BMP)
213	            pos = bmpImageoffset + (bmpHeight - 1 - row) * rowSize;
214	          else     // Bitmap is stored top-to-bottom
215	            pos = bmpImageoffset + row * rowSize;
216	          if(bmpFile.position() != pos) { // Need seek?
217	            bmpFile.seek(pos);
218	            buffidx = sizeof(sdbuffer); // Force buffer reload
219	          }
220	 
221	          for (col=0; col<w; col++) { // For each column...
222	            // Time to read more pixel data?
223	            if (buffidx >= sizeof(sdbuffer)) { // Indeed
224	              // Push LCD buffer to the display first
225	              if(lcdidx > 0) {
226	                tft.pushColors(lcdbuffer, lcdidx, first);
227	                lcdidx = 0;
228	                first  = false;
229	              }
230	              bmpFile.read(sdbuffer, sizeof(sdbuffer));
231	              buffidx = 0; // Set index to beginning
232	            }
233	 
234	            // Convert pixel from BMP to TFT format
235	            b = sdbuffer[buffidx++];
236	            g = sdbuffer[buffidx++];
237	            r = sdbuffer[buffidx++];
238	            lcdbuffer[lcdidx++] = tft.color565(r,g,b);
239	          } // end pixel
240	        } // end scanline
241	        // Write any remaining data to LCD
242	        if(lcdidx > 0) {
243	          tft.pushColors(lcdbuffer, lcdidx, first);
244	        }
245	 
246	      } // end goodBmp
247	    }
248	  }
249	 
250	  bmpFile.close();
251	  if(!goodBmp) tft.println(F("BMP format not recognized."));
252	}
253	 
254	// These read 16- and 32-bit types from the SD card file.
255	// BMP data is stored little-endian, Arduino is little-endian too.
256	// May need to reverse subscript order if porting elsewhere.
257	 
258	uint16_t read16(File f) {
259	  uint16_t result;
260	  ((uint8_t *)&result)[0] = f.read(); // LSB
261	  ((uint8_t *)&result)[1] = f.read(); // MSB
262	  return result;
263	}
264	 
265	uint32_t read32(File f) {
266	  uint32_t result;
267	  ((uint8_t *)&result)[0] = f.read(); // LSB
268	  ((uint8_t *)&result)[1] = f.read();
269	  ((uint8_t *)&result)[2] = f.read();
270	  ((uint8_t *)&result)[3] = f.read(); // MSB
271	  return result;
272	}
 




Вверх