Select Page

Descripción

Este shield esta basado en el diseño de SparkFun, con algunas pocas modificaciones, el backlight esta en el  pin PWM(D10)m los botones del joystick en los pines (A0-A4). Esta placa utiliza el controlador Philips PCF8833, y esta basada en el display Nokia 6100. Es una forma muy sencilla de añadir un lcd color a tu proyecto.

Es de 128×128, se controla via SPI, a través de los pines (D13 -SCK, D11 – DIO) lo que la hace que no sea compatible con el Arduino Mega ni con el Leonardo, debido a la ya mencionada interfaz de comunicación. El lcd transforma los 5V que le entrega el arduino y los convierte en 7V que es el voltaje en el que trabaja.

Arduino_Shield_ColorLCD_02

Arduino_Shield_ColorLCD_03

Características Técnicas

  • All Shield base on Philips PCF8833 controller
  • Nokia LCD6100
  • 4 direction Joystick w/ Switch(A0-A4)
  • Backlight PWM control
  • 128 x 128 pixels
  • 12-bit color rendition (4 bits red, 4-bits green, 4-bits blue)
  • 9-bit SPI serial interface (clock/data signals)

 Sin título

Este shield es verdaderamente muy simple, utiliza n driver muy genérico de control de LCD’s, que a traves de 3 pines:

 Arduino_Shield_ColorLCD_12

Puede controlar hasta unos 500. Este circuito integrado se puede encontrar en 2 versiones  Epson S1D15G00 o Philips PCF8833. Dicho esto, si tu intención es conectar ademas otros módulos tene en cuenta que no podes utilizar los pines arriba mencionados(SPI) ni los analógicos que se utilizan para los botones.

Arduino Shield ColorLCD 07
Arduino_Shield_ColorLCD_15

Links

Código de Programacion

Luego de descargar la libreria (En el titulo anterior podemos encontrar el link) cargamos el siguiente codigo, y vamos a tener funcionando nuestro LCD A COLOR.

Con respecto a la conexión y a los productos necesarios para la utilización, siendo un shield lo único que debemos hacer es “encastrarlo” arriba de nuestro Arduino uno.

Arduino_Shield_ColorLCD_11

Este sketch muestra en el lcd un reloj programable con horas minutos y segundos. Apretando el boton hacia la derecha da la opcion de programar. A partir de ahi siempre selecciona la posicion de las agujas presionando hacia la izquierda. SOLO CUANDO HAYAS TERMINADO DE POSICIONAR TODAS LAS AGUJAS PRESIONA EL BOTON HACIA LA DERECHA.

/*
ChronoLCD Color – An example sketch for the Color LCD Shield Library
by: Jim Lindblom
license: CC-BY SA 3.0 – Creative commons share-alike 3.0
use this code however you’d like, just keep this license and
attribute. Let me know if you make hugely, awesome, great changes.

This sketch draws an analog and digital clock on the Color LCD
Shield. You can also use the on-board buttons to set the hours
and minutes.

Use the defines at the top of the code to set the initial time.
You can also adjust the size and color of the clock.

To set the time, first hit S3. Then use S1 and S2 to adjust the
hours and minutes respsectively. Hit S3 to start the clock
back up.

This example code should give you a good idea of how to use
the setCircle, setLine, and setStr functions of the Color LCD
Shield Library.
*/
#include <ColorLCDShield.h>

// Enter the time below in 12-hr format
#define HOURS 10
#define MINUTES 21
#define SECONDS 00
#define AMPM 0 // enter 0 for AM, 1 for PM

#define CLOCK_RADIUS 50 // radius of clock face
#define CLOCK_CENTER 55 // If you adjust the radius, you’ll probably want to adjust this
#define H_LENGTH 30 // length of hour hand
#define M_LENGTH 40 // length of minute hand
#define S_LENGTH 48 // length of second hand

#define BACKGROUND BLACK // room for growth, adjust the background color according to daylight
#define C_COLOR RED // This is the color of the clock face, and digital clock
#define H_COLOR BLUE // hour hand color
#define M_COLOR GREEN // minute hand color
#define S_COLOR YELLOW // second hand color

LCDShield lcd;

int hours, minutes, seconds, ampm;
int buttonPins[3] = {A0, A1, A2}; //You can add A3 ,A4 for button

void setup()
{
/* Set up the button pins as inputs, set pull-up resistor */
for (int i=0; i<3; i++)
{
pinMode(buttonPins[i], INPUT);
digitalWrite(buttonPins[i], HIGH);
}

hours = HOURS;
minutes = MINUTES;
seconds = SECONDS;
ampm = AMPM;

pinMode(10, OUTPUT);
analogWrite(10, 1023); //PWM control blacklight
/* Initialize the LCD, set the contrast, clear the screen */
lcd.init(PHILLIPS);
lcd.contrast(40);
lcd.clear(BACKGROUND);

drawClock(); // Draw the clock face, this includes 12, 3, 6, 9
displayAnalogTime(hours, minutes, seconds); // Draw the clock hands
displayDigitalTime(hours, minutes, seconds, ampm); // Draw the digital clock text
}

void loop()
{
/* We’ll run around checking for button presses,
until it’s been a second */
while(millis() % 1000)
{
if (!digitalRead(buttonPins[2]))
setTime(); // If S3 was pressed, go set the time
}

/* We’ll get here if it’s been a second. We need to increase
seconds by 1 and then go from there */
seconds++;
if (seconds >= 60)
{
seconds = 0; // If seconds is 60, set it back to 0
minutes++; // and increase minutes by 1
if (minutes >= 60)
{
minutes = 0; // If minutes is 60, set it back to 0
hours++; // and increase hours by 1
if (hours == 12)
ampm ^= 1; // If it’s 12 o’clock, flip ampm
if (hours >= 13)
hours = 1; // If hours is 13, set it to 1. 12-hr clock.
}
}
/* Once each second, we’ll redraw the clock with new values */
drawClock();
displayAnalogTime(hours, minutes, seconds);
displayDigitalTime(hours, minutes, seconds, ampm);
}
/*
setTime uses on-shield switches S1, S2, and S3 to set the time
pressing S3 will exit the function. S1 increases hours, S2
increases seconds.
*/
void setTime()
{
/* Reset the clock to midnight */
seconds = 0;
minutes = 0;
hours = 12;
ampm = 0;

/* Draw the clock, so we can see the new time */
drawClock();
displayAnalogTime(hours, minutes, seconds);
displayDigitalTime(hours, minutes, seconds, ampm);

while (!digitalRead(buttonPins[2]))
; // wait till they let go of S1

/* We’ll run around this loop until S3 is pressed again */
while(digitalRead(buttonPins[2]))
{
/* If S1 is pressed, we’ll update the hours */
if (!digitalRead(buttonPins[0]))
{
hours++; // Increase hours by 1
if (hours == 12)
ampm ^= 1; // Flip am/pm if it’s 12 o’clock
if (hours >= 13)
hours = 1; // Set hours to 1 if it’s 13. 12-hour clock.

/* and update the clock, so we can see it */
drawClock();
displayAnalogTime(hours, minutes, seconds);
displayDigitalTime(hours, minutes, seconds, ampm);
}
if (!digitalRead(buttonPins[1]))
{
minutes++; // Increase minutes by 1
if (minutes >= 60)
minutes = 0; // If minutes is 60, set it back to 0

/* and update the clock, so we can see it */
drawClock();
displayAnalogTime(hours, minutes, seconds);
displayDigitalTime(hours, minutes, seconds, ampm);
}
}
/* Once S3 is pressed, we’ll exit, but not until it’s released */
while(!digitalRead(buttonPins[2]))
;
}

/*
displayDigitalTime() takes in values for hours, minutes, seconds
and am/pm. It’ll print the time, in digital format, on the
bottom of the screen.
*/
void displayDigitalTime(int h, int m, int s, int ap)
{
char timeChar[13] = {‘x’, ‘x’, 0x0A, ‘x’, ‘x’, 0x0A, ‘x’, ‘x’, ‘ ‘, ‘ ‘};

/* Gotta turn the values into individual integers */
timeChar[0] = h/10;
timeChar[1] = h – (timeChar[0] * 10);
timeChar[3] = m/10;
timeChar[4] = m – (timeChar[3] * 10);
timeChar[6] = s/10;
timeChar[7] = s – (timeChar[6] * 10);

/* once we have each integer separated, we need to turn them
into displayable characters. Adding 0x30 does this (check an
ASCII table. We set the colons to 0x0A initially, this will
turn them into the proper 0x3A.*/
for (int i=0; i<8; i++)
timeChar[i] += 0x30;

timeChar[8] = ‘ ‘; // add a space between the time and AM/PM

/* Add AM or PM to the end of the timeChar string */
if (!ap)
{
timeChar[9] = ‘A’;
timeChar[10] = ‘M’;
}
else
{
timeChar[9] = ‘P’;
timeChar[10] = ‘M’;
}

/* add some blank spaces after the time, otherwise it’ll display
unwanted characters */
timeChar[11] = ‘ ‘;
timeChar[12] = ‘ ‘;

/* Print the time on the clock */
lcd.setStr(timeChar, CLOCK_CENTER + CLOCK_RADIUS + 4, 22, C_COLOR, BACKGROUND);
}

