All Projects → DhrBaksteen → Arduino-SPI-LM15SGFNZ07-LCD-Library

DhrBaksteen / Arduino-SPI-LM15SGFNZ07-LCD-Library

Licence: other
An Arduino library to control the LM15SGFNZ07 LCD screen found in Siemens mobile phones A65, M55, C60, MC60, S55, A60

Programming Languages

C++
36643 projects - #6 most used programming language
c
50402 projects - #5 most used programming language

LM15SGFNZ07 LCD Library for Arduino

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.


Connecting the LCD to the Arduino

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.


Included examples

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.


Geting started with the library

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!
}

Functions reference

Below are the functions available in this library.


Constructor

LM15SGFNZ07(byte pinCs, byte pinReset, byte pinRs);

Create an instance of the LCD driver and set pin configuration

pinCsArduino pin number connected to LCD's chip select pin (LCD pin 1)
pinResetArduino pin number connected to LCD's reset pin (LCD pin 2)
pinRsArduino pin number connected to LCD's register select pin (LCD pin 3)

init

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.


clear

void clear(unsigned int color);

Clears the screen with the given color value.

colorA 12-bit color value

drawBitmap

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.

xX position on screen
yY position on screen
widthWidth of the bitmap image
heightHeight of the bitmap image
bitmapPointer to bitmap data in SRAM or program memory

drawLine

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.

x1X coordinate of start point
y1Y coordinate of start point
x2X coordinate of end point
y2Y coordinate of end point
color12-bit color value

drawPixel

void drawPixel(unsigned char x, unsigned char y,unsigned int color);

Place a single pixel on screen.

xX coordinate
yY coordinate
color12-bit color value

drawRect

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.

xX coordinate of left edge
yY coordinate of top edge
widthWidth of the rectangle
heightHeight of the rectangle
color12-bit color value

drawString

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.

strThe text string to print
xX coordinate of the text
yY coordinate of the text
color12-bit color of the text
background12-bit color of the text background

fillRect

void fillRect(unsigned char x,unsigned char y, unsigned char width, unsigned char height, unsigned int color);

Draws a filled rectangle.

xX coordinate of left edge
yY coordinate of top edge
widthWidth of the rectangle
heightHeight of the rectangle
color12-bit color value

inverseScreen

void inverseScreen(bool inverse);

Switches inverse colors on or off. This can be useful to briefly flash the screen to get a users attention.

inverseSwitches inverse color mode on when true

setContrast

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.

contrastA contrast value ranging from 0 to 127

setInverseLines

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
yStart line
heightNumber of lines to inverse
inverseModeDefines how the lines are inverted

setLcdOn

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.

onSwitches the screen on when true and off when false

setStartLine

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.

yLine number to be displayed on top ranging from 0 to 79

setWindow

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.

xX coordinate of the left edge of the active area
yY coordinate of the top edge of the active area
widthWidth of the area
heightHeight of the area

Colors

The following predefined colors are available.

BLACK0x000
BLUE0x00F
GREEN0x0F0
CYAN0x0FF
RED0xF00
PINK0xF0F
YELLOW0xFF0
WHITE0xFFF

Pin toggle functions

The following functions toggle the control pins of the LCD.

LCD_RS_ONPut the LCD in command mode
LCD_RS_OFFPut the LCD in data mode
LCD_CS_OFFDisables the LCD (current state is preserved)
LCD_CS_ONEnables the LCD
LCD_RESET_ONPuts the LCD in reset mode
LCD_RESET_OFFPuts the LCD in normal mode
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].