|     Inicio    |   |         |  |   FOROS      |  |      |      
   Elastix - VoIP B4A (Basic4Android) App inventor 2 PHP - MySQL
  Estación meteorológica B4J (Basic4Java) ADB Shell - Android Arduino
  AutoIt (Programación) Visual Basic Script (VBS) FireBase (BD autoactualizable) NodeMCU como Arduino
  Teleco - Emisora de A.M. Visual Basic Cosas de Windows Webs interesantes
T Búsqueda en este sitio:


.

Arduino en español
Circuitos con Arduino - Juan Antonio Villalpando

-- Tutorial de iniciación a Arduino --

Volver al índice del tutorial

____________________________

32.- Pantalla Nokia. Mini osciloscopio.

Vamos a tomar contacto con el funcionamiento de una pantalla LCD, concretamente con la pantalla NOKIA 5110.

Mediante esta pantalla podemos ver alfanuméricamente el estado de distintos terminales del Arduino.

En mi caso utilizo el Arduino Compatible 1.6" Nokia 5110 LCD Module w/ Blue Backlit - Blue

Está basado en el display Philips PCD8544 LCD y tiene una resolución de 84x48 (14 caracteres por líneas y 6 líneas)

Hay modelos con la placa azul y otros de placa roja. En las imágenes superiores vemos tres modelos. Observa que cambia la denominación de los terminales.

 

Data sheet: Nokia5110.pdf

______________________
- Librerías.

- En la mayoría de estos ejemplos vamos a utilizar la librería U8glib.zip

- Prueba también la librerías 5110 de esta web:

http://www.rinkydinkelectronics.com/library.php (LCD5110.zip) estas librerías son muy buenas, incluso están preparadas para dibujar gráficos.

_______________________
- Conexiones

1. RST - reset
2. CE - Chip Select
3. DC - data / instruction selection
4. DIN - string data line
5. CLK - serial clock line
6. VCC - power input (3,3V
and 5v)
7. BL - backlight control terminal
8. GND - Ground

- En algunos modelos cambian el nombre de los terminales:

RST = Reset
CE = SCE = CS = Chip Select, se utiliza para seleccionar las pantallas, como solo tenemos una, ponemos este terminal a GND.
DC = D\C = DI = A0 = Data / Command select
Din = DIN = MOSI = Serial Data In
Clk = SCK = SCLK = Clock
BL = LIGH = luz de fondo

NOTA:
- La alimentación Vcc debe ser de 3,3V.
- Los niveles de entradas DC, DIN, CLK,... pueden ser de 5V, así que los podemos conectar directamente a los terminales del Arduino.

_________________________________

1.- Vamos a realizar nuestro primer proyecto. Texto con movimiento.

- Código obtenido en... http://www.geek-workshop.com/thread-713-1-1.html

__________________________
Conexiones.  

Pantalla
RST
CE
DC
Din
Clk
Vcc
BL
Gnd
Arduino
6
7
5
4
3
3.3 V

(Si lo conectas a 5 V, se ve con poco contraste)
a Vcc con una R de 100 ohmios para iluminar el fondo de la pantalla
(no es necesario)
GND

- Saldrá la pantalla con las palabras: Nokia 5110 Scroll Demo y un texto en movimiento (scroll):
for more products please visit www.geeetech.com

- El texto en movimiento va muy rápido y se ve con dificultad, podemos poner un Delay más lento.
- Si ponemos una R de 100 ohmios desde el terminal Vcc a la entrada BL, la pantalla se ilumina de azul. Si no la ponemos la pantalla será gris.
- He puesto las demás conexiones directas (sin otras resistencias) y ha funcionado.
- Si en vez de poner la alimentación de Vcc a 3.3 V la ponemos a 5 V, la pantalla apenas se ve por poco contraste.

__________________________
Código.

Este código no necesita librería solo copiar y pegar, pero es muy largo.

Código
// The pins to use on the arduino
#define PIN_SCE 7
#define PIN_RESET 6
#define PIN_DC 5
#define PIN_SDIN 4
#define PIN_SCLK 3

// COnfiguration for the LCD
#define LCD_C LOW
#define LCD_D HIGH
#define LCD_CMD 0

// Size of the LCD
#define LCD_X 84
#define LCD_Y 48

int scrollPosition = -10;