/*
drawClock() simply draws the outer circle of the clock, and ’12’,
‘3’, ‘6’, and ‘9’. Room for growth here, if you want to customize
your clock. Maybe add dashe marks, or even all 12 digits.
*/
void drawClock()
{
/* Draw the circle */
lcd.setCircle(CLOCK_CENTER, 66, CLOCK_RADIUS, C_COLOR);

/* Print 12, 3, 6, 9, a lot of arbitrary values are used here
for the coordinates. Just used trial and error to get them
into a nice position. */
lcd.setStr(“12”, CLOCK_CENTER – CLOCK_RADIUS, 66-9, C_COLOR, BACKGROUND);
lcd.setStr(“3”, CLOCK_CENTER – 9, 66 + CLOCK_RADIUS – 12, C_COLOR, BACKGROUND);
lcd.setStr(“6”, CLOCK_CENTER + CLOCK_RADIUS – 18, 66-4, C_COLOR, BACKGROUND);
lcd.setStr(“9”, CLOCK_CENTER – 9, 66 – CLOCK_RADIUS + 4, C_COLOR, BACKGROUND);
}

/*
displayAnalogTime() draws the three clock hands in their proper
position. Room for growth here, I’d like to make the clock hands
arrow shaped, or at least thicker and more visible.
*/
void displayAnalogTime(int h, int m, int s)
{
double midHours; // this will be used to slightly adjust the hour hand
static int hx, hy, mx, my, sx, sy;

/* Adjust time to shift display 90 degrees ccw
this will turn the clock the same direction as text */
h -= 3;
m -= 15;
s -= 15;
if (h <= 0)
h += 12;
if (m < 0)
m += 60;
if (s < 0)
s += 60;

/* Delete old lines: */
lcd.setLine(CLOCK_CENTER, 66, CLOCK_CENTER+sx, 66+sy, BACKGROUND); // delete second hand
lcd.setLine(CLOCK_CENTER, 66, CLOCK_CENTER+mx, 66+my, BACKGROUND); // delete minute hand
lcd.setLine(CLOCK_CENTER, 66, CLOCK_CENTER+hx, 66+hy, BACKGROUND); // delete hour hand

/* Calculate and draw new lines: */
s = map(s, 0, 60, 0, 360); // map the 0-60, to “360 degrees”
sx = S_LENGTH * sin(3.14 * ((double) s)/180); // woo trig!
sy = S_LENGTH * cos(3.14 * ((double) s)/180); // woo trig!
lcd.setLine(CLOCK_CENTER, 66, CLOCK_CENTER+sx, 66+sy, S_COLOR); // print second hand

m = map(m, 0, 60, 0, 360); // map the 0-60, to “360 degrees”
mx = M_LENGTH * sin(3.14 * ((double) m)/180); // woo trig!
my = M_LENGTH * cos(3.14 * ((double) m)/180); // woo trig!
lcd.setLine(CLOCK_CENTER, 66, CLOCK_CENTER+mx, 66+my, M_COLOR); // print minute hand

midHours = minutes/12; // midHours is used to set the hours hand to middling levels between whole hours
h *= 5; // Get hours and midhours to the same scale
h += midHours; // add hours and midhours
h = map(h, 0, 60, 0, 360); // map the 0-60, to “360 degrees”
hx = H_LENGTH * sin(3.14 * ((double) h)/180); // woo trig!
hy = H_LENGTH * cos(3.14 * ((double) h)/180); // woo trig!
lcd.setLine(CLOCK_CENTER, 66, CLOCK_CENTER+hx, 66+hy, H_COLOR); // print hour hand

}