DISPLAY DE 128x64 PIXELES GLCD KS0108
Esta es una pantalla gráfica de128x64 pixeles blancos sobre fondo retroiluminado azul.
Se la puede controlar mediante comunicación de datos en forma paralela, o mediante la interfaz tipo SPI,
utilizando las líneas MOSI, CLK y SS, tal como lo muestra la siguiente imagen:
Los contactos BLA (pin 19) y BLK (pin 20) alimentan la iluminación del fondo de la pantalla, y conviene alimentarlos
con los 5 voltios de la placa Arduino, intercalando una resistencia de 100 omhs para limitar la corriente, y de paso
atenuar un poco el brillo del fondo, logrando una luz más descansada.
Al probar la pantalla con una placa Arduino, la primer sensación es de una notoria falta de contraste, pero
luego de muchas pruebas e incluso, de intentar configurar por hardware un control de contraste, se descubre
que esa falta de contraste tiene relación con el alimentar la placa Arduino desde su puerto USB.
Al alimentarla con una fuente de más tensión desde el conector de alimentación, las imágenes en la pantalla
resultan nítidas y con un contraste bien equilibrado, pudiéndoselas ver incluso desde ángulos extremos.
Desde el entorno de programación(IDE) de Arduino (al menos en la versión 1.6.6) se debe instalar la biblioteca
'u8glib', desde la opción PROGRAMA / INLCLUIR LIBRERÍAS / GESTIONAR LIBRERÍAS del menú. Allí se selecciona
TIPO=TODOS, TOPICO=TODOS, en filtro de búsqueda se escribe u8glib, y se pulsa la tecla ENTER.Aparece entonces
un ítem que describe la biblioteca y presenta un botón INSTALAR o ACTUALIZAR, en caso que ya estuviera instalada
pero existiesen versiones más nuevas.
Junto con la biblioteca, se instalan también diferentes ejemplos de programación, que conviene probar, para
tener una idea concreta de cómo funciona la pantalla y qué tipo de operaciones se pueden realizar con ella.
Las referencias en la Web sugieren que si se desea implementar un control de contraste, se debe conectar
un potenciómetro de 10 Kiloohms, con sus extremos conectados al pin Vout, a masa
o tierra (VSS) y su punto medio a la entrada de tensión de referencia V0. En mi caso particular, esto no
funcionó, pero tampoco es necesario, ya que las imágenes y caracteres mostrados en la misma resultan
tener un brillo y un contraste muy agradables.
Si se piensa utilizar la pantalla en más de un proyecto, puede resultar muy cómodo y eficiente el
instalarla en una cajita acrílica, junto con alguna fuente de tensión de 5 voltios (una batería externa
de las que se utilizan para cargar celulares es una opción muy recomendable), de manera que externamente
sólo presente cuatro cables, a conectar en la placa Arduino, a saber: MISO, SCK, CS y GND.
A continuación se exponen las referencias de cada
función disponible en la biblioteca 'u8glib':
begin
uint8_t u8g.begin(void);
Reinicia la pantalla y la vuelve a su estado por defecto
disableCursor;
void u8g.disableCursor(void);
Deshabilita el cursor, el cual deja de ser visible.
drawBitmap y drawBitmapP
void u8g.drawBitmap (u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, u8g_uint_t h, const uint8_t *bitmap);
void u8g.drawBitmapP(u8g_uint_t x, u8g_uint_t y, u8g_uint_t cnt, u8g_uint_t h, const u8g_pgm_uint8_t *bitmap);
Dibuja un mapa de bits en la posición especificada (de su parte superior izquierda).
Partes del mapa de bits podría quedar fuera de los límites de la pantalla.
El mapa de bits se pasa mediante el arreglo bitmap.
Un bit apagado significa: no pintar el pixel. Uno encendido implica dibujarlo con el color actual.
Para pantallas monocromáticas, un cero sería apagado, un uno, encendido.
drawBox
void u8g.drawBox(u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h)
Dibuja un rectángulo sólido (caja), comenzando por su esquina superior izquierda en la posición 'x' / 'y',
con un ancho igual a 'w' y un alto igual a 'h'
Algunas partes del rectángulo podrían caer fuera de los límites de la pantalla.
Este procedimiento dibuja la caja utilizando el índice de color actual.
En pantallas monocromáticas, el color de índice '0' suele apagar el pixel, mientras que el '1' lo enciende.
drawCircle
void u8g.drawCircle(u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t opt)
Draw a circle with radius rad at position (x0, y0).
The diameter of the circle is 2*rad+1 Depending on opt,
it is possible to draw only some sections of the circle.
Possible values for opt are:
U8G_DRAW_UPPER_RIGHT, U8G_DRAW_UPPER_LEFT, U8G_DRAW_LOWER_LEFT,
U8G_DRAW_LOWER_RIGHT, U8G_DRAW_ALL.
These values can be combined with the | operator.
void u8g_DrawDisc(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rad, uint8_t opt)
Draw a filled circle with radus rad at position (x0, y0).
The diameter of the circle is 2*rad+1 Depending on opt,
it is possible to draw only some sections of the disc.
Possible values for opt are:
U8G_DRAW_UPPER_RIGHT, U8G_DRAW_UPPER_LEFT, U8G_DRAW_LOWER_LEFT,
U8G_DRAW_LOWER_RIGHT, U8G_DRAW_ALL.
These values can be combined with the | operator.
void u8g_DrawEllipse(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rx, u8g_uint_t ry, uint8_t opt)
Draw ellipse with radus rx and 'ry' at position (x0, y0).
rx*ry must be lower than 1024 in 8 Bit mode of u8glib.
Depending on opt, it is possible to draw only some sections of the disc.
Possible values for opt are:
U8G_DRAW_UPPER_RIGHT, U8G_DRAW_UPPER_LEFT, U8G_DRAW_LOWER_LEFT,
U8G_DRAW_LOWER_RIGHT, U8G_DRAW_ALL.
These values can be combined with the | operator.
void u8g_DrawFilledEllipse(u8g_t *u8g, u8g_uint_t x0, u8g_uint_t y0, u8g_uint_t rx, u8g_uint_t ry, uint8_t opt)
Draw a filled ellipse with radus rx and 'ry' at position (x0, y0).
rx*ry must be lower than 1024 in 8 Bit mode of u8glib.
Depending on opt, it is possible to draw only some sections of the disc.
Possible values for opt are:
U8G_DRAW_UPPER_RIGHT, U8G_DRAW_UPPER_LEFT, U8G_DRAW_LOWER_LEFT,
U8G_DRAW_LOWER_RIGHT, U8G_DRAW_ALL.
These values can be combined with the | operator.
void u8g_DrawFrame(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h)
Draw a frame, starting at x/y position (upper left edge).
The frame has width w and height h. Parts of the frame can be outside of the display boundaries.
This procedure uses the current color index to draw the lines of the frame.
For a monochrome display, the color index 0 will usually clear a pixel and the color index 1 will set a pixel.
void u8g_DrawHLine(u8g_t *u8g, uint8_t x, uint8_t y, u8g_uint_t w)
Draw a horizontal line, starting at x/y position (left edge).
The width of the line is w pixels. Parts of the line can be outside of the display boundaries.
This procedure uses the current color index to draw the line.
For a monochrome display, the color index 0 will usually clear a pixel and the color index 1 will set a pixel.
void u8g_DrawLine(u8g_t *u8g, u8g_uint_t x1, u8g_uint_t y1, u8g_uint_t x2, u8g_uint_t y2)
Draw a line from (x1, y1) to (x2, y2).
There are no restrictions on the start end end position.
This procedure uses the current color index to draw the line.
For a monochrome display, the color index 0 will usually clear a pixel and the color index 1 will set a pixel.
void u8g_DrawPixel(u8g_t *u8g, uint8_t x, uint8_t y)
Draw a pixel at the specified x/y position. Position (0,0) is at the upper left corner of the display.
The position may be outside the display boundaries.
This procedure uses the current color index to draw the pixel.
For a monochrome display, the color index 0 will usually clear a pixel and the color index 1 will set a pixel.
void u8g_DrawRBox(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, u8g_uint_t r)
void u8g_DrawRFrame(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, u8g_uint_t r)
Draw a box/frame with round edges, starting at x/y position (upper left edge).
The box/frame has width w and height h. Parts of the box can be outside of the display boundaries.
Edges have radius r. It is required that w >= 2*(r+1) and h >= 2*(r+1).
This condition is not checked. Behavior is undefined if w or h is smaller than 2*(r+1).
This procedure uses the current color index to draw the box.
For a monochrome display, the color index 0 will usually clear a pixel and the color index 1 will set a pixel.
u8g_uint_t u8g_DrawStr(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const char *s);
u8g_uint_t u8g_DrawStr90(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const char *s);
u8g_uint_t u8g_DrawStr180(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const char *s);
u8g_uint_t u8g_DrawStr270(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const char *s);
u8g_uint_t u8g_DrawStrP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const u8g_pgm_uint8_t *s);
u8g_uint_t u8g_DrawStr90P(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const u8g_pgm_uint8_t *s);
u8g_uint_t u8g_DrawStr180P(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const u8g_pgm_uint8_t *s);
u8g_uint_t u8g_DrawStr270P(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, const u8g_pgm_uint8_t *s);
Draws a string at the specified x/y position.
The x/y position is the lower left corner of the first character of the string.
It is required to assign a font with the setFont procedure before the first call to this procedure.
This procedure also uses the current color index to draw the characters.
For a monochrome display, the color index 0 will usually clear a pixel and the color index 1 will set a pixel.
The (x,y) arguments are influenced by the reference point calculation mode (setFontPosBaseline).
'P' variant: s is assumed to point to a string in PROGMEM area.
'90', '180', '270' variants: Rotate string output by 90, 180 or 270 degree.
void u8g_DrawTriangle(u8g_t *u8g, uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2)
Draw a triangle (filled polygon).
Arguments are 16 bit and the polygon is clipped to the size of the display.
Multiple polygons are drawn so that they exactly match without overlap:
The left side of a polygon is drawn, the right side is not draw. The upper side is only draw if it is flat.
void u8g_DrawVLine(u8g_t *u8g, uint8_t x, uint8_t y, u8g_uint_t h)
Draw a vertical line, starting at x/y position (upper edge).
The height of the line is h pixels. Parts of the line can be outside of the display boundaries.
This procedure uses the current color index to draw the line.
For a monochrome display, the color index 0 will usually clear a pixel and the color index 1 will set a pixel.
void u8g_DrawXBM(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, const uint8_t *bitmap)
void u8g_DrawXBMP(u8g_t *u8g, u8g_uint_t x, u8g_uint_t y, u8g_uint_t w, u8g_uint_t h, const u8g_pgm_uint8_t *bitmap)
Draw a XBM Bitmap. Position (x,y) is the upper left corner of the bitmap.
XBM contains monochrome, 1-bit bitmaps. This procedure only draws pixel values 1.
The current color index is used for drawing (see setColorIndex).
Pixel with value 0 are not drawn (transparent).
void u8g_EnableCursor(u8g_t *u8g)
Enable the cursor at the specified position.
void u8g_FirstPage(u8g_t *u8g)
A call to this procedure, marks the beginning of the picture loop.
uint8_t u8g_GetColorIndex(u8g_t *u8g)
The current 'color index' is used by all 'draw' procedures to set a pixel value on the display.
This procedure returns the current value, which has been set as current color index.
u8g_int_t u8g_GetFontAscentu8g_t *u8g)
Returns the reference height of the glyphs above the baseline (ascent).
This value depends on the current reference height (see setFontRefHeightAll).
u8g_int_t u8g_GetFontDescent(u8g_t *u8g)
Returns the reference height of the glyphs below the baseline (descent)
u8g_int_t u8g_getFontLineSpacing(u8g_t *u8g)
Returns the vertical distance of two lines of text, written with the current font.
This value is derived from the ascent and descent value and multiplied with the current LineSpacingFactor.
The returned value is influenced by the current font, the 'Reference Height' and the LineSpacingFac
u8g_uint_t u8g_GetHeight(u8g_t *u8g)
Returns the height of the display.
uint8_t u8g_GetMode(u8g_t *u8g)
Returns information about the display (display mode).
The result of this procedure can be used to extract the number of bits per pixel:
u8g_uint_t u8g_GetWidth(u8g_t *u8g)
Returns the width of the display
u8g_uint_t u8g_GetStrWidth(u8g_t *u8g, const char *s)
u8g_uint_t u8g_GetStrWidthP(u8g_t *u8g, const u8g_pgm_uint8_t *s)
Returns the width of the string 's', based on the current font.
uint8_t u8g_InitSPI(u8g_t *u8g, u8g_dev_t *dev, uint8_t sck, uint8_t mosi, uint8_t cs, uint8_t a0, uint8_t reset);
uint8_t u8g_InitHWSPI(u8g_t *u8g, u8g_dev_t *dev, uint8_t cs, uint8_t a0, uint8_t reset);
uint8_t u8g_Init8Bit(u8g_t *u8g, u8g_dev_t *dev, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6,
uint8_t d7,uint8_t en, uint8_t cs1, uint8_t cs2, uint8_t di, uint8_t rw, uint8_t reset);
uint8_t u8g_InitComFn(u8g_t *u8g, u8g_dev_t *dev, u8g_com_fnptr com_fn);
Create a new interface to a graphics display.
This procedure must be called before calling any other C-procedure.
The dev argument describes the type of the display.
u8g_InitComFn will be the default init precedure for the ARM plattfrom.
It requires a specific low level procedure for the ARM controller.
uint8_t u8g_NextPage(u8g_t *u8g)
A call to this procedure, marks the end of the body of the picture loop.
U8GLIB::print(...)
A call to the print procedure of the Print base class.
See the documentation on the Arduino web page: http://arduino.cc/en/Serial/Print.
print() behaves similar to drawStr. All font settings also apply to this procedure.
All strings and values passed to the print procedure are written to the 'print position'.
The 'print position' can be set via setPrintPos.
void u8g_SetColorIndex(u8g_t *u8g, uint8_t color_index)
The current 'color index' is used by all 'draw' procedures to set a pixel value on the display.
For a monochrome display, the color index 0 will usually clear a pixel and the color index 1 will set a pixel.
For a display which supports gray levels, this procedure sets the gray level for drawing.
uint8_t u8g_SetContrast(u8g_t *u8g, uint8_t contast)
Assigns a new contrast value (0..255) to the display.
Not all displays or driver support the setting of the contrast value (see devices table).
void u8g_SetCursorColor(u8g_t *u8g, uint8_t fg, uint8_t bg)
Assign the foreground and background color index for the cursor.
void u8g_SetCursorFont(u8g_t *u8g, const u8g_pgm_uint8_t *font)
Set the cursor font (see note below). The cursor shape can be selected from this font.
void u8g_SetCursorPos(u8g_t *u8g, uint8_t x, uint8_t y)
Draw the enabled cursor at the specified x/y position.
void u8g_SetCursorStyle(u8g_t *u8g, uint8_t encoding)
Set the cursor shape. The cursor shape is defined by two bitmaps of a cursor font.
The encoding 32 will select the bitmaps 32 and 33 of a cursor font.
In the font u8g_font_cursor, this would select the x cursor in the upper left edge:
void u8g_SetDefaultBackgroundColor(u8g_t *u8g)
void u8g_SetDefaultForegroundColor(u8g_t *u8g)
void u8g_SetDefaultMidColor(u8g_t *u8g)
Assign one of the default colors as current color index.
On a monochrom display, setDefaultBackgroundColor will assign 0 to the current color index
and setDefaultForegroundColor will assign 1 to the current color index.
For all display types, it is ensured, that setDefaultBackgroundColor and setDefaultForegroundColor will assign different values.
void u8g_SetFont(u8g_t *u8g, const u8g_pgm_uint8_t *font)
Set the current font and reset the font reference position to 'Baseline' (setFontPosBaseline).
This font will be used for any further font and draw procedures.
U8glib has a lot of built-in fonts which can be used as argument.
void u8g_SetFontLineSpacingFactor(u8g_t *u8g,uint8_t factor)
Assign the factor for the LineSpacing calculation.
void u8g_SetFontPosBaseline(u8g_t *u8g);
void u8g_SetFontPosBottom(u8g_t *u8g);
void u8g_SetFontPosCenter(u8g_t *u8g);
void u8g_SetFontPosTop(u8g_t *u8g);
Set the reference position for the character and string draw procedure. In the following command
void u8g_SetFontRefHeightAll(u8g_t *u8g)
void u8g_SetFontRefHeightExtendedText(u8g_t *u8g)
void u8g_SetFontRefHeightText(u8g_t *u8g)
A call to one of these procedure will define the calculation method for the ascent and descent of the current font.
This method will be used for the current and all other fonts, which will be set with setFont().
Changing this calculation method has an effect on getFontAscent() and getFontDescent().
It has also an effect on the text position methods other than setFontPosBaseline()
void u8g_SetHardwareBackup(u8g_t *u8g, u8g_state_cb backup_cb);
The display can be connected to I/O pins which are also shared with other external devices. Examples are SPI, TWI or UART interfaces.
Example: SD card and SPI display share Clock and Data pins (but have different chip select lines).
The SD Card software uses the SPI hardware of the microcontroller to access the SD card, but U8glib should use a software SPI mode.
In such a case, the hardware state of the microcontroller SPI subsystem must be modified before access to SD card and display.
This modification is activated by this procedure.
Usage is: (1) Init u8glib, (2) call this procedure and (3) init other libraries.
void U8GLIB::setPrintPos(u8g_uint_t x, u8g_uint_t y)
Assignes the (x,y) position for the next call of the print procedure.
void u8g_SetRGB(u8g_t *u8g, uint8_t r, uint8_t g, uint8_t b)
Assignes RGB color for one of the color devices.
void u8g_SetRot90(u8g_t *u8g)
void u8g_SetRot180(u8g_t *u8g)
void u8g_SetRot270(u8g_t *u8g)
Clockwise rotates the display screen by 90, 180 or 270 degree.
For most display devices, landscape view is the default mode.
Rotation by 90 or 270 degree will put the display into portrait mode.
Please note, that this function will reduce performance of U8glib.
void u8g_SetScale2x2(u8g_t *u8g)
This command halfs x and y dimension of the display.
After calling this command, graphics commands output blocks of size 2x2 pixel until a call to u8g:undoScale().
getHeight() and getWidth() only return half of the original display values.
All graphic commands between 'u8g::setScale2x2()' and 'u8g:undoScale()' are scaled up (line draw, pixel set, font, bitmaps, ...)
void u8g_SleepOn(u8g_t *u8g)
void u8g_SleepOff(u8g_t *u8g)
Enable/disable sleep mode for the display (if possible).
void u8g_UndoRotation(u8g_t *u8g)
Remove an applied rotation done by the 'setRotXY' commands.
After calling this command, the display will have its default orientation.
Nothing happens if the display has default orientation.
void u8g_UndoScale(u8g_t *u8g)
Remove an applied scaling.
If the scaling has been applied within the body of the picture loop,
then this command should be called within the body of the picture loop
void U8GLIB::U8GLIB(u8g_dev_t *dev)
void U8GLIB::U8GLIB(u8g_dev_t *dev, uint8_t sck, uint8_t mosi, uint8_t cs, uint8_t a0, uint8_t reset)
void U8GLIB::U8GLIB(u8g_dev_t *dev, uint8_t d0, uint8_t d1, uint8_t d2, uint8_t d3, uint8_t d4, uint8_t d5, uint8_t d6,
uint8_t d7, uint8_t en, uint8_t cs1, uint8_t cs2, uint8_t di, uint8_t rw, uint8_t reset)
Create a new interface to a graphics display.
The dev argument describes the type of the display.
Usually this constructor is not called directly.
Instead there are drived classes for each available device.