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 jim hamblen

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:

mbeduLCD HeaderuLCD cable
5V=VU5V5V
GndGndGnd
TX=P9RXTX
RX=P10TXRX
P11ResetReset

/media/uploads/4180_1/ulcdpins.jpg

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.

/media/uploads/4180_1/150mm_5_way_female-female_jumper_cable_dsc_2303.jpg /media/uploads/4180_1/5_way_male-male_adaptor_dsc_2299.jpg

// 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:
7:7bd7397ab89f
Parent:
6:f752accd632c
Child:
8:31e63caf37e2
--- a/main.cpp	Fri Nov 22 02:45:05 2013 +0000
+++ b/main.cpp	Mon Nov 25 04:25:16 2013 +0000
@@ -1,5 +1,5 @@
 //
-// TFT_4DGL is a class to drive 4D Systems TFT touch screens
+// TFT_4DGL is a class to drive 4D Systems LCD screens
 //
 // Copyright (C) <2010> Stephane ROCHON <stephane.rochon at free.fr>
 //
@@ -39,10 +39,30 @@
         uLCD.printf("%2D",i);
         wait(.5);
     }
+
     uLCD.cls();
+
+    uLCD.printf("Change baud rate......");
     uLCD.baudrate(600000); //jack up baud rate to max for fast display
     //if demo hangs here - try lower baud rates
+    // printf text only full screen mode demo
+    uLCD.background_color(BLUE);
+    uLCD.cls();
+    uLCD.locate(0,0);
+    uLCD.color(WHITE);
+    uLCD.textbackground_color(BLUE);
+    uLCD.set_font(FONT_7X8);
+    uLCD.text_mode(OPAQUE);
+    int i=0;
+    while(i<64) {
+        if(i%16==0) uLCD.cls();
+        uLCD.printf("TxtLine %2D Page %D\n",i%16,i/16 );
+        i++; //16 lines with 18 charaters per line
+    }
+    wait(0.5);
     //demo graphics commands
+    uLCD.background_color(BLACK);
+    uLCD.cls();
     uLCD.background_color(DGREY);
     uLCD.circle(60, 50, 30, 0xFF00FF);
     uLCD.triangle(120, 100, 40, 40, 10, 100, 0x0000FF);
@@ -60,23 +80,10 @@
     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
-    uLCD.background_color(BLUE);
-    uLCD.cls();
-    uLCD.locate(0,0);
-    uLCD.color(WHITE);
-    uLCD.textbackground_color(BLUE);
-    uLCD.set_font(FONT_7X8);
-    uLCD.text_mode(OPAQUE);
-    int i=0;
-    while(i<64) {
-        if(i%16==0) uLCD.cls();
-        uLCD.printf("TxtLine %2D Page %D\n",i%16,i/16 );
-        i++; //16 lines with 18 charaters per line
-    }
-    wait(0.5);
+
 //Bouncing Ball Demo
-    int x=50,y=21,vx=1,vy=1, radius=4;
+    float fx=50.0,fy=21.0,vx=1.0,vy=0.4;
+    int x=50,y=21,radius=4;
     uLCD.background_color(BLACK);
     uLCD.cls();
     //draw walls
@@ -84,19 +91,21 @@
     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++) {
+    for (int i=0; i<1500; 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;
+        //bounce off edge walls and slow down a bit?
+        if ((x<=radius+1) || (x>=126-radius)) vx = -.90*vx;
+        if ((y<=radius+1) || (y>=126-radius)) vy = -.90*vy;
         //erase old ball location
         uLCD.circle(x, y, radius, BLACK);
         //move ball
-        x=x+vx;
-        y=y+vy;
+        fx=fx+vx;
+        fy=fy+vy;
+        x=(int)fx;
+        y=(int)fy;
     }
-    wait(1);
+    wait(0.5);
 //draw an image pixel by pixel
     int pixelcolors[50][50];
     uLCD.background_color(BLACK);
@@ -112,7 +121,7 @@
     double MaxIm = MinIm+(MaxRe-MinRe)*ImageHeight/ImageWidth;
     double Re_factor = (MaxRe-MinRe)/(ImageWidth-1);
     double Im_factor = (MaxIm-MinIm)/(ImageHeight-1);
-    unsigned MaxIterations = 4096;
+    unsigned MaxIterations = 2048;
     for(unsigned y=0; y<ImageHeight; ++y) {
         double c_im = MaxIm - y*Im_factor;
         for(unsigned x=0; x<ImageWidth; ++x) {
@@ -138,8 +147,9 @@
     uLCD.cls();
     int num_cols=50;
     int num_rows=50;
+    int frame=0;
     double a,b,c=0.0;
-    while(1) {
+    while(frame<50) {
         for (int k=0; k<num_cols; k++) {
             b= (1+sin(3.14159*k*0.75/(num_cols-1.0)+c))*0.5;
             for (int i=0; i<num_rows; i++) {
@@ -159,5 +169,22 @@
         uLCD.BLIT(39, 39, 50, 50, &pixelcolors[0][0]);
         c = c + 0.0314159*3.0;
         if (c > 6.2831) c = 0.0;
+        frame++;
+    }
+    uLCD.cls();
+    //SD card needed with image and video files for last two demos
+    while(1){}  //remove line, if SD card is used
+    uLCD.cls();
+    uLCD.media_init();
+    uLCD.set_sector_address(0x001D, 0x4C01);
+    uLCD.display_image(0,0);
+    wait(10);
+    while(1) {
+        uLCD.cls();
+        uLCD.media_init();
+        uLCD.set_sector_address(0x001D, 0x4C42);
+        uLCD.display_video(0,0);
     }
 }
+
+