static const byte ASCII[][5] =
{
{0x00, 0x00, 0x00, 0x00, 0x00} // 20
,{0x00, 0x00, 0x5f, 0x00, 0x00} // 21 !
,{0x00, 0x07, 0x00, 0x07, 0x00} // 22 "
,{0x14, 0x7f, 0x14, 0x7f, 0x14} // 23 #
,{0x24, 0x2a, 0x7f, 0x2a, 0x12} // 24 $
,{0x23, 0x13, 0x08, 0x64, 0x62} // 25 %
,{0x36, 0x49, 0x55, 0x22, 0x50} // 26 &
,{0x00, 0x05, 0x03, 0x00, 0x00} // 27 '
,{0x00, 0x1c, 0x22, 0x41, 0x00} // 28 (
,{0x00, 0x41, 0x22, 0x1c, 0x00} // 29 )
,{0x14, 0x08, 0x3e, 0x08, 0x14} // 2a *
,{0x08, 0x08, 0x3e, 0x08, 0x08} // 2b +
,{0x00, 0x50, 0x30, 0x00, 0x00} // 2c ,
,{0x08, 0x08, 0x08, 0x08, 0x08} // 2d -
,{0x00, 0x60, 0x60, 0x00, 0x00} // 2e .
,{0x20, 0x10, 0x08, 0x04, 0x02} // 2f /
,{0x3e, 0x51, 0x49, 0x45, 0x3e} // 30 0
,{0x00, 0x42, 0x7f, 0x40, 0x00} // 31 1
,{0x42, 0x61, 0x51, 0x49, 0x46} // 32 2
,{0x21, 0x41, 0x45, 0x4b, 0x31} // 33 3
,{0x18, 0x14, 0x12, 0x7f, 0x10} // 34 4
,{0x27, 0x45, 0x45, 0x45, 0x39} // 35 5
,{0x3c, 0x4a, 0x49, 0x49, 0x30} // 36 6
,{0x01, 0x71, 0x09, 0x05, 0x03} // 37 7
,{0x36, 0x49, 0x49, 0x49, 0x36} // 38 8
,{0x06, 0x49, 0x49, 0x29, 0x1e} // 39 9
,{0x00, 0x36, 0x36, 0x00, 0x00} // 3a :
,{0x00, 0x56, 0x36, 0x00, 0x00} // 3b ;
,{0x08, 0x14, 0x22, 0x41, 0x00} // 3c <
,{0x14, 0x14, 0x14, 0x14, 0x14} // 3d =
,{0x00, 0x41, 0x22, 0x14, 0x08} // 3e >
,{0x02, 0x01, 0x51, 0x09, 0x06} // 3f ?
,{0x32, 0x49, 0x79, 0x41, 0x3e} // 40 @
,{0x7e, 0x11, 0x11, 0x11, 0x7e} // 41 A
,{0x7f, 0x49, 0x49, 0x49, 0x36} // 42 B
,{0x3e, 0x41, 0x41, 0x41, 0x22} // 43 C
,{0x7f, 0x41, 0x41, 0x22, 0x1c} // 44 D
,{0x7f, 0x49, 0x49, 0x49, 0x41} // 45 E
,{0x7f, 0x09, 0x09, 0x09, 0x01} // 46 F
,{0x3e, 0x41, 0x49, 0x49, 0x7a} // 47 G
,{0x7f, 0x08, 0x08, 0x08, 0x7f} // 48 H
,{0x00, 0x41, 0x7f, 0x41, 0x00} // 49 I
,{0x20, 0x40, 0x41, 0x3f, 0x01} // 4a J
,{0x7f, 0x08, 0x14, 0x22, 0x41} // 4b K
,{0x7f, 0x40, 0x40, 0x40, 0x40} // 4c L
,{0x7f, 0x02, 0x0c, 0x02, 0x7f} // 4d M
,{0x7f, 0x04, 0x08, 0x10, 0x7f} // 4e N
,{0x3e, 0x41, 0x41, 0x41, 0x3e} // 4f O
,{0x7f, 0x09, 0x09, 0x09, 0x06} // 50 P
,{0x3e, 0x41, 0x51, 0x21, 0x5e} // 51 Q
,{0x7f, 0x09, 0x19, 0x29, 0x46} // 52 R
,{0x46, 0x49, 0x49, 0x49, 0x31} // 53 S
,{0x01, 0x01, 0x7f, 0x01, 0x01} // 54 T
,{0x3f, 0x40, 0x40, 0x40, 0x3f} // 55 U
,{0x1f, 0x20, 0x40, 0x20, 0x1f} // 56 V
,{0x3f, 0x40, 0x38, 0x40, 0x3f} // 57 W
,{0x63, 0x14, 0x08, 0x14, 0x63} // 58 X
,{0x07, 0x08, 0x70, 0x08, 0x07} // 59 Y
,{0x61, 0x51, 0x49, 0x45, 0x43} // 5a Z
,{0x00, 0x7f, 0x41, 0x41, 0x00} // 5b [
,{0x02, 0x04, 0x08, 0x10, 0x20} // 5c ¥
,{0x00, 0x41, 0x41, 0x7f, 0x00} // 5d ]
,{0x04, 0x02, 0x01, 0x02, 0x04} // 5e ^
,{0x40, 0x40, 0x40, 0x40, 0x40} // 5f _
,{0x00, 0x01, 0x02, 0x04, 0x00} // 60 `
,{0x20, 0x54, 0x54, 0x54, 0x78} // 61 a
,{0x7f, 0x48, 0x44, 0x44, 0x38} // 62 b
,{0x38, 0x44, 0x44, 0x44, 0x20} // 63 c
,{0x38, 0x44, 0x44, 0x48, 0x7f} // 64 d
,{0x38, 0x54, 0x54, 0x54, 0x18} // 65 e
,{0x08, 0x7e, 0x09, 0x01, 0x02} // 66 f
,{0x0c, 0x52, 0x52, 0x52, 0x3e} // 67 g
,{0x7f, 0x08, 0x04, 0x04, 0x78} // 68 h
,{0x00, 0x44, 0x7d, 0x40, 0x00} // 69 i
,{0x20, 0x40, 0x44, 0x3d, 0x00} // 6a j
,{0x7f, 0x10, 0x28, 0x44, 0x00} // 6b k
,{0x00, 0x41, 0x7f, 0x40, 0x00} // 6c l
,{0x7c, 0x04, 0x18, 0x04, 0x78} // 6d m
,{0x7c, 0x08, 0x04, 0x04, 0x78} // 6e n
,{0x38, 0x44, 0x44, 0x44, 0x38} // 6f o
,{0x7c, 0x14, 0x14, 0x14, 0x08} // 70 p
,{0x08, 0x14, 0x14, 0x18, 0x7c} // 71 q
,{0x7c, 0x08, 0x04, 0x04, 0x08} // 72 r
,{0x48, 0x54, 0x54, 0x54, 0x20} // 73 s
,{0x04, 0x3f, 0x44, 0x40, 0x20} // 74 t
,{0x3c, 0x40, 0x40, 0x20, 0x7c} // 75 u
,{0x1c, 0x20, 0x40, 0x20, 0x1c} // 76 v
,{0x3c, 0x40, 0x30, 0x40, 0x3c} // 77 w
,{0x44, 0x28, 0x10, 0x28, 0x44} // 78 x
,{0x0c, 0x50, 0x50, 0x50, 0x3c} // 79 y
,{0x44, 0x64, 0x54, 0x4c, 0x44} // 7a z
,{0x00, 0x08, 0x36, 0x41, 0x00} // 7b {
,{0x00, 0x00, 0x7f, 0x00, 0x00} // 7c |
,{0x00, 0x41, 0x36, 0x08, 0x00} // 7d }
,{0x10, 0x08, 0x08, 0x10, 0x08} // 7e ?
,{0x00, 0x06, 0x09, 0x09, 0x06} // 7f ?
};

