Am new in elecronics ans i have been trying to desplay in my GDM1602K 16x2 LCD from spukfun but in vain, the only thing i get is the LED Backlight, no data at all. I have carefully followed the connections found in this site"http://www.skpang.co.uk/content/view/29/42/"
This is the code that i have been trying to use...
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 2, 7, 8, 9, 10);
void setup()
{
Serial.begin(9600);
backlightOn();
}
void loop()
{
selectLineOne();
delay(100);
Serial.print(millis());
selectLineTwo();
delay(100);
Serial.print(millis()/2);
delay(100);
}
void selectLineOne(){ //puts the cursor at line 0 char 0.
Serial.print(0xFE, BYTE); //command flag
Serial.print(128, BYTE); //position
}
void selectLineTwo(){ //puts the cursor at line 0 char 0.
Serial.print(0xFE, BYTE); //command flag
Serial.print(192, BYTE); //position
}
void goTo(int position) { //position = line 1: 0-15, line 2: 16-31, 31+ defaults back to 0
if (position<16){ Serial.print(0xFE, BYTE); //command flag
Serial.print((position+128), BYTE); //position
}else if (position<32){Serial.print(0xFE, BYTE); //command flag
Serial.print((position+48+128), BYTE); //position
} else { goTo(0); }
}
void clearLCD(){
Serial.print(0xFE, BYTE); //command flag
Serial.print(0x01, BYTE); //clear command.
}
void backlightOn(){ //turns on the backlight
Serial.print(0x7C, BYTE); //command flag for backlight stuff
Serial.print(157, BYTE); //light level.
}
void backlightOff(){ //turns off the backlight
Serial.print(0x7C, BYTE); //command flag for backlight stuff
Serial.print(128, BYTE); //light level for off.
}
void serCommand(){ //a general function to call the command flag for issuing all other commands
Serial.print(0xFE, BYTE);
}
I have also tried to use the LiquidCrystal example but nothing desplays..
#include <LiquidCrystal.h>
// LiquidCrystal display with:
// rs on pin 12
// rw on pin 11
// enable on pin 10
// d0, d1, d2, d3 on pins 5, 4, 3, 2
LiquidCrystal lcd(12, 11, 2, 7, 8, 9, 10);
void setup()
{
// Print a message to the LCD.
lcd.print("hello, world!");
}
void loop()
{
}
Another question please. How do these sketch below (given as LCD 4-Bit example that i just downloaded and added to my environment)determines the arduino pins number and they are not declared. Or does the sketch allocate pins by default
/* Analog in to LCD 4 bits
* ---------
* Adapted from the "analog_read_send" and "lcd_8bits" tutorials.
* This example uses 4 less pins on the Arduino than the 8 bit example.
* It will take a reading from a 'K' Type thermocouple ice point reference chip
* on Analog Input 2 and display the temperature in degrees Centigrade on the LCD.
* One can also set a target temperature for turning a relay off, say for a heater,
* at a given setpoint temperature. This is done on digital pin 4.
*
* These are the pins used on the LCD:
*
* - DI(register select), RW, DB4..DB7, Enable (7 in total)
*
* the pinout for LCD displays is standard and there is plenty
* of documentation to be found on the internet.
*
* 2006, Dave Sopchak glasspusher at outofoptions dot net
*
*/
int DI = 12; // register select
int RW = 11;
int DB[] = {7, 8, 9, 10};
int Enable = 2;
//int temperaturePin = 2; // select the input pin for the temperature
//int ledPin = 13; // pin for the LED
void tickleEnable()
{
// send a pulse to enable
digitalWrite(Enable,HIGH);
delayMicroseconds(1); // pause 1 ms according to datasheet
digitalWrite(Enable,LOW);
delayMicroseconds(1); // pause 1 ms according to datasheet
}
void cmdWriteSet()
{
digitalWrite(Enable,LOW);
delayMicroseconds(1); // pause 1 ms according to datasheet
digitalWrite(DI,0);
digitalWrite(RW,0);
}
void LcdCommandWrite(int value)
{
int i = 0;
for (i=DB[3]; i >= DB[0]; i--) // high nybble first
{
digitalWrite(i, value & 128);
value <<= 1;
}
cmdWriteSet();
tickleEnable();
for (i=DB[3]; i >= DB[0]; i--) // low nybble next
{
digitalWrite(i, value & 128);
value <<= 1;
}
cmdWriteSet();
tickleEnable();
}
void LcdDataWrite(int value)
{
int i = 0;
digitalWrite(DI, HIGH);
DigitalWrite(RW, LOW);
for (i=DB[3]; i >= DB[0]; i--) // high nybble first
{
digitalWrite(i, value & 128);
value <<= 1;
}
tickleEnable();
for (i=DB[3]; i >= DB[0]; i--) // low nybble next
{
digitalWrite(i, value & 128);
value <<= 1;
}
tickleEnable();
}
void setup (void)
{
int i;
for (i=Enable; i <= DI; i++)
pinMode(i,OUTPUT);
delay(100);
// initiatize lcd after a short pause
// needed by the LCDs controller
LcdCommandWrite(0x28); // function set:
delay(64); // 4-bit interface, 2 display lines, 5x7 font
// other interaces:
// 0x20 = 4 bit, 1 display line
LcdCommandWrite(0x28); // function set:
delay(64); // 4-bit interface, 2 display lines, 5x7 font
LcdCommandWrite(0x06); // entry mode set:
// increment automatically, no display shift
delay(20);
LcdCommandWrite(0x0E); // display control:
// turn display on, cursor on, no blinking
delay(20);
LcdCommandWrite(0x01); // clear display, set cursor position to zero
delay(100);
LcdCommandWrite(0x80); // display control:
// turn display on, cursor on, no blinking
delay(20);
}
void loop (void)
{
int i, val = 0;
for(i = 0; i < 20; ++i)
{
val += 1; // read the value from the sensor
delay(50);
}
//val /= 4.06; // conversion value to millivolts
digitalWrite(ledPin, HIGH); // turn the ledPin on
delay(500); // stop the program for some time
digitalWrite(ledPin, LOW); // turn the ledPin off
if(val > 175 * 10) // temperature in deg C times 10, since we're measuring to tenths of a degree
digitalWrite(4,LOW);
else
digitalWrite(4,HIGH);
LcdCommandWrite(0x02); // set cursor position to zero
delay(10);
firstDisplay(val);
}
void firstDisplay(int value)
{
int first,second, third, fourth;
first = value / 1000; //
second = (value - 1000 * first)/ 100;
third = (value - 1000 * first - 100 * second)/ 10;
fourth = (value - 1000 * first - 100 * second - 10 * third);
LcdDataWrite('T');
LcdDataWrite('e');
LcdDataWrite('m');
LcdDataWrite('p');
LcdDataWrite(' ');
LcdDataWrite('=');
LcdDataWrite(' ');
LcdDataWrite(value > 999 ? first + 48 : ' '); // begin onscreen
LcdDataWrite(value > 99 ? second + 48 : ' ');
LcdDataWrite(third + 48);
LcdDataWrite('.');
LcdDataWrite(fourth + 48);
LcdDataWrite(' ');
LcdDataWrite('C');
LcdDataWrite(' ');
LcdDataWrite(' ');
}
What might be up? My LCD is new, can it be faulty yet backlight is working fine? Please help.