Pages: [1]   Go Down
Author Topic: Noobe needs help with LCD and "include"  (Read 3712 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 6
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have just started learning about the Arduino and have bought an LCD shield off ebay. The card comes with 6 push buttons. There is an include code posted on the ebay site. I have no idea where and how to use this include. It took me 3 hours of Googling to find out why this shield wouldn't work. It has different pin out then any of the tutorials. (8, 9, 4, 5, 6, 7) . I was unable to post the picture of the LCD sheild being this is my first post. Maybe I can in a reply.Thanks for any help Carl
Code:
#include <LCD4Bit_mod.h>

LCD4Bit_mod lcd = LCD4Bit_mod(2);

char GP2D12;
char a,b;
char str1[]="Renge:";
char str2[]="   Renge Over   ";
char str3[]="cm";

void setup()
{
  lcd.init();
  lcd.clear();
  lcd.printIn("GP2D12 testing...");
}

void loop()
{
      GP2D12=read_gp2d12_range(1);
      if(GP2D12>80||GP2D12<10)
        {
          lcd.cursorTo(2,0);
          lcd.printIn(str2);    
        }
      else
        {
          a=0x30+GP2D12/10;
          b=0x30+GP2D12%10;          
          lcd.cursorTo(2, 3);
          lcd.printIn(str1);    
          lcd.print(a);    
          lcd.print(b);
          lcd.printIn(str3);                    
        }    
    delay(50);
}

float read_gp2d12_range(byte pin)
{
  int tmp;
  tmp = analogRead(pin);
  if (tmp < 3)return -1;
  return (6787.0 /((float)tmp - 3.0)) - 4.0;
}

Logged

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

Logged

Cape Town, South Africa
Offline Offline
Full Member
***
Karma: 0
Posts: 177
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.robotshop.com/content/PDF/dfrobot-lcd-keypad-shield-schematic.pdf
Logged

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

Forget the lcd4bit library (the 'include code') its outdated and inefficient.  Best bet is the included examples in the IDE.  They will just need adjusting to suit the pinouts of your shield.

Starting with the infamous 'Hello world' is good.

Code:
 LiquidCrystal Library - Hello World
 
 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the
 Hitachi HD44780 driver. There are many of them out there, and you
 can usually tell them by the 16-pin interface.
 
 This sketch prints "Hello World!" to the LCD
 and shows the time.
 
  The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 
 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe
 modified 25 July 2009
 by David A. Mellis
 
 
 http://www.arduino.cc/en/Tutorial/LiquidCrystal
 */

// include the library code:
#include <LiquidCrystal.h>

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);  // adjust this to suit your pins.

void setup() {
  // set up the LCD's number of rows and columns:
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("hello, world!");
}

void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 1);
  // print the number of seconds since reset:
  lcd.print(millis()/1000);
}

It still has an include, but at least the include is included......... smiley-wink
Logged


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

Thanks for answering. I did try to include the include and only got errors that I don't yet understand. I was able to get the display working with pinout of 9, 8, 4, 5, 6, 7.  I looked at the schematic of the Lcd and noticed the pinouts run from pin 1 to pin 16 of the LCD, Is that why the pin asignment runs 9 8 then 4567?
« Last Edit: June 07, 2010, 04:09:10 pm by cwebs » Logged

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

The lcd4bit library (like any external library) needs adding to the relevant folder in the IDE for it to work.  The far superior liquidcrystal library is already installed as standard.  A standard character LCD can be made to work on any combination of digital pins, the ones on your shield were probably chosen for convenience of manufacture as much as anything.
Logged


Western New York, USA
Offline Offline
Faraday Member
**
Karma: 32
Posts: 4245
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Starting with the infamous 'Hello world' is good.
In your case you want to change: LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

To: LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

Don

Logged

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

Changing the pin to 9 8 4 5 6 7 is just what I did to get it going. My question is why are the pin numbers 9 8 4 5 6 7 and not 4 5 6 7 8 9 ?
Logged

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

Quote
My question is why are the pin numbers 9 8 4 5 6 7 and not 4 5 6 7 8 9 ?

Because thats the way the manufacturers chose to wire the shield. Only they could answer that.  There wouldn't be any reason they couldn't wire the shield like that so that it conformed to the liquidcrystal library.

One of my projects contains the line :

Code:
LiquidCrystal lcd(12, 2, 7, 8, 9, 10);

I chose those particular pins, because they could be spared on a pre-existing project and because they were easy to wire that way.

I have another project ( http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1260399444 ) that contains the line :

Code:
LiquidCrystal lcd(3, 4, 8, 7, 6, 5);

It was because the hand made stripboard arduino board was easy to make with the pins wired like that...........
« Last Edit: June 08, 2010, 05:13:03 am by stephen_t » Logged


Western New York, USA
Offline Offline
Faraday Member
**
Karma: 32
Posts: 4245
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

cwebs:
Quote
>My question is why are the pin numbers 9 8 4 5 6 7 and not 4 5 6 7 8 9 ?

Its 8 9 4 5 6 7 ...

Quote
Because thats the way the manufacturers chose to wire the shield.
This is correct, but is only half of the answer.  The other half was specified by the Arduino team and only they could answer why they chose what they did.

Here's a more detailed version of the answer to your question.

The LiquidCrystal library is invoked with a command having this syntax:

Syntax

LiquidCrystal(rs, enable, d4, d5, d6, d7)
LiquidCrystal(rs, rw, enable, d4, d5, d6, d7)
LiquidCrystal(rs, enable, d0, d1, d2, d3, d4, d5, d6, d7)
LiquidCrystal(rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7)


There are four versions and you must use the one corresponding to the interface that you are using.  The first two are for the 4-bit data interface the first without and the second with the R/W line implemented.  The LiquidCrystal library currently does not use the R/W line in either case so there is no benefit in implementing it.  The third and fourth versions are similar to the first two but for the 8-bit data interface.  

The important thing to note is the sequence of the pin names within the parentheses.  This is the sequence that you must use - after you have selected the proper version depending on how your particular LCD is configured and/or wired.

Reply #2 links to a schematic which, in the upper right part, indicates that there are only six connections between the LCD and the Arduino.  This means that the first version of the syntax must be used.  It also shows that RS is connected to Arduino D8, E is connected to Arduino D9, DB4 is connected to Arduino D4, etc.  This gives you the sequence of pin numbers to put within the parentheses.  

so the generic:     LiquidCrystal(rs, enable, d4, d5, d6, d7)
is implemented as: LiquidCrystal( 8,      9,  4,  5,  6,  7)

Don
Logged

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

Thanks Don. I understand that. My first observation was the LCD pins used are 4,5, 11, 12, 13, 14. And that is the Arduino pins 8, 9, 4, 5, 6, 7. So the order in the code would run from pins 1 through 16 of the LCD.  Just my first assumption. Carl
Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 32
Posts: 4245
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Carl:
Quote
the LCD pins used are 4,5, 11, 12, 13, 14
Its 4,6,11,12,13,14


Quote
So the order in the code would run from pins 1 through 16 of the LCD.
Well they do, sort of.  If you look at the last of the four syntax examples you will see that they run through pins 4 --> 14 of the LCD, in order.  All of the other syntax examples are subsets of the last one, with various pins omitted.  The remaining pins are still in order on the LCD.  You can match them up with any pins that you care to on the Arduino.

Don
« Last Edit: June 08, 2010, 01:10:25 pm by floresta » Logged

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

I was running on only 2 hours sleep when I posted the question and might not have made my question clear. I was wundering why the CODE is writen with the pin numbers in that order not why the LCD board or Arduino PINS are used. Can the CODE be (4, 5, 6, 7, 8, 9)? Or will the CODE have to be (8,9,4,5,6,7). Same numbers just differant order.
Logged

Western New York, USA
Offline Offline
Faraday Member
**
Karma: 32
Posts: 4245
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can use any of the Arduino pins in any order.  You may want to avoid pins 0 and 1 since they are used by the serial port, but you don't have to.

Don
Logged

Pages: [1]   Go Up
Jump to: