Fork of SPI18TFT: Ported to Seeeduino-Arch-Pro and tested with SainSmart 1.8 ST7735R TFT

Dependencies:   ST7735_TFT mbed

Fork of SPI18TFT by Jonne Valola

This port of the SPI18TFT demo program was to see if I could get a: SainSmart 1.8 ST7735R TFT LCD module to work with a Seeeduino-Arch-Pro mbed platform.

The gotcha is that this LCD module does not have an MSIO pin, and the MSIO pin on the Arch-Pro must be left disconnected.

Committer:
DevonHeron
Date:
Sun Dec 21 07:09:12 2014 +0000
Revision:
1:71477b6fe9a4
Parent:
0:309c546f048d
Working with Seeeduino-Arch-Pro

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DevonHeron 1:71477b6fe9a4 1 /*
DevonHeron 1:71477b6fe9a4 2 ***********************************************
DevonHeron 1:71477b6fe9a4 3 This works great on the Seeeduino-Arch-Pro using
DevonHeron 1:71477b6fe9a4 4 the SainSmart 1.8" ST7735R TFT
DevonHeron 1:71477b6fe9a4 5 provided the wiring for the SPI bus is correct...
DevonHeron 1:71477b6fe9a4 6 the MSIO pin can not be used for RS...
DevonHeron 1:71477b6fe9a4 7 it must be disconnected
DevonHeron 1:71477b6fe9a4 8 ***********************************************
DevonHeron 1:71477b6fe9a4 9 */
smultron1977 0:309c546f048d 10 #include "stdio.h"
smultron1977 0:309c546f048d 11 #include "stdlib.h"
smultron1977 0:309c546f048d 12 #include "math.h"
smultron1977 0:309c546f048d 13 #include "mbed.h"
smultron1977 0:309c546f048d 14 #include "ST7735_TFT.h"
smultron1977 0:309c546f048d 15 #include "string"
smultron1977 0:309c546f048d 16 #include "Arial12x12.h"
smultron1977 0:309c546f048d 17 #include "Arial24x23.h"
smultron1977 0:309c546f048d 18 #include "Arial28x28.h"
smultron1977 0:309c546f048d 19
smultron1977 0:309c546f048d 20 #define NUMBER_OF_STARS 300
smultron1977 0:309c546f048d 21 #define SCREEN_WIDTH 128
smultron1977 0:309c546f048d 22 #define SCREEN_HEIGHT 160
smultron1977 0:309c546f048d 23
smultron1977 0:309c546f048d 24 /*star struct*/
smultron1977 0:309c546f048d 25 typedef struct
smultron1977 0:309c546f048d 26 {
smultron1977 0:309c546f048d 27 float xpos, ypos;
smultron1977 0:309c546f048d 28 short zpos, speed;
smultron1977 0:309c546f048d 29 unsigned int color;
smultron1977 0:309c546f048d 30 } STAR;
smultron1977 0:309c546f048d 31
smultron1977 0:309c546f048d 32 static STAR stars[NUMBER_OF_STARS];
smultron1977 0:309c546f048d 33
smultron1977 0:309c546f048d 34
smultron1977 0:309c546f048d 35 void init_star(STAR* star, int i)
smultron1977 0:309c546f048d 36 {
smultron1977 0:309c546f048d 37 /* randomly init stars, generate them around the center of the screen */
smultron1977 0:309c546f048d 38
smultron1977 0:309c546f048d 39 star->xpos = -10.0 + (20.0 * (rand()/(RAND_MAX+1.0)));
smultron1977 0:309c546f048d 40 star->ypos = -10.0 + (20.0 * (rand()/(RAND_MAX+1.0)));
smultron1977 0:309c546f048d 41
smultron1977 0:309c546f048d 42 star->xpos *= 3072.0; /*change viewpoint */
smultron1977 0:309c546f048d 43 star->ypos *= 3072.0;
smultron1977 0:309c546f048d 44
smultron1977 0:309c546f048d 45 star->zpos = i;
smultron1977 0:309c546f048d 46 star->speed = 2 + (int)(2.0 * (rand()/(RAND_MAX+1.0)));
smultron1977 0:309c546f048d 47
smultron1977 0:309c546f048d 48 star->color = i*Cyan >> 2; /*the closer to the viewer the brighter*/
smultron1977 0:309c546f048d 49 }
smultron1977 0:309c546f048d 50
smultron1977 0:309c546f048d 51
smultron1977 0:309c546f048d 52 void init()
smultron1977 0:309c546f048d 53 {
smultron1977 0:309c546f048d 54 int i;
smultron1977 0:309c546f048d 55
smultron1977 0:309c546f048d 56 for (i = 0; i < NUMBER_OF_STARS; i++)
smultron1977 0:309c546f048d 57 {
smultron1977 0:309c546f048d 58 init_star(stars + i, i + 1);
smultron1977 0:309c546f048d 59 }
smultron1977 0:309c546f048d 60 }
smultron1977 0:309c546f048d 61
smultron1977 0:309c546f048d 62
smultron1977 0:309c546f048d 63 // the TFT is connected to SPI pin 5-7, CS is p8, RS is p11, reset is p15
DevonHeron 1:71477b6fe9a4 64 // ST7735_TFT TFT(p5, p6, p7, p8, p11, p15,"TFT"); // mosi, miso, sclk, cs, rs, reset
DevonHeron 1:71477b6fe9a4 65 ST7735_TFT TFT(P0_9,P0_8,P0_7,P0_6,P0_0,P2_13,"TFT"); //
DevonHeron 1:71477b6fe9a4 66
DevonHeron 1:71477b6fe9a4 67 // Pins on the display PIN on ARCH_Pro
DevonHeron 1:71477b6fe9a4 68 // VCC -- 3.3V
DevonHeron 1:71477b6fe9a4 69 // GND -- GND
DevonHeron 1:71477b6fe9a4 70 // SCL -- P0_7
DevonHeron 1:71477b6fe9a4 71 // SDA -- P0_9
DevonHeron 1:71477b6fe9a4 72 // RS /DC -- P0_0
DevonHeron 1:71477b6fe9a4 73 // RES -- P2_13
DevonHeron 1:71477b6fe9a4 74 // CS -- P0_6
DevonHeron 1:71477b6fe9a4 75 // -- P0_8 -- connection not used on display (sould be MISO)
smultron1977 0:309c546f048d 76
smultron1977 0:309c546f048d 77 Serial pc(USBTX, USBRX); // tx, rx
smultron1977 0:309c546f048d 78 Timer t;
smultron1977 0:309c546f048d 79
smultron1977 0:309c546f048d 80 extern unsigned char p1[]; // the mbed logo
smultron1977 0:309c546f048d 81
smultron1977 0:309c546f048d 82 int main() {
DevonHeron 1:71477b6fe9a4 83 printf("Getting Started Now\n\r");
smultron1977 0:309c546f048d 84
smultron1977 0:309c546f048d 85 unsigned int centerx, centery;
smultron1977 0:309c546f048d 86 int i, j, tempx, tempy;
smultron1977 0:309c546f048d 87 init();
smultron1977 0:309c546f048d 88 TFT.set_orientation(1);
smultron1977 0:309c546f048d 89 centerx = TFT.width() >> 1;
smultron1977 0:309c546f048d 90 centery = TFT.height() >> 1;
smultron1977 0:309c546f048d 91
smultron1977 0:309c546f048d 92
smultron1977 0:309c546f048d 93 TFT.claim(stdout); // send stdout to the TFT display
DevonHeron 1:71477b6fe9a4 94 TFT.claim(stderr); // send stderr to the TFT display
smultron1977 0:309c546f048d 95
smultron1977 0:309c546f048d 96 TFT.background(Black); // set background to black
smultron1977 0:309c546f048d 97 TFT.foreground(White); // set chars to white
smultron1977 0:309c546f048d 98
smultron1977 0:309c546f048d 99 TFT.cls();
DevonHeron 1:71477b6fe9a4 100 TFT.set_font((unsigned char*) Arial12x12); // select the font
DevonHeron 1:71477b6fe9a4 101
DevonHeron 1:71477b6fe9a4 102 TFT.printf("Getting Started\nLine two\nLine three\r\nEnd");
DevonHeron 1:71477b6fe9a4 103 pc.printf("Getting Started\nLine two\nLine three\r\nEnd");
smultron1977 0:309c546f048d 104 t.start();
DevonHeron 1:71477b6fe9a4 105 wait_ms(5000);
smultron1977 0:309c546f048d 106 ////// demo start
smultron1977 0:309c546f048d 107
DevonHeron 1:71477b6fe9a4 108 printf("\n\n\n\n\nStart Time %f s\n", t.read());
DevonHeron 1:71477b6fe9a4 109 TFT.set_font((unsigned char*) Arial24x23); // select the font
smultron1977 0:309c546f048d 110 for ( j = 0 ; j < 10000; j++ )
smultron1977 0:309c546f048d 111 {
smultron1977 0:309c546f048d 112
smultron1977 0:309c546f048d 113 /* move and draw stars */
smultron1977 0:309c546f048d 114
smultron1977 0:309c546f048d 115 for (i = 0; i < NUMBER_OF_STARS; i++)
smultron1977 0:309c546f048d 116 {
smultron1977 0:309c546f048d 117 tempx = (stars[i].xpos / stars[i].zpos) + centerx;
smultron1977 0:309c546f048d 118 tempy = (stars[i].ypos / stars[i].zpos) + centery;
smultron1977 0:309c546f048d 119 TFT.pixel(tempx,tempy,Black);
smultron1977 0:309c546f048d 120
smultron1977 0:309c546f048d 121
smultron1977 0:309c546f048d 122 stars[i].zpos -= stars[i].speed;
smultron1977 0:309c546f048d 123
smultron1977 0:309c546f048d 124 if (stars[i].zpos <= 0)
smultron1977 0:309c546f048d 125 {
smultron1977 0:309c546f048d 126 init_star(stars + i, i + 1);
smultron1977 0:309c546f048d 127 }
smultron1977 0:309c546f048d 128
smultron1977 0:309c546f048d 129 //compute 3D position
smultron1977 0:309c546f048d 130 tempx = (stars[i].xpos / stars[i].zpos) + centerx;
smultron1977 0:309c546f048d 131 tempy = (stars[i].ypos / stars[i].zpos) + centery;
smultron1977 0:309c546f048d 132
smultron1977 0:309c546f048d 133 if (tempx < 0 || tempx > TFT.width() - 1 || tempy < 0 || tempy > TFT.height() - 1) //check if a star leaves the screen
smultron1977 0:309c546f048d 134 {
smultron1977 0:309c546f048d 135 init_star(stars + i, i + 1);
smultron1977 0:309c546f048d 136 continue;
smultron1977 0:309c546f048d 137 }
smultron1977 0:309c546f048d 138
smultron1977 0:309c546f048d 139 TFT.pixel(tempx,tempy,stars[i].color);
smultron1977 0:309c546f048d 140
smultron1977 0:309c546f048d 141 }
smultron1977 0:309c546f048d 142 TFT.Bitmap(centerx-60,centery-19,120,38,p1);
smultron1977 0:309c546f048d 143 }
smultron1977 0:309c546f048d 144
smultron1977 0:309c546f048d 145 ///// demo stop
smultron1977 0:309c546f048d 146
smultron1977 0:309c546f048d 147 t.stop();
smultron1977 0:309c546f048d 148 TFT.locate(0,10);
smultron1977 0:309c546f048d 149 TFT.set_font((unsigned char*) Arial12x12); // select the font
smultron1977 0:309c546f048d 150 printf("Time %f s\n", t.read());
smultron1977 0:309c546f048d 151 }