Arduino LCD playground | Sparkfun 128x64 Serial Graphics LCD Library (Firmware update required)
This is an unofficial Arduino library for Sparkfuns 128x64 Serial Graphics LCD (http://www.sparkfun.com/products/9351) made by Øyvind Schei (sabesto at gmail.com)
Download Includes readme and example sketch.
The library is meant to work with Jenn Holt's serialGLCD firmware found HERE It only works for the 128x64 LCD, hence this library only works with that display. This firmware fixes all the bugs in the original firmware, and features great improvements in speed.
The code is based on Michael Nash's code found HERE This code was made for the original firmware, so I rewrote it and added more functions made possible by the new firmware.
The example sketch below is included in the download, and demonstrates some of the functions in the library. Use this sketch to check that everything is connected and working properly. (Remember the contrast pot if you cant see anything on the screen).
This is a list of functions supported by the library (Check the included readme file for further explanations)
General functions: | |
---|---|
clearLCD() | Clear the screen |
setDebug(l) | Set debug level |
backLight(x) | Set backlight |
resetLCD() | Reset the LCD |
changeBaud(x) | Change baud rate |
reverseColor() | Invert / change the color (black on white / white on black) |
toggleSplash() | Toggle splash screen |
Graphic functions: | |
drawCircle(x,y,r,z) | Draw a circle |
toggleCRLF() | Toggle CRLF |
eraseBlock(x1,y1,x2,y2) | Erase a block |
drawBox(x1,y1,x2,y2,z) | Draw a box |
togglePixel(x,y,z) | Toggle pixel on/off |
drawFilledBox(x1,y1,x2,y2,fill) | Draw a filled box |
Sprites | |
drawSprite(x,y,n,mode) | Draw a sprite |
drawLine(x1,y1,x2,y2,z) | Draw a line |
uploadSprite(n,w,h,data) | Upload a sprite |
drawData(x,y,mode,w,h,data,length) | Send data directly to LCD |
Font functions: | |
toggleFont() | Toggle font |
setFontMode(x) | Set font mode |
gotoPosition(x,y) | Go to position |
gotoLine(line) | Go to line |
#include <serialGLCD.h> // Include the library
// Example 128x64 bitmap, use Paint and BMP2ASM(http://www.piclist.com/techref/microchip/bmp2asm.htm) to // make your own. used in the drawData function further down..
byte sprite[] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x80,0x80,0xC0,0xC0,0xE0,0xE0,0xF0,0xF0,0xF8,0xF8,0xFC,0xFC,0x7E,0xFE,0xFF,0xFF, 0xFF,0xFE,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80, 0x80,0xC0,0xC0,0xE0,0xE0,0xF0,0xF0,0xF8,0xF8,0xF8,0xFC,0x7C,0x7E,0x3E,0x3F,0x1F, 0x1F,0x0F,0x0F,0x07,0x07,0x03,0x03,0x01,0x01,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF, 0xFF,0xFF,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80, 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80, 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80, 0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x80,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0x80, 0x80,0xC0,0xC0,0xE0,0xE0,0xF0,0xF0,0xF8,0xF8,0xFC,0x7C,0x7E,0x3E,0x3F,0x1F,0x1F, 0x0F,0x0F,0x0F,0x07,0x07,0x03,0x03,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x07,0x0F, 0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F, 0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F, 0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F, 0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0x0F,0xFF,0xFF,0xFF,0xFF,0xFF, 0x80,0xC0,0xE0,0xE0,0xF0,0xF0,0xF8,0xF8,0xFC,0x7C,0x7E,0x7E,0x3F,0x3F,0x1F,0x1F, 0x0F,0x0F,0x07,0x07,0x03,0x03,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF, 0x01,0x03,0x07,0x07,0x0F,0x0F,0x1F,0x1F,0x3F,0x3E,0x7E,0x7C,0xFC,0xFC,0xF8,0xF8, 0xF0,0xF0,0xE0,0xE0,0xC0,0xC0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x01, 0x03,0x03,0x03,0x07,0x07,0x0F,0x0F,0x1F,0x1F,0x3F,0x3E,0x7E,0x7C,0xFC,0xF8,0xF8, 0xF0,0xF0,0xE0,0xE0,0xC0,0xC0,0xC0,0x80,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,0xE0,0xF0, 0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0, 0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0, 0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0, 0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xF0,0xFF,0xFF,0xFF,0xFF,0xFF, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01, 0x01,0x03,0x03,0x07,0x07,0x0F,0x0F,0x1F,0x1F,0x3F,0x3F,0x3E,0x7E,0x7C,0xFC,0xF8, 0xF8,0xF0,0xF0,0xE0,0xE0,0xC0,0xC0,0x80,0x80,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF, 0xFF,0xFF,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x01,0x01,0x03,0x03,0x07,0x07,0x0F,0x0F,0x1F,0x1F,0x3F,0x3E,0x7E,0x7F,0xFF,0xFF, 0xFF,0x7F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
void setup() {
Serial.begin(115200); // Default baud rate of the display. delay(5000);
}
serialGLCD lcd; // Initialisation, "lcd" can be whatever you like, but it must be in front of the functions "lcd.functionxx"
void loop() {
lcd.clearLCD(); delay(10);
// Must send the drawData function the length of the array with the sprite, also allow for a short delay before or after int length = sizeof(sprite);
// Draw the sprite (int x, int y, int mode, int height, int witdh, byte data, int length) // x and y defines the upper left corner to draw from, mode should be 4, sprite is the array of bytes and length is the length of that array lcd.drawData(0,0,4,128,64,sprite,length); delay(2000); lcd.clearLCD();
// Draw box. This command draws an outline of a box with corners x1,y1,x2,y2 and S_R for line type (respects reverse) // so to draw a box from (5,5) to (15,15) would be (5,5,15,15,1) lcd.drawBox(40,10,60,30,1);
// draw filled box. this draws a box much like the previous command, but the inside is filled with the fill byte. the fill byte describes 1 8-pixel high stripe // that is repeated every x pixels and every 8 y pixels. the most useful are 0x00 to clear the box, and 0xFF to fill it. // arguments x1,y1,x2,y2,fillbyte lcd.drawFilledBox(10,10,30,30,0x55); delay(2000); lcd.clearLCD();
// Print text with the default font Serial.print("test");
// Toggle to the aux font (bigger) and print text again, then toggle back to default text lcd.toggleFont(); Serial.print("test"); lcd.toggleFont(); delay(2000); lcd.clearLCD();
// Draw a circle with center x=30, y=20, radius=10, and 1 for write (0 for erase) lcd.drawCircle(30,20,10,1); delay(2000);
// Set backlight to 50%, then back to 100% lcd.backLight(50); delay(2000); lcd.backLight(100); lcd.clearLCD();
// Go to line 1, print "Line1" then go to line 8 and print "Line8" // gotoLine uses gotoPosition further down in the examples, but splits the screen up in 8 lines to make it easier lcd.gotoLine(1); Serial.print("Line1"); lcd.gotoLine(8); Serial.print("Line8"); delay(2000); lcd.clearLCD();
// Draw a filled box, then use eraseBlock to erase inside // eraseBlock works just like drawbox, but no S_R is required, it simply draws a box with white lcd.drawFilledBox(10,10,30,30,0xFF); delay(1000); lcd.eraseBlock(13,13,27,27); delay(2000); lcd.clearLCD();
// Toggle a pixel on/off, needs x,y coords and 1 or 0 to write or erase // Write to pixel 10,10, then erase it lcd.togglePixel(10,10,1); delay(2000); lcd.togglePixel(10,10,0); delay(1000);
// Use gotoPosition to print between lines lcd.gotoPosition(0,7); Serial.print("0,7"); delay(500); lcd.gotoPosition(20,8); Serial.print("20,8"); delay(500); lcd.gotoPosition(46,9); Serial.print("46,9"); delay(2000);
// Draw a line from 10,10 to 50,50 lcd.drawLine(10,10,50,50,1); delay(1000); // Then erase it lcd.drawLine(10,10,50,50,0); delay(1000); lcd.clearLCD();
/* Upload sprite. this stores the sprite in the backpack, they must be 32 byte by default. a total of 8 sprites can be stored. uploadSprite(1,10,16,sprite2) stores a 10x16px sprite as sprite 1 (0 is the first). Read the documentation for the firmware to find out how this works if you really need it */ byte sprite2[] = {0x80,0xc0,0x40,0x0c,0x3e,0xfe,0xf2,0xe0,0xf0,0xe0,0xff,0x7f,0x3f,0x1f,0x1f,0x1f,0x1f,0x0f,0x07,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; lcd.uploadSprite(1,10,16,sprite2);
/* Then draw the sprite that was uploaded previosly. drawsprite(10,10,1,4) draws sprite 1 from top left corner 10,10 using method 4 (XOR, read firmware doc) */ lcd.drawSprite(10,10,1,4); while(1){};
}
SourceForge support or: sabesto at gmail.com