Demo of 4DGL library for the uLCD-144-G2 128 by 128 color display. See https://mbed.org/users/4180_1/notebook/ulcd-144-g2-128-by-128-color-lcd/ for instructions
Dependencies: 4DGL-uLCD-SE mbed
Fork of uVGAII_demo by
The uLCD-144-G2 from 4D Systems is a low-cost ($25 qty. 100) smart color LCD display board with a serial interface. They are also available from Sparkfun. It looks like a nice alternative to the now hard to find Nokia 6100 LCD breakout boards. It has a TTL level serial interface and a reset pin. An optional uSD card inserted in the display module's socket can be used to load fonts, images, and play videos in response to serial commands. It has a built in system font and the driver supports the use of printfs, so it is very easy to use and hookup. Here is the wiring for the demo program:
mbed | uLCD Header | uLCD cable |
---|---|---|
5V=VU | 5V | 5V |
Gnd | Gnd | Gnd |
TX=P9 | RX | TX |
RX=P10 | TX | RX |
P11 | Reset | Reset |
In the drawing above, the pins are labeled from the LCDs perspective with TX and RX pins. Mbed RX goes to LCD TX and mbed TX goes to LCD RX. So mbed TX goes to the middle pin on the connector which is the uVGA II RX pin. The included cable seen below is plugged into the bottom row of pins and plugged into a breadboard using the male header pins for hookup. Note that on the cable silkscreen seen in the image below RX and TX have been swapped to indicate the connections needed to the microprocessor pins.
// uLCD-144-G2 basic text demo program for uLCD-4GL LCD driver library // #include "mbed.h" #include "uLCD_4DGL.h" uLCD_4DGL uLCD(p9,p10,p11); // serial tx, serial rx, reset pin; int main() { // basic printf demo = 16 by 18 characters on screen uLCD.printf("\nHello uLCD World\n"); //Default Green on black text uLCD.printf("\n Starting Demo..."); uLCD.text_width(4); //4X size text uLCD.text_height(4); uLCD.color(RED); for (int i=10; i>=0; --i) { uLCD.locate(1,2); uLCD.printf("%2D",i); wait(.5); } }
Video of longer demo code with both text and graphics. A micro SD card on the LCD module is required for the images and videos seen at the end of the video. The display is actually a bit more colorful and clearer than it appears in the video. Demos include text using printfs, basic graphics commands, a simple bouncing ball animation, computing the Mandelbrot set pixel by pixel, a Plasma wave BLIT, a JPEG image, and a *.wmv video clip.
See https://mbed.org/users/4180_1/notebook/ulcd-144-g2-128-by-128-color-lcd/ for complete info, wiring, breadboard hints on avoiding the use of the cable, and how to work with fonts, images, and videos on the uSD card
Revision 6:f752accd632c, committed 2013-11-22
- Comitter:
- 4180_1
- Date:
- Fri Nov 22 02:45:05 2013 +0000
- Parent:
- 5:a1ef40ff0f78
- Child:
- 7:7bd7397ab89f
- Commit message:
- ver1.4
Changed in this revision
--- a/4DGL-uLCD-SE.lib Wed Nov 20 03:26:19 2013 +0000 +++ b/4DGL-uLCD-SE.lib Fri Nov 22 02:45:05 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/4180_1/code/4DGL-uLCD-SE/#74df7fc26fef +http://mbed.org/users/4180_1/code/4DGL-uLCD-SE/#8936798c19a3
--- a/main.cpp Wed Nov 20 03:26:19 2013 +0000 +++ b/main.cpp Fri Nov 22 02:45:05 2013 +0000 @@ -19,15 +19,15 @@ #include "mbed.h" #include "uLCD_4DGL.h" -#define SIZE_X 128 -#define SIZE_Y 128 +//#define SIZE_X 128 +//#define SIZE_Y 128 // uLCD_4DGL uLCD(p9,p10,p11); // serial tx, serial rx, reset pin; int main() { - int pixelcolors[40][40]; + // basic printf demo = 16 by 18 characters on screen uLCD.printf("\nHello uLCD World\n"); //Default Green on black text uLCD.printf("\n Starting Demo..."); @@ -40,8 +40,9 @@ wait(.5); } uLCD.cls(); - uLCD.baudrate(256000); //jack up baud rate to max - //demo graphics + uLCD.baudrate(600000); //jack up baud rate to max for fast display + //if demo hangs here - try lower baud rates + //demo graphics commands uLCD.background_color(DGREY); uLCD.circle(60, 50, 30, 0xFF00FF); uLCD.triangle(120, 100, 40, 40, 10, 100, 0x0000FF); @@ -52,9 +53,11 @@ uLCD.circle(120, 60, 10, BLACK); uLCD.set_font(FONT_7X8); uLCD.text_mode(TRANSPARENT); + uLCD.text_bold(ON); uLCD.text_char('B', 9, 8, BLACK); uLCD.text_char('I',10, 8, BLACK); uLCD.text_char('G',11, 8, BLACK); + uLCD.text_italic(ON); uLCD.text_string("This is a test of string", 1, 4, FONT_7X8, WHITE); wait(2); // printf text only mode demo @@ -71,23 +74,38 @@ uLCD.printf("TxtLine %2D Page %D\n",i%16,i/16 ); i++; //16 lines with 18 charaters per line } -//draw an image using BLIT (Block Image Transfer) fastest way to transfer pixel data + wait(0.5); +//Bouncing Ball Demo + int x=50,y=21,vx=1,vy=1, radius=4; uLCD.background_color(BLACK); uLCD.cls(); - for(int i=0; i<40; i++) { - for(int k=0; k<40; k++) { - pixelcolors[i][k] = RED; - } + //draw walls + uLCD.line(0, 0, 127, 0, WHITE); + uLCD.line(127, 0, 127, 127, WHITE); + uLCD.line(127, 127, 0, 127, WHITE); + uLCD.line(0, 127, 0, 0, WHITE); + for (int i=0; i<1000; i++) { + //draw ball + uLCD.circle(x, y, radius, RED); + //bounce off edge walls? + if ((x<=radius+1) || (x>=126-radius)) vx = -vx; + if ((y<=radius+1) || (y>=126-radius)) vy = -vy; + //erase old ball location + uLCD.circle(x, y, radius, BLACK); + //move ball + x=x+vx; + y=y+vy; } - uLCD.BLIT(50, 50, 40, 40, &pixelcolors[0][0]); - wait(5); + wait(1); //draw an image pixel by pixel + int pixelcolors[50][50]; uLCD.background_color(BLACK); uLCD.cls(); -//compute Mandelbrot image for display +//compute Mandelbrot set image for display //image size in pixels and setup const unsigned ImageHeight=128; const unsigned ImageWidth=128; + //region to display double MinRe = -0.75104; double MaxRe = -0.7408; double MinIm = 0.10511; @@ -100,26 +118,26 @@ for(unsigned x=0; x<ImageWidth; ++x) { double c_re = MinRe + x*Re_factor; double Z_re = c_re, Z_im = c_im; - bool isInside = true; int niterations=0; for(unsigned n=0; n<MaxIterations; ++n) { double Z_re2 = Z_re*Z_re, Z_im2 = Z_im*Z_im; if(Z_re2 + Z_im2 > 4) { niterations = n; - isInside = false; break; } Z_im = 2*Z_re*Z_im + c_im; Z_re = Z_re2 - Z_im2 + c_re; } - if(isInside==false) uLCD.pixel(x,y,((niterations & 0xF00)<<12)+((niterations & 0xF0)<<8)+((niterations & 0x0F)<<4) ); + if (niterations!=(MaxIterations-1)) + uLCD.pixel(x,y,((niterations & 0xF00)<<12)+((niterations & 0xF0)<<8)+((niterations & 0x0F)<<4) ); } } wait(5); - // PLASMA wave BLIT animation +// PLASMA wave BLIT animation +//draw an image using BLIT (Block Image Transfer) fastest way to transfer pixel data uLCD.cls(); - int num_cols=40; - int num_rows=40; + int num_cols=50; + int num_rows=50; double a,b,c=0.0; while(1) { for (int k=0; k<num_cols; k++) { @@ -131,15 +149,15 @@ // uses a and b to compute pixel colors based on rol and col location in array // also keeps colors at the same brightness level if ((a+b) <.667) - pixelcolors[i][k] = (255-(int(240.0*((a+b)/0.667)))<<16) | (int(240.0*((a+b)/0.667))<<8) | 0; + pixelcolors[i][k] = (255-(int(254.0*((a+b)/0.667)))<<16) | (int(254.0*((a+b)/0.667))<<8) | 0; else if ((a+b)<1.333) - pixelcolors[i][k] = (0 <<16) | (255-(int (240.0*((a+b-0.667)/0.667)))<<8) | int(240.0*((a+b-0.667)/0.667)); + pixelcolors[i][k] = (0 <<16) | (255-(int (254.0*((a+b-0.667)/0.667)))<<8) | int(254.0*((a+b-0.667)/0.667)); else - pixelcolors[i][k] = (int(255*((a+b-1.333)/0.667))<<16) | (0<<8) | (255-(int (240.0*((a+b-1.333)/0.667)))); + pixelcolors[i][k] = (int(255*((a+b-1.333)/0.667))<<16) | (0<<8) | (255-(int (254.0*((a+b-1.333)/0.667)))); } } - uLCD.BLIT(50, 50, 40, 40, &pixelcolors[0][0]); + uLCD.BLIT(39, 39, 50, 50, &pixelcolors[0][0]); c = c + 0.0314159*3.0; if (c > 6.2831) c = 0.0; } -} \ No newline at end of file +}
--- a/mbed.bld Wed Nov 20 03:26:19 2013 +0000 +++ b/mbed.bld Fri Nov 22 02:45:05 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/9114680c05da +http://mbed.org/users/mbed_official/code/mbed/builds/f37f3b9c9f0b \ No newline at end of file