void LcdCharacter(char character)
{
LcdWrite(LCD_D, 0x00);
for (int index = 0; index < 5; index++)
{
LcdWrite(LCD_D, ASCII[character - 0x20][index]);
}
LcdWrite(LCD_D, 0x00);
}

void LcdClear(void)
{
for (int index = 0; index < LCD_X * LCD_Y / 8; index++)
{
LcdWrite(LCD_D, 0x00);
}
}

void LcdInitialise(void)
{
pinMode(PIN_SCE, OUTPUT);
pinMode(PIN_RESET, OUTPUT);
pinMode(PIN_DC, OUTPUT);
pinMode(PIN_SDIN, OUTPUT);
pinMode(PIN_SCLK, OUTPUT);

digitalWrite(PIN_RESET, LOW);
digitalWrite(PIN_RESET, HIGH);

LcdWrite(LCD_CMD, 0x21); // LCD Extended Commands.
LcdWrite(LCD_CMD, 0xBf); // Set LCD Vop (Contrast). //B1
LcdWrite(LCD_CMD, 0x04); // Set Temp coefficent. //0x04
LcdWrite(LCD_CMD, 0x14); // LCD bias mode 1:48. //0x13
LcdWrite(LCD_CMD, 0x0C); // LCD in normal mode. 0x0d for inverse
LcdWrite(LCD_C, 0x20);
LcdWrite(LCD_C, 0x0C);
}

void LcdString(char *characters)
{
while (*characters)
{
LcdCharacter(*characters++);
}
}

void LcdWrite(byte dc, byte data)
{
digitalWrite(PIN_DC, dc);
digitalWrite(PIN_SCE, LOW);
shiftOut(PIN_SDIN, PIN_SCLK, MSBFIRST, data);
digitalWrite(PIN_SCE, HIGH);
}

/**
* gotoXY routine to position cursor
* x - range: 0 to 84
* y - range: 0 to 5
*/
void gotoXY(int x, int y)
{
LcdWrite( 0, 0x80 | x); // Column.
LcdWrite( 0, 0x40 | y); // Row.
}

void drawBox(void)
{
int j;
for(j = 0; j < 84; j++) // top
{
gotoXY(j, 0);
LcdWrite(1, 0x01);
}

for(j = 0; j < 84; j++) //Bottom
{
gotoXY(j, 5);
LcdWrite(1, 0x80);
}

for(j = 0; j < 6; j++) // Right
{
gotoXY(83, j);
LcdWrite(1, 0xff);
}

for(j = 0; j < 6; j++) // Left
{
gotoXY(0, j);
LcdWrite(1, 0xff);
}
}

void Scroll(String message)
{
for (int i = scrollPosition; i < scrollPosition + 11; i++)
{
if ((i >= message.length()) || (i < 0))
{
LcdCharacter(' ');
}
else
{
LcdCharacter(message.charAt(i));
}
}
scrollPosition++;
if ((scrollPosition >= message.length()) && (scrollPosition > 0))
{
scrollPosition = -10;
}
}

void setup(void)
{
LcdInitialise();
LcdClear();
drawBox();


gotoXY(7,1);
LcdString("Nokia 5110");
gotoXY(4,2);
LcdString("Scroll Demo");
}

void loop(void)
{
gotoXY(4,4);
Scroll("for more products please visit www.geeetech.com");
delay(200);
} 

________________________________________________

2.- Hacemos un Hello World!


