This library enables you to control an LM15SGFNZ07 LCD module with your Arduino. The LM15SGFNZ07 is an LCD with a 101x80 pixels resolution, capable of displaying 4096 colors. It is found in Siemens mobile phones (models A65, M55, C60, MC60, S55, A60).
This library is an updated version of the original by Mindogas (https://bitbucket.org/mindogas/lm15sgfnz07) that supports more of the capabilities of the LCD and runs quicker than the original thanks to the use of the Arduino's SPI port for communication.
To import this library into your Arduino IDE use the import library function and select the library folder or ZIP file. After importing you can run the included demo and PaddleWar! game found under LM15SGFNZ07 of the examples menu to get an understanding of this library's awesome capabilities.
Connect the LCD using the following wiring configuration:
LCD pin | Arduino pin |
---|---|
1 (/cs)1 | 62 |
2 (/rst) | 52 |
3 (rs) | 42 |
4 (sclk) | 13 (or SPI SCK) |
5 (sdata) | 11 (or SPI MOSI) |
6 (+3.3v) | 3.3v |
7 (gnd) | gnd |
8 (led1) | 3.3v |
9 (led gnd) | gnd |
10 (led2) | 3.3v |
1 Pin 1 of the LCD is the right most pin, closest to the edge.
2 The Arduino pin numbers shown here are the default ones. You are free to use any of the Arduino's digital pins for LCD communication. This is configured when creating a library instance.
The library comes with two examples:
- A showcase of the library functions.
- The game PaddleWar. This is the same PaddleWar game as included in the Commander Keen games. You play a game of ping pong against the Arduino and try to be the first to score 21 points. To play the game connect a potentiometer between pins A0, +5v and GND and a small speaker between pins 7 and GND. The game will start automatically when you power up the Arduino. Use the potentiometer to move wour paddle and beat the other player. The first player to reach 21 points wins and the game ends. Reset your Arduino to play again.
To get started be sure to first import the LM15SGFNZ07 library into your Arduino project. You then need to create an instance of the LCD driver and setup the pin configuration. Before sending any commands to the LCD you must always initialize it first by calling the init() function. This puts the LCD in a ready state (you will probably see some garbage on screen). See below for a boilerplate example or try the demo by selecting it from the Arduino IDE's examples menu.
#include <SPI.h>
#include <LM15SGFNZ07.h>
LM15SGFNZ07 lcd(6, 5, 4); // Create lcd instance and set pin configuration.
void setup() {
lcd.init(); // Initialize lcd.
lcd.clear(0x000);
lcd.drawString("Hello World!", 5, 5, 0xFFF);
}
void loop() {
// Do something awesome!
}
Below are the functions available in this library.
LM15SGFNZ07(byte pinCs, byte pinReset, byte pinRs);
Create an instance of the LCD driver and set pin configuration
pinCs | Arduino pin number connected to LCD's chip select pin (LCD pin 1) |
pinReset | Arduino pin number connected to LCD's reset pin (LCD pin 2) |
pinRs | Arduino pin number connected to LCD's register select pin (LCD pin 3) |
void init(void);
Configures the pinMode of the Arduino pins associated with the LCD and initializes the display controller. This function must always be called before sending any subsequent commands.
void clear(unsigned int color);
Clears the screen with the given color value.
color | A 12-bit color value |
void drawBitmap(unsigned char x,unsigned char y, unsigned char width, unsigned char height, unsigned short *bitmap);
void drawBitmap(unsigned char x,unsigned char y, unsigned char width, unsigned char height, const PROGMEM unsigned short *bitmap);
Draw a bitmap onto the screen. The bitmap can either be stored locally in SRAM or in program memory. Bitmap data must be stored as a one-dimensional array of 16-bit integers where each integer represents a 12-bit color value.
x | X position on screen |
y | Y position on screen |
width | Width of the bitmap image |
height | Height of the bitmap image |
bitmap | Pointer to bitmap data in SRAM or program memory |
void drawLine(unsigned char x1, unsigned char y1, unsigned x2, unsigned char y2, unsigned int color);
Draw a line between two points in the given color.
x1 | X coordinate of start point |
y1 | Y coordinate of start point |
x2 | X coordinate of end point |
y2 | Y coordinate of end point |
color | 12-bit color value |
void drawPixel(unsigned char x, unsigned char y,unsigned int color);
Place a single pixel on screen.
x | X coordinate |
y | Y coordinate |
color | 12-bit color value |
void drawRect(unsigned char x,unsigned char y, unsigned char width, unsigned char height, unsigned int color);
Draw a rectangle on screen in the given color.
x | X coordinate of left edge |
y | Y coordinate of top edge |
width | Width of the rectangle |
height | Height of the rectangle |
color | 12-bit color value |
void drawString(char *str, unsigned char x, unsigned char y, unsigned int color, unsigned int background);
Print a text on screen. Text can have any color and always has a solid background color. In order to put as many characters on a small screen a proportional font is used. Spacing between characters is 1 pixel.
To replace the font alter the font.h file that comes with the library. For each glyph in the font we define the number of columns in the glyph bitmap between 1 and 5. This is followed by the bit pattern of each column. Glyphs that are less than 5 columns wide must be padded so that each glyph takes 6 bytes of data.
str | The text string to print |
x | X coordinate of the text |
y | Y coordinate of the text |
color | 12-bit color of the text |
background | 12-bit color of the text background |
void fillRect(unsigned char x,unsigned char y, unsigned char width, unsigned char height, unsigned int color);
Draws a filled rectangle.
x | X coordinate of left edge |
y | Y coordinate of top edge |
width | Width of the rectangle |
height | Height of the rectangle |
color | 12-bit color value |
void inverseScreen(bool inverse);
Switches inverse colors on or off. This can be useful to briefly flash the screen to get a users attention.
inverse | Switches inverse color mode on when true |
void setContrast(unsigned char contrast);
Sets the contrast of the sreen. A good contrast value seems to be 0x1A, which is also set as default by the init function.
contrast | A contrast value ranging from 0 to 127 |
void setInverseLines(unsigned char y, unsigned char height, unsigned char inverseMode);
Sets inverse or blink mode for a certain number of lines on the screen. The controller of this LCD is able to blink a certain number of lines on the screen every 32 frames. This can be a useful function to highlight certain areas on the screen. For example a selected menu option. If the screen is already in inverse mode then setting lines to inverse will reverse the effect.
Three inverting modes are available:
- LCD_INVERSE_OFF - Disables line inversion mode
- LCD_INVERSE_ON - Inverses the given area on screen
- LCD_INVERSE_BLINK - Inverses and blinks the given area
y | Start line |
height | Number of lines to inverse |
inverseMode | Defines how the lines are inverted |
void setLcdOn(bool on);
Switches the LCD screen on or off. The init method switches the screen on, so this function is not required prior to sending any commands. When the screen is switched off the content is preserved.
on | Switches the screen on when true and off when false |
void setStartLine(unsigned char y);
Sets the line that is to be displayed as the first line in screen. After line 79 the display wraps around to line 0.
y | Line number to be displayed on top ranging from 0 to 79 |
void setWindow(unsigned char x, unsigned char y, unsigned char width, unsigned char height);
Defines the active drawing area. When color data is sent to the display it is placed in this area. Both width and height wrap around when more data is sent than fit into the area.
x | X coordinate of the left edge of the active area |
y | Y coordinate of the top edge of the active area |
width | Width of the area |
height | Height of the area |
The following predefined colors are available.
BLACK | 0x000 |
BLUE | 0x00F |
GREEN | 0x0F0 |
CYAN | 0x0FF |
RED | 0xF00 |
PINK | 0xF0F |
YELLOW | 0xFF0 |
WHITE | 0xFFF |
The following functions toggle the control pins of the LCD.
LCD_RS_ON | Put the LCD in command mode |
LCD_RS_OFF | Put the LCD in data mode |
LCD_CS_OFF | Disables the LCD (current state is preserved) |
LCD_CS_ON | Enables the LCD |
LCD_RESET_ON | Puts the LCD in reset mode |
LCD_RESET_OFF | Puts the LCD in normal mode |