KL25Z TFT ILI9341

Dependencies:   SDFileSystem SPI_TFT_ILI9341 TFT_fonts mbed

Fork of TFT_banggood by Peter Drescher

Issue with reading a 16-bit BMP file from SD card. Has anyone successfully loaded an image from the SD card of the LCD display with FRDM-25Z?

/media/uploads/kenno/img_20140317_224436.jpg

If anyone can help pointing out what I did wrong, it'll be very appreciated. Thanks.

Committer:
kenno
Date:
Tue Mar 11 12:29:54 2014 +0000
Revision:
1:2b61fee5799f
Parent:
0:7c3b9bfd6ead
Initial commit. SD card not working.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
dreschpe 0:7c3b9bfd6ead 1 // example to test the TFT Display from banggood.com
dreschpe 0:7c3b9bfd6ead 2 // Thanks to the GraphicsDisplay and TextDisplay classes
dreschpe 0:7c3b9bfd6ead 3 // test.bmp has to be on the mbed file system
dreschpe 0:7c3b9bfd6ead 4 // and on the sd-card
dreschpe 0:7c3b9bfd6ead 5
dreschpe 0:7c3b9bfd6ead 6 #include "stdio.h"
dreschpe 0:7c3b9bfd6ead 7 #include "mbed.h"
dreschpe 0:7c3b9bfd6ead 8 #include "SPI_TFT_ILI9341.h"
dreschpe 0:7c3b9bfd6ead 9 #include "string"
dreschpe 0:7c3b9bfd6ead 10 #include "Arial12x12.h"
dreschpe 0:7c3b9bfd6ead 11 #include "Arial24x23.h"
dreschpe 0:7c3b9bfd6ead 12 #include "Arial28x28.h"
dreschpe 0:7c3b9bfd6ead 13 #include "font_big.h"
dreschpe 0:7c3b9bfd6ead 14 #include "SDFileSystem.h"
dreschpe 0:7c3b9bfd6ead 15
dreschpe 0:7c3b9bfd6ead 16 // the SD-connector is connected to SPI pin 11-13
kenno 1:2b61fee5799f 17 //SDFileSystem sd(p11, p12, p13, p14, "sd"); // mosi,miso,sck,cs
kenno 1:2b61fee5799f 18 SDFileSystem sd(PTD2, PTD3, PTD1, PTA4, "sd"); // mosi,miso,sck,cs
dreschpe 0:7c3b9bfd6ead 19
kenno 1:2b61fee5799f 20 // FRDM-KL25Z doesn't have external flash
kenno 1:2b61fee5799f 21 //LocalFileSystem local("local"); // Create the local filesystem under the name "local"
dreschpe 0:7c3b9bfd6ead 22
kenno 1:2b61fee5799f 23 //extern unsigned char p1[]; // the mbed logo graphic
dreschpe 0:7c3b9bfd6ead 24
dreschpe 0:7c3b9bfd6ead 25 // the display has a backlight switch on board
kenno 1:2b61fee5799f 26 //DigitalOut LCD_LED(p21);
dreschpe 0:7c3b9bfd6ead 27
dreschpe 0:7c3b9bfd6ead 28 // the TFT is connected to SPI pin 5-7
kenno 1:2b61fee5799f 29 //SPI_TFT_ILI9341 TFT(p5, p6, p7, p8, p9, p10,"TFT"); // mosi, miso, sclk, cs, reset, dc
kenno 1:2b61fee5799f 30 SPI_TFT_ILI9341 TFT(PTD2, PTD3, PTD1, PTD5, PTD0, PTD7,"TFT"); // mosi, miso, sclk, cs, reset, dc
dreschpe 0:7c3b9bfd6ead 31
dreschpe 0:7c3b9bfd6ead 32 int main()
dreschpe 0:7c3b9bfd6ead 33 {
dreschpe 0:7c3b9bfd6ead 34 int i;
kenno 1:2b61fee5799f 35 //LCD_LED = 1; // backlite on
dreschpe 0:7c3b9bfd6ead 36
dreschpe 0:7c3b9bfd6ead 37 TFT.claim(stdout); // send stdout to the TFT display
dreschpe 0:7c3b9bfd6ead 38 TFT.set_orientation(1);
dreschpe 0:7c3b9bfd6ead 39 TFT.background(Black); // set background to black
dreschpe 0:7c3b9bfd6ead 40 TFT.foreground(White); // set chars to white
dreschpe 0:7c3b9bfd6ead 41 TFT.cls(); // clear the screen
dreschpe 0:7c3b9bfd6ead 42
dreschpe 0:7c3b9bfd6ead 43 //first show the 4 directions
dreschpe 0:7c3b9bfd6ead 44 TFT.set_orientation(0);
dreschpe 0:7c3b9bfd6ead 45 TFT.background(Black);
dreschpe 0:7c3b9bfd6ead 46 TFT.cls();
dreschpe 0:7c3b9bfd6ead 47
dreschpe 0:7c3b9bfd6ead 48 TFT.set_font((unsigned char*) Arial12x12);
dreschpe 0:7c3b9bfd6ead 49 TFT.locate(0,0);
dreschpe 0:7c3b9bfd6ead 50 printf(" Hello Mbed 0");
dreschpe 0:7c3b9bfd6ead 51 TFT.set_orientation(1);
dreschpe 0:7c3b9bfd6ead 52 TFT.locate(0,0);
dreschpe 0:7c3b9bfd6ead 53 printf(" Hello Mbed 1");
dreschpe 0:7c3b9bfd6ead 54 TFT.set_orientation(2);
dreschpe 0:7c3b9bfd6ead 55 TFT.locate(0,0);
dreschpe 0:7c3b9bfd6ead 56 printf(" Hello Mbed 2");
dreschpe 0:7c3b9bfd6ead 57 TFT.set_orientation(3);
dreschpe 0:7c3b9bfd6ead 58 TFT.locate(0,0);
dreschpe 0:7c3b9bfd6ead 59 printf(" Hello Mbed 3");
dreschpe 0:7c3b9bfd6ead 60 TFT.set_orientation(1);
dreschpe 0:7c3b9bfd6ead 61 TFT.set_font((unsigned char*) Arial24x23);
dreschpe 0:7c3b9bfd6ead 62 TFT.locate(50,100);
dreschpe 0:7c3b9bfd6ead 63 TFT.printf("TFT orientation");
dreschpe 0:7c3b9bfd6ead 64
dreschpe 0:7c3b9bfd6ead 65 wait(5); // wait two seconds
dreschpe 0:7c3b9bfd6ead 66
dreschpe 0:7c3b9bfd6ead 67 // draw some graphics
dreschpe 0:7c3b9bfd6ead 68 TFT.cls();
dreschpe 0:7c3b9bfd6ead 69 TFT.set_font((unsigned char*) Arial24x23);
dreschpe 0:7c3b9bfd6ead 70 TFT.locate(100,100);
dreschpe 0:7c3b9bfd6ead 71 TFT.printf("Graphic");
dreschpe 0:7c3b9bfd6ead 72
dreschpe 0:7c3b9bfd6ead 73 TFT.line(0,0,100,0,Green);
dreschpe 0:7c3b9bfd6ead 74 TFT.line(0,0,0,200,Green);
dreschpe 0:7c3b9bfd6ead 75 TFT.line(0,0,100,200,Green);
dreschpe 0:7c3b9bfd6ead 76
dreschpe 0:7c3b9bfd6ead 77 TFT.rect(100,50,150,100,Red);
dreschpe 0:7c3b9bfd6ead 78 TFT.fillrect(180,25,220,70,Blue);
dreschpe 0:7c3b9bfd6ead 79
dreschpe 0:7c3b9bfd6ead 80 TFT.circle(80,150,33,White);
dreschpe 0:7c3b9bfd6ead 81 TFT.fillcircle(160,190,20,Yellow);
dreschpe 0:7c3b9bfd6ead 82
dreschpe 0:7c3b9bfd6ead 83 double s;
dreschpe 0:7c3b9bfd6ead 84
dreschpe 0:7c3b9bfd6ead 85 for (i=0; i<320; i++) {
dreschpe 0:7c3b9bfd6ead 86 s =20 * sin((long double) i / 10 );
dreschpe 0:7c3b9bfd6ead 87 TFT.pixel(i,100 + (int)s ,Red);
dreschpe 0:7c3b9bfd6ead 88 }
dreschpe 0:7c3b9bfd6ead 89
dreschpe 0:7c3b9bfd6ead 90
dreschpe 0:7c3b9bfd6ead 91 wait(5); // wait two seconds
dreschpe 0:7c3b9bfd6ead 92
dreschpe 0:7c3b9bfd6ead 93 // bigger text
dreschpe 0:7c3b9bfd6ead 94 TFT.foreground(White);
dreschpe 0:7c3b9bfd6ead 95 TFT.background(Blue);
dreschpe 0:7c3b9bfd6ead 96 TFT.cls();
dreschpe 0:7c3b9bfd6ead 97 TFT.set_font((unsigned char*) Arial24x23);
dreschpe 0:7c3b9bfd6ead 98 TFT.locate(0,0);
dreschpe 0:7c3b9bfd6ead 99 TFT.printf("Different Fonts :");
dreschpe 0:7c3b9bfd6ead 100
dreschpe 0:7c3b9bfd6ead 101 TFT.set_font((unsigned char*) Neu42x35);
dreschpe 0:7c3b9bfd6ead 102 TFT.locate(10,30);
dreschpe 0:7c3b9bfd6ead 103 TFT.printf("Hello Mbed 1");
dreschpe 0:7c3b9bfd6ead 104 TFT.set_font((unsigned char*) Arial24x23);
dreschpe 0:7c3b9bfd6ead 105 TFT.locate(20,80);
dreschpe 0:7c3b9bfd6ead 106 TFT.printf("Hello Mbed 2");
dreschpe 0:7c3b9bfd6ead 107 TFT.set_font((unsigned char*) Arial12x12);
dreschpe 0:7c3b9bfd6ead 108 TFT.locate(35,120);
dreschpe 0:7c3b9bfd6ead 109 TFT.printf("Hello Mbed 3");
dreschpe 0:7c3b9bfd6ead 110 wait(5);
dreschpe 0:7c3b9bfd6ead 111
dreschpe 0:7c3b9bfd6ead 112 TFT.background(Black);
dreschpe 0:7c3b9bfd6ead 113 TFT.cls();
kenno 1:2b61fee5799f 114 //TFT.locate(10,10);
kenno 1:2b61fee5799f 115 //TFT.printf("Graphic from Flash");
dreschpe 0:7c3b9bfd6ead 116
dreschpe 0:7c3b9bfd6ead 117 // mbed logo
dreschpe 0:7c3b9bfd6ead 118 // defined in graphics.c
dreschpe 0:7c3b9bfd6ead 119 //__align(4)
dreschpe 0:7c3b9bfd6ead 120 //unsigned char p1[18920] = {
dreschpe 0:7c3b9bfd6ead 121 //0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, ....
dreschpe 0:7c3b9bfd6ead 122 //
kenno 1:2b61fee5799f 123 //TFT.Bitmap(90,90,172,55,p1);
dreschpe 0:7c3b9bfd6ead 124
kenno 1:2b61fee5799f 125 //wait(5);
kenno 1:2b61fee5799f 126 //TFT.cls();
dreschpe 0:7c3b9bfd6ead 127
dreschpe 0:7c3b9bfd6ead 128 // to compare the speed of the internal file system and a SD-card
kenno 1:2b61fee5799f 129 /* TFT.locate(10,10);
dreschpe 0:7c3b9bfd6ead 130 TFT.printf("Graphic from internal File System");
dreschpe 0:7c3b9bfd6ead 131 TFT.locate(10,20);
dreschpe 0:7c3b9bfd6ead 132 TFT.printf("open test.bmp");
dreschpe 0:7c3b9bfd6ead 133 int err = TFT.BMP_16(1,50,"/local/test.bmp");
dreschpe 0:7c3b9bfd6ead 134 if (err != 1) TFT.printf(" - Err: %d",err);
kenno 1:2b61fee5799f 135 */
dreschpe 0:7c3b9bfd6ead 136 TFT.locate(10,110);
dreschpe 0:7c3b9bfd6ead 137 TFT.printf("Graphic from external SD-card");
dreschpe 0:7c3b9bfd6ead 138 TFT.locate(10,120);
kenno 1:2b61fee5799f 139 int err = TFT.BMP_16(0,0,"/sd/teppy.bmp"); //1, 140
kenno 1:2b61fee5799f 140 if (err != 1) TFT.printf(" - Err: %d",err);
dreschpe 0:7c3b9bfd6ead 141 }