- Librería: U8glib (de http://code.google.com/p/u8glib/downloads/list)

- El código está sacado de los ejemplos de la Librería anterior.

- El patillaje tiene otros nombres en estos códigos:

RST = Reset
CE = CS = Chip Select
DC = DI = A0 = Data / Command select
Din = MOSI = Serial Data In
Clk = SCK = Clock

                               

__________________________
Conexiones.  

Pantalla
RST
CE
(CS)
DC
(A0)
Din
(MOSI)
Clk
(SCK)
Vcc
BL
Gnd
Arduino
8
10
9
11
13
3.3 V

(Si lo conectas a 5 V, se ve con poco contraste)
a Vcc con una R de 100 ohmios para iluminar el fondo de la pantalla
(no es necesario)
GND

__________________________
Código.

- Fíjate en el código que la línea activa es:

U8GLIB_PCD8544 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, Reset = 8

Las demás están marcadas como comentarios mediante //

Se pueden quitar muchos comentarios // para que el archivo quede mas pequeño.

Necesita la librería

#include "U8glib.h"

Código
/* HelloWorld.pde

"Hello World!" example code.

>>> Before compiling: Please remove comment from the constructor of the 
>>> connected graphics display (see below).

Universal 8bit Graphics Library, http://code.google.com/p/u8glib/

Copyright (c) 2012, olikraus@gmail.com
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list 
of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this 
list of conditions and the following disclaimer in the documentation and/or other 
materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 

*/


#include "U8glib.h"

// setup u8g object, please remove comment from one of the following constructor calls
// 
// BORRAR ESTAS LÍNEAS
//
// U8GLIB_PCD8544 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, Reset = 8
//
//
// BORRAR ESTAS LÍNEAS
// void draw(void) { // graphic commands to redraw the complete screen should be placed here u8g.setFont(u8g_font_unifont); //u8g.setFont(u8g_font_osb21); u8g.drawStr( 0, 22, "Hello World!"); } void setup(void) { // flip screen, if required // u8g.setRot180(); // set SPI backup if required //u8g.setHardwareBackup(u8g_backup_avr_spi); // assign default color value if ( u8g.getMode() == U8G_MODE_R3G3B2 ) u8g.setColorIndex(255); // white else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) u8g.setColorIndex(3); // max intensity else if ( u8g.getMode() == U8G_MODE_BW ) u8g.setColorIndex(1); // pixel on } void loop(void) { // picture loop u8g.firstPage(); do { draw(); } while( u8g.nextPage() ); // rebuild the picture after some delay delay(500); }

Distintos tipos de fuentes y tamaños:

Se pueden cambiar los tipos de caracteres y sus tamaños.

// graphic commands to redraw the complete screen should be placed here
u8g.setFont(u8g_font_04b_03);
//u8g.setFont(u8g_font_unifont);
//u8g.setFont(u8g_font_5x8);
//u8g.setFont(u8g_font_6x12);
//u8g.setFont(u8g_font_6x10);
//u8g.setFont(u8g_font_6x13);
//u8g.setFont(u8g_font_osb18);
//u8g.setFont(u8g_font_osb21);

___________________________

3.- Con LDR

Disponemos de una LDR, la conectamos como indica la imagen.
Según la luz incidente en la LDR, la pantalla Nokia mostrará el valor de su resistencia.

Fíjate que la LDR está alimentada con 5V y el NOKIA con 3,3V

La resistencia es de 1 K
__________________________
Conexiones.  

Utilizando las conexiones y la librería anterior.

Situo una LDR a positivo, una R de 1 K a negativo. El punto comun de la LDR y resistencia va con un cable ANALOG IN A0

__________________________
Código.

He simplificado el código anterior.

 

LDR - Arduino - Nokia

 

// Juan Antonio Villalpando
// kio4.com 



#include "U8glib.h"
char caracteres[4];
float luz;


U8GLIB_PCD8544 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, Reset = 8

void draw(void) {
Serial.println(luz, DEC);
u8g.drawStr(0, 30, caracteres);
}

void setup(void) {

Serial.begin(9600);
u8g.setFont(u8g_font_osb21); // Tamaño letra 
}

void loop(void) {
u8g.firstPage(); 
do {
draw() ;
} while( u8g.nextPage() );

luz = analogRead(A0);
dtostrf(luz, 6, 1, caracteres); // 1 decimal 
delay(3000);
}

https://code.google.com/p/u8glib/wiki/thelloworld

____________________________________

4.- App inventor - Bluetooth - Arduino - Nokia

Desde un móvil con Android envio un mensaje por Bluetooth al Arduino y ese mensaje sale en la pantalla Nokia.

La aplicación de Android se puede realizar con App inventor.

__________________________
Conexiones.  

Fíjate al módulo Bluetooth lo alimentamos con 5V y a la pantalla Nokia con 3,3V

 

__________________________
Código.

Enviar desde App Inventor un mensaje por Bluetooth y que aparezca en la pantalla Nokia.

 

Móvil Bluetooth - Arduino - Nokia

Envía un texto y sale en el Nokia

App inventor

 

// Juan Antonio Villalpando
// juana1991@yahoo.com
// kio4.com


#include "U8glib.h"
char buffer[100];

U8GLIB_PCD8544 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, Reset = 8

void draw(void) {
u8g.setFont(u8g_font_osb21);
u8g.drawStr(0, 30, buffer);
}

void setup() { 
Serial.begin(9600); // Aqui establecemos la velocidad
}

void loop() { 

int i=0;
if(Serial.available()){
delay(100);
while( Serial.available() && i< 99) {
buffer[i++] = Serial.read();
}
buffer[i++]='\0';
}

u8g.firstPage(); 
do {
draw();
} while( u8g.nextPage() );

}

___________________________
5.- Otro código: Console

- También está sacado de los ejemplos de la Librería: U8glib (de http://code.google.com/p/u8glib/downloads/list)

Este programa trata de que escribimos algo mediante el Serial Monitor del IDE
y cuando pulsamos su botón Send, el texto escrito pasa directamente a la pantalla Nokia.

__________________________
Conexiones.  

Las conexiones son iguales que en el código anterior.

Pantalla
RST
CE
(CS)
DC
(A0)
Din
(MOSI)
Clk
(SCK)
Vcc
BL
Gnd
Arduino
8
10
9
11
13
3.3 V

(Si lo conectas a 5 V, se ve con poco contraste)
Vcc con una R de 100 ohmios para iluminar la pantalla
(no es necesario)
GND

__________________________
Código.

- En el código hemos habilitado la línea:
U8GLIB_PCD8544 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, Reset = 8

Código
/*

Console.pde

Read from serial monitor, output to display

>>> Before compiling: Please remove comment from the constructor of the 
>>> connected graphics display (see below).

Universal 8bit Graphics Library, http://code.google.com/p/u8glib/

Copyright (c) 2011, olikraus@gmail.com
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, 
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list 
of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this 
list of conditions and the following disclaimer in the documentation and/or other 
materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 

*/


#include "U8glib.h"

// setup u8g object, please remove comment from one of the following constructor calls


U8GLIB_PCD8544 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, Reset = 8


// setup input buffer
#define LINE_MAX 30 
uint8_t line_buf[LINE_MAX] = "U8GLIB Console";
uint8_t line_pos = 0;

// setup a text screen to support scrolling
#define ROW_MAX 12


uint8_t screen[ROW_MAX][LINE_MAX];
uint8_t rows, cols;

// line height, which matches the selected font (5x7)
#define LINE_PIXEL_HEIGHT 7

// clear entire screen, called during setup
void clear_screen(void) {
uint8_t i, j;
for( i = 0; i < ROW_MAX; i++ )
for( j = 0; j < LINE_MAX; j++ )
screen[i][j] = 0; 
}

// append a line to the screen, scroll up
void add_line_to_screen(void) {
uint8_t i, j;
for( j = 0; j < LINE_MAX; j++ )
for( i = 0; i < rows-1; i++ )
screen[i][j] = screen[i+1][j];

for( j = 0; j < LINE_MAX; j++ )
screen[rows-1][j] = line_buf[j];
}

// U8GLIB draw procedure: output the screen
void draw(void) {
uint8_t i, y;
// graphic commands to redraw the complete screen are placed here 
y = 0; // reference is the top left -1 position of the string
y--; // correct the -1 position of the drawStr 
for( i = 0; i < rows; i++ )
{
u8g.drawStr( 0, y, (char *)(screen[i]));
y += u8g.getFontLineSpacing();
}
}

void exec_line(void) {
// echo line to the serial monitor
Serial.println((const char *)line_buf);

// add the line to the screen
add_line_to_screen();

// U8GLIB picture loop
u8g.firstPage(); 
do {
draw();
} while( u8g.nextPage() );
}

// clear current input buffer
void reset_line(void) { 
line_pos = 0;
line_buf[line_pos] = '\0'; 
}

// add a single character to the input buffer 
void char_to_line(uint8_t c) {
line_buf[line_pos] = c;
line_pos++;
line_buf[line_pos] = '\0'; 
}

// check serial in and handle the character
void read_line(void) {
if ( Serial.available() )
{
uint8_t c;
c = Serial.read();
if ( line_pos >= cols-1 ) {
exec_line();
reset_line();
char_to_line(c);
} 
else if ( c == '\n' ) {
// ignore '\n' 
}
else if ( c == '\r' ) {
exec_line();
reset_line();
}
else {
char_to_line(c);
}
}
}

// Arduino master setup
void setup(void) {
// set font for the console window
u8g.setFont(u8g_font_5x7);
//u8g.setFont(u8g_font_9x15);

// set upper left position for the string draw procedure
u8g.setFontPosTop();

// calculate the number of rows for the display
rows = u8g.getHeight() / u8g.getFontLineSpacing();
if ( rows > ROW_MAX )
rows = ROW_MAX; 

// estimate the number of columns for the display
cols = u8g.getWidth() / u8g.getStrWidth("m");
if ( cols > LINE_MAX-1 )
cols = LINE_MAX-1; 

clear_screen(); // clear screen
delay(1000); // do some delay
Serial.begin(9600); // init serial
exec_line(); // place the input buffer into the screen
reset_line(); // clear input buffer
}

// Arduino main loop
void loop(void) {
read_line();
}


________________________________

6.- Termómetro y pantalla

Basado en un tutorial visto anteriormente y en la pantalla Nokia, vamos a realizar con proyecto de un termómetro con Arduino.

Vamos a necesitar:
- Un sensor de temperatura: el DS18B20 Digital Temperature Sensor Module for Arduino (-55~125'C), viene a costar unos 1 €,

__________________________
Código.



- Librería para el sensor de temperatura: OneWire.zip

El código para ver la temperatura en la pantalla NOKIA, es una mezcla entre...
el código para ver la temperatura en el Serial Monitor, mediante un sensor de temperatura (visto en un tutorial anterior)
y el código del "Hello World!" visto anteriormente, para obtener una frase en la pantalla del NOKIA.

Las conexiones de la pantalla NOKIA al Arduino son las que hemos visto anteriormente:
(SCK = 13, MOSI = 11, CS = 10, A0 = 9, Reset = 8)
Las conexiónes del sensor de temperatura al Arduino son Vcc (5 V), GND y la Señal S al pin 3

 

- Se pueden eliminar muchos comentarios y líneas ya que está adaptado a varios modelos.

Temperatura en pantalla NOKIA .pde
#include <OneWire.h>
// Codigo para la pantalla NOKIA 
#include "U8glib.h"
U8GLIB_PCD8544 u8g(13, 11, 10, 9, 8); // SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, Reset = 8
////////////////////////////////


#include<stdlib.h> // Lo utilizamos para pasar de float a character la variable celsius
char celsius_ch [6]; // celsius en char
////////////////////////////////

// OneWire DS18S20, DS18B20, DS1822 Temperature Example
//
// http://www.pjrc.com/teensy/td_libs_OneWire.html
//
// The DallasTemperature library can do all this work for you!
// http://milesburton.com/Dallas_Temperature_Control_Library

OneWire ds(3); // on pin 3 el terminal S de sensor del termometro

void setup(void) {
Serial.begin(9600);
// Codigo para la pantalla NOKIA 
// assign default color value
if ( u8g.getMode() == U8G_MODE_R3G3B2 ) 
u8g.setColorIndex(255); // white
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT )
u8g.setColorIndex(3); // max intensity
else if ( u8g.getMode() == U8G_MODE_BW )
u8g.setColorIndex(1); // pixel on
///////////////////////////////
}

void loop(void) {
byte i;
byte present = 0;
byte type_s;
byte data[12];
byte addr[8];
float celsius, fahrenheit;

if ( !ds.search(addr)) {
// Serial.println("No more addresses.");
// Serial.println();
ds.reset_search();
delay(250);
return;
}

if (OneWire::crc8(addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return;
}
Serial.println();

// the first ROM byte indicates which chip
switch (addr[0]) {
case 0x10:
// Serial.println(" Chip = DS18S20"); // or old DS1820
type_s = 1;
break;
case 0x28:
// Serial.println(" Chip = DS18B20");
type_s = 0;
break;
case 0x22:
// Serial.println(" Chip = DS1822");
type_s = 0;
break;
default:
// Serial.println("Device is not a DS18x20 family device.");
return;
} 

ds.reset();
ds.select(addr);
ds.write(0x44,1); // start conversion, with parasite power on at the end

delay(1000); // maybe 750ms is enough, maybe not
// we might do a ds.depower() here, but the reset will take care of it.

present = ds.reset();
ds.select(addr); 
ds.write(0xBE); // Read Scratchpad

// Serial.print(" Data = ");
// Serial.print(present,HEX);
// Serial.print(" ");
for ( i = 0; i < 9; i++) { // we need 9 bytes
data[i] = ds.read();
// Serial.print(data[i], HEX);
// Serial.print(" ");
}
// Serial.print(" CRC=");
// Serial.print(OneWire::crc8(data, 8), HEX);
// Serial.println();

// convert the data to actual temperature

unsigned int raw = (data[1] << 8) | data[0];
if (type_s) {
raw = raw << 3; // 9 bit resolution default
if (data[7] == 0x10) {
// count remain gives full 12 bit resolution
raw = (raw & 0xFFF0) + 12 - data[6];
}
} else {
byte cfg = (data[4] & 0x60);
if (cfg == 0x00) raw = raw << 3; // 9 bit resolution, 93.75 ms
else if (cfg == 0x20) raw = raw << 2; // 10 bit res, 187.5 ms
else if (cfg == 0x40) raw = raw << 1; // 11 bit res, 375 ms
// default is 12 bit resolution, 750 ms conversion time
}
celsius = (float)raw / 16.0;
fahrenheit = celsius * 1.8 + 32.0;
Serial.print(" Temperature = ");
Serial.print(celsius);
Serial.print(" Celsius, ");
Serial.print(fahrenheit);
Serial.println(" Fahrenheit");



// Codigo para la pantalla NOKIA 
u8g.firstPage(); 
do {
//u8g.setFont(u8g_font_unifont);
u8g.setFont(u8g_font_osb21);

dtostrf(celsius,2,2,celsius_ch); // Para pasar de float a char
u8g.drawStr(8, 30, celsius_ch);

} while( u8g.nextPage() );

// rebuild the picture after some delay
delay(500);
///////////////////////////////
}

________________________________

7.- Gráficos.

- Con el IDE 1.0.6 funciona estas librerías para dibujar gráficos:

-
Adafruit-PCD8544.zip

- Adafruit-GFX.zip

- Se pueden dibujar triángulo, cuadrado, líneas, figuras,...

- Descomprime el archivo anterior, carga la librería en la carpeta libraries del IDE 1.0.6, busca el Sketch pcdtest.ino

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>

// Software SPI (slower updates, more flexible pin options):
// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)

-----------------------------------------------

Este código dibuja un punto y dos líneas.

Gráfico básico
// - Con el IDE 1.0.6 funciona estas librerías para dibujar gráficos:
// - Adafruit-PCD8544.zip
// - Adafruit-GFX.zip 

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>

// Software SPI (slower updates, more flexible pin options):
// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);

// Hardware SPI (faster, but must use certain hardware pins):
// SCK is LCD serial clock (SCLK) - this is pin 13 on Arduino Uno
// MOSI is LCD DIN - this is pin 11 on an Arduino Uno
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
// Adafruit_PCD8544 display = Adafruit_PCD8544(5, 4, 3);
// Note with hardware SPI MISO and SS pins aren't used but will still be read
// and written to during SPI transfer. Be careful sharing these pins!

void setup() {
Serial.begin(9600);
display.begin();
display.setContrast(50); // Contraste
display.clearDisplay();
// Dibuja un punto
display.drawPixel(10, 10, BLACK);
display.display();
delay(2000);
testdrawline();
}

void loop() {
}

void testdrawline() { 
display.drawLine(0, 0, 50, 100, BLACK); 
display.drawLine(0, 0, display.width(), display.height(), BLACK); 
display.display();
}

Este código dibuja la función seno.

Gráfico función senoidal
// - Con el IDE 1.0.6 funciona estas librerías para dibujar gráficos:
// - Adafruit-PCD8544.zip
// - Adafruit-GFX.zip 

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>

// Software SPI (slower updates, more flexible pin options):
// pin 7 - Serial clock out (SCLK)
// pin 6 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);

// Hardware SPI (faster, but must use certain hardware pins):
// SCK is LCD serial clock (SCLK) - this is pin 13 on Arduino Uno
// MOSI is LCD DIN - this is pin 11 on an Arduino Uno
// pin 5 - Data/Command select (D/C)
// pin 4 - LCD chip select (CS)
// pin 3 - LCD reset (RST)
// Adafruit_PCD8544 display = Adafruit_PCD8544(5, 4, 3);
// Note with hardware SPI MISO and SS pins aren't used but will still be read
// and written to during SPI transfer. Be careful sharing these pins!
float y;
float yold=20;
float x;
float xold;
float rad; 

void setup() {
Serial.begin(9600);
display.begin();
display.setContrast(50); // Contraste
display.clearDisplay();
testdrawline();
}

void loop() {
}

void testdrawline() { 
for (int16_t i=0; i<360; i+=1) {
x = i * display.width()/360;
y = 20 - 20 * sin(i * DEG_TO_RAD);

// rad = (i*6.28)/360; Otra forma de convertir grados a radianes 
// y = 20 - 20 * sin(rad);


display.drawLine(x, y, xold, yold, BLACK);
yold = y;
xold = x;
display.display();
}
}

 

________________________________

8.- Gráficos. Logos.

 

Con este programa se pueden hacer gráficos y logos.

http://www.elecfreaks.com/1319.html

________________________________

9.- Mini Osciloscopio.

- Vamos a construir este pequeño osciloscopio con la pantalla Nokia.

- El proyecto lo encontramos en: http://filear.com/?p=211 para el IDE 0022, pero lo he adaptado al IDE 1.0.6

- Los pines de la pantalla y el Arduino se conectarán de la siguiente forma:

// pin 3 - Serial clock out (SCLK)
// pin 4 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 7 - LCD chip select (CS)
// pin 6 - LCD reset (RST)
// 3,3 V - Vcc
// Gnd - Gnd

- Se colocarán dos potenciómetros de 10k. Se conectarán a 5V y Gnd. Los cursores centrales se conectarán uno a la ENTRADA ANALÓGICA A1 y otro a la A2

int channelAI = A0; // select the input pin for the Oscilioscope
int scaleYAI = A1; // select the input pin for the Y (horizontal) potentiometer
int scaleXAI = A2; // select the input pin for the X (Vertical) potentiometer

- El potenciómetro conectado a A1 gestiona la base de tiempos
- El potenciómetro conectado a A2 gestiona la escala vertical.

- La señal a medir se conectará entre la ENTRADA ANALÓGICA A0 y Gnd.

- Puede medir hasta 5 V.

- Solo mide tensiones contínuas, si queremos medir alternas debemos suministrarle a ésta una componente contínua.

Osciloscopio adaptado al IDE 1.0.6

// - Adaptado al IDE 1.0.6 con las siguientes librerías:
// -
Adafruit-PCD8544.zip
// - Adafruit-GFX.zip

 

/* 
###########################################################
Title: Arduino Oscilloscope
Purpose: Use a Nokia 3310 GLCD screen with the arduino
Created by: Filear to. see In eark. com for more info.
Note: Please reuse, repurpose, and redistribute this code.
Note: This code uses the Adafruit PDC8544 LCD library 
Note: Adaptado a Adafruit_PCD8544 y IDE 1.0.X por Juan A. Villalpando
kio4.com 
###########################################################
*/

#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_PCD8544.h>

// pin 3 - Serial clock out (SCLK)
// pin 4 - Serial data out (DIN)
// pin 5 - Data/Command select (D/C)
// pin 7 - LCD chip select (CS)
// pin 6 - LCD reset (RST)
//PCD8544 nokia = PCD8544(3, 4, 5, 7, 6);
Adafruit_PCD8544 nokia = Adafruit_PCD8544(3, 4, 5, 7, 6);

// a bitmap of a 16x16 fruit icon
static unsigned char __attribute__ ((progmem)) logo16_glcd_bmp[]={
0x06, 0x0D, 0x29, 0x22, 0x66, 0x24, 0x00, 0x01, 0x87, 0x00, 0x27, 0x6C, 0x20, 0x23, 0x06, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x00, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, };
#define LOGO16_GLCD_HEIGHT 16 
#define LOGO16_GLCD_WIDTH 16 

int channelAI = A0; // select the input pin for the Oscilioscope
int scaleYAI = A1; // select the input pin for the Y (horizontal) potentiometer
int scaleXAI = A2; // select the input pin for the X (Vertical) potentiometer

int delayVariable = 0; // define a variable for the Y scale / delay
int xVariable = 0; // define a variable for the x scale 
int yCtr = 0; // define a variable for the y counter used to collect y position into array
int posy = 0; // define a variable for the y position of the dot 
int myArray[85]; // define an array to hold the data coming in 


void setup(void) 
{
nokia.begin(); // Comienzo
nokia.setContrast(100); // Contraste

// turn all the pixels on (a handy test)
nokia.command(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYALLON);
delay(500);
// back to normal
nokia.command(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL);

// show splashscreen
nokia.display();
delay(500);
nokia.clearDisplay();
}

void loop() 
{ 
delayVariable = analogRead(scaleYAI);
delayVariable = (delayVariable/50);
xVariable = analogRead(scaleXAI);
xVariable = (xVariable/22); 

for(yCtr = 0; yCtr < 85; yCtr += 1) // the for loop runs from 0 and < 85, it fills the array with 84 records
{ 
posy = analogRead(channelAI); // read the value from the sensor:
myArray[yCtr] = (posy/xVariable); // scale the value based on the x scale potentiometer 
delay (delayVariable); // scale the y collection of data using the delay from the y potentiometer 
}

yCtr == 0; // set the counter to zero so we can use it again
nokia.clearDisplay(); // clear the LCD screen so we can draw new pixels

for(yCtr = 0; yCtr < 85; yCtr += 1) // for loop runs 84 times
{
//nokia.drawPixel(yCtr, myArray[yCtr], BLACK); // draw the 84 pixels on the screen
nokia.drawPixel(yCtr, 47 - myArray[yCtr], BLACK); // draw the 84 pixels on the screen 
}

nokia.display(); // show the changes to the buffer
yCtr == 0; // set the counter to zero so we can use it again

} 

- (El mismo código para el antiguo IDE 0022: Arduino Oscilloscope.zip)

- Graduación.

Te darás cuenta que la señal sale invertida.

Cambia esta línea para que salga sin invertir:
(el alto de la pantalla es de 48 pixel, lo ponemos a 47 para que se vea la línea cero.)

nokia.drawPixel(yCtr, 47 - myArray[yCtr], BLACK); // draw the 84 pixels on the screen

- Activa la línea anterior en el código: nokia.drawPixel(yCtr, 47 - myArray[yCtr], BLACK); // draw the 84 pixels on the screen

- Conecta la sonda A0 entre los 5V del Arduino y su GND.

- Mueve el potenciómetro de A2 para que la línea presente en la pantalla se sitúe arriba de ésta. De esta manera la parte superior de la pantalla será 5 V.

- Conecta la sonda A0 a Gnd del Arduino. Se mostrará una línea en la parte de abajo de la pantalla, será los 0 V.

- Para probarlo...

a) Sitúa otro potenciómetro conectado entre los 5V y Gnd del Arduino, el cursor central de ese potenciómetro conectalo a la entrada analógica A0. Al mover este potenciómetro, saldrá en la pantalla su nivel de tensión.

Ajusta con un potenciómetro al altura de la señal y con el otro la base de tiempos.

b) Si dispones de otro Arduino, carga este programa...

analogWriteNOKIA

#define pin9 9

void setup() {
pinMode(pin9, OUTPUT);
Serial.begin(9600);
analogWrite(pin9, 125);
}

void loop() {
}

 

Y conecta la sonda del mini osciloscopio entre el pin9 del Arduino y su Gnd.

Observarás unos pulsos de tipo PWM, cambiando el número 125 podrás cambiar la anchura del pulso.

La señal sale invertida, es decir el valor más positivo abajo.

____________________________________________
____________________________________________
____________________________________________
____________________________________________

 










En algunos modelos su alimentación debe ser de 3,3 V, en estos casos debemos poner:
- resistencias en divisor de tensión como indica esta web
- o bien, un circuito buffer cambiador de nivel basado en el circuito integrado 4050 como indica en esta otra web.

https://learn.adafruit.com/nokia-5110-3310-monochrome-lcd

http://www.avdweb.nl/arduino/hardware-interfacing/nokia-5110-lcd.html

Otras librerías

http://www.rinkydinkelectronics.com/library.php

________________________________

 

- Mi correo:
juana1991@yahoo.com
- KIO4.COM - Política de cookies. Textos e imágenes propiedad del autor:
© Juan A. Villalpando
No se permite la copia de información ni imágenes.
Usamos cookies propias y de terceros que entre otras cosas recogen datos sobre sus hábitos de navegación y realizan análisis de uso de nuestro sitio.
Si continúa navegando consideramos que acepta su uso. Acepto    Más información