The LCD keypad shield looks pretty cool. I like the blue LCD. It is extremely easy to mount the shield onto the arduino. The pin assignment has been taken care of in the example code. However, there is a problem. The unused pins will be totally useless as there will be no easy way to connect them. This is unacceptable. Then, I'm forced to use the old school--manually connect the pins. Luckily, the LCD board on the shield has provided separately its input pins.
Arduino's liquidcrystal library can use minimum of 6 pins to control the LCD:
LiquidCrystal(rs, enable, d4, d5, d6, d7)
Though there are other pin designation methods, I decide to use the one require least pin numbers for obvious reasons.
Rx need to be tied to GND to enable write. However, it seems to work without grounding it.
I found a website describing the functions of the input pins on the LCD
http://www.8052.com/tutlcd
Here is an example code to print the analog input readings:
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int adc_key_in = 0;
void setup()
{
lcd.begin(16, 2); // start the library this is a 2 line LCD with 16 characters in each line
lcd.setCursor(0,0);
lcd.print("Analog Input"); // print a simple message
}
void loop()
{
lcd.setCursor(0,1); // move cursor to second line "1" and 9 spaces over
adc_key_in = analogRead(0);
lcd.print(adc_key_in);
}
There is a bug that the 4th digit of the analog value does not get refreshed. I will figure something out in the future.
The simplest way turns out to be add a lcd.print(" "); line in the loop. There are probably more decent ways like compare the value with old, if it is different then do a refresh and print the new one. Anyway, it's not very important.
***********************************************************
12/9/2012 update
Regarding the shadow problem of the LCD, it turns out to be more complicated. I discovered another 'working' method:
lcd.print(distance);
lcd.print(" ");
lcd.print(distance);
print the thing you want to print twice with a empty string between them. At least it works for my ultrasonic range finder code.
No comments:
Post a Comment