Pages: 1 2 3 [4]   Go Down
Author Topic: analog in to 4 bit LCD driver  (Read 12712 times)
0 Members and 1 Guest are viewing this topic.
London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

this diagram shows how to connect an LCD panel using the example sketch for the LiquidCrystal library.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 76
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

am i right that there's no way to override the default pin assignments without editing and recompiling the library?
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
am i right that there's no way to override the default pin assignments without editing and recompiling the library?
no, if you use the Arduino liquid crystal library you can change the pins.

http://arduino.cc/en/Reference/LiquidCrystalConstructor
Logged

tytower
Guest
 Bigger Bigger  Smaller Smaller  Reset Reset

Well as a newbie at this I just spent most of the day working out how to use an LCD. I finally found this site  
http://www.skpang.co.uk/content/view/29/42/ and I commend it to you.

If you are here looking for how to do it I would suggest its as good a place  as any to start because it gives you photos and data sources. Using the 4bit saves having another 4 wires hanging off your arduino so you can get more sensors on it.

Now I could not get my second line to work until I read here to change the sketch line "LCD4Bit lcd = LCD4Bit(1);"
to
LCD4Bit lcd = LCD4Bit(2);
Otherwise it all comes up on line 1 only.

Thanks to S K Pang, Dubbie  and the other posters in this thread
Now to get it to print the Freezer temperature and maybe a page of Murdochs news as well.

Edit: Yes mem and  Pluggy are right see later posts .This is an old library and the latest LiquidCrystal library runs as 4 or 8 bits . Go see the photos there though . One picture certainly saves a thousand words on this subject.
« Last Edit: September 01, 2009, 12:32:45 am by tytower » Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi tytower, that site uses the old LCD4Bit library which IMO is inferior to the LiquidCrystal library supplied with the latest Arduino release. The Arduino library supports a rich set of print formatting commands that is compatible with the Serial library.

Did you try the latest version of the LiquidCrystal library?

Logged

Lancashire, UK
Offline Offline
Edison Member
*
Karma: 9
Posts: 1991
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I used the SK Pang site as a basis for my LCD setup.  It does use the old 4bit library, but it also works perfectly with the latest LiquidCrystal Library.   Grounding the R/W pin seems to make some boards work when they didn't when it was wired to the arduino. The LCD4bit library is slow in comparison to the new LiquidCrystal one.
« Last Edit: August 31, 2009, 06:36:37 am by stephen_t » Logged


0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi glasspusher
thanks for providing this code



/* 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 = 6;

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 += analogRead(temperaturePin);    // 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(' ');
}

...its really helping me alot...
it will be very kind of u, if u also provide the schematic diagram to allow driving an LCD display in 4 bit mode that can display temperature on it and to make this code workable
as i m taking the help frm this code in order to complete my obective that pretty much resemble with urs one....
THanks in Advance
Logged

London
Offline Offline
Tesla Member
***
Karma: 10
Posts: 6255
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Glasspusher hasn't posted here for a couple of years. Have you looked at the LiquidCrystal library: http://www.arduino.cc/en/Tutorial/LiquidCrystal

The code you posted becomes much simpler if you use that library, here is the firstDisplay function rewritten for the Arduino library:

Code:
void firstDisplay(int value)
{
    lcd.print("Temp = ");
    lcd.print(value / 10.0);  // value is in tenths of a degree
    lcd.print(" C");
}    
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 2
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks...Mem ...
my problem is Solved..smiley
Logged

Pages: 1 2 3 [4]   Go Up
Jump to: